Page 6 of 27

Posted: Sun 14 Nov 2010, 15:49
by jpeps
PjotAwake wrote:Jpeps,

It makes sense as the programs in that 'bacon.tar.gz' package are also more than a year old.

So forget about them!

Please use the programs shipped by Puppy Linux, or the current programs hosted on the BaCon website.
Hi Peter,
As noted, the gtk demo from website also gave the error:

Code: Select all

~ $ bacon -v

BaCon version 1.0 build 19 - (c) Peter van Eerten - GPL v3.

~ $ sudo bacon ./gtk-server-new.bac 
Starting conversion... done.   
Starting compilation... done.
Program './gtk-server-new' ready.
~ $ ./gtk-server-new
ERROR: signal for SEGMENTATION FAULT received - memory invalid or array out of bounds? Try to compile the program with TRAP LOCAL to find the cause.
For fun I have adjusted the 'gtkabout1.bac' program so it compiles and runs with BaCon 1.0 build 19. Compare with the orignal one and you'll see the differences.

Here is the code:
Works better, but doesn't get the battery object like the old demo:
(see attachment)

Code: Select all

~ $ sudo ./gtkabout2 

(<unknown>:7908): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
Edit: I see, you didn't include battery image

Code: Select all

< 	DECLARE window, about, battery, image, rv TYPE long
< 	gtk_init(0, 0)
< 	window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
Thanks for showing differences

Code: Select all

< IMPORT "gtk_init" FROM "libgtk-x11-2.0.so" TYPE void
< IMPORT "gtk_init" FROM "libgtk-x11-2.0.so" TYPE void
< IMPORT "gtk_window_new" FROM "libgtk-x11-2.0.so" TYPE long
< IMPORT "gtk_widget_show_all" FROM "libgtk-x11-2.0.so" TYPE void
---
> IMPORT "gtk_init(int*,void*)" FROM "libgtk-x11-2.0.so" TYPE void
> IMPORT "gtk_window_new(int)" FROM "libgtk-x11-2.0.so" TYPE long
> IMPORT "gtk_widget_show_all(long)" FROM "libgtk-x11-2.0.so" TYPE void
...

Posted: Sun 14 Nov 2010, 16:45
by seaside
While the topic is hot, I thought I'd ask about this one..

Program BOTD (aka BaCon On This Day) here http://www.basic-converter.org/botd.tar.gz

It compiles with new BaCon build nicely, but hangs here when run at this point
# ./botd 2 4

---------------------------------------------
On this day in history: 2 April
---------------------------------------------
The following events occurred:
---------------
No error - just stops at this point.

I really want to find out what happened then?? :D :D :D

Cheers,
s

Posted: Sun 14 Nov 2010, 16:59
by big_bass
auto download, compile and install BaCon and
download ,compile and test the 18 basic examples to get started easily and a means to update easily when new versions come out

this will take awhile but it does get you started correctly
*you must have bash 4 or later installed before running this script
it pre installed in TXZ_pup 450

@thanks mechanic for the speed tip bacon test1.bac
updated code to add Xdialog yes or no and broke the program up in two parts

maybe you want to kill all the wget downloads there's a bunch

Code: Select all

pid=`ps aux| grep wget | awk '{print $2}'`&&kill -9 $pid
Joe
UPDATED CODE 11-18-2010 to add syntax highlighting to make it more compact and easy to add more bac files
by using a list added bash version test

Code: Select all

#!/bin/bash


# Joe Arose  big_bass 11-18-2010
# call this  auto-build-compile-bacon
# auto download compile install  and test Bacon and the 18 basic examples
# so you can easily update when needed

# thanks "mechanic" for the speed tip  using bacon instead of bacon.bash for compiling

# thanks seaside for the bash version test
# added syntax highlighting


BASHV=$(bash --version | head -1)
VN=$(echo $BASHV | cut -f1 -d. | sed 's/^.*\(.\)$/\1/')
[ $VN -lt 4 ] && Xdialog --title "bash version test " \
           --infobox "\nBash Version Problem $BASHV installed
---------------> Bash must be version 4 or above for BaCon <-------------------" "\n" 0 0





#   =====================================
#    downoad ,compile and install BaCon
#   =====================================


Xdialog --wrap --title "bacon instlaller" \
        --yesno "Do you want to install bacon  " 0 0

case $? in
  0)
    echo "Yes chosen."
   


rm -f  bacon.bash*
rm -f  bacon.bac*
rm -f  bacon



xterm  -geometry 40x30+150+40 -e wget http://www.basic-converter.org/bacon.bash
chmod a+x bacon.bash


