BaCon Bits

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#151 Post by sunburnt »

I need to check if a config. file`s setting is the same as the current one.

# Can Bacon read a file that assigns variables like Bash can by sourcing?

IF NOT... Then I came up with this code mess:

The Bacon parser errors on the REPLACE line. Says: Can`t parse it.

Code: Select all

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

'# File: /tmp/0 has the line: A = "aaa"

Set$ = "A"
Val$ = "AAA"
Cmd$ = CONCAT$("cat /tmp/0")
Cfg$ = CHOP$(EXEC$(Cmd$))
SPLIT Cfg$ BY NL$ TO Lines$ SIZE Lsize
OPEN /tmp/0 FOR WRITING AS file
FOR i = 0 TO Lsize - 1
	SPLIT Lines$[i] BY " " TO Col$ SIZE size
	IF Col$[0] = Set$ THEN
PRINT Col$[2], "   ", Val$
		IF Col$[2] != Val$ THEN
PRINT Lines$[i]
			REPLACE$(Lines$[i], Col$[2], Val$)
		END IF
	END IF
'	WRITELN Lines$[i] TO file
NEXT
CLOSE FILE file

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#152 Post by big_bass »

Hey sunburnt

GatorDog has several examples using
http://murga-linux.com/puppy/viewtopic. ... &start=114

I tried also to understand the same thing you are trying to do and this is an
example code I made for myself to get an idea how to get the strings into an array

http://murga-linux.com/puppy/viewtopic. ... &start=382

Joe

Code: Select all


COLOR FG TO BLUE
PRINT
PRINT "================================="
PRINT " READ"
PRINT "/etc/rc.d/PUPSTATE"  
PRINT "================================="
PRINT
COLOR RESET




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


WHILE NOT(ENDFILE(myfile)) DO
    READLN txt$ FROM myfile
    IF NOT(ENDFILE(myfile)) THEN
    '---remove all lines that are bash commented # ---'
    SYSTEM ("sed /^#/d /etc/rc.d/PUPSTATE > /tmp/newPUPSTATE")
    '---remove all lines that have bash single quotes  ---'
    SYSTEM ("sed \"s/'//g\"  /tmp/newPUPSTATE > /tmp/newPUPSTATE2")
	PRINT txt$,NL$;  
    ENDIF
WEND
CLOSE FILE myfile
PRINT "--------"



COLOR FG TO BLUE
PRINT
PRINT "================================="
PRINT " WROTE"
PRINT "/tmp/newPUPSTATE2"  
PRINT "================================="
PRINT
COLOR RESET





'--- cat the file into an array using  x$ --'
x$ = EXEC$("cat /tmp/newPUPSTATE2")
SPLIT x$ BY NL$ TO myarray$ SIZE mysize 

'--- this prints all arrays --'
FOR x = 0 TO mysize  - 1
    PRINT myarray$[x]
NEXT 




COLOR FG TO GREEN
PRINT
PRINT "================================="
PRINT " READ arrays"
PRINT "from /tmp/newPUPSTATE2"  
PRINT "================================="
PRINT
COLOR RESET

'--- this prints only the first array --'
PRINT myarray$[0]

'--- this prints only the scecond array --'
PRINT myarray$[1]

'--- this prints only the third array --'
PRINT myarray$[2]



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

#153 Post by sunburnt »

big_bass; Yeah, I thought about just using only the values in a list,
and putting them into an array as Basic likes it.
The amount of code is about the same, and it doesn`t error.

Thanks... Terry

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

#154 Post by sunburnt »

Came up with this simple solution.
READCFG returns the setting value: Val$
WRITECFG modifies the config. file`s setting value.

CfgFile$ = /path/config.file
Set$ = Val$ ................................ Example: FilePath = (/path/file)

Code: Select all

																										' read config. file setting
SUB READCFG(STRING Set$)
	IF FILEEXISTS(CfgFile$) = TRUE THEN
		Cmd$ = CONCAT$("grep ", Set$, " ", CfgFile$, "|cut -d' ' -f3")
		Val$ = CHOP$(EXEC$(Cmd$))
	END IF
END SUB
																										' write config. file setting
SUB WRITECFG(STRING Set$, STRING Val$)
	Cmd$ = CONCAT$("echo \"$(<", CfgFile, ")\" |sed \"s/^", Set$, ".*$/", Set$, " = ", Val$, "/\"")
	New$ = EXEC$(Cmd$)
	SYSTEM CONCAT$("echo \"", New$, "\" > ", CfgFile$)
'	PRINT New$
END SUB
.
# Time to start making executables and function files for this reusable code.

Seems best to make this part of an executable library, just run it...
Easier to use in programs that way rather than writing: INCLUDE (file) (function).

But maybe the INCLUDE parser can be extended with added libraries?
.

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

#155 Post by sunburnt »

No one seems to be responding to vovchik`s thread, so I`ll risk double posting here...

