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
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#481 Post by vovchik »

Dear Terry,

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

http://208.109.22.214/puppy/viewtopic.p ... cb706abdd5

With kind regards,
vovchik

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

#482 Post by e_mattis »

Hey guys,

@ L18L

yea, isn't it funny how such a small mistake can make you look like such a big dummy :oops: ! 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.... :shock: :roll:

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). :D

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?

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

Thanks!

E

.

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

#483 Post by sunburnt »

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: Select all

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.

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

#484 Post by e_mattis »

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? :?

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 :) ):

TEXT(listbox,variable)

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

.

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

#485 Post by vovchik »

Dear e_mattis,

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

Code: Select all

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: Select all

' --------------------
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: Select all

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

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

Peg Solitaire - BaCon version

#486 Post by vovchik »

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: Select all

bacon -o -s -o -Os -o -fdata-sections -o -ffunction-sections -o -Wl,--gc-sections psol-1
Have fun.... :)

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.
Attachments
psol1.png
(20.92 KiB) Downloaded 795 times
psol1.tar.gz
(27.72 KiB) Downloaded 377 times

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

#487 Post by e_mattis »

@ Vovchik

That was exactly what I have been searching for! :D 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 :( but it may just replace my old "time-killer" solitaire card game at this rate!

You, my friend, are awsome! 8)

@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.
Attachments
man_db.png
GUI for manufacturer database
(18.83 KiB) Downloaded 768 times

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

#488 Post by L18L »

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:

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

#489 Post by sunburnt »

The commands are:

Code: Select all

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: Select all

