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 Wed 01 Oct 2014, 00:20
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: 2507
Location: Moved from Hosla to 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: 1285
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: 5032
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 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Thu 28 Feb 2013, 12:38    Post subject:  

Dear Terry,

Glad to see youa re so busy Smile There is a link to UXP binaries on the forum:

http://208.109.22.214/puppy/viewtopic.php?t=77793&sid=9977951c618ccb16cc4e27cb706abdd5

With kind regards,
vovchik
Back to top
View user's profile Send private message 
e_mattis


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

PostPosted: Thu 28 Feb 2013, 21:35    Post subject:  

Hey guys,

@ L18L

yea, isn't it funny how such a small mistake can make you look like such a big dummy Embarassed ! I went back and sure enough- no line after the end. I put one there and got a good run through. Thanks m8!
@ vovchik

I see what you mean. Tried the hug_imports just for 'grins & giggles' to see what would happen. what a mess! LOL Thanks for the fore-warning!


@ everyone

Now I have more questions.... Shocked Rolling Eyes

I need to incorporate a text-area on my window. Also, I will have a listbox to list the 'records' within a file (i.e. lines of data contained within). Very Happy

I've looked through the docs I have, but do not see any indication of a text area command. I'm sure it is probably something i am overlooking - like multiline or something - so I ask, is there a means of producing multi-lined entry?

As far as the second issue, I have the listbox set up. Question is what would be the best method of inserting data obtained from the read-in of a file? Can I simply create an array and print it to the listbox?

Exclamation You guys are the best! I have gained a lot of insight from you and appreciate it more than I can express. Exclamation

Thanks!

E

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


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

PostPosted: Thu 28 Feb 2013, 22:47    Post subject:  

If you`re using OPEN to read the file then it`s already in an array, correct?
If your using Txt$ = EXEC$(CONCAT$("cat ", $PathFile)) as I suggested then:
Code:
SPLIT Txt$ BY NL$ TO File$ Size fileSz

Now the file`s contents is in the array $File$[]

The MARK is Bacon`s "Label", it only shows text and can do multiple lines.
Back to top
View user's profile Send private message 
e_mattis


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

PostPosted: Thu 28 Feb 2013, 23:48    Post subject:  

Thanks sunburnt,

Yea, the info is already in an array, just not sure how to print it in the list box. assuming the 'MARK' attribute will do that? Confused

Also, the multi lined area is not the listbox. It will actually be a 'notes' area - for entering your personal notations. As an ENTRY box, i would assume there would be some sort of word-wrap or multi-line setting to use in order to accomplish this. Haven't found the code yet though.

Thanks!

E

[update] 022813 23:32 est

Looks like i figured out the print to listbox (finally Smile ):

TEXT(listbox,variable)

Still working on how to make a multi-line ENTRY box, so any help will be appreciated Very Happy

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


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Fri 01 Mar 2013, 04:41    Post subject:  

Dear e_mattis,

This may or may not be what you are after, but HUG's EDIT box allows for multiple lines:

Code:

EDIT(xsize, ysize)
Type: directive
Defines a multiline text widget with a width of <xsize> and a height of <ysize>.
Returns the ID of the created text widget.


With kind regards,
vovchik

PS. For reading in text files, which I do often, I use my own hand-rolled CAT command:

Code:

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

x$ = CAT("/etc/profile")
PRINT x$


And, as sunburnt has said, if you use NL$ as your SPLIT delimiter, every separate line will be an array element. If you don't want to use arrays, you can always use my little GETWORD$ function:

Code:

' --------------
FUNCTION GETWORD$(STRING mystring$, NUMBER word_number, STRING delimiter$)
' --------------
   LOCAL  i, mypos, n TYPE NUMBER
   LOCAL string_temp$ TYPE STRING
   i = 0
   mypos  = 0
   n = 1
   string_temp$ = ""
   mystring$ = CONCAT$(mystring$, delimiter$)
   REPEAT
      mypos  = INSTR(mystring$, delimiter$, n)
      INCR i
      IF i = word_number THEN
         string_temp$ = MID$(mystring$, n, (mypos - n))
      END IF
      n = mypos + 1
   UNTIL mypos IS FALSE
   RETURN string_temp$
END FUNCTION

x$ = CAT("/etc/profile")
' grab first line
y$ = GETWORD$(x$, 1, NL$)
PRINT y$
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Fri 01 Mar 2013, 06:22    Post subject: Peg Solitaire - BaCon version  

Hi guys,

This is a little game I programmed in Bacon durng the summer but revised it today to take into account the stricter type casting in newer BaCon versions. The excercise was interesting, at least to me, for a number of reasons:

The graphics are all internal to the source - they are generated internally and not loaded from disk.

The program shows how to change mouse cursors and how to create a unique taskbar icon.

My implementation, after some long and hard thought, avoids any real movement of objects. They are simply hidden or shown, and I keep track of thier status.

The rsvg lib is put to good use, and gtk and gkd imports are used because native HUG did not have them.

The program demostrates how to REGISTER new widgets in HUG.

I compiled the binary in lucid (using Bacon beta 1.30 and hug 0.83) and then UPX'd it, so it is not large (23k).

