Anonymous user
Update a configuration file: Difference between revisions
m
→version 1: added/changed comments, indentations, and whitespace.
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header, added other whitespace to the task's preamble, corrected some misspellings.) |
m (→version 1: added/changed comments, indentations, and whitespace.) |
||
Line 1,763:
Programming note: not all REXXes support the closing of files using the '''lineout''' BIF with a single argument.
<lang rexx>/*REXX
parse arg iFID oFID . /*obtain optional
if iFID=='' | iFID==
if oFID=='' | oFID==
call lineout iFID; call lineout oFID /*close the input
$.=0 /*placeholder of the options
call dos 'ERASE' oFID /*erase a file (with no
changed=0 /*nothing changed in the file (so far).*/
/* [↓] read the entire
do rec=0 while lines(iFID)\==0 /*read a record; bump the record
z=linein(iFID); zz=space(z) /*get
say '───────── record:' z /*echo the record just
a=left(zz,1); _=space( translate(zz, ,';') ) /*_: is used to elide
if zz=='' | a=='#' then do; call cpy z; iterate; end /*blank
if _=='' then do; changed=1; iterate; end /*elide any semicolons; empty records.*/
parse upper var z op . /*obtain the option from the
/* [↓]
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
iterate /*rec*/ /* ··· and then go read the next record*/
end
if $.op then do; changed=1; iterate; end /*is the option already defined? */
$.op=1 /* [↑] Yes?
if op=='NEEDSPEELING' then call new
if op=='NUMBEROFBANANAS' then call new op 1024
if op=='NUMBEROFSTRAWBERRIES' then call new op 62000
call cpy z /*write the
end /*rec*/
nos='NUMBEROFSTRAWBERRIES' /* [↓] Does NOS option need updating? */
if \$.nos then do; call new nos 62000; call cpy z; end /*update
call lineout iFID; call lineout oFID /*close the input
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
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
cpy: call lineout oFID, arg(1); return /*write one line of
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
'''output''' when using the default input file (which has additional removable statements) and input options:
<pre>
───────── record: # This is a configuration file in standard configuration file format
───────── record: #
───────── record: # Lines
───────── record: # program. Blank lines are also ignored by the application program.
───────── record: ;
|