Code archives/File Utilities/Source Code CLeaner

This code has been declared by its author to be Public Domain code.

Download source code

Source Code CLeaner by Damien Sturdy2004
use this function to clean out your source code-

What is left is a nice chunk of code with no crap.

I dont know if this speeds things up, and i doubt it, but i was kinda proud..

And it can make things look better source wise.

The final parameter tells it wheather to compress all blank lines to one blank line, or to remove blank lines alltogether. :)


By the way, this removes too much. when i wrote it i overlooked Tabs and stuff, so you will loose all your allignment.
;Source file cleaner: By Damien Sturdy (Cygnus Games) 2004!
;USAGE EXAMPLE:
;		 cleansource("supernova 2d.bb","supernova2d clean.bb",0)   cleans the code and leaves NO empty lines
;		 cleansource("supernova 2d.bb","supernova2d clean.bb",1)   cleans the code and leaves ONE empty line
;				where one or a bunch of empty lines were before. Useful for keeping things looking nice.
;Removes all unnecesary Tabs and remarks...
;Leaves all ";" signs when in brackets....


Function cleansource(infile$,outfile$,leave_single_gaps)
Local fs,fs2,n,m$,m2$,stp,doagn,ok,oneline=1
If infile$=outfile$ Then
CopyFile infile$,infile$+"_nbak"
CopyFile infile$,"temp.bb"
infile$="temp.bb"
EndIf
fs=ReadFile(infile$)
fs2=WriteFile(outfile$)

Repeat

m$=ReadLine(fs)
m2$=""
For n=1 To Len(m$)
If Mid$(m$,n,1)<>Chr$(9) Then m2$=m2$+Mid$(m$,n,1)
Next
ok=1

 m$=m2$
 stp=1
.doitagain
inst= Instr(m$,";",stp)
If inst>0 Then
doagn=0
For n=stp To inst
If Mid$(m$,n,1)=Chr$(34) Then ok=1-ok
Next
If ok=1 Then m$=Mid$(m$,1,inst-1) Else doagn=1:stp=inst+1
EndIf
If doagn=1 Then Goto doitagain
.dagn

If (Right$(m$,1)=" " Or Right$(m$,1)="	") And Len(m$)>0 Then m$=Mid$(m$,1,Len(m$)-1):Goto dagn
If leave_single_gaps=0 Then oneline=1
If inst<>1 And m$<>" " And m$<>"	" And (m$<>"" Or oneline=0) Then
	;Print m$
	If Instr(m$,"Function")<>0 And Instr(m$,"End")=0 Then WriteLine fs2,";;;;;;;;;;;;;;;;;;;;;;;"
	WriteLine fs2,m$
EndIf
If m$<>"" Then oneline=0
If m$="" Then oneline=1

Until Eof(fs) Or KeyDown(1)
CloseFile fs
CloseFile fs2
End
End Function

Comments

N2004
I dont know if this speeds things up, and i doubt it, but i was kinda proud..


Doesn't.

And it can make things look better source wise.


People use blank lines for a reason: to seperate crap. Removing them would create a HUGE mess. I do see that there's an option to collapse lines into single lines, but unfortunately for some people that doesn't get rid of the 'messiness'. Perhaps you should allow specification of how many lines before cutoff.


Damien Sturdy2004
Ahar, good idea..


IM not going to be working on this- somebody may find it useful

I intended it to be a formatter but i kinda got fed up- Main use was when i was saving loads of .bb files to floppies and they were full of junk. and my floppy was full... ^.^


aab2004
Well, anyone using The Blitz3d demo cause the've only bought BlitzPlus Can use it to get the most out that 16kb.
Plus the code can be adapted to remove other char's values and do different things..


Tracer2004
Floppies?!?

WOW.. welcome back to the 80's ;)

Tracer


Damien Sturdy2004
yup! floppies! still use em- i burn my drives out super quick and im trained in drive repair!


churchaxe2004
ok, it's fast and reduces the file-size by 26% (wow really a lot), but sorry, I find the output kinda hard to read, IMHO it did too a good job in cancelling *all* the tabs, instead of the *useless* ones (e.g. the ones in empty lines or at the end of other lines)

btw. I'm still using floppies also, sometimes. For loads of .bb files I'd better zip them, which will even save (much) more space, and retain all code formattings :)


Damien Sturdy2005
Doesnt look like this worked well then? ;)

yeah it needed to have a tabber in there... didnt think much bout that till about 30 mins later.


misth2013
I wonder why you don't use packing software instead of this?
Source code of 22,7KB packs into 5,7KB rar-package, and that's 4 times smaller. Even if you have more code files, it's still gonna pack them a lot.

Of course handling codes will be much nicer when you just put them in as is.


Code Archives Forum