This program is a port of the resizepfile script to a Bacon program.
In particular it makes use of Bacon's Associative array.
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: Select all
fullname$("bob") = "Robert Fuller"
fullname$("jane") = "Janet Jenkins"
name$ = "bob"
PRINT fullname$(name$)
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: Select all
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=''
I used a SUB-routine to translate the shell variables. Here is commented code.
Code: Select all
' ------------------
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
The rest of the program implements the actions of the shell script along with the addition of a GUI.
GatorDog