glade2str utility
May 6, 2012 6:51:46 GMT 1
Post by mobeus on May 6, 2012 6:51:46 GMT 1
Inspired by vovchik, this is a small command line utility that can transform a glade file into a string variable named xml$ to use in your BaCon program. The string is properly escaped and line continuation characters are added. It saves a lot of hand editing on large glade files and a separate glade file does not need to be included with your executable.
To use just echo the command to to a file, INCLUDE it in your program, then use the glade or builder command to load the GUI.
Thanks for the inspiration vovchik!
basic-converter.proboards.com/index.cgi?action=gotopost&board=general&thread=254&post=1592
To use just echo the command to to a file, INCLUDE it in your program, then use the glade or builder command to load the GUI.
Thanks for the inspiration vovchik!
basic-converter.proboards.com/index.cgi?action=gotopost&board=general&thread=254&post=1592
TRAP LOCAL
CATCH GOTO BadStuff
SUB show_help()
PRINT ""
PRINT " Help for glade2str."
PRINT ""
PRINT " Usage: glade2str file.glade"
PRINT ""
PRINT " Creates a string variable from a GTK Glade file"
PRINT ""
PRINT " Example: Create a string variable in a include-file for BaCon."
PRINT " echo `glade2str \"path to *.glade file\"` > includefile.bac"
END SUB
IF (argc != 2) OR EQUAL(argv[1], "-h") OR EQUAL(argv[1], "-help") OR EQUAL(argv[1], "--help") THEN
show_help()
RETURN 1
END IF
' double quote
y$ = CHR$(34)
' backslash
z$ = CHR$(92)
' escaped double quote \"
zz$ = CONCAT$(z$,y$)
file1$ = argv[1]
OPEN file1$ FOR READING AS gladefile
IF NOT(ENDFILE(gladefile)) THEN
READLN txt1$ FROM gladefile
txt1$ = CHOP$(txt1$)
IF NOT(EQUAL(LEFT$(txt1$, 14),"<?xml version=")) THEN
PRINT "File ", file1$, " is not a glade file"
RETURN 1
ELSE
output$ = CONCAT$(REPLACE$(txt1$, y$, zz$), z$, CHR$(13))
WHILE NOT(ENDFILE(gladefile)) DO
READLN txt$ FROM gladefile
IF EQUAL(LEFT$(txt$, 12), "</interface>") THEN
nxt$ = txt$
ELSE
nxt$ = CONCAT$(REPLACE$(txt$, y$, zz$), z$, CHR$(13))
END IF
output$ = CONCAT$(output$, nxt$)
WEND
END IF
END IF
CLOSE FILE gladefile
PRINT "xml$ = ", y$, output$, y$
END
LABEL BadStuff
PRINT ERR$(ERROR)
RETURN 1
END