xterm  -geometry 40x30+150+40 -e wget http://www.basic-converter.org/bacon.bac
chmod a+x bacon.bac


xterm  -geometry 40x30+150+40 -e ./bacon.bash bacon.bac

# copy bacon bin into the path
cp bacon /usr/sbin


Xdialog --title "Complete" \
           --infobox "\nInstalling bacon has finished.\n" 0 0 3000


   ;;
  1)
    echo "No chosen."
    exit
   ;;
  255)
    echo "Box closed."
    exit
   ;;

esac


#   =====================================
#    syntax highlighting
#   =====================================

#(0) download the file http://www.basic-converter.org/bacon.lang
     

    xterm  -geometry 40x30+150+40 -e wget http://www.basic-converter.org/bacon.lang

#(1) Create language directory for GtkSourceView:

    mkdir -p ~/.local/share/gtksourceview-2.0/language-specs/

#(2) Copy this file to the new directory:

    cp bacon.lang ~/.local/share/gtksourceview-2.0/language-specs/

#Now start gedit, Anjuta, Scribes etc and the BaCon sourcecode has
#   syntax highlighting!



Xdialog --title "syntax highlighting" \
           --infobox "\nsyntax highlighting has installed.\n" 0 0 3000



#   =====================================
#    download  compile and test  the 18 test files
#   =====================================

Xdialog --wrap --title "test bac downloader" \
        --yesno "Do you want to download the bac examples   " 0 0

case $? in
  0)
    echo "Yes chosen."
   

 

###########################################

clean up old projects
rm -f  /root/bacon-examples/test*

cat << 'EOF' >/tmp/basic-examples
test1.bac
test2.bac
test3.bac
test4.bac
test5.bac
test6.bac
test7.bac
test8.bac
test9.bac
test10.bac
test11.bac
test12.bac
test13.bac
test14.bac
test15.bac
test16.bac
test17.bac
test18.bac
EOF

mkdir -p /root/bacon-examples
cd /root/bacon-examples  #note if not done it goes to root directory
MYURL="http://www.basic-converter.org/"


for i in `cat /tmp/basic-examples`
do xterm  -geometry 40x30+150+40 -e wget -c $MYURL$i


xterm  -geometry 40x30+150+40 -e bacon /root/bacon-examples/$i
Xdialog --title "testing compiler " \
           --infobox "\n$i compiled with bacon .\n" 0 0 3000


BAC_BIN=`basename  "$i" .bac`
xterm -hold  -geometry 40x30+150+40 -e /root/bacon-examples/$BAC_BIN

done
   ;;
  1)
    echo "No chosen."
    exit
   ;;
  255)
    echo "Box closed."
    exit
   ;;

esac






BOTD

Posted: Sun 14 Nov 2010, 17:39
by mechanic
seaside wrote:While the topic is hot, I thought I'd ask about this one..

Program BOTD (aka BaCon On This Day) here http://www.basic-converter.org/botd.tar.gz

It compiles with new BaCon build nicely, but hangs here when run at this point
# ./botd 2 4

---------------------------------------------
On this day in history: 2 April
---------------------------------------------
The following events occurred:
---------------
No error - just stops at this point.

I really want to find out what happened then?? :D :D :D

Cheers,
s

Replace the function CAT(STRING FileName$):

With:

Code: Select all


' --------------------
FUNCTION CAT(STRING FILENAME$)
' --------------------
	LOCAL fileline$, txt$ TYPE STRING
	IF FILEEXISTS(FILENAME$) THEN
		OPEN FILENAME$ FOR READING AS catfile
		WHILE NOT(ENDFILE(catfile)) DO
			READLN fileline$ FROM catfile
			txt$ = CONCAT$(txt$, fileline$, NL$)
		WEND
		CLOSE FILE catfile
	END IF
	RETURN CHOP$(txt$)
END FUNCTION


Recompile and run in a terminal. Works here.

---------------------------------------------
On this day in history: 2 April
---------------------------------------------
The following events occurred:
---------------
2097
1792 : US Mint established
1952 : Bernard Ferdinand Lyot, French astronomer (coronagraph), dies
1958 : 18 km south of Taree, NSW, sealing of Pacific Highway between Sydney and Brisbane completed
---------------
The following persons were born:
---------------
2382
1725 : Giacomo Casanova, Italian writer (+1798)
1805 : Hans Christian Andersen, Danish writer (+1875)
1840 : Emile Zola, French author (+1902)
1914 : Sir Alec Guinness, actor
1926 : Sir Jack Brabham, Australian racing car driver
---------------------------------------------
All in all, a very interesting day.

