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 Tue 23 Sep 2014, 16:36
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 9 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 7, 8, 9, 10, 11, ..., 34, 35, 36 Next
Author Message
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Tue 16 Nov 2010, 11:57    Post subject: Re: Raio buttons  

jpeps wrote:
vovchik wrote:
Dear jpeps,

In my tests, radio buttons in HUG work exactly as advertised. Try this code:

Code:

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("On", 50, 30, my_radio2)
my_radio2 = RADIO("Off", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
DISPLAY


With kind regards,
vovchik


Thanks vovchik,

And for a group? Specifically, I was looking at:

FUNCTION RADIO (STRING text$, int xsize, int ysize, NUMBER group)

(I did something similar using checkbuttons with a reset function)


This seems to work:
Code:

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("One", 50, 30, my_radio3)
my_radio2 = RADIO("Two", 50, 30, my_radio1)
my_radio3 = RADIO("Three", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
ATTACH(mainwin, my_radio3, 20, 80)   

DISPLAY
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Tue 16 Nov 2010, 12:35    Post subject: radio buttons  

Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

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

Joined: 31 May 2008
Posts: 3220

PostPosted: Tue 16 Nov 2010, 13:22    Post subject: Re: radio buttons  

vovchik wrote:
Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

With kind regards,
vovchik


Very Happy

Here's revised code for MyFavorites loader:
(note: points to my own programs, so edit)

http://jpeters.net/apps/MyPrograms2.txt
MyPrograms.png
Description 
png

 Download 
Filename  MyPrograms.png 
Filesize  366.16 KB 
Downloaded  257 Time(s) 

Last edited by jpeps on Tue 16 Nov 2010, 16:50; edited 1 time in total
Back to top
View user's profile Send private message 
2lss

Joined: 20 Sep 2009
Posts: 225

PostPosted: Tue 16 Nov 2010, 15:25    Post subject:  

I gave the source code editor on basic-converter.org a shot and I liked it. So I decided to try adding a few features to make it more like an ide (similar to tinyide)

I added the ability to compile the code (Menu > Build > Compile) and the ability to execute the code ( Menu > Build > Execute).

There are a few issues with each though. When "compile" is clicked, it prompts the user to save the file. If the user clicks yes and the file has not been saved before it will bring up the 'save_as' dialog however, it will compile the code before the 'save' or 'cancel' button is clicked giving an error .

Clicking "execute" will launch xterm (if TERM=xterm) and execute the program. I'm not sure how to make this work with rxvt since it does not have a '-hold' option.

I originally wanted to pipe stdout into a text box widget instead of calling xterm but I was unable to get the pipe to work. Maybe someone else could find the problem. (lines 825 - 846)
source_mod.tar.gz
Description 
gz

 Download 
Filename  source_mod.tar.gz 
Filesize  6.62 KB 
Downloaded  264 Time(s) 
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Thu 18 Nov 2010, 08:29    Post subject:  

Maybe you guys who are BaCon experts can see how this can be done elegantly....

In many shell scripts we have:

. /etc/rc.d/PUPSTATE

Where PUPSTATE is a file, which has something like this in it:
Code:
PUPMODE=12
PDEV1='sr0'
DEV1FS='iso9660'
PUPSFS='sda7,ext3,/w0981011.143/wary_098.sfs'
PUPSAVE='sda7,ext3,/warysave-098.2fs'
PMEDIA='usbcd'
#kernel with libata pata has both sata and pata drives in ATADRIVES...
ATADRIVES='sda '
#these directories are unionfs/aufs layers in /initrd...
SAVE_LAYER='/pup_rw'
PUP_LAYER='/pup_ro2'
#The partition that has the warysave file is mounted here...
PUP_HOME='/mnt/dev_save'
#(in /initrd) ...note, /mnt/home is a link to it.
#this file has extra kernel drivers and firmware...
ZDRV='sda7,ext3,/w0981011.143/zw098114.sfs'
#complete set of modules in the initrd (moved to main f.s.)...
ZDRVINIT='no'
#Partition no. override on boot drive to which session is (or will be) saved...
PSAVEMARK=''


So the problem is how to read in each line in a BaCon program, ignoring comments, and assign those variables so they can be used in the program.

Unlike the INCLUDE operation in BaCon, this has to be a run-time evaluation. I can't quite see how to do it. I suppose an associative array? ...but I would really like to assign each variable independently.

Perhaps there is some obvious way to do it, and I just can't see the obvious.

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
PjotAwake


Joined: 03 Nov 2010
Posts: 34
Location: The Hague, The Netherlands

PostPosted: Thu 18 Nov 2010, 08:34    Post subject:    

Hi 2lss,

Thanks for your contributions. In fact, I have plans for this editor - I would like to add the BaCon converter itself, as a whole, to the program, so it's all embedded in one. We would have a fourth incarnation of BaCon but completely graphical based on GTK.

For the conversion progress, this is something I would rewrite using a Progress Bar.

Furthermore I would add a configuration panel where it is possible to fill in which type of output terminal is being used: xterm, rxvt, Terminal, gnome-terminal. Also in which size it has to appear.

The 'hold' of the terminal, you could embed the execution of the resulting program in a script which simply finishes with a 'read' - this will wait for input from the keyboard.

Tabbing should be added as well.

Syntax completion would be nice but I could not get that to work.

Your additions are a valuable step to these ideas, thanks! So, lots to do, wish there was more time! Smile

Regards
Peter

Last edited by PjotAwake on Thu 18 Nov 2010, 09:06; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
ICQ Number 
PjotAwake


Joined: 03 Nov 2010
Posts: 34
Location: The Hague, The Netherlands

PostPosted: Thu 18 Nov 2010, 09:00    Post subject:  

Quote:

So the problem is how to read in each line in a BaCon program, ignoring comments, and assign those variables so they can be used in the program.

Unlike the INCLUDE operation in BaCon, this has to be a run-time evaluation.


Well that is a difficult thing to do as the program will be compiled - C cannot evaluate strings into actual variable names. An interpreter is needed for that. So you probably end up with a program like the below, which probably can be optimized.

Regards
Peter

Code:

OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle

WHILE NOT(ENDFILE(handle))

    READLN line$ FROM handle

    SPLIT line$ BY "=" TO item$ SIZE dim
   
    IF dim > 0 THEN
        SELECT item$[0]
            CASE "PUPMODE"
                PUPMODE = VAL(item$[1])
            CASE "PDEV1"
                PDEV1$ = item$[1]
            CASE "DEV1FS"
                DEV1FS$ = item$[1]
            CASE "PUPSFS"
                PUPSFS$ = item$[1]
            CASE "PUPSAVE"
                PUPSAVE$ = item$[1]
            CASE "PMEDIA"
                PMEDIA$ = item$[1]
            CASE "ATADRIVES"
                ATADRIVES$ = item$[1]
            CASE "SAVE_LAYER"
                SAVE_LAYER$ = item$[1]
            CASE "PUP_LAYER"
                PUP_LAYER$ = item$[1]
            CASE "PUP_HOME"
                PUO_HOME$ = item$[1]
            CASE "ZDRV"
                ZDRV$ = item$[1]
            CASE "ZDRVINIT"
                ZDRVINIT$ = item$[1]
            CASE "PSAVEMARK"
                PSAVEMARK$ = item$[1]
        END SELECT
    END IF

WEND

CLOSE FILE handle
Back to top
View user's profile Send private message Visit poster's website 
ICQ Number 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Thu 18 Nov 2010, 10:28    Post subject:  

Dear Barry,

This isn't elegant or pretty, but it works. If the varnames are known in advance (and they are), this is one easy way of getting the assignments done.

Code:

OPTION BASE 1
myfile$ = "PUPSTATE"
mygrep$=CONCAT$(" | grep -v ", CHR$(34),"#",CHR$(34))
mycmd$ = CONCAT$("cat ", myfile$, mygrep$)
mypupstate$ = CHOP$(EXEC$(mycmd$))
SPLIT mypupstate$ BY NL$ TO mypuplines$ SIZE pupline_entries
FOR i = 1 TO pupline_entries
   valvar$ = ""
   varname$ = ""
   mypuplines$[i] = REPLACE$(mypuplines$[i],"'","")
   varname$ = LEFT$(mypuplines$[i], INSTR(mypuplines$[i], "=") - 1)
   valvar$ = MID$(mypuplines$[i], INSTR(mypuplines$[i], "=") + 1)
   SELECT varname$
      CASE "PUPMODE"
         PUPMODE$ = valvar$
      CASE "PDEV1"
         PDEV1$ = valvar$
      CASE "DEV1FS"
         DEV1FS$ = valvar$
      CASE "PUPSFS"
         PUPSFS$ = valvar$
      CASE "PUPSAVE"
         PUPSAVE$ = valvar$
      CASE "PMEDIA"
         PMEDIA$ = valvar$
      CASE "ATADRIVES"
         ATADRIVES$ = valvar$
      CASE "SAVE_LAYER"
         SAVE_LAYER$ = valvar$
      CASE "PUP_LAYER"
         PUP_LAYER$ = valvar$
      CASE "PUP_HOME"
         PUP_HOME$ = valvar$
      CASE "ZDRV"
         ZDRV$ = valvar$
      CASE "ZDRVINIT"
         ZDRVINIT$ = valvar$
      CASE "PSAVEMARK"
         PSAVEMARK$ = valvar$
   END SELECT
NEXT i


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


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Thu 18 Nov 2010, 10:57    Post subject:  

I actually did do this in another compiled language ...I don't recall which one, it might have been Genie. On that occasion I think that I used an associative array.

I just tried it in BaCon:

Code:
GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 IF NOT(ENDFILE(handle1)) THEN
  first$=LEFT$(line$,1)
  IF NOT(EQUAL(first$,"#")) THEN
   SPLIT line$ BY "=" TO array$ SIZE dimension
   val$=CHOP$(array$[1],"' ")
   pupstate$(array$[0])=val$
  ENDIF
 ENDIF
WEND
CLOSE FILE handle1

REM test result:
REM retrieves all elements of assoc array:
LOOKUP pupstate$ TO c$ SIZE d
FOR x=0 TO d-1
 PRINT c$[x]
NEXT
REM print one variable:
PRINT pupstate$("PUPSFS")


...yep, that works. It just means that the variable PUPSFS has to be referrred to in the program as pupstate$("PUPSFS") ...I can live with that.

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Thu 18 Nov 2010, 11:22    Post subject: Much better  

Dear Barry,

Nicer solution, to be sure....

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


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Thu 18 Nov 2010, 11:35    Post subject:  

Thanks to Peter who has implemented CONTINUE, I have tidied up the program. It now checks for blank lines and indented '#' comment lines (doesn't test for comments on the end of lines, but that could be done):

Code:
GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 chopped$=CHOP$(line$)
 IF EQUAL(chopped$,"") THEN CONTINUE
 first$=LEFT$(chopped$,1)
 IF EQUAL(first$,"#") THEN CONTINUE
 SPLIT chopped$ BY "=" TO array$ SIZE dimension
 val$=CHOP$(array$[1],"' ")
 pupstate$(array$[0])=val$
WEND
CLOSE FILE handle1

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Ted Dog


Joined: 13 Sep 2005
Posts: 2333
Location: Heart of Texas

PostPosted: Thu 18 Nov 2010, 19:03    Post subject: Can't we just let BASIC die already.......  

Twisted Evil Can't we just let BASIC die already.......

Slightly kidding..

I know it works with tcc according to the website, would be nice to chain them together. so we would not need dev.sfs
Back to top
View user's profile Send private message 
mechanic

Joined: 12 Apr 2009
Posts: 29

PostPosted: Thu 18 Nov 2010, 19:19    Post subject: Another version of assoc arrays  

BarryK wrote:
I actually did do this in another compiled language ...I don't recall which one, it might have been Genie. On that occasion I think that I used an associative array.

I just tried it in BaCon:

Code:
GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 IF NOT(ENDFILE(handle1)) THEN
  first$=LEFT$(line$,1)
  IF NOT(EQUAL(first$,"#")) THEN
   SPLIT line$ BY "=" TO array$ SIZE dimension
   val$=CHOP$(array$[1],"' ")
   pupstate$(array$[0])=val$
  ENDIF
 ENDIF
WEND
CLOSE FILE handle1

REM test result:
REM retrieves all elements of assoc array:
LOOKUP pupstate$ TO c$ SIZE d
FOR x=0 TO d-1
 PRINT c$[x]
NEXT
REM print one variable:
PRINT pupstate$("PUPSFS")


...yep, that works. It just means that the variable PUPSFS has to be referrred to in the program as pupstate$("PUPSFS") ...I can live with that.


Hi Barry, here is an alternate version that I played with when testing the assoc arrays. Yours may be faster, I haven't checked.

Code:


DECLARE prop$ ASSOC STRING

infile$ = "/etc/rc.d/PUPSTATE"
OPEN infile$ FOR READING AS fh
WHILE NOT(ENDFILE(fh)) DO
    READLN txt$ FROM fh
    txt$ = CHOP$(txt$)
   IF EQUAL(LEFT$(txt$, 1), "#") THEN CONTINUE
   l$ = LEFT$(txt$,INSTR(txt$,"=")-1)
   r$ = RIGHT$(txt$,LEN(txt$)-INSTR(txt$,"="))
   prop$(l$) = r$
WEND

PRINT prop$("DEV1FS")
PRINT prop$("ZDRV")
PRINT prop$("PUPSAVE")



PS. Thanks for Puppy Linux!

_________________
regards,
mechanic
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Thu 18 Nov 2010, 21:45    Post subject:  

BarryK wrote:
Thanks to Peter who has implemented CONTINUE, I have tidied up the program. It now checks for blank lines and indented '#' comment lines (doesn't test for comments on the end of lines, but that could be done):


Barry,

This user added contribution function on the website-
Code:
ExtractStr(STRING Main$,STRING Delim$)

might work to return everything to the left of #
Code:
val$=ExtractStr(array$[1],"#")


Regards,
s

(I'm afraid there's probably nothing quite as simple and eloquent as
Code:
 .  VARFILE
) Very Happy
Back to top
View user's profile Send private message 
2lss

Joined: 20 Sep 2009
Posts: 225

PostPosted: Fri 19 Nov 2010, 01:09    Post subject:  

PjotAwake wrote:
Hi 2lss,

Thanks for your contributions. In fact, I have plans for this editor - I would like to add the BaCon converter itself, as a whole, to the program, so it's all embedded in one. We would have a fourth incarnation of BaCon but completely graphical based on GTK.

For the conversion progress, this is something I would rewrite using a Progress Bar.

Furthermore I would add a configuration panel where it is possible to fill in which type of output terminal is being used: xterm, rxvt, Terminal, gnome-terminal. Also in which size it has to appear.

The 'hold' of the terminal, you could embed the execution of the resulting program in a script which simply finishes with a 'read' - this will wait for input from the keyboard.

Tabbing should be added as well.

Syntax completion would be nice but I could not get that to work.

Your additions are a valuable step to these ideas, thanks! So, lots to do, wish there was more time! Smile

Regards
Peter


Glad I could offer some help. I'll keep plugging away at it when I get time.

As far as the terminal "hold" I had a similar thought, but figured the extra script would confuse things. Unless the editor creates/downloads the script when run (similar to the syntax file).....

What do you think about a FIND/HIGHLIGHT option? I found some example C code that might work.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 9 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 7, 8, 9, 10, 11, ..., 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.1249s ][ Queries: 12 (0.0073s) ][ GZIP on ]