indenthtml
Dec 1, 2011 16:08:54 GMT 1
Post by bigbass on Dec 1, 2011 16:08:54 GMT 1
this is indenthtml
what it does is justifies html
with adding leading indentation automatically
*notice it works for all html not just BaCon code
but I made it for BaCon in mind*
I am working on some html and bb code tools
I am compiling a few stand alone apps instead of one monster sized
app that would be difficult to debug
this way each part is a stand alone and could be called or code easily modified
in just one part
what it does is justifies html
with adding leading indentation automatically
*notice it works for all html not just BaCon code
but I made it for BaCon in mind*
I am working on some html and bb code tools
I am compiling a few stand alone apps instead of one monster sized
app that would be difficult to debug
this way each part is a stand alone and could be called or code easily modified
in just one part
'--- ***************************************************** '
'--- PROGRAM: indenthtml.bac '
'--- PURPOSE: indent html code '
'--- AUTHOR: big_bass Joe Arose '
'--- DEPENDS: gcc, bacon, '
'--- PLATFORM: linux '
'--- DATE: Nov-28-2011'
'--- 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: ./indenthtml /path-and-filename" ---'
'--- note the file will get a .indent 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 "USUAGE: ./indenhtml /path-and-filename"
END
END IF
Tab$ = CHR$(9)
FIVE_BLANKS$ = SPC$(5)
'--- Non-Breaking Space ---'
'--- set the default line indents ---'
FIVE_SPACES$ = " "
TEN_SPACES$ = " "
FIFTEEN_SPACES$ = " "
TWENTY_SPACES$ = " "
TWENTY_FIVE_SPACES$ = " "
THIRTY_SPACES$= " "
THIRTY_FIVE_SPACES$= " "
FORTY_SPACES$= " "
FORTY_FIVE_SPACES$= " "
FIFTY_SPACES$= " "
FIFTY_FIVE_SPACES$= " "
'--- 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$,".indent")
'--- Rename working file to TMP ext.
RENAME CONCAT$(copy_this$,".indent") TO CONCAT$(copy_this$,".indentTMP")
OPEN CONCAT$(copy_this$,".indent") FOR WRITING AS my_outfile
OPEN CONCAT$(copy_this$,".indentTMP") FOR READING AS my_infile
WHILE NOT(ENDFILE(my_infile))
READLN txt$ FROM my_infile
'--- pre step replace tabs with five spaces ---'
txt$ = REPLACE$(txt$, Tab$, FIVE_BLANKS$)
'--- check if line of text starts with spaces or tabs ---'
IF REGEX(txt$, "^ ") OR REGEX(txt$, "^FIVE_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 55 spaces ---'
IF start_space_count < 53 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 five so it looks good "
PRINT FIVE_SPACES$, txt$
WRITELN FIVE_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 7 AND start_space_count <= 12 THEN
PRINT "will shift you to ten so it looks good "
PRINT TEN_SPACES$, txt$
WRITELN TEN_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 13 AND start_space_count <= 17 THEN
PRINT "will shift you to fifteen so it looks good "
PRINT FIFTEEN_SPACES$, txt$
WRITELN FIFTEEN_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 18 AND start_space_count <= 22 THEN
PRINT "will shift you to twenty so it looks good "
PRINT TWENTY_SPACES$, txt$
WRITELN TWENTY_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 23 AND start_space_count <= 27 THEN
PRINT "will shift you to twenty five so it looks good "
PRINT TWENTY_FIVE_SPACES$, txt$
WRITELN TWENTY_FIVE_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 28 AND start_space_count <= 32 THEN
PRINT "will shift you to thirty so it looks good "
PRINT THIRTY_SPACES$, txt$
WRITELN THIRTY_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 33 AND start_space_count <= 37 THEN
PRINT "will shift you to thirty five so it looks good "
PRINT THIRTY_FIVE_SPACES$, txt$
WRITELN THIRTY_FIVE_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 38 AND start_space_count <= 42 THEN
PRINT "will shift you to forty so it looks good "
PRINT FORTY_SPACES$, txt$
WRITELN FORTY_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 43 AND start_space_count <= 47 THEN
PRINT "will shift you to forty five so it looks good "
PRINT FORTY_FIVE_SPACES$, txt$
WRITELN FORTY_FIVE_SPACES$, txt$ TO my_outfile
END IF
IF start_space_count >= 48 AND start_space_count <= 52 THEN
PRINT "will shift you to fifty so it looks good "
PRINT FIFTY_SPACES$, txt$
WRITELN FIFTY_SPACES$, txt$ TO my_outfile
END IF
'--- if over 53 spaces force all 55 spaces ---'
IF start_space_count > 53 THEN
PRINT "ERROR more than 53 spaces indented you have " ;
COLOR FG TO RED
PRINT start_space_count ," indent limit 55 forced !"
COLOR RESET
WRITELN FIFTY_FIVE_SPACES$, txt$ 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$,".indentTMP")
PRINT
PRINT
PRINT "The indent conversion is done!"
PRINT copy_this$,".indent", " <--- is the modified file "