Page 8 of 9

Posted: Wed 11 Jan 2012, 07:41
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

Posted: Wed 11 Jan 2012, 14:45
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]



Posted: Thu 12 Jan 2012, 02:20
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

Posted: Fri 13 Jan 2012, 23:06
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?
.

Posted: Tue 17 Jan 2012, 19:56
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...
.

Bacongui

Posted: Sat 27 Apr 2013, 04:30
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--

Re: Bacongui

Posted: Sat 27 Apr 2013, 07:57
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 :?:

Posted: Sat 27 Apr 2013, 14:42
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

Posted: Sat 27 Apr 2013, 17:09
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.!

Posted: Sat 27 Apr 2013, 20:20
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

Posted: Sun 28 Apr 2013, 03:47
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

Posted: Sun 28 Apr 2013, 18:10
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.

Posted: Sun 28 Apr 2013, 21:36
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

Posted: Sun 28 Apr 2013, 21:37
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--

Posted: Sun 28 Apr 2013, 21:53
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

Posted: Mon 29 Apr 2013, 00:22
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.

PL2303

Posted: Fri 13 Sep 2013, 08:33
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).

Posted: Fri 13 Sep 2013, 22:00
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/
.