2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,45 +1,45 @@
|
|||
/*REXX pgm shows how to update a configuration file (4 specific tasks).*/
|
||||
parse arg iFID oFID . /*obtain optional input file─id. */
|
||||
if iFID=='' | iFID==',' then iFID= 'UPDATECF.TXT' /*use default? */
|
||||
if oFID=='' | oFID==',' then oFID='\TEMP\UPDATECF.$$$' /*use default? */
|
||||
call lineout iFID; call lineout oFID /*close the input & output files.*/
|
||||
$.=0 /*placeholder of options found. */
|
||||
call dos 'ERASE' oFID /*erase a file (with no err MSGs)*/
|
||||
changed=0 /*nothing changed in file so far.*/
|
||||
/* [↓] read the entire cfg file.*/
|
||||
do rec=0 while lines(iFID)\==0 /*read a record; bump record cnt.*/
|
||||
z=linein(iFID); zz=space(z) /*get rec; del extraneous blanks.*/
|
||||
say '───────── record:' z /*echo the record just read──►con*/
|
||||
a=left(zz,1); _=space(translate(zz,,';')) /*_ is used to elide multi;*/
|
||||
if zz=='' | a=='#' then do; call cpy z; iterate; end /*blank|comment*/
|
||||
if _=='' then do; changed=1; iterate; end /*elide any ; empty records*/
|
||||
parse upper var z op . /*obtain the option from the rec.*/
|
||||
/* [↓] OP may have leading or */
|
||||
if a==';' then do; parse upper var z 2 op . /*trailing blanks.*/
|
||||
if op='SEEDSREMOVED' then call new space(substr(z,2))
|
||||
call cpy z; $.op=1 /*write the Z record to output.*/
|
||||
iterate /*rec*/ /*··· and go read the next record*/
|
||||
/*REXX program demonstrates how to update a configuration file (four specific tasks).*/
|
||||
parse arg iFID oFID . /*obtain optional arguments from the CL*/
|
||||
if iFID=='' | iFID=="," then iFID= 'UPDATECF.TXT' /*Not given? Then use default.*/
|
||||
if oFID=='' | oFID=="," then oFID='\TEMP\UPDATECF.$$$' /* " " " " " */
|
||||
call lineout iFID; call lineout oFID /*close the input and the output files.*/
|
||||
$.=0 /*placeholder of the options detected. */
|
||||
call dos 'ERASE' oFID /*erase a file (with no error message).*/
|
||||
changed=0 /*nothing changed in the file (so far).*/
|
||||
/* [↓] read the entire config file. */
|
||||
do rec=0 while lines(iFID)\==0 /*read a record; bump the record count.*/
|
||||
z=linein(iFID); zz=space(z) /*get record; elide extraneous blanks.*/
|
||||
say '───────── record:' z /*echo the record just read ──► console*/
|
||||
a=left(zz,1); _=space( translate(zz, ,';') ) /*_: is used to elide multiple ";" */
|
||||
if zz=='' | a=='#' then do; call cpy z; iterate; end /*blank or a comment.*/
|
||||
if _=='' then do; changed=1; iterate; end /*elide any semicolons; empty records.*/
|
||||
parse upper var z op . /*obtain the option from the record. */
|
||||
/* [↓] option may have leading or ···*/
|
||||
if a==';' then do; parse upper var z 2 op . /*trailing blanks.*/
|
||||
if op='SEEDSREMOVED' then call new space( substr(z, 2) )
|
||||
call cpy z; $.op=1 /*write the Z record to the output file*/
|
||||
iterate /*rec*/ /* ··· and then go read the next record*/
|
||||
end
|
||||
if $.op then do; changed=1; iterate; end /*option already defined?*/
|
||||
$.op=1 /* [↑] Yes? Delete it.*/
|
||||
if op=='NEEDSPEELING' then call new ';' z
|
||||
if op=='NUMBEROFBANANAS' then call new op 1024
|
||||
if op=='NUMBEROFSTRAWBERRIES' then call new op 62000
|
||||
call cpy z /*write the Z record to output.*/
|
||||
if $.op then do; changed=1; iterate; end /*is the option already defined? */
|
||||
$.op=1 /* [↑] Yes? Then delete it. */
|
||||
if op=='NEEDSPEELING' then call new ";" z
|
||||
if op=='NUMBEROFBANANAS' then call new op 1024
|
||||
if op=='NUMBEROFSTRAWBERRIES' then call new op 62000
|
||||
call cpy z /*write the Z record to the output file*/
|
||||
end /*rec*/
|
||||
|
||||
nos='NUMBEROFSTRAWBERRIES' /* [↓] NOS option need updating?*/
|
||||
if \$.nos then do; call new nos 62000; call cpy z; end /*update opt.*/
|
||||
call lineout iFID; call lineout oFID /*close the input & output files.*/
|
||||
if rec==0 then do; say "ERROR: input file wasn't found:" iFID; exit; end
|
||||
if changed then do /*possibly overwrite input file. */
|
||||
call dos 'XCOPY' oFID iFID '/y /q',">nul" /*quietly*/
|
||||
say; say center('output file', 79, "▒") /*title. */
|
||||
call dos 'TYPE' oFID /*display output file's content. */
|
||||
nos='NUMBEROFSTRAWBERRIES' /* [↓] Does NOS option need updating? */
|
||||
if \$.nos then do; call new nos 62000; call cpy z; end /*update option.*/
|
||||
call lineout iFID; call lineout oFID /*close the input and the output files.*/
|
||||
if rec==0 then do; say "ERROR: input file wasn't found:" iFID; exit; end
|
||||
if changed then do /*possibly overwrite the input file. */
|
||||
call dos 'XCOPY' oFID iFID '/y /q',">nul" /*quietly*/
|
||||
say; say center('output file', 79, "▒") /*title. */
|
||||
call dos 'TYPE' oFID /*display content of the output file. */
|
||||
end
|
||||
call dos 'ERASE' oFID /*erase a file (with no err msg)*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────one─line subroutines────────────────*/
|
||||
cpy: call lineout oFID,arg(1); return /*write one line of text───►oFID.*/
|
||||
dos: ''arg(1) word(arg(2) "2>nul",1); return /*execute a DOS command.*/
|
||||
new: z=arg(1); changed=1; return /*use new Z, indicate changed rec*/
|
||||
call dos 'ERASE' oFID /*erase a file (with no error message).*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
cpy: call lineout oFID, arg(1); return /*write one line of text ───► oFID. */
|
||||
dos: ''arg(1) word(arg(2) "2>nul",1); return /*execute a DOS command (quietly). */
|
||||
new: z=arg(1); changed=1; return /*use new Z, indicate changed record. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue