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
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#461 Post by e_mattis »

Thanks guys,

Tried both ways. The method L18L gave is a little more familiar to me. I also was able to get the method sunburnt gave me to work, but it read a little confusing to me. Thank both of you for helping me through it. :D

One thing I found is that the 'callback' must come before the 'display'. that was one thing I had wrong in my original. :oops: (ima still learning :) )

Now to get the subs for the actions working properly. I'll probably be back soon for more assistance!

Thanks

E

.

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

#462 Post by sunburnt »

Okay... Apparently GTK+ reworked the ComboBox.

If you look way back in this thread you`ll see how it use to only work with TIMEOUT.
It`s good to see changes like this, I always thought TIMEOUT was a stupid way to do it.

I just made a download: mirror, distro., and arch. selector GUI with ComboBoxes.

# The Bacon site needs to point out these changes to it`s patrons.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#463 Post by L18L »

e_mattis wrote:... One thing I found is that the 'callback' must come before the 'display'. that was one thing I had wrong in my original. :oops: (ima still learning :) )
Nothing after DISPLAY is executed.
...after DISPLAY don't forget a new line

We all are learning...
... and continue :)

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

#464 Post by vovchik »

Dear L18L,

If you are using HUG - and you are - and you need the screen size in pixels, there is no need to call xrandr or another external utility. HUG has this command:

Code: Select all

SCREENSIZE(dimension)
Type: function
Gets the current screensize in pixels. If <dimension> is 0 then the horizontal size is retrieved, and if <dimension> is 1 the vertical size.
Example:

Code: Select all

x = SCREENSIZE(0)
y = SCREENSIZE(1)
If you use it and have a list of keywords after the INCLUDE "hug.bac" business, don't forget to include SCREESIZE in that list.

With kind regards,
vovchik

PS. COMBO works fine with CALLBACK on my machine.
PPS. I also have the situation with a newline being required at the end of the code - but not on all machines![/code]

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#465 Post by e_mattis »

Hey guys,

Thanks for the input Vov - I was needing that :D

