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 30 Sep 2014, 05:48
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 8 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 9, 10, 11, 12 Next
Author Message
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Fri 30 Sep 2011, 14:02    Post subject:  

Quote:
If hug_imports.bac hasn't been edited, it has a path set to /usr/lib/hug.so

thats not correct the official file is here (maybe you have an already edited file )
http://www.basic-converter.org/hug_imports.bac.html

I stand corrected Embarassed
-----------------
Just had a power outage Evil or Very Mad
So I booted a fresh pup 528 into memory (pfix=ram).
- /usr/lib/hug.so is there.
- /usr/share/BaCon/ dir is there with two lang definition files. (For nicoedit and vim I think)

I ran a couple of bacon programs that were compiled with hug_imports.bac pointing to /usr/lib/hug.so
One file ran fine. The other failed. It expected a feature available in a later hug verson. (see below)

This points to a need for version tracking for hug. Bacon has a reserved variable $VERSION, but
this is for bacon itself and does not apply to hug.

The only way I know to find the hug version number is to open hug.bac. Peter maintains a commented
section there that includes the hug version number.

I've been backing up older files by naming them (for example) hug.59.so, hug.60.so, etc.

Simply having /usr/lib/hug.so (or libhug.so) gives no clue to what your working with.
In earlier post in this thread, I made tar files for the latest (beta) versions of hug as they became available.

Another point I'll mention; the hug_imports.bac version is loosely tied to the hug.bac/hug.so version.
To wit-
- hug_imports.bac is the mechanism to load HUG features from the shared library, hug.so
- When Peter adds a new HUG feature, hug_imports.bac is updated to include loading those new features.
- If a program is compiled with the new hug_imports.bac, it expects all the features are available in /usr/lib/hug.so
- If hug.bac is only updated for a bug fix, then hug_imports.bac version doesn't change, as there is no new features added.
. (Probably an oversimplification but works for this discussion)
- This is why the second program I tried didn't run. The program was compiled with a newer hug_imports, which was looking for
. /usr/lib/hug.so, which it found. However, that hug.so is outdated (pup 528), so the program failed because it couldn't
. import a feature from hug.so

So version control is another issue to consider when offering bacon programs for Puppy.
I really don't want to be limited to the "offical" hug version in Puppy. The current beta versions of Bacon, hug and hug_imports
have several bug fixes and some new features.

I don't follow gtkDialog closely, but it seems that it too is under development. Therefore new scripts require the latest gtkDialog version.
So, wonder how that is being addressed?

In conclusion, to shoot for success, this is what I've done with the programs that I've recently posted.
1.) I include the source code. Anyone that has bacon set up can compile it on their machine.
. They can use hug_imports.bac for the smallest possible program. And I comment in the
. source what versions of bacon, hug etc. were used.
2.) I include a "standalone" version of the binary/executable program. This is compiled using INCLUDE ".../hug.bac".
. It makes for a significantly larger program, but, it should only have common linux dependencies, (gtk etc.) and
. should run independent of any bacon related settings or programs.

Your Mi!eage May Vary,
GatorDog
Back to top
View user's profile Send private message 
sunburnt


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

PostPosted: Fri 30 Sep 2011, 16:17    Post subject:  

Hey guys, an item I looked into that GatorDog spoke of.

I ran "dd" on hug.so to see if I could find it`s version.
I found "1.0 build 24 beta r3" about half way down the output in rxvt.
Code:
dd if=hug.so [of=hug.dd]

Providing the "of=" to make an output file just makes another copy of hug.
It seems to throw rxvt for a loop, I had to shut it down after doing this.

I can`t get sed to do anything with the output as it`s a binary file.
dd can convert, but I don`t know what it`s capabilities are.
If the output could be convert to text then sed might work.
It`s just one big long string with no LF or CR so grep isn`t much good.
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Fri 30 Sep 2011, 17:44    Post subject:  

sunburnt wrote:
Hey guys, an item I looked into that GatorDog spoke of.

I ran "dd" on hug.so to see if I could find it`s version.
I found "1.0 build 24 beta r3" about half way down the output in rxvt.
Code:
dd if=hug.so [of=hug.dd]

