BaCon - Bash-based Basic-to-C converter/compiler

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#406 Post by big_bass »


big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#407 Post by big_bass »

html tools

indenthtml
compliment to bacon2html
it pre indents the html

it could be used as a stand alone for any file or code
it doesnt have to be bacon code
it auto indents justifies in spaces of five



Code: Select all


'--- ***************************************************** '
'--- PROGRAM:	indenthtml.bac '
'--- PURPOSE:	indent  html code  '
'--- AUTHOR:	big_bass Joe Arose   '
'--- DEPENDS:	gcc, bacon,  '
'--- PLATFORM:	linux '
'--- DATE:		Nov-28-2011'
'--- NOTES:	   
'--- 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 "

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#408 Post by sunburnt »

Hi guys... I just installed Puppy528 and BaConGUI won`t run a file. :(

Error: Could not open library ./hug.so: cannot open shared object file: No such file or directory

hug.so is in: /usr/share/BaCon as usual.
Don`t know why it`s looking in the current dir.
I`m sure it`s something simple I`m missing...

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#409 Post by big_bass »

bb2bbpress
http://www.puppy2.org/slaxer/bb2bbpress-1.0-4_SLXR.tgz

a command line tool that converts murga forum to puppylinux.info code
in technical terms phpBBcode to bbpress code

so you can pass your posts to puppylinux.info
and back up your valuable data there

written in pure BaConwhich compiles in C code so its fast fast
already compiled and packaged the source is included as always
if you look at my txz thread you can see the results of running the tool
it is 95% working correctly in automatically correcting the code

the other 5%
what doesnt work are all those http bla bla see here links
they look neater but they are terrible to convert from one forum to another and should be avoided
the full url is the best format for passing threads from one forum to another

and the list ,list = I still have to do some more testing on that to get it to convert to bbpress format

enjoy



you must be the author of the thread
open your thread you want to edit on murga
select all the text then save it to a file
at the command line type
bb2bbpress /the name of the file to correct
then paste *.bbpress-fixed in puppylinux.info

Joe
Last edited by big_bass on Mon 05 Dec 2011, 16:23, edited 3 times in total.

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#410 Post by GatorDog »

Error: Could not open library ./hug.so: cannot open shared object file: No such file or directory
Hey Sunburnt,

How is your IMPORT statement in your program set up?

GatorDog
Image

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#411 Post by sunburnt »

Hey GatorDog; Same as always...

Code: Select all

INCLUDE "/usr/share/BaCon/hug_imports.bac"
Is there something that is setup upon installing BaCon ( I don`t recall any...)?
I thought BaCon hard coded the file path /usr/share/BaCon/hug.so

Code: Select all

sh-4.1# find /usr/share/BaCon/h*.so
/usr/share/BaCon/hug.so

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#412 Post by GatorDog »

Sunburnt,

If you're using the default devx, then check the hug_imports.bac file.
Probably change the top line (or close to top) to
CONST HUG_lib$ = "/usr/lib/hug.so"

And you may want to make sure you have the latest hug.so (in /usr/lib/...)

rod
Image

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#413 Post by sunburnt »

Still the same error: Could not open library ./hug.so
/usr/share/BaCon/hug_imports.bac

Code: Select all

' Imports when HUG is used as shared object
'CONST HUG_lib$ = "./hug.so"
'CONST HUG_lib$ = "/usr/share/BaCon/hug.so"
CONST HUG_lib$ = "/usr/lib/hug.so"
I see why the error says ./hug.so ( the original CONST declare ).
But why didn`t it change with my two edits?

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#414 Post by big_bass »

Hey sunburnt

hug.so is a run time dependency
this means you can move it around
to debug where it needs to be
which is determined by what was used at compile time

if you place hug.so in the same directory as your compiled bin
which is the bacon gui
it will work

you can recompile placing
hug.so where you want
but to maintain a standard
it should be placed in /usr/lib

move it around till it works
then recompile

Joe

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#415 Post by sunburnt »

Don`t know why it started working, though sketchy.

And Xterm pops up with the title bar: xterm_simulate_hold.sh
It seems the shell script is being run with the exec.

Is this correct? Is this a new improvement for the BaConGUI ?

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#416 Post by sunburnt »

Can`t remember if this has been asked/answered yet...

How to get pixel width of a string to set width of buttons, etc.
A tricky thing as it has to do with font, font size, bold, and italic.

A simple fix would be to use only mono-spaced fonts.
btnWidth = character count + pixels per character + padding

In V.B. I use to just have a hidden text box with the "snap to size" set.
So I`d fill it with text and read it`s width property.

# If a MARK could be made and set it`s "snap to size" property...

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

pixel width

#417 Post by vovchik »

Dear Terry,

It is possible with pango, but you will have to recode this bit in BaCon (not hard):

Code: Select all

extern GttWidget * curdlg; // of current dialog

void gettextwdht ( char * family , int ptsize , int weight , bool normalstyle ,
char * stringtomeasure ,
int * wdret , int * htret )
{
PangoFontDescription * fd = pango_font_description_new ( );

pango_font_description_set_family (fd, family );
pango_font_description_set_style (fd, normalstyle ? PANGO_STYLE_NORMAL :
PANGO_STYLE_ITALIC );
pango_font_description_set_variant (fd, PANGO_VARIANT_NORMAL);
pango_font_description_set_weight (fd, (PangoWeight)weight );
pango_font_description_set_stretch (fd, PANGO_STRETCH_NORMAL);
pango_font_description_set_size (fd, ptsize * PANGO_SCALE);

PangoContext * context = gtk_widget_get_pango_context ( curdlg ) ;

PangoLayout * layout = pango_layout_new ( context );
pango_layout_set_text ( layout, stringtomeasure, -1 );
pango_layout_set_font_description ( layout, fd );
pango_layout_get_pixel_size (layout, wdret , htret );
g_object_unref ( layout );
}
If I have time, I will do this and make it a BaCon function. If you have time and do it first, please post it. :)

