November 28, 2020, 11:02:38 AM

Author Topic: [bb] Source Code CLeaner by Damien Sturdy [ 1+ years ago ]  (Read 651 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Source Code CLeaner by Damien Sturdy [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Source Code CLeaner
Author : Damien Sturdy
Posted : 1+ years ago

Description : 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.

Code :
Code: BlitzBasic
  1. ;Source file cleaner: By Damien Sturdy (Cygnus Games) 2004!
  3. ;                cleansource("supernova","supernova2d",0)   cleans the code and leaves NO empty lines
  4. ;                cleansource("supernova","supernova2d",1)   cleans the code and leaves ONE empty line
  5. ;                               where one or a bunch of empty lines were before. Useful for keeping things looking nice.
  6. ;Removes all unnecesary Tabs and remarks...
  7. ;Leaves all ";" signs when in brackets....
  10. Function cleansource(infile$,outfile$,leave_single_gaps)
  11. Local fs,fs2,n,m$,m2$,stp,doagn,ok,oneline=1
  12. If infile$=outfile$ Then
  13. CopyFile infile$,infile$+"_nbak"
  14. CopyFile infile$,""
  15. infile$=""
  16. EndIf
  17. fs=ReadFile(infile$)
  18. fs2=WriteFile(outfile$)
  20. Repeat
  22. m$=ReadLine(fs)
  23. m2$=""
  24. For n=1 To Len(m$)
  25. If Mid$(m$,n,1)<>Chr$(9) Then m2$=m2$+Mid$(m$,n,1)
  26. Next
  27. ok=1
  29.  m$=m2$
  30.  stp=1
  31. .doitagain
  32. inst= Instr(m$,";",stp)
  33. If inst>0 Then
  34. doagn=0
  35. For n=stp To inst
  36. If Mid$(m$,n,1)=Chr$(34) Then ok=1-ok
  37. Next
  38. If ok=1 Then m$=Mid$(m$,1,inst-1) Else doagn=1:stp=inst+1
  39. EndIf
  40. If doagn=1 Then Goto doitagain
  41. .dagn
  43. If (Right$(m$,1)=" " Or Right$(m$,1)="  ") And Len(m$)>0 Then m$=Mid$(m$,1,Len(m$)-1):Goto dagn
  44. If leave_single_gaps=0 Then oneline=1
  45. If inst<>1 And m$<>" " And m$<>"        " And (m$<>"" Or oneline=0) Then
  46.         ;Print m$
  47.         If Instr(m$,"Function")<>0 And Instr(m$,"End")=0 Then WriteLine fs2,";;;;;;;;;;;;;;;;;;;;;;;"
  48.         WriteLine fs2,m$
  49. EndIf
  50. If m$<>"" Then oneline=0
  51. If m$="" Then oneline=1
  53. Until Eof(fs) Or KeyDown(1)
  54. CloseFile fs
  55. CloseFile fs2
  56. End
  57. End Function

Comments :

N(Posted 1+ years ago)

 <div class="quote"> I dont know if this speeds things up, and i doubt it, but i was kinda proud.. </div>Doesn't.<div class="quote"> And it can make things look better source wise.  </div>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 Sturdy(Posted 1+ years ago)

 Ahar, good idea..IM not going to be working on this- somebody may find it usefulI 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... ^.^

aab(Posted 1+ years ago)

 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..

Tracer(Posted 1+ years ago)

 Floppies?!?WOW.. welcome back to the 80's ;)Tracer

Damien Sturdy(Posted 1+ years ago)

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

churchaxe(Posted 1+ years ago)

 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 Sturdy(Posted 1+ years ago)

 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.

misth(Posted 1+ years ago)

 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.


SimplePortal 2.3.6 © 2008-2014, SimplePortal