Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 27 Nov 2014, 14:35
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon - Bash-based Basic-to-C converter/compiler
Post new topic   Reply to topic View previous topic :: View next topic
Page 32 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 30, 31, 32, 33, 34, 35, 36 Next
Author Message
L18L

Joined: 19 Jun 2010
Posts: 2579
Location: www.eussenheim.de/

PostPosted: Mon 25 Feb 2013, 05:44    Post subject:  

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 Rolling Eyes
Quote:
# 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:
Quote:
# 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 Rolling Eyes

With kind regards
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2579
Location: www.eussenheim.de/

PostPosted: Mon 25 Feb 2013, 06:10    Post subject:  

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
Quote:
x = SCREENSIZE(0) / 3
mainwin = WINDOW("combo example", x, 100)
SETPROPERTY(mainwin, "decorated", FALSE)
Back to top
View user's profile Send private message 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Mon 25 Feb 2013, 12:01    Post subject:  

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

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

You guys are the best! Thanks so much!

E
Back to top
View user's profile Send private message Visit poster's website 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Mon 25 Feb 2013, 15:51    Post subject:  

Well, i'm back again. Shocked

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. Smile I have tried to adapt it to be able to use for multiple records, but have not been able to figure it out. Sad Below is the current state of this attempt:

Code:
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:
# 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 Embarassed 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:
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

.
Back to top
View user's profile Send private message Visit poster's website 
Mobeus


Joined: 26 Aug 2010
Posts: 94

PostPosted: Tue 26 Feb 2013, 17:03    Post subject:  

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:
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. Confused

_________________
/root for the home team
Back to top
View user's profile Send private message 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Tue 26 Feb 2013, 20:23    Post subject:  

Thanks Mobeus!

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

Your assistance is very appreciated!

Thanks!

E

[update]

Well, that didn't take long. Sad

Apparently the documentation at basic-converter.org is worthless. Evil or Very Mad

Code:
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 Evil
Code:
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:
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 Crying or Very sad

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

Thanks!

E

.
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2579
Location: www.eussenheim.de/

PostPosted: Wed 27 Feb 2013, 06:50    Post subject:  

Keep cool
e_mattis wrote:
...
Apparently the documentation at basic-converter.org is worthless. Evil or Very Mad

Code:
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 Evil
...
.


I pasted your example into file in.bac
Code:
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
Quote:
#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...
Quote:
# bacon in.bac
Converting 'in.bac'... done.
Compiling 'in.bac'... done.
Program 'in' ready.
# ./in
one
two

three
#
Exactly as expected Very Happy

documentation.html wrote:
SPLIT

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

Type: statement


So please keep cool Cool
Don't type if you can copy & paste
Back to top
View user's profile Send private message 
Mobeus


Joined: 26 Aug 2010
Posts: 94

PostPosted: Wed 27 Feb 2013, 10:32    Post subject:  

Quote:
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:
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:
# 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
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2579
Location: www.eussenheim.de/

PostPosted: Wed 27 Feb 2013, 14:28    Post subject:  

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.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 27 Feb 2013, 15:48    Post subject:  

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.
Back to top
View user's profile Send private message 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Wed 27 Feb 2013, 22:00    Post subject:  

@ 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 Sad -
Code:
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? Confused

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 Wed 27 Feb 2013, 22:58; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Wed 27 Feb 2013, 22:58    Post subject:  

@ Mobeus

Code:
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
.
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2579
Location: www.eussenheim.de/

PostPosted: Thu 28 Feb 2013, 05:31    Post subject:
Subject description: line feed at end of source code
 

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 Sad -
Code:
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? Confused

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:
# 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
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1287
Location: Ukraine

PostPosted: Thu 28 Feb 2013, 08:57    Post subject:  

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:

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
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Thu 28 Feb 2013, 11:55    Post subject:  

e_mattis ; You can also use Bash to read and write files.
Code:
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.?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 32 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 30, 31, 32, 33, 34, 35, 36 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1303s ][ Queries: 13 (0.0129s) ][ GZIP on ]