The compile line was:

Code:

bacon -o -s -o -Os -o -fdata-sections -o -ffunction-sections -o -Wl,--gc-sections psol-1


Have fun.... Smile

With kind regards,
vovchik

PS. The game is winnable, but it ain't easy. Press the Help button for instructions on how to play. The archive contains a compiled binary and the source.
psol1.png
 Description   
 Filesize   20.92 KB
 Viewed   413 Time(s)

psol1.png

psol1.tar.gz
Description 
gz

 Download 
Filename  psol1.tar.gz 
Filesize  27.72 KB 
Downloaded  167 Time(s) 
Back to top
View user's profile Send private message 
e_mattis


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

PostPosted: Fri 01 Mar 2013, 12:02    Post subject:  

@ Vovchik

That was exactly what I have been searching for! Very Happy Never thought it would be listed as 'edit'. Thanks so much!

Also like the 'getword function'. may make it easier to accomplish what I will need. I will give it a shot!

Nice game, too! Haven't gotten to play it much yet, no wins Sad but it may just replace my old "time-killer" solitaire card game at this rate!

You, my friend, are awsome! Cool

@everyone

I really appreciate all your inputs. It is important to me that I learn how to make a 'program' for Puppy as I intend for this OS to be my goto in the future. Thank you so much!

Thanks!

E

PS: So you guys will get an idea, here is a screen of what I'm working on.
man_db.png
 Description   GUI for manufacturer database
 Filesize   18.83 KB
 Viewed   399 Time(s)

man_db.png

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

Joined: 19 Jun 2010
Posts: 2507
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Fri 01 Mar 2013, 13:48    Post subject:  

e_mattis wrote:
PS: So you guys will get an idea, here is a screen of what I'm working on.
No country, no internationalization.
Globalisation disabled. Wink
Back to top
View user's profile Send private message 
sunburnt


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

PostPosted: Fri 01 Mar 2013, 13:58    Post subject:  

The commands are:
Code:
TEXT for entering or changing text in a widget.
GRAB$ for getting text from a widget.

This transfers text from widget to widget by widget`s index ( List or Combo ):
Code:
TEXT(widget, GET(index))

Transfer text from widget to widget by widget`s text ( Button, Mark, List, Combo, etc.):
Code:
TEXT(widget, GRAB$(widget))


It sounded like you were looking for a Label widget, sorry...

Looking at your GUI, it looks like it could be for both display and entry.
To enter or edit an item use a ENTRY, to display text only use a MARK.
Back to top
View user's profile Send private message 
e_mattis


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

PostPosted: Fri 01 Mar 2013, 22:20    Post subject:  

@L18L

Yea, sorry bud, haven't gotten to putting in the internationalization yet. Gotta get my coding right first for the basis, then I can get 'fancy' Very Happy

@sunburnt

Thanks m8, that should help make my coding a little prettier when I feel comfortable that I understand it properly. Smile And you are correct, it will be used to both enter and view information. Figure editing can be done by changing displayed info and then saving.

Thanks you guys - all the help has made it possible for me to actually write stuff! I know I will need your inputs as I trudge through on this journey. It is great to know I can count on some assistance along the way!

Thanks!

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: Sat 02 Mar 2013, 23:44    Post subject:
Subject description: opening web page via variable
 

Hey guys,

Well, i'm back again Very Happy I have run into a situation I can't resolve with my limited knowledge.

I have an ENTRY box t input a web address. When the entry is reviewed, if desired, I have a button to launch the web browser to the address listed in the ENTRY box.

Here is how I have it set up at the present. it opens the browser but instead of the web page I get the 'FILE:///' index:

Code:

webz$=GRAB$(webaddy)
IF LEFT$(webz$,7) = "http://" THEN doit
   webz$=CONCAT$("http://",webz$)
END IF

LABEL doit

SYSTEM "exec defaultbrowser webz$ &"




would it work better to just use the GRAB$ in the SYSTEM cmd? If the http:// is not included in webaddy, would this disrupt the flow?

Thanks!

E

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


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 03 Mar 2013, 04:30    Post subject:  

Dear e_mattis,

Just a little mod to your code:

Code:

SUB LAUNCH_BROWSER(STRING my_url$)
  SYSTEM CONCAT$("exec defaultbrowser ",  my_url$, " &")
END SUB

webz$=GRAB$(webaddy)
IF LEFT$(webz$, 7) = "http://" AND LEN(CHOP$(webz)) > 7 THEN
  LAUNCH_BROWSER(webz$)
ELIF LEN(CHOP$(webz$)) > 1 THEN
  webz$ = CONCAT$("http://", webz$)
  LAUNCH_BROWSER(webz$)
ELSE
  PRINT "Bad URL. Try again."
END IF


I am assuming you want to make sure that you include the "http://" before you pass the URL to the browser, so you want a properly formatted URL. The tests for validity above are, of course, not good or exhaustive. You could "ping" the site to ensure that it exists first - or use BaCon's networking function - to see that it is responding before launching your browser.

With kind regards,
vovchik
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.1162s ][ Queries: 12 (0.0133s) ][ GZIP on ]