Providing the "of=" to make an output file just makes another copy of hug.
It seems to throw rxvt for a loop, I had to shut it down after doing this.

I can`t get sed to do anything with the output as it`s a binary file.
dd can convert, but I don`t know what it`s capabilities are.
If the output could be convert to text then sed might work.
It`s just one big long string with no LF or CR so grep isn`t much good.


Hey sunburnt,

How about the command "strings".

Regards,
s
Back to top
View user's profile Send private message 
sunburnt


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

PostPosted: Fri 30 Sep 2011, 20:45    Post subject:  

SeaSide; That did it !!! I`m always amazed at the number of exec. there are.
Unix has been around sooo long that there`s a file for almost everything.

This gets the "build version" from /usr/lib/hug.so
Code:
strings /usr/lib/hug.so |grep ' build '
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Fri 30 Sep 2011, 22:08    Post subject:  

seaside,
Wow!
strings
Who knew?

Thank you for taking time to share that. That's (another) one I hadn't run into before.

sunburnt,
The "build" that is reported is the version of "Bacon" that was used to generate the hug.so file.
So the search goes on.
-------------------

hug_imports.bac looks for hug.so
Q. If a new version of hug.so includes the version number (hug.62.so), can a pet package not only
put it in /usr/lib/ but also take care of linking hug.so/libhug.so to the new hug.62.so?

GatorDog
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Fri 30 Sep 2011, 23:04    Post subject:  

Hey guys

great ideas

probably the fastest most secure way of knowing for sure its the right one is just
Code:
md5sum /usr/lib/libhug.so

Code:
md5sum /usr/lib/hug.so


then place that in the source code

in the header maybe the third line down of hug_imports.bac
then quickly use sed or the head command to get the value
or place it in an array if its always in the same place

how about this for keeping up to date with Bacon
to avoid old files in the first place this is what I use
*if you want to use hug.so instead just edit the code
the default is libhug.so (this way I dont clobber your hug.so )



used on the new *.so
Code:

md5sum libhug.so >md5sum_libhug.txt
MD=$(<md5sum_libhug.txt)
sed -i "2a \'$MD " hug_imports.bac

to keep your thread cleaner to read I'll point to the full source code
http://www.murga-linux.com/puppy/viewtopic.php?t=72136&start=3

Joe

_________________
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: 5032
Location: Arizona, U.S.A.

PostPosted: Sun 02 Oct 2011, 08:18    Post subject:  

Looks like with all this version problem, compiling with hug.bac is the way to go.
Develop with hug_imports.bac for a fast compile, and use hug.bac for the final app.
Seems to only add about 100 KB or so to the size. For GUIs that`s okay.
And any cli or code only app. ( no GUI ), I would write in Bash anyway.


# A thought... Each compile the same hug.bac file is compiled.
Why not compile it once into hug.so and then include it in the app.?

I assume Peter would have already done this if he could have.
But what`s the problem with adding already compiled code?
As I understand it, the include code gets pasted in at the line of the include.
And the include is the first line in the file, do a "join" files?

