home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
cfgcmd.zip
/
CFG.CMD
next >
Wrap
OS/2 REXX Batch file
|
1994-09-26
|
6KB
|
161 lines
/* NCLrcvf */
'@echo off'
say '┌─────────────────────────────────────────┐'
say '│ CFG - configuration file update utility │'
say '│ │'
say '│ Written September 1994 by Jeff J. Langr │'
say '│ Public domain software │'
say '└─────────────────────────────────────────┘'
say ' '
/*─────────────────────────────────────────────────────────────────────>
load Rexx system functions
<─────────────────────────────────────────────────────────────────────*/
if RxFuncQuery('SysLoadFuncs') then
do
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
end
/*─────────────────────────────────────────────────────────────────────>
gather & verify arguments
<─────────────────────────────────────────────────────────────────────*/
parse upper arg Parm_File Parm_Var Parm_Value Parm_Location
if Parm_File = '' | Parm_Var = '' | Parm_Value = '' then do
say 'Syntax:'
say ' CFG cfgfile environmentvar value [location]'
say ' '
say ' where'
say ' cfgfile = name of configuration file to update; often C:\CONFIG.SYS'
say ' environmentvar = environment variable; for example, PATH, LIBPATH, COBDIR'
say ' value = value string to ADD to the environment variable setting'
say ' [location] = optional positioning of added value: F=front, B=back'
exit 10
end
if Parm_Location = '' then do
Parm_Location = 'B'
end
if Parm_Location <> 'F' & Parm_Location <> 'B' then do
say 'Location parameter must be either F or B'
exit 12
end
/*─────────────────────────────────────────────────────────────────────>
open input file passed as parameter
<─────────────────────────────────────────────────────────────────────*/
rc = stream(Parm_File, 'C', 'OPEN READ')
if rc <> 'READY:' then do
say 'Unable to open configuration file' Parm_File '- program halted.'
exit 11
end
/*─────────────────────────────────────────────────────────────────────>
create temporary file to hold copy of input file
<─────────────────────────────────────────────────────────────────────*/
TmpCfg=SysTempFileName(FILESPEC('drive',Parm_File)||FILESPEC('path',Parm_File)||'CFGTEMP.???')
/*─────────────────────────────────────────────────────────────────────>
loop through input control file
<─────────────────────────────────────────────────────────────────────*/
env_match = 0
do while lines(Parm_File)
Rec_Out = LineIn(Parm_File)
Rec_In = Strip(Rec_Out, 'b', ' ')
match = 0
/*──────────────────────────────────────────────────────────────────>
check for LIBPATH statement; parse accordingly
<──────────────────────────────────────────────────────────────────*/
if Parm_Var = 'LIBPATH' then do
if translate(left(Rec_In,7))='LIBPATH' then do
parse value Rec_In with cfgVar '=' cfgRest
match = 1
cfgStart = cfgVar||'='
end
end
else do
/*───────────────────────────────────────────────────────────────>
check for SET statement; parse accordingly
<───────────────────────────────────────────────────────────────*/
if translate(left(Rec_In,4))='SET ' then do
parse value Rec_In with cfgSet cfgVar '=' cfgRest
if cfgVar = Parm_Var then do
match = 1
cfgStart = cfgSet cfgVar||'='
end
end
end
/*──────────────────────────────────────────────────────────────────>
match made on environment variable name - update entry
<──────────────────────────────────────────────────────────────────*/
if match = 1 then do
env_match=1
cfgValues=translate(cfgRest,' ',';') /* change ; to spaces */
numValues=words(cfgValues) /* count # of entries in string */
match_value = 0
/*───────────────────────────────────────────────────────────────>
loop through all entries in environment string
<───────────────────────────────────────────────────────────────*/
do i=1 to numValues
if subword(cfgValues, i, 1) = Parm_Value then do
match_value = 1
say 'Value' Parm_Value 'already exists for' Parm_Var||';' Parm_File 'not updated.'
call lineout TmpCfg
call SysFileDelete(TmpCfg)
exit 1
end
end
/*───────────────────────────────────────────────────────────────>
add new value if not found in environment string entries
<───────────────────────────────────────────────────────────────*/
if match_value = 0 then do /* value not already in list */
say 'Adding value' Parm_Value
if Parm_Location = 'F' then do
Rec_Out = cfgStart||Parm_Value||';'||cfgRest
end
else do
if right(cfgRest,1)=';' then do
Rec_Out = cfgStart||cfgRest||Parm_Value
end
else do
Rec_Out = cfgStart||cfgRest||separator||Parm_Value
end
end
end
end
rc=lineout(TmpCfg,Rec_Out)
end
/*─────────────────────────────────────────────────────────────────────>
no environment variable matched; add SET line at end of file
<─────────────────────────────────────────────────────────────────────*/
if env_match = 0 then do /* no match; add new set statement */
Rec_Add = 'SET' Parm_Var||'='||Parm_Value
say 'Adding line to' Parm_File||':'
say Rec_Add
rc=lineout(TmpCfg,Rec_Add)
end
/*─────────────────────────────────────────────────────────────────────>
close files; delete input file; rename temp file to input file
<─────────────────────────────────────────────────────────────────────*/
call lineout TmpCfg
rc=stream(Parm_File, 'C', 'CLOSE')
rc=SysFileDelete(Parm_File)
if rc=0 then do
'rename' TmpCfg FILESPEC('name',Parm_File)
end
else do
say 'Could not update' Parm_File||'; new version saved as' TmpCfg||'.'
say 'Error code='||rc
end
exit 0