I`m writing a function file to do file I/O for text and arrays.

Strange problem with writing an array to a file.

Code: Select all

SUB OUTARRAY(STRING Txt$[Size], int Size) 
    OPEN File$ FOR WRITING AS file 
    FOR i = 0 TO Size-1 
       WRITELN Txt$[i] TO file 
    NEXT 
    CLOSE FILE file 
 END SUB
Error is: Cause: 'Size' undeclared here (not in a function)
It looks like the Size needs to be a literal declaration.
If so, then passing an array to a SUB can`t be done.

To use a global array not a passed one, limits the usefulness of the function.

The Bacon docs say the array dimension isn`t needed to pass it to a SUB.
But that errors saying:
ERROR: cannot pass string array without dimension at line 54 in file 'test_FileIO.bac'!
So you can pass a numerical array without a dimension, but not a string array?
If that`s the case, then the Bacon docs should mention that little detail...
.

NinerSevenTango
Posts: 186
Joined: Sun 17 Jun 2007, 18:25

Bacongui

#156 Post by NinerSevenTango »

How do I get Bacongui installed in Racy?

I downloaded and compiled BaCon, and am able to compile and run the examples from the web page using Geany.

But when I try to compile Bacongui, it fails, maybe because the version of Bash is 3.0 and it needs 4? There is a Pet for 4, I installed it, but it says the executable is named to Bash4. Am I going to have to change stuff around?

Thanks for any help you can give ...

Damn I hate being such a noob. I tried all this awhile back in Wary and ended up giving up after breaking a bunch of stuff trying to change and install things, when I had to concentrate on work. Decided I'd be better off waiting for a newer Puppy to try to use for Bacon programming.

--97T--

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

Re: Bacongui

#157 Post by L18L »

NinerSevenTango wrote:How do I get Bacongui installed in Racy?
I don't know because I use geany only.
Maybe a pet from http://bkhome.org/blog2/?page=13 will work for you :?:

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#158 Post by seaside »

NinerSevenTango,

I was not able to compile with the new version of bacongui.bac either.

Code: Select all

Problem:
	 file 'bacongui.bac' line 3150: ptr$ = EXTRACT$(var$, "\"-./_()")
Cause:
	 passing argument 1 of 'strdup' makes pointer from integer without a cast [enabled by default]
Try compiling this older version - I have bash 3 and it compiles ok in Precise 5.4.3 using bacon29.

It is very slow starting the first time.

Cheers,
s
Attachments
bacongui.bac.tar.gz
older version of bacongui.bac
(57.84 KiB) Downloaded 387 times

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

#159 Post by sunburnt »

seaside; That`s the same error I was getting.

Compile the latest bacon.bac and use the latest hug.bac
The new command EXTRACT is the problem here...

http://basic-converter.proboards.com/in ... thread=466
http://basic-converter.org/hug.bac

Keep keying the code good buddy.!
Last edited by sunburnt on Sun 28 Apr 2013, 17:58, edited 1 time in total.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#160 Post by seaside »

Sunburnt, great to hear from you. :)

Just got the same type of error compiling the latest bacon.bac 2.1.2 which was being compiled by bacon binary (1.0 build 29 patch 2) on bash 3. # bacon bacon.bac

Code: Select all

Problem:
	 file 'bacon.bac' line 541: ptr$ = EXTRACT$(var$, "\"-./_()")
Cause:
	 passing argument 1 of 'strdup' makes pointer from integer without a cast [enabled by default] 
How did you get it working? :?:

Best regards,
s

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#161 Post by seaside »

Ok, it looks like it has to compile from bacon.bash using bash 4 or bash above 3.

Attached is the Bacon-2.1.2 binary below, in case anyone would like it.

Bacongui still starts slowly first time.

Cheers,
s
Attachments
bacon-2.1.2.tar.gz
bacon-2.1.2 binary compiled in bash 4
(117.7 KiB) Downloaded 399 times

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

#162 Post by sunburnt »

You found the problem before I had a chance to help.!!! Damn it.! :lol:

Yep, Bash-4 is required to compile any newer BaCon files.
I had to patch Puppy-5.4.X.5 and it`s new enough that it should have had 4.!

# Q: What kinds of things are you working/planning on for BaCon?

I`m working on a enhancement that will load/copy SUB/FUNCs to any level.
So SUB/FUNC dependencies can be chained allowing truly reusable code.
SUB/FUNCs currently are only 1 level deep and 1 raw code file beyond that.
So SUB/FUNC libraries will be able to use anyone`s libraries, on and on, etc.

It then writes the HUG INCLUDE and INIT lines, so this is automated,
This is needed as SUBs and FUNCs. can contain HUG widgets.
Then runs bacon on the file to convert and compile it in the normal manner.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#163 Post by seaside »

sunburnt wrote:You found the problem before I had a chance to help.!!! Damn it.! :lol:

