home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / TOOLS / RUNFOR16 / runfor.doc next >
Text File  |  1997-04-27  |  21KB  |  449 lines

  1. ============================================================================
  2. RUNFOR.DOC                              April 28, 1997
  3. ============================================================================
  4.  
  5. Ver 1.6
  6.  
  7. A utility that can run a command for a particular set of files/dirs.
  8. This works for OS/2 and DOS commands under various (hopely) command shell.
  9.  
  10. This is a freeware if you don't modify the program.  Use this program at
  11. your own risk.    Please distribute this document together with executables.
  12.  
  13. ----------------------------------------------------------------------------
  14. INTRODUCTION
  15. ----------------------------------------------------------------------------
  16.  
  17. I wrote this program to make jobs easier with more flexible selections of
  18. files/dirs and with more flexible handling arguments of a program to be run
  19. when I had to repeatedly enter the similar command for each file or dir for
  20. a large set of files, especially when a program does not accept wildcards.
  21.  
  22.  
  23. ----------------------------------------------------------------------------
  24. INSTALLATION
  25. ----------------------------------------------------------------------------
  26.  
  27. Files included in runfor*.zip are
  28.     runfor.exe        - For OS/2 and DOS (require emxrt.zip, or rsx)
  29.     runfor2.exe     - For OS/2 only    (require emxrt.zip)
  30.     runfors.exe     - stand-alone OS/2 executable (doesn't need emxrt.zip)
  31.     runfor.doc        - this documentation
  32.  
  33. These programs were compiled by emx/gcc 0.9c and you can get emxrt.zip
  34. (EMX runtime package) from the following ftp sites:
  35.  
  36.     ftp.uni-stuttgart.de:   /pub/systems/os2/emx-0.9c/emxrt.zip
  37.     hobbes.nmsu.edu:        /os2/unix/emx09c/emxrt.zip
  38.     ftp.cdrom.com:        /pub/os2/unix/emx09c/emxrt.zip
  39.  
  40. Refer to documentations of emxrt.zip to install it.
  41.  
  42. [For OS/2 Users]
  43. ----------------
  44. After you install emxrt.zip, copy an executable to a directory in your PATH.
  45. runfors.exe does not require emxrt.zip, but it is bigger than runfor2.exe.
  46. If you decided to use 'runfor2.exe', then you may:
  47.  
  48.   copy runfor2.exe f:\bin\runfor.exe
  49.  
  50. where f:\bin is a dir in PATH.    You may delete other executables.
  51. This completes the installation.
  52.  
  53. [For DOS users]
  54. ---------------
  55. runfor.exe can run under both platforms of OS/2 and plain DOS with
  56. emxrt installed, but OS/2 DOS box or Windows DOS box needs RSX package.
  57. You can get RSX runtime package from its home site (ftp.uni-bielefeld.de:
  58. /pub/systems/ msdos/misc) or any CTAN sites:
  59.  
  60.     ftp.cdrom.com:  /pub/tex/ctan/systems/msdos/dpmigcc/rsx510b.zip
  61.     ftp.cdrom.com:  /pub/tex/ctan/systems/msdos/emtex/emxrsx.zip
  62.     ftp.dante.de:   /tex-archive/systems/msdos/emtex/emxrsx.zip
  63.  
  64. After emxrt.zip and rsx501b.zip are installed (emxrsx.zip has both),
  65. copy runfor.exe to a PATH.  And, add:
  66.  
  67.   set EMXOPT=-p
  68.  
  69. in your autoexec.bat to ensure enough free memory, and reboot.    That's it.
  70.  
  71. If RunFor could not start some DOS programs or crashes, you may not
  72. have enough free memory.  You need to enable UMB (Upper Memory Block)
  73. and allocate enough memory to your memory manager and load DOS in HMA
  74. (High Memory Area) in your CONFIG.SYS.    A sample CONFIG.SYS would be
  75.  
  76.     DEVICE=C:\WIN3\HIMEM.SYS
  77.     DEVICE=C:\WIN3\EMM386.EXE RAM frame=none HIGHSCAN x=a000-c7ff
  78.     DOS=HIGH,UMB
  79.  
  80. RunFor was written for OS/2, and DOS support was not intended.    The DOS
  81. support is entirely due to emx/gcc's feature of DOS support via emxrt
  82. run-time package.   RunFor may behave differently or incorrectly under
  83. DOS.  However, don't blame me.  Use at your own risk.
  84.  
  85. [Extra Consideration]
  86. ----------------------
  87. If you want to change the default settings of RunFor, you may set 'RUNFOROPT'
  88. env variable in your CONFIG.SYS or from a batch cmd file.  For example,
  89.  
  90.   set RUNFOROPT=-HS    (No hidden, no system attrib; same as RUNFOROPT=-H -S)
  91.  
  92. Any options can be set in 'RUNFOROPT' env, but I would not recommend you
  93. put options that can't be turned off from the command line.
  94.  
  95. If you keep a few copies of executables of different names, you can keep
  96. different default settings via env settings.  The rule for env name is that
  97. program name (before first '.') in uppercase plus "OPT".
  98.  
  99. For example, if you copied the executable to 'spawn.exe', the program will
  100. first look for 'SPAWNOPT' env before searching 'RUNFOROPT'.  If 'SPAWNOPT'
  101. is found, 'RUNFOROPT' is not searched.  If you make another copy named
  102. 'doit.exe', you can set 'DOITOPT' env for doit.exe.  Of course, if those
  103. envs are not found, spawn.exe and doit.exe share 'RUNFOROPT' env setting.
  104.  
  105.  
  106. ----------------------------------------------------------------------------
  107. USAGE
  108. ----------------------------------------------------------------------------
  109.  
  110. This program is self-explanatory.  'runfor' and 'runfor -?' will display help
  111. screens.  (Even if you rename the executable file 'runfor.exe' to other name
  112. the help screen will correctly display its new program name.)
  113.  
  114. Refer to the help screen.
  115.  
  116.  
  117. ----------------------------------------------------------------------------
  118. HISTORY
  119. ----------------------------------------------------------------------------
  120.     Ver 0.x
  121.     Ver 1.0    January 18, 1996
  122.     - first release to public
  123.  
  124.     Ver 1.1    January 19, 1996
  125.     - Added English month name in date argument of +T or -T.
  126.     - Very flexible ordering of date parameters.
  127.  
  128.     Ver 1.1a    January 19, 1996 (not released)
  129.     - Fixed: outfile could be incorrectly included in target file list.
  130.  
  131.     Ver 1.1b    March 19, 1996 (not released)
  132.     - Use PAGER for long help screen
  133.  
  134.     Ver 1.2    June 7, 1996
  135.     - New option: @<file>    target/exclude list in a file.
  136.     - New option: -t    not to look at disk for valid targets.
  137.     - New macros: %P and %R for path dir without ending '\' or '/'.
  138.     - New macro prefix modifiers:
  139.         %l    convert to lowercases
  140.         %u    convert to uppercases
  141.         %x    convert to unix style path ('/') (e.g. %xF)
  142.     - Changed: %l, %u, %x are global options when used before ':'.
  143.  
  144.     Ver 1.2a    September 17, 1996 (not released)
  145.     - Bug fix: broken PAGER support in DOS.
  146.     - Compiled with emx/gcc 0.9c (fixed some minor glitches)
  147.  
  148.     Ver 1.3    October 31, 1996
  149.     - Enhanced wildcard expansion support (more robust).
  150.     - Known bug(?): case-ignore in POSIX pattern matching with [...]
  151.             doesn't work due to emx/gcc 0.9c's fnmatch().
  152.     - @<file> now can include quoted names.
  153.  
  154.     Ver 1.4    February 28, 1997
  155.     - New feature to -w option:
  156.         Double option (-ww, -w -w) changes current working dir into
  157.         target dir, which is one level deeper than single option (-w).
  158.     - New macro prefix modifier:  %m for mixed-case conversion.
  159.     - New +T and -T options for HPFS drives:
  160.         +Tm  -Tm    modified time (default; same as +T, -T)
  161.         +Ta  -Ta    accessed time
  162.         +Tc  -Tc    created time
  163.     - +/-T options can now take seconds with hh:mm:ss (previously, hh:mm)
  164.     - Bug fixed: for +/-T options, incorrect selection by wrong timezone
  165.         computation and incorrect day of week on screen message.
  166.     - Removed a verbose message of changing dir ("Entering directory:").
  167.  
  168.     Ver 1.5    March 12, 1997
  169.     - New options:
  170.         +B -B ddd[k|kb|m|mb]    file selection by minimum/maximum sizes
  171.         -o-     '-' for standard output.
  172.         -e-     '-' to disable macro expansion in env setting.
  173.         -@ *    next argument is a target name (to escape switch symbol)
  174.         -x@ *   next argument is a exclude name (to escape switch symbol)
  175.     - New macro codes:
  176.         %T        file date and time (with various formats by prefixes)
  177.         %[m]B   file size
  178.         %ddd    positioning at column 'ddd' in expanded string.
  179.     - Changes and enhancements:
  180.         -m        don't expand macros (just renamed -n of previous version)
  181.         -x[@] * now supports disk and path in exclude name pattern.
  182.         %r macro now gives relative path even if target is in other drive.
  183.         +/-T now accepts two-digit year for the years of 1970-2069.
  184.     - Bug fixed:
  185.         Location of output file (-o) when -w was used.
  186.         Removed output file from target list.
  187.         Cleaned some minor glitches when no target or -t was given.
  188.  
  189.     Ver 1.6    April 28, 1997
  190.     - New option:
  191.         -C dir  change the default dir (of runfor) to "dir" before
  192.             running. (Useful in makefiles)
  193.  
  194.  
  195. ----------------------------------------------------------------------------
  196. Help Screen (Actual output from 'runfor -?')
  197. ----------------------------------------------------------------------------
  198.  
  199. runfor    Ver 1.6 - Run a command - Apr 28 1997,    W. Kim
  200.  
  201. Syntax: runfor [options] [targets] [-x exclude_names] : [@]command [args]
  202.  
  203. Options: (can go anywhere before ':')
  204.   -?     Help screen (long) (Add suffix '-' to override PAGER: -?-, -h-)
  205.   -a     Targets are both directories and files
  206.   -c     Confirm before each command execution
  207.   -C *     Change the default dir as if runfor was started from there
  208.      ("runfor -C foo : prog" is equivalent to "cd foo & prog & cd ..")
  209.   -d     Targets are directories (default targets are files only)
  210.   -h     (same as -?)
  211.   -i     Ignore letter cases in POSIX pattern matching (not work without -p)
  212.   -m     Do not expand macro codes in command + arguments
  213.   -o {*|-}  Output expanded cmd args to a file or stdout(-) without executions
  214.   -p     POSIX pattern matching (affects -x as well); Add -i to ignore case
  215.   -q[q]  Quiet [quieter] mode  (place -qq before +T or -T to turn off time log)
  216.   -Q[#]  Quit if a command returns an exit code >= #   (-Q = -Q1)
  217.   -r     Recursive run for all subdirs
  218.   -t     Don't look at disk to get target names (i.e. use given names as-is.)
  219.      -t must be given before any target/exlude names.
  220.   -u     Unix style path name ('/' for directory separators); convert all args.
  221.   -w[w]  Change working dir of command to subdir of target [into target dir]
  222.  
  223.   +R -R  Only files/dirs with(+) or without(-) READ-ONLY attribute
  224.   +H -H  Only files/dirs with(+) or without(-) HIDDEN attribute
  225.   +S -S  Only files/dirs with(+) or without(-) SYSTEM attribute
  226.   +A -A  Only files/dirs with(+) or without(-) ARCHIVE attribute
  227.  
  228.   +B -B ddd[K|KB|M|MB]       Files bigger(+B)/smaller(-B) than 'ddd' bytes/KB/MB
  229.  
  230.   +T[?][date][;][[hh]:[mm]:[ss]]   Files/dirs ON or AFTER the given date/time
  231.   -T[?][date][;][[hh]:[mm]:[ss]]   Files/dirs ON or BEFORE the given date/time
  232.        [?] can be m (modified; default), a (accessed), or c (created) for HPFS.
  233.        (On FAT drives, modified time == accessed time == created time.)
  234.        date = [yy]yy-{mm|mmm}-dd in almost any order. (mm=1-12, mmm=Jan-Dec)
  235.        Among 3 parts of date, ';', and time, at least one must be given.
  236.  
  237.        Valid date strings with numeric month (mm doesn't go after dd) are:
  238.  
  239.      [yy]yy-mm-dd, mm-dd, dd, [yy]yy, mm-dd-[yy]yy, [yy]yy-mm, mm-[yy]yy
  240.  
  241.        With English month names (mm <= mmm in above), the additional forms are:
  242.  
  243.      dd-mmm-[yy]yy, dd-mmm, mmm  (very flexible ordering!)
  244.  
  245.        Any missing date parameters (yy, mm, dd) are copied from today,
  246.        and if a time parameter (hh,mm,ss) is missing, it assumes to be zero.
  247.        (e.g. If this year is 1996, +/-T95 means after/before a year ago.)
  248.  
  249.        Year yyyy should be in the range of 1970-2106.  However, for small yy,
  250.        if yy >= 70, yy means the year of 1900+yy;
  251.        if yy <  70, yy means the year of 2000+yy.
  252.  
  253.   %l %u %x  Convert all arguments and macros to lower/upper/unix-style path
  254.        Use macro prefix modifiers to selectively modify macro expansions.
  255.  
  256.   targets  Target file or dir names (wildcards can be used in target string.)
  257.        (Note: Any target not found on disk is excluded by default. See -t.)
  258.        @<file> can be used together to get targets from <file> in which
  259.        no line can have more than one name. (i.e. one name per line.)
  260.  
  261.   @file    Read "file" for target names or exclude names (if given after -x).
  262.  
  263.   -@ *       Next argument is a target name (to escape '-','@','%' switches)
  264.        (e.g. -@ @abc -@ -foo   where "@abc", "-foo" are target names)
  265.  
  266.   -e[-] *  Set env vars before running;  Use double quotes to include a space.
  267.        Macro codes in env settings are expanded.  -e- won't exand them.
  268.        Env settings are passed to executables, but not to batch commands.
  269.  
  270.   -x[@] *  Exclude names from target dirs or files. (e.g. -x *.zip d:*\abc\*)
  271.        -x accepts multiple arguments including @file form as in targets.
  272.        Use -x@ to escape switch symbol for the next argument: -x@ @foo @bar
  273.        where "@foo" itself and the names from file "bar" will be excluded.
  274.  
  275.    :       Command (and its arguments) to be run goes after this separator
  276.  
  277.    @       Direct execute without spawning a command shell.  '@' makes faster
  278.        execution, but does not work for .cmd/.bat or I/O redirections.
  279.  
  280. Macro Codes for command + arguments:
  281.  
  282.    %%     % itself
  283.    %d     drive                  (e.g. "H:")
  284.    %p     subdir path              (e.g. "\src\C\utils\")
  285.    %P     subdir path without ending '\'   (e.g. "\src\C\utils")
  286.    %n     file/dir name without extension  (e.g. "runfor")
  287.    %e     file/dir extension          (e.g. ".doc")
  288.    %f     file/dir name with extension      (e.g. "runfor.doc")
  289.    %F     full path name of a file/dir      (e.g. "H:\src\C\utils\runfor.doc")
  290.    %r     relative dir from working dir      (e.g. "utils\")
  291.    %R     relative dir without ending '\'  (e.g. "utils")
  292.    %T     file date & time of last modification (various formats by prefixes)
  293.    %B     file size in bytes (%m prefix converts to K (=1024) or M if too big)
  294.    %w#     (#+1)th wildcard expansion; %w = %w0  (e.g. %w0="for." for run*doc)
  295.    %(ENV_NAME)    Env variable; name is case-sensitive; usually in uppercase.
  296.    %#[#...]    Target counter; %## will be replaced by 2+ digits: 01, 02, ...
  297.    %ddd[ ]    Position at column 'ddd' or add 'ddd' spaces if space followed
  298.          ('%20X' puts X at column 20 while '%20 X' adds 20 spaces before X)
  299.  
  300. Macro prefix modifiers: (override global %l, %u, %x options)
  301.    (Syntax: %[modifiers][%]macro_code,    e.g. %uxF or %u%x%F)
  302.    %l     convert to lowercases          (e.g. %l(PATH))
  303.    %m     convert to mixedcases          (e.g. %mf = "Runfor.doc")
  304.    %u     convert to uppercases          (e.g. %uf = "RUNFOR.DOC")
  305.    %x     unix-style path ('/')            (e.g. %lxP = %xlP = "/src/c/utils")
  306.  
  307.    Note: These modifiers may have different meaning for %T or %B macro codes.
  308.  
  309. Wildcards in POSIX Pattern Matching:
  310.  
  311.    ?       matches any single character.
  312.    *       matches zero or more occurances of anything.
  313.    [abc]   matches any character of 'a', 'b', or 'c'.
  314.    [!abc]  matches any character except 'a', 'b', and 'c'.
  315.    [a-z]   matches any character from 'a' to 'z'.
  316.  
  317. Description:
  318.  
  319.    It executes a command using a command shell given by COMSPEC or SHELL env,
  320.    or directly executes the command if '@' is in front of the command.  If a
  321.    target name is given with wildcards, it executes a command (that may not
  322.    accept wildcards) for every matching target file or dir, and its arguments
  323.    can have macro codes of substitution for drive, dir, name, extension, etc.
  324.    taken from the matching target file/dir. It can recursively run for subdirs.
  325.  
  326. Environmental Variables:
  327.  
  328.    RUNFOROPT   Set this env var to change the default behavior of this program
  329.            from either OS/2 config.sys (DOS autoexec.bat) or a batch file.
  330.            If the last option in "RUNFOROPT" setting is either -e or -x,
  331.            then "RUNFOROPT" setting must end with a '-'.  For example,
  332.  
  333.            set RUNFOROPT=-q -H -S -x *.Z -       (note '-' at end)
  334.            (A shorter setting would be "set RUNFOROPT=-x *.Z -qHS")
  335.  
  336.    xxxOPT      where "xxx" is the executable name before '.' in uppercases.
  337.            For example, if you copied this program to "spawn.exe", spawn
  338.            first searches SPAWNOPT env for its default settings, and
  339.            then RUNFOROPT is searched only if SPAWNOPT was not found.
  340.  
  341.    PAGER       Optionally set this env to use a pager (like less or list) for
  342.            this long help screen.  If PAGER is not found, stdout is used.
  343.  
  344. Using Double Quotes: (I/O redirections and blank spaces in names)
  345.  
  346.    For I/O redirections, '@' (direct execution) should NOT be used in front of
  347.    an executable command so as to invoke a command shell that can redirect I/O.
  348.    To pass redirection symbols (like '>') to the child process (command shell),
  349.    enclose them (or the whole command string) with matching double quotes.
  350.    Double quotes are stripped off before passing to child process.
  351.    To pass a double quote explicitly, use a backslash('\') before double quote.
  352.    If target names have blank spaces, enclose them with explicit double quotes.
  353.  
  354. Examples:
  355.  
  356.    - To take `diff' between all same named files of *.c and *.doc in e:
  357.      and current dir:
  358.  
  359.        runfor *.c *.doc : @diff e:%f %f
  360.  
  361.    - To create a batch file "batch.cmd" for later execution:
  362.  
  363.        runfor -q -o batch.cmd *.c *.doc : @diff e:%f %f
  364.  
  365.    - Find all files >= 1MB from subdirs, which were last modified on or after
  366.      97-Mar-01, and save those file names (relative path names) to a file:
  367.  
  368.        runfor -o files.lst * +B 1mb +Tmar-01-97 -rq : @%r%f
  369.  
  370.    - To list files (date/time, size, name) under subdirs to standard output:
  371.  
  372.        runfor -qro- * : @%T %mB %r%f
  373.  
  374.    - To run a command after converting its arguments to unix-style path:
  375.  
  376.        runfor -u : prog args   (TeX is a good example.)
  377.  
  378.    - Wildcard macro expansion:    To rename "abc*-??.dat" files to "xyz??-*.dat"
  379.      with confirmation:
  380.  
  381.        runfor -c abc*-??.plt : ren %f xyz%w1%w2-%w0.dat
  382.  
  383.    - POSIX pattern matching:   runfor [a-k]* -x *.z -piqq : echo %f
  384.  
  385.    - For files with some attributes:   runfor * +HS -A : attrib \"%f\"
  386.      (Double quotes protect spaces in expanded names for "attrib" command.)
  387.  
  388.    - Some examples of arguments for +/-T: (+ or - before T is not shown here)
  389.        T;  T-  T:  T0  T-;:  T0;0       == 00:00:00 of today.
  390.        T8-12      TAug-12   T12-August       == Aug-12 00:00:00 of this year.
  391.        T95-8-12   T8-12-95  T12-Aug-95       == 1995-Aug-12 00:00:00.
  392.        T2001-8-12 T01-12-Aug  T101-12-Aug  == 2001-Aug-12 00:00:00.
  393.        T8-  T-8-  TAug           == 00:00:00 of today in August of this year.
  394.        T12  T12;  T-12    T--12  == 00:00:00 of the 12th day of this month.
  395.        T15: T;15  T15:00       == 15:00:00 of today.
  396.        T95  T1995 T95-    T-95   == today 00:00:00 of 1995.
  397.  
  398.        "-TAug-12-96 +Ta97-1-1" selects files modified on or before
  399.        1996-Aug-12 00:00:00 but accessed on or after 1997-Jan-01 00:00:00
  400.  
  401.    - Selecting files/dirs of attributes is based on `AND' operator. That is,
  402.      "+HS -RA" means `Hidden=1 AND System=1 AND ReadOnly=0 AND Archive=0'.
  403.  
  404.      "-HS" (= -H -S) means files/dirs of not hidden nor system attributes.
  405.  
  406.    - Target counter %# (Try these in a dir having more than 10 files):
  407.        runfor -qq * : echo %#: %f
  408.        runfor -qq * : echo %##: %f
  409.        runfor -qq * : echo %###: %f
  410.  
  411.    - Env settings: (Usually env names are in uppercase.)
  412.        runfor -q -e abc=Hello. ABC="There is." : echo %(ABC) %(abc)
  413.        runfor -q -e ABC="prog.exe can see this env setting." : prog.exe args
  414.  
  415.    - Environment variable may contain macro codes to be expanded:
  416.        runfor -q * -e ABC="File name is %f." : echo %(ABC)
  417.        (To avoid macro expanding for envs, use "-e-".)
  418.    - Reading target or exclude list from a file: (@<file>)
  419.        runfor -tq @file1 -x @file2 : cmd ...
  420.        (file1 has target names, and file2 has names to be excluded.)
  421.        (-t is given so that targets in file1 are not searched on disk.)
  422.        If '@' is part of file/dir name, use -@ or -x@. (-@ @file1 -x@ @file2)
  423.  
  424.    - To run "prog" for every file that matches with "blank in file name*"
  425.      and save the screen outputs (redirection) to a log file "result.log":
  426.  
  427.        runfor "blank in file name*" : "prog \"%f\" >> result.log"
  428.  
  429.      where \"%f\" is used because the expanded file name(s) have blank
  430.      spaces (thus explicit double quotes should be used).
  431.  
  432.    - Recursive run into subdirs and changing working dirs:  The following
  433.      examples will show the difference between -w and -ww (-w -w).
  434.        runfor -rqqdww * : cd           -- target dirs
  435.        runfor -rqqdw * : cd           -- parent dirs of targets
  436.        runfor -rqqdw * : (cd %f & cd)
  437.  
  438. Return Codes: (for single input)
  439.    0 - Successful Completion
  440.    1 - Invalid Command Switch or Argument
  441.    2 - Unable to OPEN
  442.    3 - Unable to READ
  443.    4 - Unable to WRITE
  444.    5 - Invalid Data/Format
  445.    6 - Invalid Name
  446.    7 - Error During Execution
  447.    8 - Help screen due to an error
  448.  
  449. -- Wonkoo Kim (wkim+@pitt.edu)