home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
netdor2.zip
/
DISK_10
/
IMAGE9.ZIP
/
MODPATH.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-08-20
|
12KB
|
283 lines
/*****************************************************************************
* ModPath - Modify Path Information in Environment Statements *
* Author: Tom Heald (Heald at Almaden) *
*****************************************************************************
* Licensed Materials-Property of IBM *
* 5604-472 (c) Copyright IBM Corporation, 1993 *
* All rights reserved. *
* US Government Users Restricted Rights - *
* Use, duplication or disclosure restricted *
* by GSA ADP Schedule Contract with IBM Corp. *
*****************************************************************************
* Change History: *
* 04/19/90 - ATH - Original version written. *
* 02/05/91 - ATH - Placed on the ALTools Disk. *
* 05/07/91 - ATH - Add the "BOTH" option to set both Path and DPath. *
* 06/12/91 - ATH - Fix trailing ";" & defaulting "First" with an option. *
* 01/23/92 - TEB - Bug fix for null path entries (C:\XXX;;C:\YYY) *
* 02/17/92 - ATH - Add '@ECHO OFF' in Quiet mode. *
* 03/19/92 - ATH - Change Quiet to Silent make Dupcheck the default. *
* 04/24/92 - TEB - Add (undocumented) /Force option to force changes *
* even if the path is not currently defined. *
* 04/30/92 - TJM - Checked for C: and corrected some misspellings. *
* 05/27/92 - ATH - Add /Force and default to /Silent if called from Rexx *
* 08/18/92 - TEB - Find_Path would not lowercase path entries. *
* 2/05/93 - ATH - Add New "Help" information. *
* 06/04/93 - teb - Treat HELP as "?" if book not found. *
*****************************************************************************/
Trace 'e'
'@ECHO OFF' /* ATH 02/17/92 */
/* Default Option Settings can be changed for individual preferences. */
Quiet = 0 /* Show all messages */
DupCk = 1 /* Check for duplicate paths. ATH 3/19/92 */
Force = 0 /* Make mods even if path not def. TEB 4/24/92 */
Parse Upper Source Env Type Command /* ATH 5/27/92 */
If Type = "COMMAND" /* ATH 5/27/92 */
Then Echo = 1 /* Show new path ATH 5/27/92 */
Else Echo = 0 /* Don't Echo the Path ATH 5/27/92 */
parse upper arg Operands "/" Option etc /* ATH 02/17/92 */
Do while Option <> ""
Select
When Abbrev("QUIET", Option,1) Then Quiet = 1; /* ATH 3/19/92 */
When Abbrev("NOQUIET", Option,3) Then Quiet = 0; /* ATH 3/19/92 */
When Abbrev("SILENT", Option,1) Then Quiet = 1; /* ATH 3/19/92 */
When Abbrev("NOSILENT",Option,3) Then Quiet = 0; /* ATH 3/19/92 */
When Abbrev("ECHO", Option,1) Then Echo = 1; /* ATH 3/19/92 */
When Abbrev("NOECHO", Option,3) Then Echo = 0; /* ATH 3/19/92 */
When Abbrev("DUPCHECK",Option,1) Then DupCk = 1; /* ATH 3/19/92 */
When Abbrev("NODUPCHECK",Option,3) Then DupCk=0; /* ATH 3/19/92 */
When abbrev('FORCE', Option,1) then Force = 1 /* TEB 4/24/92 */
When abbrev('NOFORCE', Option,3) then Force = 0 /* ATH 5/27/92 */
Otherwise Do;
If \Quiet then Say 'Invalid Option:' Option
Exit 1;
End
End
Parse var etc junk "/" Option etc
End
parse upper var Operands Set_Target Word_1 Path_1 Word_2 Path_2 etc
if Word_1 = "" then do
Select
When Set_Target = "" Then signal Help;
When Set_Target = "?" Then signal Help;
When Abbrev("HELP",Set_Target,1) /* Show the Book ATH 2/05/93 */
Then Call View_Help "DirTools.Inf ModPath BookShelf Path DPath"
Otherwise Do;
If Quiet then Exit 1;
Say 'Missing keywords.'
Exit 1;
End
End
End
/* OS/2 requires Double Quotes around strings containing ";=," etc. */
/* Remove any "" from the path strings. */
If left(Path_1,1) = '"' & right(Path_1,1) = '"'
then Path_1 = substr(Path_1,2,length(Path_1)-2)
If left(Path_2,1) = '"' & right(Path_2,1) = '"'
then Path_2 = substr(Path_2,2,length(Path_2)-2)
/* Remove any trailing ";" from the path strings. ATH 06/12/91 */
If right(Path_1,1) = ';' then Path_1 = Left(Path_1,length(Path_1)-1)
If right(Path_2,1) = ';' then Path_2 = Left(Path_2,length(Path_2)-1)
/* If "BOTH" then do "Path" and "DPath" */
If Set_Target = "BOTH"
Then Do
Set_Target = "PATH"; Call Do_Path
Set_Target = "DPATH"; Call Do_Path
end;
Else Call Do_Path
Exit 0;
Do_Path:
Path_Data = Value(Set_Target,,'OS2ENVIRONMENT')
If Path_Data = ''
then if Force /* teb */
then Path_I = 0
else do
If \Quiet then Say 'No path information set for the Environment Statement "'Set_Target'".'
Exit 2
end
else do Path_I = 1 until Path_Data = '' /* teb */
parse var Path_Data Path.Path_I ";" Path_Data
if Path.Path_I = '' & Path_Data <> '' /* teb - Remove null entry */
then Path_I = Path_I - 1 /* teb */
end
Select
When Abbrev("ADD",Word_1,1) Then Do
If Word_2 = "" Then Word_2 = "FIRST" /* Default to first */
If DupCk then Call Del_Path Path_1 /* Delete the New Path */
Select
When Abbrev("FIRST", Word_2,1) Then Do
Call Move_Path 1 Path_I
Path.1 = Path_1
End
When Abbrev("LAST", Word_2,1) Then Do
Path_I = Path_I + 1
Path.Path_I = Path_1
End
When Abbrev("BEFORE",Word_2,1) Then Do
I1 = Find_Path(Path_2)
Call Move_Path I1 Path_I;
Path.I1 = Path_1
End
When Abbrev("AFTER", Word_2,1) Then Do
I1 = Find_Path(Path_2)
I1 = I1 + 1
Call Move_Path I1 Path_I;
Path.I1 = Path_1
End
Otherwise Do;
If \Quiet then do
If Word_2 <> ""
then Say '"'Word_2'" is not a valid keyword.'
else Say "Missing keyword."
Say " Use First, Last, Before or After."
End
Exit 1
End
End
End
When Abbrev("DELETE",Word_1,1) Then Do
I1 = Find_Path(Path_1)
Path_I = Path_I - 1
Do I = I1 to Path_I
I2 = I + 1
Path.I = Path.I2
End
End
When Abbrev("REPLACE",Word_1,1) Then Do
If \Abbrev("WITH",Word_2,1) Then Do
If \Quiet then do
If Word_2 <> ""
then Say '"'Word_2'" is not a valid keyword. Use "With".'
else Say 'Missing the "With" keyword.'
End
Exit 1
End
If DupCk then Call Del_Path Path_2 /* Delete the New Path */
I1 = Find_Path(Path_1)
Path.I1 = Path_2
End
When Abbrev("TEST",Word_1,1) Then Do
I1 = Find_Path(Path_1)
Exit 0; /* If control returns from Find_Path the dir. was found */
End
Otherwise Do;
If \Quiet then Say '"'Word_1'" is not a valid function. Use Add, Delete, Replace or Test.'
Exit 1
End
End
New_Path = ""
Do I = 1 to Path_I
New_Path = New_Path || Path.I";"
End
/* Set the Path in the Rexx environment and the OS/2 parent environment. */
/*"SET" Set_Target"="New_Path This is no longer needed ATH 3/19/92 */
Path_Data = Value(Set_Target,New_Path,'OS2ENVIRONMENT') /* The parent. */
If \Quiet & Echo Then Say Set_Target" = "New_Path
Return
Move_Path: Procedure Expose Path. Path_I;
Parse arg I1 I2 etc
Do I3 = I2 to I1 by -1
I4 = I3 + 1
Path.I4 = Path.I3 /* Move everything down 1 */
End
Path_I = Path_I + 1
Return;
Find_Path: Procedure Expose Path. Path_I Quiet;
Parse arg Path_1 etc
Found = 0
Do I = 1 to Path_I
If translate(Path.I) = Path_1 then Do /* teb */
Found = 1
Leave
End
End
If \Found then Do
If \Quiet then Say 'Target path "'Path_1'" not found.'
Exit 3
End
Return I;
Del_Path: Procedure Expose Path. Path_I Quiet;
Parse arg Path_1 ";" etc
Do while Path_1 <> ""
Do I1 = 1 to Path_I
If Path.I1 = Path_1 & I1 <= Path_I
then do
Path_I = Path_I - 1
Do I2 = I1 to Path_I
I3 = I2 + 1
Path.I2 = Path.I3 /* Move everything up 1 */
End
End
End
Parse var etc Path_1 ";" etc
End
Return;
/*----------------------------------------------------------------------*/
View_Help: /* View the Help for this command ATH 2/05/93 */
Parse Arg Help_Book Subject Paths
/* Load the RxUtils if not already loaded */
Call RxFuncAdd 'RxFileExist', 'RXUTILS', 'RxFileExist'
Call RxFuncAdd 'RxSearchPath', 'RXUTILS', 'RxSearchPath'
Book_Spec = Help_Book
Parse Var Paths Path Etc
If \RxFileExist(Help_Book) /* Is the file in the current directory? */
Then Do until Path = "" /* No - look for it. */
Book_Spec = RxSearchPath(Path, Help_Book)
If Book_Spec <> "" Then leave /* Found it */
Parse Var Etc Path Etc /* Next */
End
If Book_Spec <> "" /* Did we find the Book? */
Then Do
Say "View" Book_Spec Subject
"View" Book_Spec Subject
Exit RC
End
else signal Help
End
Return
Help:
"@ECHO OFF"
Opt.1 = ''; Opt.0 = 'NO' /* Used to display defaults ATH 3/19/92 */
"CLS"
Say
Say ' ModPath (Modify Path) will change an OS/2 Environment variable containing'
Say ' "Path" information by modifying a single path element within the variable. A'
Say ' single path element is any valid path statement separated by a semicolon (;).'
Say ''
Say ' M ─┬─ PATH ─┬┬ Delete ── old_path ──────────────────────────┬┬───────────┬┬'
Say ' O ├─ DPATH ┤├ Replace ─ old_path ──── With ─── new_path ───┤├ /Dupcheck ┤│'
Say ' D ├─ BOTH ─┤├ Test ──── target_path ───────────────────────┤├ /Silent ──┤│'
Say ' P ├─ ... ──┘└ Add ───── new_path ───┬────────┬─────────────┤├ /Echo ────┤│'
Say ' A │ ├ First ─┤ │├ /Force ───┤│'
Say ' T │ ├ Last ──┘ │├ /NO...────┤│'
Say ' H │ ├ Before ─ target_path ┤└──────────┘│' /* TJM 04/30/92 */
Say ' ├─ ? ───┐ └ After ── target_path ┘ │' /* TJM 04/30/92 */
Say ' └─ Help ┴──────────────────────────────────────────────────────────────┘'
Say ''
Say ' Where: PATH or DPATH can be any valid environment statement using the same'
Say ' data format set by the OS/2 "PATH" command. BOTH will '
Say ' modify both the PATH and DPATH environment statements.'
Say ' new_path one or more paths to be set in the environment statement.'
Say ' old_path a path to be modified in the environment statement.'
Say ' target_path a path to be searched for in the environment statement.'
Say ''
Say ' Defaults Options = /'opt.DupCk'Dupcheck, /'opt.Quiet'Silent, /'opt.Echo'Echo, /'opt.Force'Force.'
Exit;