' *****************************************************
' PROGRAM: bacon2bb.bac
' PURPOSE: convert Bacon and HUG keywords to phpBB code
' AUTHOR: big_bass Joe Arose + a big thanks to rod the GatorDog
' DEPENDS: gcc, bacon, replace
' PLATFORM: linux
' DATE: Oct 21-2011
' NOTES: you must have the replace package installed http://replace.richardlloyd.org.uk/
' LICENSE: GPL version 3 or later
' *****************************************************

' a big thanks to rod the GatorDog for giving me help and code snippets
' to improve , simply and correctly format the code for BaCon

' USUAGE: ./bacon2bbc /path-and-filename"

' note the file will get a -BBcode 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: ./bacon2bbc /path-and-filename"
END
ENDIF

'--- 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]

'--- now I want this bacon argument copy_this$ to be valid in a bash shell---
'--- so an extra step is needed to convert it using Cmd$ = CONCAT$---
'--- notice that we place in double quotes on bash commands and separate with commas---
'--- remember to allow pad spaces for command splitting---
'--- the conversion from bacon mindset to bash in bacon takes some time---
'--- so below is a simple example using copy---
'--- backup original file to tmp---
'Cmd$ = CONCAT$("cp ", copy_this$, " /tmp")
'Opt$ = EXEC$(Cmd$)

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

'--- the correct way thanks to GatorDog
COPY copy_this$ TO CONCAT$(copy_this$,"-BBcode")

'--- this was some job formatting and took a long time to get working---
'--- mostly because you have to think how CONCAT$ needs to be formatted---
'--- then how you have to modify bash code to be used in bacon's EXEC$(Cmd$)---

'--- 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 blue text---
'--- the second part looks for all HUG keywords and converts them to phpBB---
'--- color code in green text---

PRINT
PRINT "=========================="
PRINT " READ/DATA BaCon"
PRINT "=========================="
PRINT

'--- Define some string data these are BaCon keywords
DATA "ABS", "ADDRESS", "ALARM", "ALIAS", "AND", "APPENDING", "AS", "ASC"
DATA "ASSOC", "ATN", "BASE", "BG", "BLACK", "BLUE", "BREAK", "BY"
DATA "CALL", "CASE", "CATCH", "CHANGEDIR", "CHOP", "CHR", "CHUNK", "CLEAR"
DATA "CLOSE", "COLLAPSE", "COLOR", "COLUMNS", "CONCAT", "CONST", "COPY"
DATA "COS", "CURDIR", "CURRENT", "CURSOR", "CYAN"
DATA "DATA", "DAY", "DEC", "DECLARE", "DECR", "DEF", "DEFAULT", "DELETE"
DATA "DIRECTORY", "DO", "DOWN"
DATA "ELIF", "ELSE", "END", "ENDFILE","ENDFUNCTION", "ENDIF", "ENDSELECT"
DATA "ENDSUB", "ENDUSEC", "ENDWITH", "EQ", "EQUAL", "ERR", "ERROR"
DATA "EVEN", "EXEC", "EXP", "FG", "FILE", "FILEEXISTS", "FILELEN"
DATA "FILETYPE", "FILL", "FLOATING", "FLOOR", "FN", "FOR", "FORMAT"
DATA "FREE", "FROM", "FUNCTION", "GETBYTE", "GETENVIRON", "GETFILE"
DATA "GETKEY", "GETLINE", "GETX", "GETY", "GLOBAL", "GOTO", "GOTOXY"
DATA "GREEN", "GROUP", "HEX", "HOST", "HOUR", "IF", "IMPORT", "INCLUDE"
DATA "INCR", "INPUT", "INSTR", "INSTRREV", "INT", "INTENSE", "IS"
DATA "ISFALSE", "ISNOT", "ISTRUE", "LABEL", "LCASE", "LEFT", "LEN"
DATA "LET", "LOCAL", "LOG", "LOOKUP", "MAGENTA", "MAKEDIR", "MEMORY"
DATA "MEMREWIND", "MEMSTREAM", "MEMTELL", "MEMTYPE", "MID", "MINUTE"
DATA "MOD", "MONTH", "MONTH", "NE", "NETWORK", "NEXT", "NORMAL", "NOT"
DATA "NOW", "NUMBER", "ODD", "OFF", "OFFSET", "ON", "OPEN", "OPTION"
DATA "OR", "PEEK", "POKE", "POW", "PRINT", "PROTO", "PULL", "PUSH"
DATA "PUTBYTE", "PUTLINE", "RANDOM", "READ", "READING", "READLN"
DATA "READWRITE", "RECEIVE", "RECORD", "RED", "REGEX", "RELATE"
DATA "RENAME", "REPEAT", "REPLACE", "RESET", "RESIZE", "RESTORE", "RESUME"
DATA "RETURN", "REVERSE", "REWIND", "RIGHT", "RND", "ROUND", "ROWS"
DATA "SEARCH", "SECOND", "SEED", "SEEK", "SELECT", "SEND", "SERVER"
DATA "SETENVIRON", "SGN", "SIN", "SIZE", "SIZEOF", "SLEEP", "SOCKET"
DATA "SORT", "SPC", "SPLIT", "SQR", "START", "STEP", "STOP", "STR"
DATA "STRING", "SUB", "SYSTEM", "TAB", "TAN", "TELL", "THEN", "TIMEVALUE"
DATA "TO", "TRACE", "TRAP", "TYPE", "UCASE", "UNTIL", "USEC", "VAL"
DATA "WAIT", "WEEK", "WEEKDAY", "WEND", "WHENCE", "WHILE", "WHITE"
DATA "WITH", "WRITELN", "WRITING", "XSIZE", "YEAR", "YELLOW", "YSIZE"