Yep, Bash-4 is required to compile any newer BaCon files.
I had to patch Puppy-5.4.X.5 and it`s new enough that it should have had 4.!

# Q: What kinds of things are you working/planning on for BaCon?

I`m working on a enhancement that will load/copy SUB/FUNCs to any level.
So SUB/FUNC dependencies can be chained allowing truly reusable code.
SUB/FUNCs currently are only 1 level deep and 1 raw code file beyond that.
So SUB/FUNC libraries will be able to use anyone`s libraries, on and on, etc.

It then writes the HUG INCLUDE and INIT lines, so this is automated,
This is needed as SUBs and FUNCs. can contain HUG widgets.
Then runs bacon on the file to convert and compile it in the normal manner.
sunburnt,

It is a very rare occasion that I would find out something before you had a chance to..... I'll try to make sure it won't happen again :) (that will not be difficult) :)

I didn't bother to install bash4, I just have the bash4 binary and run "#bash4 bacon.bash bacon.bac" which produces the bacon binary which works just fine in bash 3.

I don't really have anything particular in mind for bacon (perhaps because almost everything that crosses my mind is more in the "tool" category which seems just about as quick in bash as being compiled)

Your work in Bacon sounds interesting and I'll have to check out what you're doing over at the Bacon forum.

Best Regards,
s

NinerSevenTango
Posts: 186
Joined: Sun 17 Jun 2007, 18:25

#164 Post by NinerSevenTango »

seaside wrote:Ok, it looks like it has to compile from bacon.bash using bash 4 or bash above 3.

Attached is the Bacon-2.1.2 binary below, in case anyone would like it.

Bacongui still starts slowly first time.

Cheers,
s
Thank you for that. I downloaded and extracted it, then renamed the file that was in /usr/bin and copied the new one there. When I try to compile bacongui.bac

I get the same error.

Dunno what I'm doing wrong. Also on searching, I see there is a file for (older?) bacongui already there. The reason I was trying to compile it in the first place was because I didn't know it was there, hehe. If there is a launcher for it somewhere in Racy's menu system I didn't find it. LOL.

--97T--

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#165 Post by seaside »

NinerSevenTango wrote:
seaside wrote:Ok, it looks like it has to compile from bacon.bash using bash 4 or bash above 3.

Attached is the Bacon-2.1.2 binary below, in case anyone would like it.

Bacongui still starts slowly first time.

Cheers,
s
Thank you for that. I downloaded and extracted it, then renamed the file that was in /usr/bin and copied the new one there. When I try to compile bacongui.bac

I get the same error.

Dunno what I'm doing wrong. Also on searching, I see there is a file for (older?) bacongui already there. The reason I was trying to compile it in the first place was because I didn't know it was there, hehe. If there is a launcher for it somewhere in Racy's menu system I didn't find it. LOL.

--97T--
NinerSevenTango,

Well, I'm not sure why that happened, but here's a copy of the 2.1.2-bacongui.

Cheers,
s
Attachments
bacongui-2.1.2.tar.gz
bacongui-2.1.2
(146.3 KiB) Downloaded 399 times

NinerSevenTango
Posts: 186
Joined: Sun 17 Jun 2007, 18:25

#166 Post by NinerSevenTango »

Disregard, got it sorted. What I ended up doing was installing bash4, compiling with that, and copying the resulting executable to /usr/bin.
seaside wrote:
Well, I'm not sure why that happened, but here's a copy of the 2.1.2-bacongui.

Cheers,
Thanks, I can use it, I'll work on it and see what's up with it. From Geany, it should be using the executable in /usr/bin, right?

Edit: Using the terminal in /usr/share/bacon, which has the executable you supplied, with the command line bacon bacongui.bac, it still gives the same message, that it choked on the extract command. Hmmm.

Edit 2: Well now I'm confused. With a terminal open in usr/share/bacon, invoking bacon -v returns version 1 build 29. The executable shows today's date and a file size of 401K. Man I hate being such a noob.

Volhout
Posts: 547
Joined: Sun 28 Dec 2008, 08:41

PL2303

#167 Post by Volhout »

Hi,

2 years ago I used BaCon with a FTDI USB device, and got help making this work. Since the FTDI USB device was not part of the kernel, I need an extra library, but in the end, all seemed to work.

Now I am facing something more simple, but that made it even more confusing....

I want to do serial communication using a USB-RS232 converter with a PL2303 chip. On both Slacko 5.3.3 (BaCon 1.0) as well as Precise 5.7.1 (BaCon 2.x) this registers nicely, and I see kernel modules usbserial.ko and PL2303.ko loaded.

The device is connected at /dev/ttyUSB0. This is all perfect. Aint-it ?

But how do I access it from BaCon ??? What header file do I need to include ? On none at all ? Any suggestion is welcome.

I included both BaCon versions, since the new BaCon 2.x may have better (different) support for (usb) serial devices. In the documentation however I still could not find an "OPEN COMx" basic statement.

Since the serial port is far from dead in embedded systems (*), I can imagine support in BaCon is added.

Volhout

(*)= Microsoft removed hyperterminal from W7 (COM=dead?), but that contradicts with languages like python that have support (very simple to use .. compliments).

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

#168 Post by sunburnt »

Hi Volhout; I`m almost certain I saw some code for serial ports at the BaCon forum.
The problem is finding it. Like some Puppy forum threads it`s impossible to find anything.
So unfortunately this valuable info. gets lost virtually for ever.
I`ve been commenting elsewhere about the loss of code and folks efforts...

I`ll keep an eye open and let you know if I find it.
Ask at the BaCon forum: http://basic-converter.proboards.com/
.

Post Reply