BaCon binary is much faster than the BaCon script

Posted: Sun 14 Nov 2010, 18:02
by mechanic
Hi Joe, just a suggestion here. After you compile and install the bacon binary use it to compile the examples for a big speed increase.
big_bass wrote:
xterm -geometry 40x30+150+40 -e ./bacon.bash bacon.bac

# copy bacon bin into the path
cp bacon /usr/sbin


Xdialog --title "Complete" \
--infobox "\nInstalling bacon has finished.\n" 0 0 3000
At this point the binary is installed and ready so use it for the tests.

Code: Select all


bacon test1.bac 
...


The binary is MUCH faster than the bacon.bash file.

Posted: Sun 14 Nov 2010, 18:13
by seaside
Mechanic,
Replace the function CAT(STRING FileName$): with....
Thanks, that is indeed somewhat different :D :D

Regards,
s

Posted: Sun 14 Nov 2010, 21:16
by PjotAwake
Hi jpeps,
As noted, the gtk demo from website also gave the error:

~ $ sudo bacon ./gtk-server-new.bac
Starting conversion... done.
Starting compilation... done.
Program './gtk-server-new' ready.
~ $ ./gtk-server-new
ERROR: signal for SEGMENTATION FAULT received - memory invalid or array out of bounds? Try to compile the program with TRAP LOCAL to find the cause.
It seems you are referring to the GTK-server program? This is not a GTK demo, but a demo with the GTK-server.

Did you actually install GTK-server prior to running the BaCon program? Because for me this demo works fine.

Note that you will find actual GTK demo programs a little bit down below on the BaCon website.

BTW why are you using 'sudo'?

Regards
Peter

Posted: Sun 14 Nov 2010, 22:28
by jpeps
PjotAwake wrote:

It seems you are referring to the GTK-server program? This is not a GTK demo, but a demo with the GTK-server.
ah...initially saw it in the gtk-demos dir of bacon.tar.gz, so thought it was independent.
Note that you will find actual GTK demo programs a little bit down below on the BaCon website.
..just tried a few, everything working fine.
BTW why are you using 'sudo'?
As Barry says, it's like religion. I don't run in root. Thanks for the great work!

Posted: Sun 14 Nov 2010, 23:39
by big_bass
Hey mechanic
I took your suggestion and used it for the speed increase (to compile faster)

and updated the bacon auto install script a bit more
updated again to make code much more compact to read a list
this way adding the bac files you need in a snap

thanks
Joe

@Thank you Peter van Eerten

get started on the right foot
one of the little gotchas is just getting the .bac file without the html so this is
only the .bac file
it will save as text hope its handy for some one

-------Demonstration programs---------------------------------------------

Base64 decoder http://www.basic-converter.org/b64dec.bac
The Zeller algorithm http://www.basic-converter.org/zeller.bac
UTF8 encoder http://www.basic-converter.org/utf8.bac
Simple calculator programhttp://www.basic-converter.org/calculator.bac
CGI demonstration http://www.basic-converter.org/cgi.bac
GTK-server demo http://www.basic-converter.org/gtk-server.bac



Brainfuck interpreter http://www.basic-converter.org/bf.bac
Respace files http://www.basic-converter.org/respace.bac
ROT13 encoder/decoder http://www.basic-converter.org/rot13.bac
Mastermind gamehttp://www.basic-converter.org/mastermind.bac
My favorite one liner http://www.basic-converter.org/hex.bac



Recursive http://www.basic-converter.org/fibonacci.bac and http://www.basic-converter.org/factorial.bac
Walk through a directory tree http://www.basic-converter.org/tree.bac
Generate prime numbers http://www.basic-converter.org/prime.bac
Generate m3u files http://www.basic-converter.org/m3u.bac



Convert decimal to Roman http://www.basic-converter.org/roman.bac
A Quine program http://www.basic-converter.org/quine.bac, an even smaller Quine http://www.basic-converter.org/quine2.bac, even smaller http://www.basic-converter.org/quine3.bac
DPI calculator http://www.basic-converter.org/dpicalc.bac created by Vovchik
A simple GOPHER client http://www.basic-converter.org/gopher.bac



System boot time http://www.basic-converter.org/bootime.bac
Binary file dumper http://www.basic-converter.org/bindump.bac
BaCon Bullshit Bingo http://www.basic-converter.org/bbb.tar.gz created by Vovchik
Password generator http://www.basic-converter.org/bpwgen.bac created by Vovchik
Testing randomness program http://www.basic-converter.org/prob.bac created by Vovchik