I`m sure there`s start points in ram for the calls to hug, etc., etc., etc.
But wouldn`t these be the same for all apps.?

A new compiler would be needed I suppose... Just thinking...
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Sun 02 Oct 2011, 18:20    Post subject:  

Quote:
Why not compile it once into hug.so and then include it in the app.?
...
And the include is the first line in the file, do a "join" files?
Why not compile it once into hug.so and then include it in the app.?

The INCLUDE file is a text file. Similar to a dot file ( . filename ) in bash.
You're right, the text gets pasted in at that position.

From BaconGUI (and probably from the command line too), there is an option to
save the intermediate c-code. There is also a Bacon command "USEC" that allows
using c-code in a Bacon program. So in theory, the c-code could be generated
and use in a bacon program. But I'll bet that'd be a can of worms. Rolling Eyes

g
Back to top
View user's profile Send private message 
sunburnt


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

PostPosted: Sun 02 Oct 2011, 22:11    Post subject:  

A can of worms it certainly sounds like, but a promising approach.
Someone like Peter would have little problem with the concept.

Like Basic itself, a next layer of code is needed to streamline the methods.
Like so many languages and other tools I see, too much code to do the job.
You look at what`s needed to describe what`s wanted and it`s not much at all.
Hug is pretty straight forward, and it`s syntax is way better than gtkDialog.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 31 Oct 2011, 06:03    Post subject: Bacon port of "resizepfile"
Subject description: Using Bacon's Associative arrays
 

"resizepfile.sh" is a Puppy script to resize the Puppy save file.
This program is a port of the resizepfile script to a Bacon program.
In particular it makes use of Bacon's Associative array.
Quote:
An associative array is an array of which the index is determined by a string, instead of a number. Associative arrays use
round brackets '(…)' instead of the square brackets '[…]' used by normal arrays.

An associative array can use any kind of string for the index, and it can have an unlimited amount of elements.

Code:
fullname$("bob") = "Robert Fuller"
fullname$("jane") = "Janet Jenkins"
name$ = "bob"
PRINT fullname$(name$)

Output: Robert Fuller
EDIT: Corrected missing "$" on variable name.

The resizepfile shell script uses an external file (/etc/rc.d/PUPSTATE) to retrieve variables and their values.
The variables are in shell syntax. ie. variable = 'text'. This syntax is decoded and assigned
values in Bacon using an associative array.

This is the contents of (my) /etc/rc.d/PUPSTATE:
Code:
PUPMODE=12
PDEV1='sr1'
DEV1FS='iso9660'
PUPSFS='sda1,vfat,/l5281108.173/lupu_528.sfs'
PUPSAVE='sda1,vfat,/lupusave-528_IM-.3fs'
PMEDIA='cd'
#ATADRIVES is all internal ide/pata/sata drives, excluding optical, excluding usb...
ATADRIVES='sda '
#ATAOPTICALDRIVES is list of non-usb optical drives...
ATAOPTICALDRIVES='sr0 sr1 '
#these directories are unionfs/aufs layers in /initrd...
SAVE_LAYER='/pup_rw'
PUP_LAYER='/pup_ro2'
#The partition that has the lupusave 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=''
#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=''

The variable name (ex. PUPMODE) will be used for the associative arrays index (ex. Pupstate$("PUPMODE")
I used a SUB-routine to translate the shell variables. Here is commented code.
Code:
' ------------------
SUB READ_PUPSTATE_VARIABLES
' ------------------
   ' Declare the associative array
   DECLARE Pupstate$ ASSOC STRING

   ' Open the file for reading
   OPEN Pupstate_file$ FOR READING AS Filehandle_

   ' Check for end of file
   WHILE NOT(ENDFILE(Filehandle_)) DO

      ' read in line by line
      READLN Pass$ FROM Filehandle_

      ' CHOP$ - remove leading/trailing space, tab, CR, etc.
      Pass$ = CHOP$(Pass$)

      ' If line begins with "#" it's a comment.
      IF LEFT$(Pass$, 1) = "#" THEN
         'Dump bash comment lines
         CONTINUE
      END IF

      ' If line contains "=", there's a variable assignment going on.
      IF INSTR(Pass$, "=") THEN

         ' Break line up using "=" as seperator
         ' Arg$[1] will be variable name. Arg$[2] is the value.
         SPLIT Pass$ BY "=" TO Arg$ SIZE na

         ' Replace the single quotes with null
         Pass$ = CHOP$(REPLACE$(Arg$[2], Single_quote$, ""))

         ' Set up variable = value
         Pupstate$(Arg$[1]) = Pass$
      END IF
   WEND
   ' Close file
   CLOSE FILE Filehandle_
END SUB

This is a simple use of associative arrays. There are some extended examples in the Bacon reference pages.
The rest of the program implements the actions of the shell script along with the addition of a GUI.

GatorDog
resizepfile.png
 Description   
 Filesize   36.56 KB
 Viewed   850 Time(s)

resizepfile.png

Bacon-resizepfile-src.tar.gz
Description  Bacon source code for resizepfile.bac
gz

 Download 
Filename  Bacon-resizepfile-src.tar.gz 
Filesize  3.64 KB 
Downloaded  244 Time(s) 

Last edited by GatorDog on Mon 31 Oct 2011, 14:59; edited 1 time in total
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Mon 31 Oct 2011, 10:43    Post subject:  

Hey GatorDog

thanks for posting that http://www.murga-linux.com/puppy/viewtopic.php?t=69647&start=114 (I had already ported the old xmessage resizepfile.sh
to Xdialog and added larger save options) so going over your BaCon version
will be easier for me to understand and follow this new associative array in action
thanks this will be fun to learn in Bacon Very Happy

*I know this is a BaCon thread but only to ease into understanding what is happening
the equivalent bash4 example is given below using your example converted to bash4

GatorDog
Quote:
# associative array Bacon example
fullname("bob") = "Robert Fuller"
fullname("jane") = "Janet Jenkins"
name = "bob"
echo $fullname($name)




big_bass
Code:
# bash4 associative array equivalence to the Bacon example above

declare -A fullname
#       -A option declares associative array.

fullname[bob]="Robert Fuller"
fullname[jane]="Janet Jenkins"


echo "bob's fullname is ${fullname[bob]}."
echo "jane's fullname is ${fullname[jane]}."

echo "${!fullname[*]}"   # The array indices used


Joe

_________________
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 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 31 Oct 2011, 11:49    Post subject:  

Hi Joe,

To further the comparison a little, LOOKUP is used to get the array indices in Bacon.
(LOOKUP works similar to the SPLIT command)
LOOKUP <assoc> TO <array> SIZE <variable>
Code:
LOOKUP Pupstate$ TO Index_name$ SIZE Count

and to access -
Code:
FOR x = 0 TO Count - 1
    PRINT Index_name$[x]
NEXT


GatorDog
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Thu 03 Nov 2011, 09:36    Post subject: Links to example programs in this thread  

Edited first post to include these links to example programs in this thread.

Video-Play
HKP - Hug Keyword Parser
Start of "Hello Bacon (World)"
More Hello Bacon
Even More Hello Bacon
Still more Hello Bacon
Hello Bacon - a complete app
Bacon File I/O
Bacon port of resizepfile "Resize pup personal save file"

GatorDog
Back to top
View user's profile Send private message 
sunburnt


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

PostPosted: Tue 08 Nov 2011, 17:00    Post subject:  

Hi guys; Thought I`d ask before just doing this in Bash.

