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
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#361 Post by sunburnt »

Problem with an associative array: SEGMENTATION FAULT array out of bounds?

Array gives out correct data, clicking a button and calling a sub gets error.
But the button`s ID array is a std. array, not the associative array.
Sub called has widget_ passed to it: SUB btnCLK(int widget_)

Put the files in: "/tmp/apps.sq"
Compile: "sqApps.mnu.bac" and run in rxvt.
Click Menu button and menu Item and it errors calling sub.

It never even makes it to the SYSTEM command, line #65.

Print command shows the associative array is properly filled.

If it finally runs properly, it`ll error because there`s no Squash App. file.
Attachments
AssociativeArrayError.zip
Make dir.: /tmp/apps.sq , copy file to it and unzip it.
(1.34 KiB) Downloaded 512 times

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

#362 Post by GatorDog »

Terry,

Code: Select all

CALLBACK(btnIDs_[i], "btnCLK")
Nix the quotes :P

Code: Select all

CALLBACK(btnIDs_[i], btnCLK)
(interesting code, by the way :idea: )

rod

(IMHO)There doesn't seem to be an exact correlation between button geometry and window geometry in HUG.
Most of the time it doesn't mater, but you're trying to keep this widget compact.
Did this to fit all the buttons vertically in the widget, with a slight visual
spacing between buttons. It may need more fudging when more buttons
are present; but it's a good start.

Code: Select all

'added to variable presets
btnSpc = 2
btnY = btnH + btnSpc
...
'mod'ed these two lines
btnY = btnY + btnH + btnSpc
winH = winH_0 + ( (btnH + (btnSpc * 2)) * btnCNT ) + btnSpc
...

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

#363 Post by sunburnt »

L.O.L. _ _ _ Late night coding, a real quality producer...
The compiler could be better sometimes, but it can`t out-guess dumb!

I`ll look at your spacing to see it`s visual appeal, any other ideas?

Maybe Puppy has a new pop-menu, with sub menus when I get it added.

Thanks Rod ( the GatorDog )

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

#364 Post by sunburnt »

EXEC keeps giving me grief no matter how I try to use it.
What`s wrong with this? ......... Get options from args.

Code: Select all

FOR i = 2 TO 5
	Opt$ = CHOP$(EXEC$("echo", ARGUMENT$, "|cut -d'-' -f", i))
'	IF Opt$ = "" THEN BREAK

PRINT Opt$

NEXT
"echo ....." works from the shell, but not here. Empty output lines.
Tried CONCAT$ also, looks like EXEC$ only sees "echo".

I spent hours trying to get INSTRREV to work, it will not with MID$ !
I got INSTR to work, but decided to take my own advice and do it in the shell.

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

#365 Post by GatorDog »

Code: Select all

Opt$ = CHOP$(EXEC$("echo", ARGUMENT$, "|cut -d'-' -f", i)) 
You just insist on hittin' your thumb with a hammer :P
EXEC$ is seeing 3 strings and a number. 3 strikes you're out.

Code: Select all

Cmd$ = CONCAT$("echo ", ARGUMENT$, "|cut -d'-' -f", STR$(i))
Opt$ = CHOP$(EXEC$(Cmd$))
-----------------------------------------
However, this may serve you better

Code: Select all

SPLIT ARGUMENT$ BY " -" TO Arg$ SIZE Arg_count
That'll give you all the command line arguments.
Arg$[0] is the command/program name
Arg_count gives the number of arguments
Then you can pick them off one-by-one Arg$[1] Arg$[2] ....Arg$[Arg_count]

Note that I used a "space dash" ( " -" ) in the SPLIT as the seperator.
That should preclude a trailing space on the Arg$[] variables.

The Arg$[] number is affected by the use of OPTION BASE 1; adjust accordingly. :wink:

rod

By the way, I didn't actually test any of that. Ye pays yer money and ye takes yer chances! RRR...

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

#366 Post by sunburnt »

Your code works of course... But the Bacon docs are wrong... >:(

Also the command "FILETYPE" doesn`t correctly report a sym. link as "6".
It says it`s a "1", a Regular file. I thought it was reporting the file the link points to.
But I made a link pointing to a link and it still reports it as "1", a Regular file.
Seems "FILETYPE" can`t be relied on for sym. links at least.

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