'--- Get all string data BaCon
FOR y = 1 TO 225
READ q$
SYSTEM CONCAT$("replace " , " -e" , " '", q$ ,"' " , " '", "",q$,"", "' " , copy_this$,"-BBcode")
PRINT ".";
NEXT

PRINT
PRINT
PRINT
PRINT "=========================="
PRINT " READ/DATA HUG"
PRINT "=========================="
PRINT

'--- Define some string data these are HUG keywords
DATA "ATTACH", "BUTTON", "CALLBACK", "CALLBACKX", "CANVAS", "CHECK"
DATA "CIRCLE", "CLIPBOARD", "COMBO", "DISABLE", "DISPLAY", "DRAW"
DATA "EDIT", "ENABLE", "ENTRY", "FILEDIALOG", "FOCUS", "FONT", "FRAME"
DATA "GET", "GRAB$", "HIDE", "HSEPARATOR", "HUGLIB$", "HUGOPTIONS"
DATA "IMAGE", "INIT", "KEY", "LINE", "LIST", "MARK", "METHOD"
DATA "MSGDIALOG", "MOUSE", "NOTEBOOK", "OUT", "PASSWORD", "PICTURE"
DATA "PIXEL", "PROGRESSBAR", "PROPERTY", "QUIT", "RADIO", "REGISTER"
DATA "SCREENSIZE", "SET", "SHOW", "SPIN", "SQUARE", "STOCK", "SYNC"
DATA "TEXT", "TIMEOUT", "TOGGLE", "UNFOCUS", "VSEPARATOR", "WINDOW"

'--- Get all string data HUG
FOR y = 1 TO 57
READ q$
SYSTEM CONCAT$("replace " , " -e" , " '", q$ ,"' " , " '", "",q$,"", "' " , copy_this$,"-BBcode")
PRINT ".";
NEXT

'--- Reset data pointers
RESTORE

PRINT
PRINT
PRINT "The conversion is done!"

PRINT copy_this$,"-BBcode", " <--- is the modified file with BB code"