My years of Quick Basic are slowly coming back to me as I use BaCon.
I recalled that Basic works with arrays not lists, Bash is powerful with both.
Basic`s problem with arrays is getting data into them... It`s one line at a time.
Bash will read and write files and arrays all in one statement.
I`m going to suggest this for the next BaCon, and also passing arrays to/from Bash.

# The Q:
An easy way to get the number of lines in a file to declare the array index?
All I can think of to do is:
Code:
   OPEN File$ FOR INPUT AS file
   i = -1
   WHILE NOT(ENDFILE(file)) DO
      INCR i
      READLN txt$ FROM file
   WEND
   CLOSE file

   GLOBAL Array$[i] TYPE STRING

   OPEN File$ FOR INPUT AS file
   i = 0
   WHILE NOT(ENDFILE(file)) DO
      READLN txt$ FROM file
      IF ENDFILE(file) THEN BREAK
      Array$[i] = txt$
      INCR i
   WEND
   CLOSE file

Not a very efficient or elegant way to do anything at all.!
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Tue 08 Nov 2011, 21:47    Post subject:  

sunburnt,

Perhaps something like this-

Code:
i$=EXEC$("wc -l filename")


Whether that's faster or not remains to be seen.... Smile

regards,
s
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 8 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, ..., 6, 7, 8, 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:  

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.1225s ][ Queries: 13 (0.0064s) ][ GZIP on ]