$!----------------------------------------------------------------------------+ $! WILDCMD.COM - Wildcard file command substitute procedure | $!----------------------------------------------------------------------------+ $! Author: Harry Flowers $! $! P1 - File specification: May contain wildcards $! P2 - Command to execute: Quotes are preserved if prompted for command $! $! Substitutions in the command: $! #FIL# is replaced with File name (full as returned by F$SEARCH) $! #DEV# is replaced with Device name (with the colon ":") $! #DIR# is replaced with Directory (with the brackets "[]") $! #NAM# is replaced with Name (part between directory and type) $! #TYP# is replaced with Type (without the period ".") $! #VER# is replaced with Version (without the semi-colon ";") $! (Thus, #FIL# = #DEV##DIR##NAM#.#TYP#;#VER#) $! $! See the examples at the end of this file. This can be very powerful. $!----------------------------------------------------------------------------+ $ SAVERIFY = 'F$VERIFY(0)' $ SET NOON $ ON CONTROL_Y THEN GOTO ABORTED $ SUBPART = "FIL/DEV/DIR/NAM/TYP/VER" ! Valid substitutions $ SUBPART = "fil/dev/dir/nam/typ/ver/" + SUBPART ! Add in the lowercase $ TOTPART = 11 ! Number subs minus 1 $ P2 = P2+" "+P3+" "+P4+" "+P5+" "+P6+" "+P7+" "+P8 ! Gather command P2 $ P2 = F$EDIT(P2,"TRIM") ! Trim the command $ IF P1 .EQS. "" $ THEN INQUIRE P1 "_File" $ IF P1 .EQS. "" THEN GOTO ABORTED $ ENDIF $ IF F$SEARCH(P1) .EQS. "" $ THEN WRITE SYS$OUTPUT "%WILDCMD-F-FNF, File not found: " + P1 $ GOTO ABORTED $ ENDIF $ IF P2 .EQS. "" $ THEN READ/PROMPT="_Command: " SYS$COMMAND P2 $ IF P2 .EQS. "" THEN GOTO ABORTED $ P2 = F$EDIT(P2,"UPCASE,TRIM") $ ENDIF $ PROMPT = F$ENVIRONMENT("PROMPT") $ FIL_S = "" ! Blank for our non-wildcard check $ FILELOOP: $ FILNAM = F$SEARCH(P1,1) $ IF (FILNAM .EQS. "") .OR. (FILNAM .EQS. FIL_S) THEN GOTO FINISHED $ FIL_S = FILNAM ! Full file name $ DEV_S = F$PARSE(FILNAM,,,"DEVICE") ! Device name $ DIR_S = F$PARSE(FILNAM,,,"DIRECTORY") ! Directory $ NAM_S = F$PARSE(FILNAM,,,"NAME") ! Name $ TYP_S = F$PARSE(FILNAM,,,"TYPE") - "." ! Type $ VER_S = F$PARSE(FILNAM,,,"VERSION") - ";" ! Version $ SUB_S = 0 $ CMD_S = P2 $ LEN_S = F$LENGTH(CMD_S) $ CMDLOOP: $ PRT_S = F$ELEMENT(SUB_S,"/",SUBPART) $ LOC_S = F$LOCATE("#''PRT_S'#",CMD_S) $ IF LOC_S .NE. LEN_S $ THEN CMD_S = F$EXTRACT(0,LOC_S,CMD_S) + 'PRT_S'_S +- F$EXTRACT(LOC_S+5,255,CMD_S) $ LEN_S = F$LENGTH(CMD_S) $ ELSE SUB_S = SUB_S + 1 $ ENDIF $ IF SUB_S .LE. TOTPART THEN GOTO CMDLOOP $ WRITE SYS$OUTPUT PROMPT + CMD_S $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND $ 'CMD_S' $ IF F$TRNLNM("SYS$INPUT",,,"USER",,"ACCESS_MODE") .EQS. "USER" THEN - DEASSIGN/USER SYS$INPUT ! In case no image rundown $ GOTO FILELOOP $ ABORTED: $ WRITE SYS$OUTPUT "%WILDCMD-F-ABORT, Aborted." $ FINISHED: $ EXIT 1 + 0*F$VERIFY(SAVERIFY) $!----------------------------------------------------------------------------+ $! Examples: $! $! @WILDCMD *.COM $! _Command: SEARCH/OUTPUT=#NAM#.#TYP#-TEMP/EXACT #FIL# "SET TERM" $! Would search all .COM files for the string "SET TERM", putting $! the output in a file with the original name but "-TEMP" appended. $! Having WILDCMD prompt for the command preserves the quotes in $! the SEARCH command. $! $! @WILDCMD *.RNO; DELETE #NAM#.MEM;* $! Would delete all .MEM files for which a source .RNO file exists. $! $! @WILDCMD *.TXT; EDIT #FIL# $! Would edit all .TXT files $! $! @WILDCMD THERE:*.FOR; FORTRAN/OBJ=THERE:#NAM#.OBJ #FIL# $! Would compile all fortran programs in location "THERE:", placing $! the resulting object files "THERE:" as well. $! $! Restriction: If the command has too many spaces in it (more than $! six), enclose it in quotes so that it is passed complete $! in P2. Otherwise, you will get a %DCL-W-DEVOVF error. $! Of course, this only applies to the command line, not to $! the "_Command:" prompt.