2tabs to fix any code from spaces to tabs NEW
Nov 25, 2011 16:26:38 GMT 1
Post by bigbass on Nov 25, 2011 16:26:38 GMT 1
this is a total rewrite June 14 2012 to fix any code from spaces to tabs
I replaced code in this thread and changed the title
spaces are replaced by tabs extra spaces are justified
can be used to space justify bacon /HUG bbcode or any other code or text file
it can be used as a stand alone app with no dependencies
there is auto indenting (justifying ) of starting space
so everything lines up nicely in steps of four spaces
everyone knows that white space gets chopped off
in any phpBB code forum this fixes the problem
just a plain text test file you could use to see before and after
spaces
www.puppy2.org/slaxer/indent-test.txt
tabs
www.puppy2.org/slaxer/indent-test2.txt
was five spaces for tabs adjusted code for four spaces
I replaced code in this thread and changed the title
spaces are replaced by tabs extra spaces are justified
can be used to space justify bacon /HUG bbcode or any other code or text file
it can be used as a stand alone app with no dependencies
there is auto indenting (justifying ) of starting space
so everything lines up nicely in steps of four spaces
everyone knows that white space gets chopped off
in any phpBB code forum this fixes the problem
just a plain text test file you could use to see before and after
spaces
www.puppy2.org/slaxer/indent-test.txt
tabs
www.puppy2.org/slaxer/indent-test2.txt
USUAGE: ./2tabs /path-and-filename"
was five spaces for tabs adjusted code for four spaces
'--- ***************************************************** '
'--- PROGRAM: 2tabs.bac '
'--- PURPOSE: indent phpBB code '
'--- AUTHOR: big_bass Joe Arose '
'--- DEPENDS: gcc, bacon, '
'--- PLATFORM: linux '
'--- DATE: Nov-28-2011 replaced with TABS$ 6/13/2012'
'--- NOTES: underscores need to be removed to compile code
'--- LICENSE: GPL version 3 or later '
'--- *****************************************************'
'--- this is only for modifing of code with justified indentation
'--- USUAGE: ./2tabs /path-and-filename" ---'
'--- note the file will get a .2tabs added to the filename ---'
'--- on error print usage ---'
'--- this part was added to for variables to be passed at command line ---'
TRAP LOCAL
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim
IF LEN(arg$[1]) EQ 0 THEN
PRINT "Copy file to /tmp"
PRINT "USUAGE: ./2tabs /path-and-filename"
END IF
Tab$ = CHR$(9)
FOUR_BLANKS$ = " "
'--- copy_this$ is the first argument passed from the command line ---'
'--- path-and-filename is arg$[1] this is a valid bacon argument ---'
'--- give it a string name for clarity ---'
copy_this$ = arg$[1]
'--- another code snippet from GatorDog thanks ---'
IF ISFALSE(FILEEXISTS(copy_this$)) THEN
PRINT NL$, "=>> ", copy_this$, " <<== not found."
PRINT "Please check your directory for assistance ;>)", NL$
END FALSE
END IF
'--- thanks GatorDog ---'
COPY copy_this$ TO CONCAT$(copy_this$,".2tabs")
'--- Rename working file to TMP ext.
RENAME CONCAT$(copy_this$,".2tabs") TO CONCAT$(copy_this$,".2tabsTMP")
OPEN CONCAT$(copy_this$,".2tabs") FOR WRITING AS my_outfile
OPEN CONCAT$(copy_this$,".2tabsTMP") FOR READING AS my_infile
WHILE NOT(ENDFILE(my_infile))
READLN txt$ FROM my_infile
'--- pre step replace TABS$ with four spaces ---'
txt$ = REPLACE$(txt$, Tab$, FOUR_BLANKS$)
'--- check if line of text starts with spaces or TABS$ ---'
IF REGEX(txt$, "^ ") OR REGEX(txt$, "^FOUR_BLANKS$") THEN
PRINT "Yep, ", txt$, "--> starts with spaces !"
PRINT
PRINT
full_count = LEN(txt$)
'--- a chop left is used here to remove only left spaces ---'
chopped_count = LEN(CHOP$(txt$," ",1))
start_space_count = full_count - chopped_count
'--- error checking ---'
'--- blue is ok yellow is error with a limit of 43 spaces ---'
IF start_space_count < 43 THEN
PRINT "you have ";
COLOR FG TO BLUE
PRINT start_space_count," leading space(s)"
COLOR RESET
ELSE
PRINT "you have ";
COLOR FG TO YELLOW
PRINT start_space_count," leading space(s)"
COLOR RESET
END IF
'--- start main ---'
IF start_space_count < 3 THEN
PRINT "will chop off this < 3 spaced indented "
PRINT CHOP$(txt$," ",1)
WRITELN CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 3 AND start_space_count <= 6 THEN
PRINT "will shift you to four so it looks good "
'--- pre step replace TABS$ with four spaces ---'
WRITELN Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 7 AND start_space_count <= 10 THEN
PRINT "will shift you to eight so it looks good "
WRITELN Tab$, Tab$ ,CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 11 AND start_space_count <= 14 THEN
PRINT "will shift you to twelve so it looks good "
WRITELN Tab$, Tab$ ,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 15 AND start_space_count <= 18 THEN
PRINT "will shift you to sixteen so it looks good "
WRITELN Tab$, Tab$ ,Tab$ ,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 19 AND start_space_count <= 22 THEN
PRINT "will shift you to twenty so it looks good "
WRITELN Tab$, Tab$, Tab$ ,Tab$ ,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 23 AND start_space_count <= 26 THEN
PRINT "will shift you to twenty four so it looks good "
WRITELN Tab$ ,Tab$, Tab$ ,Tab$ ,Tab$ ,Tab$,CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 27 AND start_space_count <= 30 THEN
PRINT "will shift you to twenty eight so it looks good "
WRITELN Tab$, Tab$ ,Tab$ ,Tab$, Tab$, Tab$ ,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 31 AND start_space_count <= 34 THEN
PRINT "will shift you to thirty two so it looks good "
WRITELN Tab$, Tab$ ,Tab$ ,Tab$ ,Tab$, Tab$ ,Tab$,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 35 AND start_space_count <= 38 THEN
PRINT "will shift you to thirty six so it looks good "
WRITELN Tab$, Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$, Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
IF start_space_count >= 39 AND start_space_count <= 42 THEN
PRINT "will shift you to forty so it looks good "
WRITELN Tab$, Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$, Tab$ ,Tab$ ,Tab$, Tab$ ,CHOP$(txt$," ",1) TO my_outfile
END IF
'--- if over 53 spaces force all 55 spaces ---'
IF start_space_count > 42 THEN
PRINT "ERROR more than 42 spaces indented you have " ;
COLOR FG TO RED
PRINT start_space_count ," indent limit 40 forced !"
COLOR RESET
WRITELN Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$ ,Tab$, Tab$ ,Tab$ ,Tab$,Tab$, CHOP$(txt$," ",1) TO my_outfile
END IF
ELSE
PRINT "no leading spaces "
PRINT txt$
WRITELN txt$ TO my_outfile
WEND
END IF
CLOSE FILE my_infile
CLOSE FILE my_outfile
DELETE FILE CONCAT$(copy_this$,".2tabsTMP")
PRINT
PRINT
PRINT "The indent conversion is done!"
PRINT copy_this$,".2tabs", " <--- is the modified file "