With kind regards,
vovchik

PS. Here is a URL: http://www.gtk.org/api/2.6/pango/pango- ... pixel-size

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

EXTRACT$ function

#418 Post by vovchik »

Dear puppians,

Here is a string function (also attached) for BaCon that I just coded and you might also find useful. I haven't tested it extensively, but it seems to work fine. The notes in the code explain what it does.

Code: Select all

' *****************************************************
' PROGRAM:	extract.bac
' PURPOSE:	EXTRACT$ function for BaCon (see NOTES)
' AUTHOR:		vovchik (Puppy Linux forum)	
' DEPENDS:	gcc, bacon
' PLATFORM:	Puppy Linux (actually, any *nix)
' DATE:		09-12-2011
' LICENSE:	GPL3
' *****************************************************
' NOTES	
'
' EXTRACT$(STRING src$, STRING match$, NUMBER mode) where
' 
' src$ is a string of length > 1 that is to be
' examined and split
' 
' match$ is a string of chars for testing the presence
' of ANY of which in src$ and whose earliest position in
' src$ (starting from the left) represents the point for
' substring delimitation.
'
' mode is a flag toggling "extract" and "remain" modes of
' the EXTRACT$ function
'  
' If mode = 0, then
'
' EXTRACT$ returns a substring of src$ starting with the first
' character of src$ and up to (but not including) the first
' occurrence of match$.  If match$ is not present in src$,
' all of src$ is returned.
'
' If mode = 1, then
'
' EXTRACT$ returns a substring of src$ starting with the first
' character in src$ that matches any string within match$ to the
' end of src$.  
' 
' In summary, src$ is a string expression from which to
' extract a substring and match$ is a string of chars
' against which matches will be attempted. mode determines
' whether the left part (mode 0) or right part (mode 1)
' of src$ will be returned.

' EXTRACT$ is case-sensitive.
'
' The function is especially useful when parsing a
' string containing arguments to a program.
'
' This implementation combines the functions of typical
' EXTRACT$ and REMAIN$ functions in other languages.
' *****************************************************

' -------------
FUNCTION EXTRACT$(STRING src$, STRING match$, NUMBER mode)
' -------------
	LOCAL tst$, ret$, tmp$ TYPE STRING
	LOCAL i TYPE NUMBER
	' check to see whether there is really something to be split
	IF LEN(src$) > 1 THEN
		tst$ = ""
		tmp$ = ""
		' create REGEX compound "OR" type string from match$ string
		FOR i = 1 TO LEN(match$)
			tst$ = CONCAT$(tst$, MID$(match$, i, 1), "|")
		NEXT i
		tst$ = LEFT$(tst$, LEN(tst$) - 1)
		' if one of the REGEX chars is found in src$,
		' then determine the first instance (position) of any of
		' the match$ chars within src$
		IF REGEX(src$, tst$) THEN
			FOR i = 1 TO LEN(match$)
				IF INSTR(src$, MID$(match$, i, 1)) THEN
					tmp$ = CONCAT$(tmp$, RIGHT$(CONCAT$("0000000000", STR$(INSTR(src$, MID$(match$, i, 1)))), 8), " ")
				END IF
			NEXT i
			tmp$ = CHOP$(tmp$)
			SPLIT tmp$ BY " " TO tmp_array$ SIZE tmp_size
			SORT tmp_array$
			' make substring to return based on mode
			SELECT mode
				' everything from the left except that which matches
				CASE 0
					ret$ = LEFT$(src$, VAL(tmp_array$[0]) - 1)
				' everything from the right that matches
				CASE 1
					ret$ = RIGHT$(src$, LEN(src$) - VAL(tmp_array$[0]) + 1)
				' placeholder for additional/new modes
				DEFAULT
					ret$ = src$
			END SELECT
		ELSE
			ret$ = src$
		END IF
	ELSE
		ret$ = src$
	END IF
	RETURN ret$