I have another dilema now :( I need to understand how to launch and run another 'script' from within a 'script'.

as example,:

Code: Select all

SUB com_btn2
   SELECT GET(com_btn)
      CASE 0
         PRINT "File Chosen"
      CASE 1
         HIDE (mainwin)
         SYSTEM "exec /opt/myProg"
      CASE 2
         PRINT "Restore Chosen"
etc, etc....

END SUB
I have looked over the docs for Bacon and Hug, this is the closet thing I've found. I am familiar with the 'RUN "program_name" ' call in other basics, but see no such function here.

Any help is very appreciated!

Thanks!

E


[update]...

ok, so I found that adding the '&' would cause the script to launch. :oops:
SYSTEM "exec /opt/myProgram &"
works. Now, is there a means to keep the window close (X) button from showing on the window?

And i'm still trying to figure out how to change font color.

Thanks!



.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#466 Post by L18L »

Dear vovchik,

thanks for your SCREENSIZE hint.
vovchik wrote:...If you use it and have a list of keywords after the INCLUDE "hug.bac" business, don't forget to include SCREESIZE in that list. ...
...and now it is first time that I use hug.bac and a list :roll:
# head -1 m_INCLUDE.bac
INCLUDE "/usr/share/BaCon/hug.bac", INIT, GET, SCREENSIZE, WINDOW, COMBO, CALLBACK, DISPLAY, QUIT, ATTACH, TEXT
#
# time bacon m_INCLUDE.bac
Converting 'm_INCLUDE.bac'... done.
Compiling 'm_INCLUDE.bac'... done.
Program 'm_INCLUDE' ready.

real 0m56.783s
user 0m20.282s
sys 0m0.617s
#
# ls -l m_INCLUDE
-rwxr-xr-x 1 root root 166924 Feb 25 10:27 m_INCLUDE
#
before, always using hug_imports (without a list) only:
# head -1 m_import.bac
INCLUDE "/usr/share/BaCon/hug_imports.bac"
#
# time bacon m_import.bac
Converting 'm_import.bac'... done.
Compiling 'm_import.bac'... done.
Program 'm_import' ready.

real 0m4.561s
user 0m1.757s
sys 0m0.190s
# # ls -l m_import
-rwxr-xr-x 1 root root 61006 Feb 25 10:29 m_import
#
Thus I do not understand why anybody should use hug.bac list
I must be missing something :roll:

With kind regards

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#467 Post by L18L »

e_mattis wrote:... Now, is there a means to keep the window close (X) button from showing on the window?..
and all the others like _
try
x = SCREENSIZE(0) / 3
mainwin = WINDOW("combo example", x, 100)
SETPROPERTY(mainwin, "decorated", FALSE)

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#468 Post by e_mattis »

AH! Thanks L18L! I hadn't thought about properties. :oops:

Have not found all the settings to go with properties, but I am familiar with decorated - I should have realized :D

You guys are the best! Thanks so much!

E

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#469 Post by e_mattis »

Well, i'm back again. :shock:

I'm now trying to learn how to red/write record files using BaCon. I understand the simplest form:

Record <var>
LOCAL <member1> TYPE <type>
LOCAL <member2> TYPE <type>
END RECORD

I have been successful writing a file using this approach. :) I have tried to adapt it to be able to use for multiple records, but have not been able to figure it out. :( Below is the current state of this attempt:

Code: Select all

REM read/write data to file

REM GLOBAL Date$,Rnds$,TF$ TYPE str
GLOBAL Date$ ARRAY 3
GLOBAL Rnds$ ARRAY 3
GLOBAL TF$ ARRAY 3
GLOBAL Rec$ ARRAY 3
LOCAL TF

INCLUDE "/usr/share/BaCon/hug.bac"

FOR a = 1 TO 2


	Date$(a)= "Monday, Feb. 25.2013"

	Rnds$(a)= STR$((0+a)*100)

        TF=a

	TF$(a)= STR$(TF)
	

	RECORD Rec$(a)
		
		PUTLINE Date$(a) TO Rec$
		
		PUTLINE Rnds$(a) TO Rec$ 
		
		PUTLINE TF$(a) TO Rec$
	
	END RECORD

NEXT A
	
 
OPEN "test.dab" FOR WRITING AS handle
	
	FOR b = 1 TO 2
		
		WRITELN Rec$(b) TO handle
	
	NEXT b
 
CLOSE FILE handle



END
However, this returns the following errors at compile:

Code: Select all

# bacon recordtest.bac

Converting 'recordtest.bac'. . . done

Compiling 'recordtest.bac . . . Compiler emits messages!



Problem:
	
	file 'recordtest.bac line 16: END RECORD



Cause:
	
	paramter names (without types) in function decloration [enabled by default]
I'm kinda at a loss :oops: In the program I am working on, I will have 3 variables (date/rnds/tf) with several 'records'. In the other basic languages I am familiar with, this would be done in an csv array using the first element as the record number. So I am wondering if using the CONCAT$ would be a better alternative here, such as

Code: Select all

FOR a = 1 TO 2
...
   Rec$(a) = CONCAT$(Date$(a),":",Rnds$(a),":",TF$(a))
NEXT a

...

FOR b = 1 TO 2
   WRITELN Rec$(b) TO handle
NEXT b
I tried this method but also had an error at compile (not the same error I do not think). So I turn to the master(s) for assistance! Any help is appreciated!

Thanks

E

.

User avatar
Mobeus
Posts: 94
Joined: Thu 26 Aug 2010, 15:49

#470 Post by Mobeus »

E

This got me too when I started learning BaCon. BaCon does not support arrays of records, but it does support records of arrays.

Code: Select all

TRAP LOCAL
CATCH GOTO CATCHERROR

' One record of dynamic arrays
RECORD Rec
    LOCAL Date$ ARRAY 3
    LOCAL Rnds$ ARRAY 3
    LOCAL TF$ ARRAY 3
END RECORD


FOR a = 1 TO 2
	TF=a
	Rec.Date$[a] = "Monday, Feb. 25.2013"
	Rec.Rnds$[a] = STR$((0+a)*100)
	Rec.TF$[a] = STR$(TF)
NEXT

OPEN "test.dab" FOR WRITING AS handle

FOR b = 1 TO 2
	WRITELN CONCAT$(Rec.Date$[b], ":", Rec.Rnds$[b], ":", Rec.TF$[b]) TO handle
NEXT b

CLOSE FILE handle

REDIM Rec.Date$ TO 6
REDIM Rec.Rnds$ TO 6
REDIM Rec.TF$ TO 6

FOR a = 3 TO 5
	TF=a
	Rec.Date$[a] = "Tuesday, Feb. 26.2013"
	Rec.Rnds$[a] = STR$((0+a)*100)
	Rec.TF$[a] = STR$(TF)
NEXT

OPEN "test.dab" FOR APPENDING AS handle

FOR b = 3 TO 5
	WRITELN CONCAT$(Rec.Date$[b], ":", Rec.Rnds$[b], ":", Rec.TF$[b]) TO handle
NEXT b

CLOSE FILE handle

END

LABEL CATCHERROR
PRINT ERR$(ERROR)
END
Regards,
Mobeus

PS. It really doesn't make any sense to me to use records like this. It's less typing to use the dynamic arrays by themselves without wrapping them in a record. :?
/root for the home team

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#471 Post by e_mattis »

Thanks Mobeus!

I believe I better understand it now. :D
I am now working with reading the file (should be able to figure that out on my own - I hope :roll: ) and get deeper into this thing.

Your assistance is very appreciated!

Thanks!

E

[update]

Well, that didn't take long. :(

Apparently the documentation at basic-converter.org is worthless. :evil:

Code: Select all

OPTION BASE 1
LOCAL dimension
SPLIT "one,two,,three" BY "," TO array$ SIZE dimension
FOR i = 1 to dimension
  PRINT array$[i]
NEXT i
I typed in the example given (above) for the 'split' command and it returns an error : "Line 5: SPLIT "one,two,,three" BY "," TO array$ SIZE dimension - expected declaration or statement at end of input" . I replaced the '[ ]' with '( )' (below) and got another error : Line 5... called object 'array$' is not a function.! :twisted:

Code: Select all

OPTION BASE 1
LOCAL dimension
SPLIT "one,two,,three" BY  "," TO array$ SIZE  dimension
FOR x = 1 to dimension
  PRINT array$(i)
NEXT x
Basically, all I am doing is having the user input some information (about 8 - 10 variables total ). I need to write those variables to a file that i can later read and show in a window.

In the 'old school' basic I'm familiar with, it would go something like this:

Code: Select all

INPUT "Name ";name$
INPUT "Date ";Date$
INPUT "Age ";age$

OPEN "test.dab" FOR WRITE AS #handle
  PUT name$;",";Date$;",";age$
Close #handle

OPEN "test.dab" FOR READ AS #handel
 FOR X - 1 to VAL(array$)
     INPUTTO ","; array$
  PRINT array$(x)
NEXT x
This code would take the input, write it to file, then read it, and finally print it to screen.

Maybe i'm just over-frustrated at this point, but Bacon should have a method as simple - I just cannot find it :cry:

I am still trudging along trying to figure this out, so any suggestions is appreciated.

Thanks!

E

.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#472 Post by L18L »

Keep cool
e_mattis wrote:...
Apparently the documentation at basic-converter.org is worthless. :evil:

Code: Select all

OPTION BASE 1
LOCAL dimension
SPLIT "one,two,,three" BY "," TO array$ SIZE dimension
FOR i = 1 to dimension
  PRINT array$[i]
NEXT i
I typed in the example given (above) for the 'split' command and it returns an error : "Line 5: SPLIT "one,two,,three" BY "," TO array$ SIZE dimension - expected declaration or statement at end of input" . I replaced the '[ ]' with '( )' (below) and got another error : Line 5... called object 'array$' is not a function.! :twisted:
...
.
I pasted your example into file in.bac

Code: Select all

INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT
OPTION BASE 1
LOCAL dimension
SPLIT "one,two,,three" BY "," TO array$ SIZE dimension
FOR i = 1 to dimension
  PRINT array$[i]
NEXT i 
and
#bacon in.bac
Converting 'in.bac'... 8
ERROR: missing TO in FOR statement at line 8 in file 'in.bac'!
#

corrected to to TO
and...
# bacon in.bac
Converting 'in.bac'... done.
Compiling 'in.bac'... done.
Program 'in' ready.
# ./in
one
two

three
#
Exactly as expected :D
documentation.html wrote:SPLIT

SPLIT <string> BY <sub> TO <array> SIZE <variable>

Type: statement
So please keep cool 8)
Don't type if you can copy & paste

