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.
Post Reply
Message
Author
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#106 Post by seaside »

Mechanic,
Replace the function CAT(STRING FileName$): with....
Thanks, that is indeed somewhat different :D :D

Regards,
s

User avatar
PjotAwake
Posts: 34
Joined: Wed 03 Nov 2010, 20:58
Location: The Hague, The Netherlands
Contact:

#107 Post 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

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#108 Post 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!

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

#109 Post 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
Last edited by big_bass on Wed 17 Nov 2010, 14:39, edited 3 times in total.

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

Screen size

#110 Post 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.
Attachments
screensize-src.tar.gz
(10.88 KiB) Downloaded 448 times

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

#111 Post 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:
Attachments
proxy-setup.gz
(24.22 KiB) Downloaded 491 times
[url]https://bkhome.org/news/[/url]

User avatar
esmourguit
Posts: 1410
Joined: Fri 17 Nov 2006, 14:45
Location: Entre l'ile aux oiseaux.et l'ile de sainte Lucie

#112 Post 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 ;)
[url=http://moulinier.net/][color=blue][b]Toutou Linux[/b][/color][/url] - [url=http://toutoulinux.free.fr/pet.php][color=blue][b]Paquets français[/b][/color][/url]

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#113 Post 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
Attachments
proxy-server.png
(28.97 KiB) Downloaded 1431 times

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#114 Post by jpeps »

Looking forward to a directory of examples using various widgets, which will save a huge amount of trial & error.

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

#115 Post 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.
[url]https://bkhome.org/news/[/url]

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#116 Post 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

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#117 Post 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.

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

Raio buttons

#118 Post 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

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Re: Raio buttons

#119 Post 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)

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

#120 Post 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 

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Re: Raio buttons

#121 Post by jpeps »

jpeps wrote:
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)
This seems to work:

Code: Select all

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("One", 50, 30, my_radio3)
my_radio2 = RADIO("Two", 50, 30, my_radio1)
my_radio3 = RADIO("Three", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
ATTACH(mainwin, my_radio3, 20, 80)    

DISPLAY 

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

radio buttons

#122 Post by vovchik »

Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

With kind regards,
vovchik

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Re: radio buttons

#123 Post by jpeps »

vovchik wrote:Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

With kind regards,
vovchik
:D

Here's revised code for MyFavorites loader:
(note: points to my own programs, so edit)

http://jpeters.net/apps/MyPrograms2.txt
Last edited by jpeps on Tue 16 Nov 2010, 20:50, edited 1 time in total.

2lss
Posts: 225
Joined: Sun 20 Sep 2009, 23:54

#124 Post by 2lss »

I gave the source code editor on basic-converter.org a shot and I liked it. So I decided to try adding a few features to make it more like an ide (similar to tinyide)

I added the ability to compile the code (Menu > Build > Compile) and the ability to execute the code ( Menu > Build > Execute).

There are a few issues with each though. When "compile" is clicked, it prompts the user to save the file. If the user clicks yes and the file has not been saved before it will bring up the 'save_as' dialog however, it will compile the code before the 'save' or 'cancel' button is clicked giving an error .

Clicking "execute" will launch xterm (if TERM=xterm) and execute the program. I'm not sure how to make this work with rxvt since it does not have a '-hold' option.

I originally wanted to pipe stdout into a text box widget instead of calling xterm but I was unable to get the pipe to work. Maybe someone else could find the problem. (lines 825 - 846)
Attachments
source_mod.tar.gz
(6.62 KiB) Downloaded 415 times

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

#125 Post by BarryK »

Maybe you guys who are BaCon experts can see how this can be done elegantly....

In many shell scripts we have:

. /etc/rc.d/PUPSTATE

Where PUPSTATE is a file, which has something like this in it:

Code: Select all

PUPMODE=12
PDEV1='sr0'
DEV1FS='iso9660'
PUPSFS='sda7,ext3,/w0981011.143/wary_098.sfs'
PUPSAVE='sda7,ext3,/warysave-098.2fs'
PMEDIA='usbcd'
#kernel with libata pata has both sata and pata drives in ATADRIVES...
ATADRIVES='sda '
#these directories are unionfs/aufs layers in /initrd...
SAVE_LAYER='/pup_rw'
PUP_LAYER='/pup_ro2'
#The partition that has the warysave file is mounted here...
PUP_HOME='/mnt/dev_save'
#(in /initrd) ...note, /mnt/home is a link to it.
#this file has extra kernel drivers and firmware...
ZDRV='sda7,ext3,/w0981011.143/zw098114.sfs'
#complete set of modules in the initrd (moved to main f.s.)...
ZDRVINIT='no'
#Partition no. override on boot drive to which session is (or will be) saved...
PSAVEMARK=''
So the problem is how to read in each line in a BaCon program, ignoring comments, and assign those variables so they can be used in the program.

Unlike the INCLUDE operation in BaCon, this has to be a run-time evaluation. I can't quite see how to do it. I suppose an associative array? ...but I would really like to assign each variable independently.

Perhaps there is some obvious way to do it, and I just can't see the obvious.
[url]https://bkhome.org/news/[/url]

Post Reply