END FUNCTION
Here is how to invoke it:

Code: Select all

source$ = "abcedf"
test$ = "xyz"
PRINT EXTRACT$(source$, test$, 0)
PRINT "--------"
source$ = "zsdabcedf"
test$ = "bc"
PRINT EXTRACT$(source$, test$, 0)
PRINT "--------"
source$ = "zsdabcedf"
test$ = "bz"
PRINT EXTRACT$(source$, test$, 0)
PRINT "--------"
source$ = "zsdabcedf"
test$ = "bz"
PRINT EXTRACT$(source$, test$, 1)
PRINT "--------"
source$ = "There is only trouble ahead"
test$ = "bzt"
PRINT EXTRACT$(source$, test$, 0)
PRINT "--------"
source$ = "There is only trouble ahead"
test$ = "but"
PRINT EXTRACT$(source$, test$, 0)
PRINT "--------"
source$ = "There is only trouble ahead"
test$ = "but"
PRINT EXTRACT$(source$, test$, 1)
PRINT "--------"
source$ = "bnice -t -g 80x90"
test$ = "-gt"
PRINT EXTRACT$(source$, test$, 1)
PRINT "--------"
source$ = "IF x$ > 10 THEN"
test$ = ">"
PRINT EXTRACT$(source$, test$, 1)
PRINT "--------"
source$ = "IF x$ > 10 THEN"
test$ = ">"
PRINT EXTRACT$(source$, test$, 0)
With kind regards,
vovchik
Attachments
extract.bac.tar.gz
(1.51 KiB) Downloaded 379 times

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#419 Post by sunburnt »

Hi guys; Anyway to get mouse info ( button, scroll, X, Y ) from Xwin.?
The gtkDialog threads probably have something on this, but they`re five miles long.

BaCon only gets mouse info if the cursor is over a canvas I think, but not over other controls.
Right-click would be nice for BaCon, but Xwin. controls the window, so click action starts there.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#420 Post by BarryK »

Heh heh, I lobbied for BaCon in the Raspberry Pi forum:

http://www.raspberrypi.org/forum?mingle ... pic&t=1474

...well, I have introduced BaCon into their awareness, I probably should back-off now.
[url]https://bkhome.org/news/[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#421 Post by sunburnt »

Installed the latest Puppy528-3 so Firefox could have a working Flash player.

As usual, BaCon doesn`t work in the new install.
I need to write another setup script to get it running for every new Save file.

Error:

Code: Select all

Symbol not found in library /usr/share/BaCon/hug.so: undefined symbol: METHOD
hug.so has the METHOD function in it of course...

### Also I posted about getting mouse info. 2 posts above here.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#422 Post by vovchik »

Dear Terry,

I know it slows the compile/debug process, but I just use hug.bac as an INCLUDE for everything. Later I go and determine which functions I use from the HUG lib. That way I never run in to your type of problem - where the system may have an old hug.so or can't find the right one. And if you have a working BaCon or BaConGui, the program with the hug.bac INCLUDE will compile. Later you can make your hug.so and recompile, once you know that everything is working.

With kind regards,
vovchik

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#423 Post by sunburnt »

I replaced /usr/lib/hug.so with a link to the newer hug.so
Barry should make /usr/lib/hug.so a link to /root/my-applications/lib/hug.so

Puppy`s Save file is it`s biggest problem, it corrupts occasionally.
So I replaced the dirs. my-applications and my-documents with links to /apps and /docs dirs. on a partition so nothing`s lost.
Keep a backup Save file, to restore just copy it over the old one.

This should be a menu item, to make a gzip backup Save file, and have an option to restore it at the bootup menu.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

New HUG with sliders

#424 Post by vovchik »

Dear puppians,

Peter has just posted a new HUG (0.66) that now has support for vscale and hscale sliders. If you want to use these widgets, please download the latest HUG http://www.basic-converter.org/hug.bac. The documentation will be updated in due course.

With kind regards,
vovchik

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#425 Post by GatorDog »

vovchik,

Thanks for update :D

gatordog
Image

Post Reply