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 21 Oct 2014, 23:41
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon Bits
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 11 of 12 Posts_count   Goto page: Previous 1, 2, 3, ..., 9, 10, 11, 12 Next
Author Message
sunburnt


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

PostPosted: Wed 11 Jan 2012, 03:41    Post_subject:  

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:
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
Back to top
View user's profile Send_private_message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 11 Jan 2012, 10:45    Post_subject:  

Hey sunburnt

GatorDog has several examples using
http://murga-linux.com/puppy/viewtopic.php?t=69647&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.php?t=48901&start=382

Joe


Code:


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]



_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send_private_message 
sunburnt


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

PostPosted: Wed 11 Jan 2012, 22:20    Post_subject:  

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
Back to top
View user's profile Send_private_message 
sunburnt


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

PostPosted: Fri 13 Jan 2012, 19:06    Post_subject:  

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:
                                                                              ' 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?
.
Back to top
View user's profile Send_private_message 
sunburnt


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

PostPosted: Tue 17 Jan 2012, 15:56    Post_subject:  

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:
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...
.
Back to top
View user's profile Send_private_message 
NinerSevenTango

Joined: 17 Jun 2007
Posts: 186

PostPosted: Sat 27 Apr 2013, 00:30    Post_subject: Bacongui  

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--
Back to top
View user's profile Send_private_message 
L18L

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

PostPosted: Sat 27 Apr 2013, 03:57    Post_subject: Re: Bacongui  

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 Question
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sat 27 Apr 2013, 10:42    Post_subject:  

NinerSevenTango,

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

Code:
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
bacongui.bac.tar.gz
Description  older version of bacongui.bac
gz

 Download 
Filename  bacongui.bac.tar.gz 
Filesize  57.84 KB 
Downloaded  170 Time(s) 
Back to top
View user's profile Send_private_message 
sunburnt


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

PostPosted: Sat 27 Apr 2013, 13:09    Post_subject:  

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/index.cgi?board=news&action=display&thread=466
http://basic-converter.org/hug.bac

Keep keying the code good buddy.!

Edited_time_total
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sat 27 Apr 2013, 16:20    Post_subject:  

Sunburnt, great to hear from you. Smile

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

Best regards,
s
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sat 27 Apr 2013, 23:47    Post_subject:  

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
bacon-2.1.2.tar.gz
Description  bacon-2.1.2 binary compiled in bash 4
gz

 Download 
Filename  bacon-2.1.2.tar.gz 
Filesize  117.7 KB 
Downloaded  180 Time(s) 
Back to top
View user's profile Send_private_message 
sunburnt


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

PostPosted: Sun 28 Apr 2013, 14:10    Post_subject:  

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

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.
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sun 28 Apr 2013, 17:36    Post_subject:  

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

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 Smile (that will not be difficult) Smile

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
Back to top
View user's profile Send_private_message 
NinerSevenTango

Joined: 17 Jun 2007
Posts: 186

PostPosted: Sun 28 Apr 2013, 17:37    Post_subject:  

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--
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Sun 28 Apr 2013, 17:53    Post_subject:  

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
bacongui-2.1.2.tar.gz
Description  bacongui-2.1.2
gz

 Download 
Filename  bacongui-2.1.2.tar.gz 
Filesize  146.3 KB 
Downloaded  181 Time(s) 
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 11 of 12 Posts_count   Goto page: Previous 1, 2, 3, ..., 9, 10, 11, 12 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1136s ][ Queries: 13 (0.0149s) ][ GZIP on ]