#367 Post by GatorDog »

Also the command "FILETYPE" doesn`t correctly report a sym. link as "6".
It says it`s a "1", a Regular file. I thought it was reporting the file the link points to.
This is probably something to address in the Bacon Forum. Either to be explained or
if it's a bug, then to be dealt with.

GatorDog

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

#368 Post by sunburnt »

Hey big_bass; The Geany syntax highlighting is great!

Problem with Geany... The filetypes.freebasic selection in Document doesn`t stay that way.

Not a problem with your mod. I know, but I`m sure there`s a simple fix.
Thanks for the help... Terry

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

#369 Post by big_bass »

this is BaCon related news

Bacon and Hug color for forum posts in phpBB code

(it is a scriptable keyword generator ) I chose Bacon to be its first format
to add color to other formats will follow


you'll have fun adding many things to this

http://www.murga-linux.com/puppy/viewto ... 99&start=2

Joe

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

#370 Post by big_bass »

http://murga-linux.com/puppy/viewtopic. ... &start=353
updated Oct-11-2011 to add some missing keywords

if for some reason you just cant click on the file to open it *with color
later I'll post my compiled geany to see if that may be the cause
*or use the same build script just to clear up any doubts


because I have tried this puppy pfix=ram and
just clicking on the file works for me (color is there automatically )
I would like to find out why it isnt working for some people
in order to fix it quickly



@BarryK
Thanks for the comments
I have just seen the link from your blog (I forgot my password to comment there )
I would like this geany fix to be done" correctly" and eventually
be compiled into geany having a bacon.filetype so that we dont clobber freebasic
this is just a small step in that direction

any feedback welcomed
Thanks

Joe

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

#371 Post by big_bass »

now we can use even another very easy message system
using pango-view

http://en.wikipedia.org/wiki/Pango
http://manpages.ubuntu.com/manpages/jau ... oad.1.html
The GTK+ UI toolkit uses Pango for all of its text rendering
my first example code
this Bacon is too cool


Joe

Code: Select all

' *****************************************************
' PROGRAM:	pango-test1.bac
' PURPOSE:	show how to use pango-view
' AUTHOR:	big_bass Joe Arose 
' DEPENDS:	gcc, bacon, pango
' PLATFORM:	linux
' DATE:		Oct 10-2011	
' NOTES:	one more simple message option 
' LICENSE:	GPL version 3 or later
' *****************************************************
' first example using pango-view
' could also be used to debug showing exact line numbers


PRINT "============================="
PRINT "Test 1: Testing pango-view"
PRINT "============================="
PRINT

PRINT "Close box to continue"

' one long command line 
result$ = EXEC$("pango-view  --font=\"DejaVu Sans 12\"  --markup  --text 'This is a DejaVu Sans 12 output on a X screen'")



PRINT "Close box to continue"

' dialog formatting for easy reading notice the new lines  are respected 
result$ = EXEC$("pango-view \
 --font=\"DejaVu Sans 24\" \
 --markup \
 --text 'DejaVu Sans 24 \
 output on a X screen'")

PRINT result$


Attachments
pango-test1.tar.gz
(12.14 KiB) Downloaded 423 times
Last edited by big_bass on Thu 13 Oct 2011, 17:19, edited 3 times in total.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#372 Post by 8-bit »

I just uploaded the package to make Bacon for Slacko RC 5.29.5 at
this location.
You will heed to have the kernel source and devx loaded to compile it.
Run the "bacon.bash" script from the package after extracting the package. You can then copy the bacon binary to a place of your choosing.

Have fun as always.

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

Making noise in BaCon

#373 Post by vovchik »

Dear Puppians,

This is one way to generate sounds simply in BaCon - provided you have the device /dev/audio. I will experiment a bit more with this so that we can get hex strings that correspond to certain frequencies. It will then be possible to create a useful PLAY statement without invoking external libs. Peter's beep and piano demos require the PC speaker, and mine happens to be switched off.:)

Code: Select all

' *****************************************************
' PROGRAM:	bleep.bac (subroutine)
' PURPOSE:	to generate sine, square, triangle,
' 			sawtooth and pulse waveforms simply
' AUTHOR:		vovchik (Puppy Linux forum)
' DEPENDS:	gcc, bacon and device /dev/audio
' PLATFORM:	Puppy Linux (actually, any *nix)
' DATE:		15-10-2011
' *****************************************************


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

OPTION MEMTYPE short

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


' *********************
' SUBS & FUNCTIONS
' *********************

' ---------------
SUB BLEEP(NUMBER mysound, NUMBER myduration)
' ---------------
	LOCAL count, i TYPE NUMBER
	LOCAL wave$[7]
	' check whether audio device exists
	IF FILEEXISTS("/dev/audio") THEN
		' check whether passed sound value is in bounds for array definition
		IF mysound < 0 OR mysound > 6 THEN
			mysound = 2
		END IF
		' check whether sound is not too short or too long
		IF myduration < 10 OR myduration > 3000 THEN
			myduration = 50
		END IF
		' define the various waveforms as a series of hex bytes
		' sine
		wave$[0] = "0F2D3F2D0F030003"
		' square
		wave$[1] = "3F3F3F3F00000000"
		' triangle
		wave$[2] = "00070F1D3F1D0F07"
		' sawtooth plus
		wave$[3] = "3F271A120C080400"
		' sawtooth minus
		wave$[4] = "0004080C121A273F"
		' pulse plus
		wave$[5] = "003F3F3F3F3F3F3F"
		' pulse minus
		wave$[6] = "3F00000000000000"
		' convert hex waveform bytes to binary memvar
		' this bit is necessary because C does not like the null character
		binsize = LEN(wave$[mysound]) / 2
		mybindata = MEMORY(binsize)
		count  = 0
		FOR i = 1 TO LEN(wave$[mysound]) STEP 2
			binbyte = DEC(MID$(wave$[mysound], i, 2))
			POKE mybindata + count, binbyte
			INCR count
		NEXT i
		' generate a sound for a certain duration
		' the actual duration will be processor-specific
		OPEN "/dev/audio" FOR WRITING AS myaudio
		count = 0
		WHILE count < myduration
			' send binary waveform to audio device
			PUTBYTE mybindata TO myaudio SIZE binsize
			INCR count
		WEND
		CLOSE FILE myaudio
		FREE mybindata
	ELSE
		PRINT "Cannot open audio device /dev/audio."
	END IF
END SUB

' *********************
' END SUBS & FUNCTIONS
' *********************


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

FOR i = 0 TO 6
	BLEEP(i, 180)
	SLEEP 200
NEXT i

' *********************
' END MAIN
' ********************
I have also attached the source.

With kind regards,
vovchik

UPDATE. I have added a FREE mybindata right after CLOSE FILE myaudio, just to be proper.
Attachments
bleep.bac.tar.gz
(1.13 KiB) Downloaded 421 times
Last edited by vovchik on Sun 16 Oct 2011, 14:21, edited 3 times in total.

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

#374 Post by GatorDog »

Hi vovchik,

This is pretty cool. 8) I'll be checking it out right now.

rod

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

#375 Post by big_bass »

Hey vovchik

nice example code I ran into the same problem with beep.bac
and tried to get around it but with no luck so I moved on to other things
glad to see you kept at it and posted a solution :D

the code you wrote is intended to simulate beep
or sound ,tones to the speaker

*but it looks a lot like code I used for sending info to the ports
(not your code but what it is doing) back in the old Qbasic days using the OUT command
and I used decimal numbers converted from binary numbers and hex
just so I could read it better for debugging
and hooked up led lights to the port while testing

I didnt use sound but did use waves /pulses
to control stepper motors what you wrote is
a great start for a small robotics project now


Joe

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

#376 Post by big_bass »

I have been trying to get a backend conversion tool (a binary I could call )for BaCon and HUG keyword highlighting bacon2bb thats bacon to phpBB code the format we use in this forum
and I finally got one in Bacon

why ? so we can post some "pretty" code examples here in the forum
since the code thingy we use here in the forum chops up the formatting and doesnt have color
I will expand this to bacon2html and other formats


I was able to get an Idea working in bash
but I really wanted to take a swing at doing it in BaCon

some background info
so this is my second Bacon code attempt
I looked over some of the official examples and some here in the forum
and made very minor edits to get a feel for what is taking place
and then went for it and it works :D

what takes place is all the bacon keywords get coded to be seen as blue
and all the HUG keywords get coded to be seen as green

imagine all the keywords in a file are searched
and replaced automatically so any GUI could call this binary now
I will be able to make a bacon2html or other formats to follow later

Joe


' *****************************************************
' PROGRAM: bacon2bbc.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 17-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

Code: Select all

# ./bacon2bbc /root/bacon-highlighting/hug.bac 
now look at the file all the phpBB code is there

when you post the code in the forum place it between the quote brackets instead that
allows for color to be used [/quote]
Attachments
bacon2bbc.bac.tar.gz
Oct -17-2011 this is greatly improved thanks to GatorDog use this
(3.84 KiB) Downloaded 394 times
Last edited by big_bass on Fri 21 Oct 2011, 15:15, edited 4 times in total.

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

#377 Post by big_bass »

this is an output of code generated by using bacon2bbc in the above post
sometimes just seeing what it does is better than explaining what it does
so any code snippets you want to post can have color now :D
BaCon keywords in blue
HUG keywords in green

Joe
' Imports when HUG is used as shared object
CONST HUG_lib$ = "./hug.so"

' Setup error handling
TRAP LOCAL
CATCH GOTO hug_handle_error

' Import HUG functions
IMPORT "ATTACH(long,long,int,int)" FROM HUG_lib$ TYPE void
IMPORT "BUTTON(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "CALLBACK(long,void*)" FROM HUG_lib$ TYPE void
IMPORT "CALLBACKX(long,void*,long)" FROM HUG_lib$ TYPE void
IMPORT "CANVAS(int,int)" FROM HUG_lib$ TYPE long
IMPORT "CHECK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "CIRCLE(char*,int,int,int,int,long)" FROM HUG_lib$ TYPE void
IMPORT "CLIPBOARD" FROM HUG_lib$ TYPE long
IMPORT "COMBO(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "DISABLE(long)" FROM HUG_lib$ TYPE void
IMPORT "DISPLAY" FROM HUG_lib$ TYPE void
IMPORT "EDIT(int,int)" FROM HUG_lib$ TYPE long
IMPORT "ENABLE(long)" FROM HUG_lib$ TYPE void
IMPORT "ENTRY(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "FILEDIALOG(char*,char*,int,int,int)" FROM HUG_lib$ TYPE long
IMPORT "FOCUS(long)" FROM HUG_lib$ TYPE void
IMPORT "FONT(long,char*)" FROM HUG_lib$ TYPE void
IMPORT "FRAME(int,int)" FROM HUG_lib$ TYPE long
IMPORT "GET(long)" FROM HUG_lib$ TYPE long
IMPORT "GRAB$(long)" FROM HUG_lib$ TYPE char*
IMPORT "HIDE(long)" FROM HUG_lib$ TYPE void
IMPORT "HSEPARATOR(int)" FROM HUG_lib$ TYPE long
IMPORT "HUGOPTIONS(char*)" FROM HUG_lib$ TYPE void
IMPORT "HUGLIB$(char*)" FROM HUG_lib$ TYPE char*
IMPORT "IMAGE(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "INIT" FROM HUG_lib$ TYPE void
IMPORT "KEY" FROM HUG_lib$ TYPE long
IMPORT "LINE(char*,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "LIST(int,int)" FROM HUG_lib$ TYPE long
IMPORT "MARK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "METHOD(long,int,void*)" FROM HUG_lib$ TYPE void
IMPORT "MOUSE(long)" FROM HUG_lib$ TYPE long
IMPORT "MSGDIALOG(char*,int,int,int,int)" FROM HUG_lib$ TYPE long
IMPORT "NOTEBOOK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "OUT(char*,char*,char*,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PASSWORD(int,int)" FROM HUG_lib$ TYPE long
IMPORT "PICTURE(char*,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PIXEL(char*,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PROGRESSBAR(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "QUIT" FROM HUG_lib$ TYPE void
IMPORT "RADIO(char*,int,int,long)" FROM HUG_lib$ TYPE long
IMPORT "REGISTER(long,int,int,int,long,long,long,long)" FROM HUG_lib$ TYPE void
IMPORT "SCREENSIZE(int)" FROM HUG_lib$ TYPE int
IMPORT "SET(long,int)" FROM HUG_lib$ TYPE void
IMPORT "SHOW(long)" FROM HUG_lib$ TYPE void
IMPORT "SPIN(int,int,double,double,double)" FROM HUG_lib$ TYPE long
IMPORT "SQUARE(char*,int,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "STOCK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "SYNC" FROM HUG_lib$ TYPE void
IMPORT "TEXT(long,char*)" FROM HUG_lib$ TYPE void
IMPORT "TIMEOUT(int,void*)" FROM HUG_lib$ TYPE void
IMPORT "TOGGLE(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "UNFOCUS(long)" FROM HUG_lib$ TYPE void
IMPORT "VSEPARATOR(int)" FROM HUG_lib$ TYPE long
IMPORT "WINDOW(char*,int,int)" FROM HUG_lib$ TYPE long

' Define the PROPERTY directive
hug_Gobject$ = HUGLIB$("gobject")
IMPORT "g_object_set(long,char*,...)" FROM hug_Gobject$ TYPE void
PROTO PROPERTY
DEF FN PROPERTY(widget, name, ...) = g_object_set(widget, name, __VA_ARGS__, NULL)

' The dialog response codes
CONST GTK_RESPONSE_ACCEPT = -3
CONST GTK_RESPONSE_DELETE_EVENT = -4
CONST GTK_RESPONSE_OK = -5
CONST GTK_RESPONSE_CANCEL = -6
CONST GTK_RESPONSE_CLOSE = -7
CONST GTK_RESPONSE_YES = -8
CONST GTK_RESPONSE_NO = -9
CONST GTK_RESPONSE_APPLY = -10
CONST GTK_RESPONSE_HELP = -11

' All is well, finish
GOTO hug_import_finish

' Print error
LABEL hug_handle_error
PRINT ERR$(ERROR)
END

' Retsore default error handling
LABEL hug_import_finish
CATCH RESET
TRAP SYSTEM

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

#378 Post by vovchik »

Dear Joe,

That looks great. And the text copies normally - i.e. none of the BB codes get copied when doing copy/paste and grabbing code snippets. I will really have to get used to using your little prog for posting examples...:)

With thanks and kind regards,
vovchik

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

#379 Post by big_bass »

I have this test script and up to here it works I want to expand it but need help
I have a bash command that needs to see arg$[1]
' call this arg-find.bac

TRAP LOCAL
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim

'make a string name from the argument

'--- copy_this$ is the first argument passed from the command line ---
'--- arg$[1] this is a valid bacon argument now ---
'--- give it a string name for clarity ---
copy_this$ = arg$[1]


PRINT "string name is -->" ,"copy_this$" , " it contains this info ",copy_this$
PRINT "this is the name of the program ", arg$[0]
PRINT "this is the first argument " , arg$[1]
PRINT "this is the second argument " , arg$[2]





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

'--- BaCon has its own COPY command I used the above for an easy example only

'***************stuck here *****************************
now how do I get bash to read the value in the arguments
in this example


I know this is the wrong syntax but this is the idea I want to be able to get the arguments
to be seen in bash because I have a command that needs to see arg$[1]
SYSTEM ("echo copy_this$")

I also know this is the wrong syntax but
the actual command shortend is
SYSTEM (replace "this" "forthis" arg$[1])
or SYSTEM (replace "this" "forthis" copy_this$)

any help will be welcomed

Joe
Last edited by big_bass on Wed 19 Oct 2011, 13:28, edited 2 times in total.

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

#380 Post by sunburnt »

Hey Joe ( big_bass ); I`ve wondered how to pass a complete array to bash.

But passing just arg$[1] seems like it would work ( pass by value ).

# A... Probably the same way linux does many things, with files in /tmp

BaCon`s connection to other execs. is very thin and needs improving.
With it`s small command set, BaCon will rely heavily on external execs.
Basic and it`s command set`s very old, I hope Peter makes it more Pascalish.
Mainly it has glaring holes in it`s capability... Plug them up with new commands.

Post Reply