Changeset 3087 for trunk/tools
- Timestamp:
- Mar 11, 2000, 6:11:30 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/bin/DoWithDirs.cmd
r2919 r3087 1 /* $Id: DoWithDirs.cmd,v 1. 3 2000-02-27 00:40:21bird Exp $1 /* $Id: DoWithDirs.cmd,v 1.4 2000-03-11 17:11:30 bird Exp $ 2 2 * 3 * Syntax: dowithdirs.cmd [-e<list of excludes>] [-c p] [-i] <cmd with args...>3 * Syntax: dowithdirs.cmd [-e<list of excludes>] [-c] [-i] [-l] [-r] <cmd with args...> 4 4 * -e Exclude directories. 5 5 * <list of excludes> is a INCLUDE-path styled list of directories. 6 * -c pCD into the directory and execute the command.6 * -c CD into the directory and execute the command. 7 7 * Default action is to pass the directory name as last argument. 8 8 * -i Ignore command failure (rc=0) 9 9 * -r Process diretories in reverse order. 10 * -l Lock directories for other dowithdirs.cmd processes. (-c required!) 10 11 */ 11 12 … … 17 18 asIgnore.0 = 0; 18 19 fCD = 0; 20 fLocking = 0; 19 21 fReverse = 0; 20 22 21 23 /* parse arguments */ 22 parse arg sArg.1 sArg.2 sArg.3 sArg.4 sArg.5 sArg.6 23 sArg.0 = 6;24 parse arg sArg.1 sArg.2 sArg.3 sArg.4 sArg.5 sArg.6 sArg.7 25 sArg.0 = 7; 24 26 do i = 1 to sArg.0 25 27 if (sArg.i <> '') then … … 68 70 end 69 71 72 when ch = 'L' then 73 do 74 fLocking = 1; 75 end 76 70 77 otherwise 71 78 say 'unknown argument:' sArg.i; … … 88 95 call syntax; 89 96 end 97 end 98 99 /* sanity check */ 100 if (fLocking & \fCD) then 101 do 102 say '-l (Locking) requires -cd to be specified!'; 103 call syntax; 90 104 end 91 105 … … 116 130 117 131 if \fFound then 118 do /* execute the command */ 132 do 133 /* switch execution type. */ 119 134 if (fCD) then 120 135 do 136 /* exectute the command in the directory */ 121 137 say '# entering directory:' asDirs.i; 138 /* save old dir and enter the new dir. */ 122 139 sOldDir = directory(); 123 140 call directory asDirs.i; 124 sCmds; 141 142 /* Lock the directory? */ 143 fOK = 1; 144 if (fLocking) then 145 if (\lockdir()) then 146 do 147 say '# - warning: Skipping '|| asDirs.i || ' - directory was locked.'; 148 fOK = 0; 149 end 150 151 /* continue only if locking was successful. */ 152 if (fOK) then 153 do 154 /* execute command */ 155 sCmds; 156 ret = rc; 157 158 /* unlock directory */ 159 if (fLocking & fOk) then 160 call unlockdir; 161 162 /* check for return? */ 163 if (ret <> 0) then 164 do 165 /* complain and fail if errors aren't ignored. */ 166 say '# - rc = 'ret; 167 if (\fIgnoreFailure) then 168 exit(rc); 169 end 170 end 171 172 /* restore old directory */ 173 call directory sOldDir; 125 174 end 126 175 else 176 do 177 /* execute the command with the directory as the last parameter */ 127 178 sCmds filespec('name', asDirs.i); 128 129 if (rc <> 0) then 130 do 131 say 'rc='rc; 132 if (\fIgnoreFailure) then 133 exit(rc); 134 end 135 136 if (fCD) then 137 call directory sOldDir; 138 end 179 if (rc <> 0) then 180 do 181 say '# - rc = ' || rc; 182 if (\fIgnoreFailure) then 183 exit(rc); 184 end 185 end 186 end /* loop */ 139 187 end 140 188 … … 143 191 144 192 syntax: 145 say 'Syntax: dowithdirs.cmd [-e<list of excludes>] [-c p] [-i] <cmd with args...>';193 say 'Syntax: dowithdirs.cmd [-e<list of excludes>] [-c] [-i] [-l] [-r] <cmd with args...>'; 146 194 say ' -e Exclude directories.'; 147 195 say ' <list of excludes> is a INCLUDE-path styled list of directories.'; 148 say ' -c pCD into the directory and execute the command.';196 say ' -c CD into the directory and execute the command.'; 149 197 say ' Default action is to pass the directory name as last argument.'; 150 198 say ' -i Ignore command failure (rc=0)'; 151 199 say ' -r Process diretories in reverse order.'; 200 say ' -l Lock directories for other dowithdirs.cmd processes. (-c required!)'; 201 exit(-1) 202 203 204 /* 205 * Locks the directory by creating a .dirlocked file in the directory. 206 * Returns 1 on success 207 * 0 on error 208 */ 209 lockdir: procedure 210 rc = stream('.dirlocked', 'c', 'open write'); 211 return substr(rc, 1, 5) = 'READY'; 212 213 214 /* 215 * Unlocks thedirectory by deleting the .dirlocked file. 216 */ 217 unlockdir: procedure 218 rc = stream('.dirlocked', 'c', 'close'); 219 call SysFileDelete '.dirlocked'; 220 return 0; 221
Note:
See TracChangeset
for help on using the changeset viewer.