The Soundex algorithm http://www.basic-converter.org/soundex.bac created by Vovchik
The Metaphone algorithm http://www.basic-converter.org/metaphone.bac created by Vovchik
The Double Metaphone algorithm http://www.basic-converter.org/dbl-metaphone.bac created by Vovchik
BaCon On This Day http://www.basic-converter.org/botd.tar.gz created by Vovchik


Calculate netmask http://www.basic-converter.org/netmask.bac
Console sinus waves http://www.basic-converter.org/sinus.bac
Check remote site http://www.basic-converter.org/network.bac modified version http://www.basic-converter.org/bing.bac by Vovchik
Get the weather http://www.basic-converter.org/bweather.bac created by Vovchik



Benchmark program for http://www.basic-converter.org/benchmark.bac
Binary downloads http://www.basic-converter.org/download.bac
Simple BaCon Shell http://www.basic-converter.org/shell.bac
Some goniometric functions http://www.basic-converter.org/trig.bac created by Vovchik





User contributions

STRCMP function http://www.basic-converter.org/strcmp.bac

Screen size

Posted: Mon 15 Nov 2010, 09:10
by vovchik
Dear Puppians,

I banged this together to demonstrate how you you can use GDK/GTK libs in a CLI program in BaCon to obtain, for instance, the size of the display.

Code: Select all

' *************************************************************
' PROGRAM:	screensize.bac
' PURPOSE:	get X screen size in pixels from default display
' AUTHOR:		vovchik (Puppy Linux forum)
' COMMENTS:	GPL		
' DEPENDS:	bacon 1.0 build 0.19, gtk, gdk libs
' PLATFORM:	Linux (actually, any *nix)
' DATE:		03-10-2010
' VERSION:	0.1a
' *************************************************************

' *********************
' DEF ERROR HANDER
' *********************

TRAP LOCAL
CATCH GOTO PRINT_ERROR

' *********************
' END DEF ERROR HANDER
' *********************


' *********************
' CONSTANTS
' *********************

CONST Gtk$ = "libgtk-x11-2.0.so.0"
CONST Gdk$ = "libgdk-x11-2.0.so.0"

' *********************
' END CONSTANTS
' ********************


' *********************
' DECLARATIONS
' *********************

DECLARE MyScreen$ TYPE STRING

' *********************
' END DECLARATIONS
' *********************


' *********************
' IMPORTS
' *********************

IMPORT "gtk_init(int*,void*)" FROM Gtk$ TYPE void
IMPORT "gtk_exit(int)" FROM Gtk$ TYPE void
IMPORT "gtk_window_get_size(long,int*,int*)" FROM Gtk$ TYPE void
IMPORT "gdk_screen_get_default" FROM Gdk$ TYPE long
IMPORT "gdk_screen_get_width(long)" FROM Gdk$ TYPE int
IMPORT "gdk_screen_height(long)" FROM Gdk$ TYPE int

' *********************
' END IMPORTS
' *********************


' *********************
' FUNCTIONS
' *********************

' ------------------
FUNCTION SCREENSIZE(NUMBER mode)
' ------------------
	' mode = 0 returns x (width)
	' mode = 1 returns y (height)
	' mode = 2 returns space-delimited x (width) and y (height)
	' otherwise function returns error message
	LOCAL x, y TYPE int
	LOCAL myresult$ TYPE STRING
	y = gdk_screen_height(gdk_screen_get_default())
	x = gdk_screen_get_width(gdk_screen_get_default())
	SELECT mode
		CASE 0
			myresult$ = STR$(x)
		CASE 1
			myresult$ = STR$(y)
		CASE 2
			myresult$ = CONCAT$(STR$(x), " ", STR$(y))
		DEFAULT
			myresult$ = CONCAT$("Error: SCREENSIZE(", STR$(mode), ") mode is bad: 0 = w, 1 = h and 2 = h and w.")
	END SELECT
	RETURN CHOP$(myresult$)
END FUNCTION


' *********************
' END FUNCTIONS
' *********************


' *********************
' MAIN
' *********************

gtk_init(0, 0)
MyScreen$ = SCREENSIZE(0)
PRINT MyScreen$
MyScreen$ = SCREENSIZE(1)
PRINT MyScreen$
MyScreen$ = SCREENSIZE(2)
PRINT MyScreen$
MyScreen$ = SCREENSIZE(3)
PRINT MyScreen$
gtk_exit(0)
END

' *********************
' END MAIN
' *********************


