|
Post by bigbass on Nov 17, 2011 18:52:56 GMT 1
I wanted html of Bacon for a long time but I had to do this in steps first BBcode now html ... going to html was tricky taking your *.bac BaCon code and adding keyword highlighting color in html format so that you can post your BaCon / HUG code anywhere **without all the craziness of using CSS and java bloat I wouldnt know where to even start with that *** updated Nov-28-2011 www.puppy2.org/slaxer/bacon2html-2-6_SLXR.tgzI re cycled so much code from bacon2bb I just added all the html coding instead of BB and a few surprises @thanks vovchik for your help with the newline problem read the code comments you are in there removed a link need to update it Joe
|
|
|
Post by GatorDog on Nov 17, 2011 21:50:13 GMT 1
. Hey Big_bass, That's lookin' pretty good And this is a sweet little hack <snip> '--- non looping string replace using arrays ---' '--- cat the file into an array using x$ ---' x$ = EXEC$(CONCAT$("cat ",copy_this$,".htmlTMP2"))
x$ = REPLACE$(x$, NL$, "<br />@")
'--- have a divide point "@" to return the new line again ---' '--- so that it is not one long continuos line ---' SPLIT x$ BY "@" TO myarray$ SIZE mysize <snip> FWIW - REPLACE$ can use multi-chr string as the replacement. If a line in the program you are parsing should happen to have an "@" in it, it will be used to split the line there. You could do something like this - Linebreak$ = "<-*@*->" Replace$ = CONCAT$("<br />", Linebreak$)
x$ = REPLACE$(x$, NL$, Replace$) . . SPLIT x$ BY Linebreak$ TO myarray$ SIZE mysize . . You can make Linebreak$ as random as you like to prevent false hits. _________________________________________________________________If you have nothing else to keep you awake, maybe this would have you up for a night or two What would it take to color text inside of quotes. Variable$ = " FOR EXAMPLE" Maybe REGEXP can sort it out quickly Back at it. rod
|
|
|
Post by bigbass on Nov 18, 2011 6:58:42 GMT 1
rod GatorDoghow about an ascii fish? Linebreak$ = "<*)))>{" *updated first post* I was working on that awhile ago in just bash but there is a lot of filtering empty quotes and code inside the CONCAT$ it can be done though its like a pre parser for strings all variables need to be checked if they are valid strings I'd have to work it out in bash first to get it working and test first before going at it in BaCon ...but why not let there be more color maybe orange for valid strings Variable$ = "FOR EXAMPLE" no color Variable2$ = " " this one is tricky you would have to get the result not whats in the double quotes txt$ = CONCAT$("<span style=","\"color: grey;","\">", txt$, "</span>") ================code edit==================================== I removed these lines they are not needed an array does the job now OPEN CONCAT$(copy_this$,".htmlTMP") FOR READING AS my_infile CLOSE FILE my_infile I modified this part '--- the linebreak$ is a random string appended after the html line break ---' '--- that will be used to return the NL$ ---' '--- note that REPLACE$ is a built in command ---' '--- note that replace is a compiled binary called from the SYSTEM ---' Linebreak$ = "<*)))>{" Htmlbreak_Linebreak$ = CONCAT$("<br />", Linebreak$) x$ = REPLACE$(x$, NL$, Htmlbreak_Linebreak$) =========================================================== Joe
|
|
|
Post by GatorDog on Nov 20, 2011 16:52:55 GMT 1
Love the fish ;D . . <*)))>{ ____________________________________________________________________Colored variable names - that looks good. But I would contend that Variable2$ = " " is as valid as Variable$ = "FOR EXAMPLE". Especially if you are scratching your head trying to figure out why the text string you've been printing out keeps coming out blank. (ask how I know ) gDog
|
|
|
Post by bigbass on Nov 26, 2011 6:51:34 GMT 1
Hey GatoDog
I agree they are the same its CONCAT$ with many quoted lines that are hard to filter
something like this is a happy solution we could use
ONE_BLANK$ = SPC$(1)
TWO_BLANKS$ = SPC$(2)
Joe
|
|
|
Post by bigbass on Nov 29, 2011 17:30:44 GMT 1
bacon2htmlupdated Nov-28-2011 update first page to reflect the change sourceforge.net/projects/baconproto/files/bacon2html-2-6_SLXR.tgz/download'--- ***************************************************** ' '--- PROGRAM: bacon2html.bac ' '--- PURPOSE: convert Bacon and HUG keywords to html code ' '--- AUTHORS: big_bass Joe Arose + rod the GatorDog ' '--- DEPENDS: gcc, bacon, replace ' '--- PLATFORM: linux ' '--- DATE: Nov-19-2011, Nov-28-2011 fix an output glitch html code' '--- NOTES: the replace package http://replace.richardlloyd.org.uk/ ---' '--- LICENSE: GPL version 3 or later ' '--- *****************************************************'
'--- a big thanks to vovchik for providing a key piece of code ---' '--- how to replace the newline character using a string---' '--- many updates reads files outside the binary to allow easy edits ---' '--- to the keyword list this also reduces code in the binary ---'
'--- USUAGE: ./bacon2html /path-and-filename" ---' '--- note the file will get a .html added to the filename ---' '--- arguments are in an array in this example only arg$[1] is used ---' '--- we look for a blank space that divides the commands '--- a check is made to see if the user entered a path and filename ---' '--- on error print usage---' ' --- this part was added to allow 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: ./bacon2html /path-and-filename" END END IF
'--- check for dependencies thanks GatorDog ---' Check = LEN(EXEC$("which replace")) IF Check = 0 THEN PRINT "You must have the replace package installed http://replace.richardlloyd.org.uk/" END FALSE END IF
'--- copy_this$ is the first argument passed from the command line ---' '--- path-and-filename is arg$[1] this is a valid bacon argument now ---' '--- 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$,".html")
'--- fix an output glitch when displaying html code of this code ---' '--- by breaking up the full command Nov-28-2011 ---' Color_Indigo$ = CONCAT$("<span style=","\"color: Indigo;" ,"\">") Color_grey$ = CONCAT$("<span style=","\"color: grey;" ,"\">") Color_green$ = CONCAT$("<span style=","\"color: green;" ,"\">") Color_close$ = CONCAT$("</", "span>")
'--- the replace binary is used in the backend I am calling it from bash ---' '--- directly with no dependency linking (its nice to know it can be done) ---' '--- what is happening here is replace is looking for all the keywords in BaCon ---' '--- and converts them to phpBB color code in Indigo text---' '--- the second part looks for all HUG keywords and converts them to phpBB ---' '--- color code in green text ---'
COLOR FG TO BLUE PRINT PRINT "=================================" PRINT " READ" PRINT " /etc/BaCon/bacon-keywords-data.txt" PRINT "=================================" PRINT COLOR RESET
'--- Get all string data BaCon ---' '--- read from a file outside of the binary to simplify ---' '--- modifications of the keyword lists and no preset limits ---'
OPEN "/etc/BaCon/bacon-keywords-data.txt" FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile IF NOT(ENDFILE(myfile)) THEN SYSTEM CONCAT$("replace " , " -e" , " '", txt$ ,"' " , " '", Color_Indigo$, txt$, Color_close$, "' " , copy_this$,".html") PRINT "."; END IF WEND CLOSE FILE myfile
COLOR FG TO GREEN PRINT PRINT PRINT "=================================" PRINT " READ" PRINT " /etc/BaCon/hug-keywords-data.txt" PRINT "=================================" PRINT COLOR RESET
'--- Get all string data HUG ---' '--- read from a file outside of the binary to simplify ---' '--- modifications of the keyword lists and no preset limits ---'
OPEN "/etc/BaCon/hug-keywords-data.txt" FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile IF NOT(ENDFILE(myfile)) THEN SYSTEM CONCAT$("replace " , " -e" , " '", txt$ ,"' " , " '", Color_green$, txt$, Color_close$, "' " , copy_this$,".html") PRINT "."; END IF WEND CLOSE FILE myfile
'--- grey comments using only Bacon (I had this part with sed) but GatorDog ---' '--- did this in Bacon and I like it ---' '--- Rename working file to TMP ext.
RENAME CONCAT$(copy_this$,".html") TO CONCAT$(copy_this$,".htmlTMP")
OPEN CONCAT$(copy_this$,".html") FOR WRITING AS my_outfile OPEN CONCAT$(copy_this$,".htmlTMP") FOR READING AS my_infile WHILE NOT(ENDFILE(my_infile)) READLN txt$ FROM my_infile '--- Get rid of any leading or trailing whitespace, CR, TAB, etc. Tmp$ = CHOP$(txt$) IF LEFT$(Tmp$, 1) = "'" OR LEFT$(Tmp$, 4) = "REM " THEN txt$ = CONCAT$(Color_grey$, txt$, Color_close$) END IF WRITELN txt$ TO my_outfile PRINT "."; WEND CLOSE FILE my_infile CLOSE FILE my_outfile DELETE FILE CONCAT$(copy_this$,".htmlTMP")
'--- the new line to html break part ---'
RENAME CONCAT$(copy_this$,".html") TO CONCAT$(copy_this$,".htmlTMP2") OPEN CONCAT$(copy_this$,".html") FOR WRITING AS my_outfile
'--- non looping string replace using arrays ---' '--- cat the file into an array using x$ ---' x$ = EXEC$(CONCAT$("cat ",copy_this$,".htmlTMP2"))
'--- the linebreak$ is a random string appended after the html line break ---' '--- that will be used to return the NL$ ---' '--- note that REPLACE$ is a built in command ---' '--- note that replace is a compiled binary called from the SYSTEM ---' Linebreak$ = "<*)))>{" Htmlbreak_Linebreak$ = CONCAT$("<br />", Linebreak$)
x$ = REPLACE$(x$, NL$, Htmlbreak_Linebreak$)
'--- have a divide point "ascii fish" to return the new line again ---' '--- so that it is not one long continuos line ---'
SPLIT x$ BY Linebreak$ TO myarray$ SIZE mysize '--- instead of opening a file to read ---' '--- an array is used as input ---' '--- remember we used cat to get a string then the string was used ---' '--- to format an array with the new line ---' '--- from the array we write directly to my_outfile ---' FOR x = 0 TO mysize - 1 WRITELN myarray$[x] TO my_outfile NEXT
CLOSE FILE my_outfile DELETE FILE CONCAT$(copy_this$,".htmlTMP2")
PRINT PRINT PRINT "The html conversion is done!" PRINT copy_this$,".html", " <--- is the modified file with bac code"
|
|