September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,47 +0,0 @@
/*REXX program to read a config file and assign VARs as found within. */
signal on syntax; signal on novalue /*handle REXX program errors. */
parse arg cFID _ . /*cFID = config file to be read. */
if cFID=='' then cFID='CONFIG.DAT' /*Not specified? Use the default*/
bad= /*this will contain all bad VARs.*/
varList= /*this will contain all the VARs.*/
maxLenV=0; blanks=0; hashes=0; semics=0; badVar=0 /*zero 'em.*/
do j=0 while lines(cFID)\==0 /*J count's the file's lines. */
txt=strip(linein(cFID)) /*read a line (record) from file,*/
/*& strip leading/trailing blanks*/
if txt ='' then do; blanks=blanks+1; iterate; end
if left(txt,1)=='#' then do; hashes=hashes+1; iterate; end
if left(txt,1)==';' then do; semics=semics+1; iterate; end
eqS=pos('=',txt) /*can't use the TRANSLATE bif. */
if eqS\==0 then txt=overlay(' ',txt,eqS) /*replace 1st '=' with blank*/
parse var txt xxx value; upper xxx /*get the variableName and value.*/
value=strip(value) /*strip leading & trailing blanks*/
varList=varList xxx /*add it to the list of vARiables*/
if value='' then value='true' /*if no value, then use "true". */
if symbol(xxx)=='BAD' then do /*can REXX use the variable name?*/
badVar=badVar+1; bad=bad xxx; iterate
end
call value xxx,value /*now, use VALUE to set the var. */
maxLenV=max(maxLenV,length(value)) /*maxLen of varNames, pretty disp*/
end /*j*/
vars=words(varList)
say #(j) 'record's(j) "were read from file: " cFID
if blanks\==0 then say #(blanks) 'blank record's(blanks) "were read."
if hashes\==0 then say #(hashes) 'record's(hashes) "ignored that began with a # (hash)."
if semics\==0 then say #(semics) 'record's(semics) "ignored that began with a ; (semicolon)."
if badVar\==0 then say #(badVar) 'bad variable name's(badVar) 'detected:' bad
say; say 'The list of' vars "variable"s(vars) 'and' s(vars,'their',"it's") "value"s(vars) 'follows:'; say
do k=1 for vars
v=word(varList,k)
say right(v,maxLenV) '=' value(v)
end /*k*/
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────error handling subroutines and others.─*/
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1)
#: return right(arg(1),length(j)+11) /*right justify a number +indent*/
err: say; say; say center(' error! ', max(40, linesize()%2), "*"); say
do j=1 for arg(); say arg(j); say; end; say; exit 13
novalue: syntax: call err 'REXX program' condition('C') "error",,
condition('D'),'REXX source statement (line' sigl"):",sourceline(sigl)

View file

@ -1,161 +0,0 @@
#!/usr/bin/rexx
/*.----------------------------------------------------------------------.*/
/*|readconfig: Read keyword value pairs from a configuration file into |*/
/*| Rexx variables. |*/
/*| |*/
/*|Usage: |*/
/*| .-~/rosetta.conf-. |*/
/*|>>-readconfig-+----------------+------------------------------------><|*/
/*| |-configfilename-| |*/
/*| |-- -? ----------| |*/
/*| |-- -h ----------| |*/
/*| '- --help -------' |*/
/*| |*/
/*|where |*/
/*| configfilename |*/
/*| is the name of the configuration file to be processed. if not|*/
/*| specified, ~/rosetta.conf is used. |*/
/*| |*/
/*|All values retrieved from the configuration file are stored in |*/
/*|compound variables with the stem config. Variables with multiple |*/
/*|values have a numeric index appended, and the highest index number |*/
/*|is stored in the variable with index 0; e.g. if CONFIG.OTHERFAMILY.1 |*/
/*|and CONFIG.OTHERFAMILY.2 have values assigned, CONFIG.OTHERFAMILY.0 = |*/
/*|2. |*/
/*|-?, -h or --help all cause this documentation to be displayed. |*/
/*| |*/
/*|This program was tested using Open Object Rexx 4.1.1. It should work |*/
/*|with most other dialects as well. |*/
/*'----------------------------------------------------------------------'*/
call usage arg(1)
trace normal
signal on any name error
/* Prepare for processing the configuration file. */
keywords = 'FULLNAME FAVOURITEFRUIT NEEDSPEELING SEEDSREMOVED OTHERFAMILY'
/* Set default values for configuration variables here */
config_single?. = 1
config. = ''
config.NEEDSPEELING = 0
config.SEEDSREMOVED = 1
/* Validate command line inputs. */
parse arg configfilename
if length(configfilename) = 0 then
configfilename = '~/rosetta.conf'
configfile = stream(configfilename,'COMMAND','QUERY EXISTS')
if length(configfile) = 0 then
do
say configfilename 'was not found.'
exit 28
end
signal on notready /* if an I/O error occurs. */
/* Open the configuration file. */
response = stream(configfile,'COMMAND','OPEN READ SHARED')
/* Parse the contents of the configuration file into variables. */
do while lines(configfile) > 0
statement = linein(configfile)
select
when left(statement,1) = '#',
| left(statement,1) = ';',
| length(strip(statement)) = 0,
then /* a comment or a blank line. */
nop /* skip it. */
otherwise
do
if pos('=',word(statement,1)) > 0,
| left(word(statement,2),1) = '=',
then /* a keyword/value pair with = between. */
parse var statement keyword '=' value
else /* a keyword/value pair with no =. */
parse var statement keyword value
keyword = translate(strip(keyword)) /* make it uppercase. */
single? = pos(',',value) = 0 /* a single value, or multiple values? */
call value 'CONFIG_single?.'keyword,single? /* remember. */
if single? then
do
if length(value) > 0 then
call value 'CONFIG.'keyword,strip(value)
end /* strip keeps internal whitespace only. */
else /* store each value with its index. */
do v = 1 by 1 while length(value) > 0
parse var value value1 ',' value
if length(value1) > 0 then
do
call value 'CONFIG.'keyword'.'v,strip(value1)
call value 'CONFIG.'keyword'.0',v /* remember this. */
end
end
end
end
end
/* Display the values of the configuration variables. */
say 'Values associated with configuration file' configfilename':'
say
do while words(keywords) > 0
parse var keywords keyword keywords
if value('CONFIG_single?.'keyword) then
say right(keyword,20) '= "'value('CONFIG.'keyword)'"'
else
do
lastv = value('CONFIG.'keyword'.0')
do v = 1 to lastv
say right(keyword,20-(length(v)+2))'['v'] = "'value('CONFIG.'keyword'.'v)'"'
end
end
end
say
notready: /* I/O errors come here. */
filestatus = stream(configfile,'STATE')
if filestatus \= 'READY' then
say 'An I/O error occurred; the file status is' filestatus'.'
response = stream(configfile,'COMMAND','CLOSE')
error:
/*? = sysdumpvariables() */ /* see everything Rexx used. */
exit
usage: procedure
trace normal
if arg(1) = '-h',
| arg(1) = '-?',
| arg(1) = '--help'
then
do
line = '/*|'
say
do l = 3 by 1 while line~left(3) = '/*|'
line = sourceline(l)
parse var line . '/*|' text '|*/' .
say text
end
say
exit 0
end
return