' *********************
' ERROR HANDLER
' *********************

LABEL PRINT_ERROR
    PRINT "GTK library ", Gtk$, " is not available on this platform!"
    END

' *********************
' END ERROR HANDLER
' *********************
With kind regards,
vovchik

PS. Nice work, Joe.
PPS. Source and binary are in the attached archive.

Posted: Mon 15 Nov 2010, 14:53
by BarryK
Hey guys, my first GTK application written in BaCon!!!!! :D

http://bkhome.org/bacon/my-1st-gtk-app/index.html

I will be tweaking it a bit more, to get it integrated into Puppy, and with the network setup tools. It is expected to be in all future puppies.

Note, I'm not sure, but it might be necessary to also put this into /etc/wgetrc:

Code: Select all

use_proxy = on
It was a fun experience.

Here is the binary executable, gunzip it, make sure it is executable and bung it somewhere in the path:

Posted: Mon 15 Nov 2010, 16:32
by esmourguit
Bonjour à tous,

I tested it in Toutou Linux 4.3.1, it seems to work. At least, it opens.

As it seems we're at the beginning of the creation (and maybe later adaptation of old scripts) of programs, written with bacon, for new versions of Wary, Quirky, etc., would it be possible to localize them now with a .mo file?
If possible of course.

Cordialement ;)

Posted: Mon 15 Nov 2010, 22:23
by seaside
Barry,

Always nice to try something new....

I get the following problem of cut off characters, not only in your program, but in some of the gui demos as well. See below.

Regards,
s

Posted: Mon 15 Nov 2010, 22:44
by jpeps
Looking forward to a directory of examples using various widgets, which will save a huge amount of trial & error.

Posted: Tue 16 Nov 2010, 00:43
by BarryK
seaside wrote:Barry,

Always nice to try something new....

I get the following problem of cut off characters, not only in your program, but in some of the gui demos as well. See below.

Regards,
s
Vovchik has kindly looked through my code and made some refinements, including improving that problem with big fonts.
I will be updating the application soon.

Posted: Tue 16 Nov 2010, 01:48
by seaside
big_bass ,

Thanks for all that material on BaCon - it makes it very inviting to try out everything.

Also, perhaps a test of bash version would be useful in your script

Code: Select all

BASHV=$(bash --version)
VN=$(echo $BASHV | cut -f1 -d. | sed 's/^.*\(.\)$/\1/')
[ $VN -lt 4 ] && gxmessage -title "Bash Version Problem" -center -bg orange "$BASHV installed 
---------------> Bash must be version 4 <-------------------" & exit
Barry & Vovchik,

Thanks for all your efforts.

Regards,
s

Posted: Tue 16 Nov 2010, 07:03
by jpeps
Any demos of hug radiobuttons? Looks like it should be similar to check buttons with an added group number, but I get segmentation errors after compiling. 'btn_1 = RADIO("text", x, y, grp)' Thanks in advance.

Raio buttons

Posted: Tue 16 Nov 2010, 09:11
by vovchik
Dear jpeps,

In my tests, radio buttons in HUG work exactly as advertised. Try this code:

Code: Select all

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("On", 50, 30, my_radio2)
my_radio2 = RADIO("Off", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
DISPLAY
With kind regards,
vovchik

Re: Raio buttons

Posted: Tue 16 Nov 2010, 11:01
by jpeps
vovchik wrote:Dear jpeps,

In my tests, radio buttons in HUG work exactly as advertised. Try this code:

Code: Select all

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("On", 50, 30, my_radio2)
my_radio2 = RADIO("Off", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
DISPLAY
With kind regards,
vovchik
Thanks vovchik,

And for a group? Specifically, I was looking at:

FUNCTION RADIO (STRING text$, int xsize, int ysize, NUMBER group)

(I did something similar using checkbuttons with a reset function)

Posted: Tue 16 Nov 2010, 14:03
by big_bass
Hey seaside


I used your suggestion and code for the bash test
I just converted it to Xdialog to keep the theme the same
and cut the message down a bit




thanks I will add it to the down loader, compiler, tester

*I added a credit comment to the script for you and mechanic

thanks

Joe

Code: Select all

BASHV=$(bash --version | head -1)
VN=$(echo $BASHV | cut -f1 -d. | sed 's/^.*\(.\)$/\1/')
[ $VN -lt 4 ] && Xdialog --title "bash version test " \
           --infobox "\nBash Version Problem $BASHV installed 
---------------> Bash must be version 4 or above for BaCon <-------------------" "\n" 0 0