TEXT(widget, GET(index))
Transfer text from widget to widget by widget`s text ( Button, Mark, List, Combo, etc.):

Code: Select all

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.

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

#490 Post by e_mattis »

@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' :D

@sunburnt

Thanks m8, that should help make my coding a little prettier when I feel comfortable that I understand it properly. :) 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

.

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

#491 Post by e_mattis »

Hey guys,

Well, i'm back again :D 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: Select all

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

.

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

#492 Post by vovchik »

Dear e_mattis,

Just a little mod to your code:

Code: Select all

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

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

#493 Post by e_mattis »

Thanks Vovchik!

That was exactly what I needed :D You are AWSOME!

Now all that is left is to construct the 'remove record', 'edit record', and add internationalization. 8)

Almost there! :wink:

Thanks!

E

.

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

#494 Post by e_mattis »

:evil: ok, so i've been working on this like the past 5 hours....

I have created the SUB to remove the unwanted record. The flow I am following is this:

clear gui workarea
find the record selected in list
confirm removal of record
find record in database file
remove record from database file and list
tidy up

I am at the 'confirm removal of record' task. Here is the code I have thus far for this section:

Code: Select all

  killmsg$=CONCAT$("You are about to delete ",kilme$," !")
  kilme_dlg= MSGDIALOG(killmsg$,350,110,1,1)
  SHOW(kilme_dlg)
  CALLBACK(kilme_dlg,killme_btn)
  PRINT kmv
I have the 'killme_btn' FUNCTION outside the above SUB.

Code: Select all

  FUNCTION killme_btn( NUMBER value)
     HIDE (kilme_dlg)
     IF value = GTK_RESPONSE_OK THEN
         kmv = 0
     ELIF value = GTK_REPONSE_DELETE_EVENT THEN
         kmv=1
    END IF
    RETURN kmv
  END FUNCTION
My problem is two-fold; 1. KMV shows '0' as soon as the selection is made in the listbox and does not change after the MSGDIALOG FUCTION :( (value kmv not being returned?) and 2. - this is most likely why there is a problem #1 :oops: - I cannot figure out the process of using buttons with MSGDIALOG (ie how they react/respond or how to manipulate the result of the button being pushed).

I have also tried CALLBACKX(kilme_dlg,killme_btn,dmv) which gave compile errors because dmv is not assigned yet (?) - even when I set it to 0 (dmv=0) beforehand.

In the Winbloze basic i'm familiar with, the code would be :

Code: Select all

CONFIRM"Delete this file?";a$
LOWERCASE$(a$)
  IF a$ = "y" OR a$ = 'yes" THEN dmv=0:GOTO next
  dmv=1
[next]
this would send kmv to the PRINT line as '0' if OK_BTN was pushed or as '1' if the window were closed without the button being pushed.

I would prefer that the yes/no buttons be used in the dialog and want to set it up so that only the 'yes' button would go through to find the selected file in the database.

I have consulted these references for help:

http://www.basic-converter.org/documentation.html

http://www.basic-converter.org/hugdoc.html

http://basic-converter.proboards.com

I still cannot seem to put it all together :cry: Can someone, anyone, please explain how I might get this to work and how to use the MSGDIALOG buttons? All help is greatly appreciated!

Thanks!

E

.
Last edited by e_mattis on Mon 04 Mar 2013, 04:23, edited 1 time in total.

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

#495 Post by Mobeus »

E
Could this be the problem? From http://www.basic-converter.org/hugdoc.html#MSGDIALOG
The dialog can be connected to a callback function which should have two arguments, the first for the dialog and the second for the button.
SUB HandleError(NUMBER dialog, int button)
Your function def is

Code: Select all

FUNCTION killme_btn( NUMBER value) 
Regards,
Mobeus
/root for the home team

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

#496 Post by e_mattis »

Thanks Mobeus,

Yea, I finally figured that part out :oops: my sloppy coding :roll: :lol:

I think I have it working now, however, I need the program to wait, halt, or stop until the MSGDIALOG decision is made (ie. wait until either the 'yes' or the 'no' button are pushed; or the window is closed indicating not to delete the record)

At present, it continues execution while the MSGDIALOG is present, continuing on to the 'END SUB'. Here is what I have atm (kmv is now being returned :D ):

Code: Select all

  killmsg$=CONCAT$(Are yo usure you want to delete ",kilme$," ?")
  kilme_dlg=MSGDIALOG(killmsg$,300,110,1,4)
  SHOW(kilme_dlg)
  CALLBACK(kilme_dlg,killme_btn)
  IF kmv = 1 THEN
      GOTO findrec
  END IF
  GOTO nokill
LABEL findrec
  PRINT "at finding record"
LABEL nokill
PRINT "ending"
END SUB
'ending' is being printed while the MSGDIALOG is being shown. I click the 'yes' button,GUI hides, then nothing happens. I re-click the button on the gui to go into the delete SUB and then the 'at finding record' prints followed by the 'ending' message while the new MSGDIALOG is being shown. :?

I'm familiar with the 'WAIT' command, but how and where do you set it up to pause the program until the MSGDIALOG buttons are pressed? :? :?:

I am thinking of trying this:

Code: Select all

  dmv = 3
  REPEAT
      SHOW(kilme_dlg)
      CALLBACK(kilme_dlg,killme_btn)
       dmv=WAIT(killme_btn, 30)
  UNTIL dmv < 3
OR

Code: Select all

  dmv = 3
  WHILE dmv >= 3
      SHOW(kilme_dlg)
      CALLBACK(kilme_dlg,killme_btn)
  WEND
It is late here, so I will try them and post what happens in the next few minutes or so. Then Ima going to bed!

Thanks!

E

.

[UPDATE]

Both failed :cry:

Using the WHILE/WEND method caused the MSGDIALOG window to pop up with nothing inside it and locked the system up. Strike one :(

Using the REPEAT/UNTIL with 'dmv=WAIT(kilme_dlg,30)' would not compile due to a segmentation fault. Strike Two :evil:

Using REPEAT/UNTIL with 'dmv=WAIT(killme_btn,30)' would not compile due to an integer from pointer error. Strike three- I'm out! :twisted:

Well, off to bed...I'll see what happens with it tomorrow. Meanwhile, any solutions , feel free to post them for me :D

Thanks all!


E

.

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

pausing to get MSGDIALOG input (solved?)

#497 Post by e_mattis »

Hey all,

Well, after a couple of days working at it, I finally got the result I was looking for. :D Here is how I got the program to 'pause' until the MSGDIALOG button was pressed:

Code: Select all

  killmsg$=CONCAT$("Are yo sure you want to delete record ",kilme$," ?")
  kill_dlg=MSGDIALOG(killmsg$,300,100,1,4)
  SHOW(kill_dlg)
  CALLBACK(kill_dlg,killit)
END SUB


SUB killit (NUMBER kill_dlg, int button)
  HIDE(kill_dlg)
  IF button = GTK_RESPONSE_YES THEN
      CALL kilrec
  END IF
END SUB


SUB kilrec
  PRINT "killing record"
END SUB
I want to thank all those who helped me understand how this works. All the responses and inputs were very helpful!

Thanks!

E

.

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

manufacturer db completed

#498 Post by e_mattis »

Hey guys,

Finally completed my first BaCon prog! :D Wo0h0o!

@L18L

Thought you might want to give it a look over with the international finished on it (I hope :roll: ). So here's the whole thing, the prog, the code, and the '.pot' file. Hope you like it! Fair warning, the code is going to be repdative and at times jumpy - but like I said, my first in Bacon :)

Thanks!

E

.
Attachments
manuf_prog_bacon.tar.gz
small flat-file manufacturer contact list/db
(147.36 KiB) Downloaded 570 times

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

manufacturer db completed

#499 Post by e_mattis »

Hey guys,

Finally completed my first BaCon prog! :D Wo0h0o!

@L18L

Thought you might want to give it a look over with the international finished on it (I hope :roll: ). So here's the whole thing, the prog, the code, and the '.pot' file. Hope you like it! Fair warning, the code is going to be repeatative and at times jumpy - but like I said, my first in Bacon :)

Thanks!

E

.
Attachments
manuf_prog_bacon.tar.gz
small flat-file manufacturers contact list/ database
(147.36 KiB) Downloaded 580 times

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

#500 Post by vovchik »

Dear all,

I have been doing a bit of label and svg coding recently and most of the examples are at http://basic-converter.proboards.com/in ... 314&page=3.

I was impressed with SFR's recent DYCP script and did a BaCon port/mod. Here is the source and a Lucid 32-bit binary.

With kind regards,
vovchik
Attachments
bmw-demo.tar.gz
(22.71 KiB) Downloaded 534 times
bmw1.png
(16.07 KiB) Downloaded 643 times

Post Reply