User avatar
Mobeus
Posts: 94
Joined: Thu 26 Aug 2010, 15:49

#473 Post by Mobeus »

Don't type if you can copy & paste
Watch out if you use Midori 0.2.2 (in Lupu) to open the documentation.html to copy and paste any examples!

This perfectly correct code, copied in Midori and pasted into a .bac file in Geany

Code: Select all

OPEN "data.txt" FOR READING AS myfile
WHILE NOT(ENDFILE(myfile)) DO
    READLN txt$ FROM myfile
    IF NOT(ENDFILE(myfile)) THEN
        PRINT txt$
    ENDIF
WEND
CLOSE FILE 
Gives this when built with BaCon

Code: Select all

# bacon ./pasted.bac
Converting ‘./pasted.bac’... 3
ERROR: could not parse line 3 in file ‘pasted.bac’!
#  
The reason? The white space characters in Midori do not play well with code!
/root for the home team

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#474 Post by L18L »

Mobeus wrote:The white space characters in Midori do not play well with code!
We all are learning! Thanks, good to know that midori is buggy.
seamonkey is OK.
...and copy & paste from console to forum post is working well.

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

#475 Post by sunburnt »

And also using hug_imports.bac is buggy.
Works most of the time, but fails occasionally and it`s a bear to detect.

There`s code at the forum for a menu bar import that hug doesn`t have.
Now if someone would post the import code for the GTK+ grid.

Importing GTK+ compiles much faster than hug.bac.
GTK`s widgets are such a jumble of methods and the code`s a mess.

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#476 Post by e_mattis »

@ L18L

Copied your code for in.bac to my system, ran '#bacon in.bac' in console. Returned error for the ''MISSING TO in FOR ..LINE 6" error. Corrected that, recompiled, got another error :( -

Code: Select all

PROBLEM:
file 'in.bac' line 7: PRINT array$[i]

Cause: 
expected declaration or statement at end of input
Again, code copied directly from your post.

Is it just my system? :?

I'm using precise 5.4.3, Geany, & urxvt terminal.


@Sunburnt

A link to that forum for the menu post?

Thanks guys!

E

.
Last edited by e_mattis on Thu 28 Feb 2013, 02:58, edited 1 time in total.

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#477 Post by e_mattis »

@ Mobeus

Code: Select all

OPEN "data.txt" FOR READING AS myfile
WHILE NOT(ENDFILE(myfile)) DO
    READLN txt$ FROM myfile
    IF NOT(ENDFILE(myfile)) THEN
        PRINT txt$
    ENDIF
WEND
CLOSE FILE 
Thanks! I actually got a file to write and was able to read from it! Now if I can get this "SPLIT" thing to work, I'll be able to to have some data!

Thanks!

E
.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#478 Post by L18L »

e_mattis wrote:@ L18L

Copied your code for in.bac to my system, ran '#bacon in.bac' in console. Returned error for the ''MISSING TO in FOR ..LINE 6" error. Corrected that, recompiled, got another error :( -

Code: Select all

PROBLEM:
file 'in.bac' line 7: PRINT array$[i]

Cause: 
expected declaration or statement at end of input
Again, code copied directly from your post.

Is it just my system? :?

I'm using precise 5.4.3, Geany, & urxvt terminal.
Maybe you did copy exactly i.e. without last new line.
I'm also using precise 5.4.3, Geany, & urxvt terminal
and could reproduce the same error after deleting last empty line.

Code: Select all

# bacon ./in.bac
Converting './in.bac'... done.
Compiling './in.bac'... Compiler emits messages!

Problem:
	 file './in.bac' line 7: PRINT array$[i]
Cause:
	 expected declaration or statement at end of input

# 
vovchik wrote:PPS. I also have the situation with a newline being required at the end of the code - but not on all machines!
Thus the "all systems proof" method would be:
Always have a new line at end of code

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

#479 Post by vovchik »

Dear guys,

There is a reason to use a list after INCLUDE "hug.bac", and there is a reason not to use "hug_imports.bac". If you use a list with "hug.bac", the compilation is faster. I compile a lot, use the latest bacon and hug versions and do not want an extra dependency in my code that is based on the libhug.so that might be present on my machine only - and being different on other machines. That dependency is created by using hug_imports.bac, which uses the shared lib libhug.so.

Also, I am interested in small and self-contained binaries (the smaller the better). For that reason, I use the following compile line:

Code: Select all

bacon -o -s -o -Os -o -fdata-sections -o -ffunction-sections -o -Wl,--gc-sections "$mybaconfile"
and then UPX the binary (the compile line already strips unneeded symbols). This typically gives me 16-25k binaries without any huglib.so dependency issues for GTK apps and 7-10k CLI binaries - much better than 70k+ or larger. I also do this when compiling bacon and bacongui. They weigh in at 61k and 78k respectively after this "treament".

With kind regards,
vovchik

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

#480 Post by sunburnt »

e_mattis ; You can also use Bash to read and write files.

Code: Select all

Txt$ = EXEC$(CONCAT$("cat ", $PathFile))

SYSTEM CONCAT$("echo \"", $Txt, "\" > ", $PathFile)
The read code is good, and I think the write code should be too.


vovchik; Thanks again, the Bacon apps. I`m working on can use a shrinking.

# Also... Could you post code for UPXing the exec.?

Post Reply