home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / tpower.zip / TPOWER.DOC < prev   
Text File  |  1991-03-28  |  80KB  |  2,077 lines

  1.   The TurboPower Utilities were originally designed for users of
  2.   Turbo Pascal 2.0 and 3.0. Since then, the Pascal-specific
  3.   utility programs have been updated and extended to form the
  4.   Turbo Analyst product. Several of the original utilities are
  5.   still useful in their original form, and these are now being
  6.   released for free distribution. These utilities are general
  7.   purpose DOS utilities for displaying directories, finding
  8.   files, comparing files, performing regular expression search
  9.   and replace on text files, and automating repetitive command
  10.   sequences.
  11.  
  12.   The following documentation is comprised of the relevant
  13.   portions of the original TurboPower Utilities manual. (It's
  14.   interesting how much things have changed since it was written
  15.   in 1985!)
  16.  
  17.   You may use and distribute these files freely, but you may not
  18.   sell them (except for nominal handling costs charged by
  19.   shareware distributors) without the express written permission
  20.   of TurboPower Software.
  21.  
  22.   Kim Kokkonen
  23.   March 1991
  24.   CompuServe 76004,2611
  25.  
  26.   -----------------------------------------------------------
  27.  
  28.  
  29.               TurboPower Programmer's Utilities
  30.  
  31.                         User's Manual
  32.  
  33.            Copyright (C) 1985 TurboPower Software.
  34.  
  35.                      All Rights Reserved.
  36.                         Second Edition
  37.  
  38.  
  39.                      Trademarks Mentioned
  40.  
  41.   TurboPower Software and the distinctive TurboPower logo are
  42.   trademarks of TurboPower Software. TurboPower Utilities is a
  43.   trademark of TurboPower Software.
  44.  
  45.   WordStar is a trademark of Micropro International.
  46.  
  47.   IBM is a trademark of International Business Machines
  48.   Corporation.
  49.  
  50.   Turbo Pascal, Turbo Tutor and Sidekick are trademarks of
  51.   Borland International.
  52.  
  53.   Unix is a trademark of Bell Laboratories.
  54.  
  55.   -----------------------------------------------------------
  56.  
  57. TABLE OF CONTENTS
  58.  
  59.   1. Introduction
  60.   2. Getting Started
  61.   3. Using the Utilities
  62.   4. References
  63.  
  64.   5. SDIR - Super Directory Utility
  65.     A. Purpose
  66.     B. Usage
  67.     C. Sorting Options
  68.     D. Filtering Options
  69.     E. Listing Options
  70.     F. File Attribute Codes
  71.     G. Examples
  72.  
  73.   6. ROOT - File Finder
  74.     A. Purpose
  75.     B. Usage
  76.     C. Command Options
  77.     D. Examples
  78.  
  79.   7. REP - Command Repeater
  80.     A. Purpose
  81.     B. Usage
  82.     C. Command Options
  83.        1. Redirecting Input and Output
  84.        2. Changing Current Directory
  85.        3. Changing Delimiters
  86.        4. Sending Keystrokes
  87.        5. Double-Checking Commands
  88.        6. Output Options
  89.        7. Command Line from a File
  90.        8. Miscellaneous Options
  91.     D. Examples
  92.  
  93.   8. DIFF - Text File Difference Finder
  94.     A. Purpose
  95.     B. Usage
  96.     C. Command Options
  97.        1. Disregarding Differences
  98.        2. Formatting the Output of DIFF
  99.        3. Miscellaneous Options
  100.     D. Using the Script Mode
  101.     E. Further Examples
  102.  
  103.   9. RPL - Pattern Match and Replace
  104.     A. Purpose
  105.     B. Usage
  106.        1. Command Files
  107.        2. Specifying Input and Output
  108.        3. Behavior at Runtime
  109.     C. Command Options
  110.        1. Specifying Regular Expressions
  111.        2. Deciding What Lines to Output
  112.        3. Miscellaneous Formatting
  113.     D. Select and Match Expressions
  114.     E. Replace Expressions
  115.     F. Examples
  116.  
  117.   -----------------------------------------------------------
  118.  
  119. 1. INTRODUCTION
  120.  
  121.   Each of the Utilities is described in a separate section of
  122.   this manual. Here is an overview of each program:
  123.  
  124. o DIFF - Difference Finder
  125.   Finds differences between two text files. Reports differences
  126.   in any of several formats, one of which allows efficient
  127.   archiving of file history. Allows certain differences to be
  128.   disregarded (including spacing, case, selected characters and
  129.   Pascal comments).
  130.  
  131. o RPL - Pattern Match and Replace
  132.   Uses regular expressions to find arbitrarily complex text
  133.   patterns in a file, then optionally allows replacement of
  134.   those patterns. Supports many advanced regular expression
  135.   features, including nesting, tagged match words, alternation
  136.   and three types of closures.
  137.  
  138. o SDIR - Super Directory
  139.   Displays the MS-DOS disk directory with a large number of
  140.   options, including sort order, extended pattern matching,
  141.   hidden file display, date filtering and others.
  142.  
  143. o ROOT - File Finder
  144.   Finds files (singular or wildcarded) anywhere in the directory
  145.   hierarchy and then allows you to act on them with a single
  146.   keystroke (e.g. copy, type, execute, or delete). Displays the
  147.   directory structure in any of several formats.
  148.  
  149. o REP - Command Repeater
  150.   Combines a programmable text parser with general purpose
  151.   command execution capability to automate many repetitive
  152.   tasks. Uses include applying file operations across multiple
  153.   subdirectories and running RPL and DIFF operations on all
  154.   source files comprising a program.
  155.  
  156.   -----------------------------------------------------------
  157.  
  158. 2. GETTING STARTED
  159.  
  160.   The TurboPower Utilities require that you be operating under
  161.   PC-DOS 2.X or later on an IBM PC, XT, AT or 100% compatible.
  162.   We are testing on non-IBM hardware as it becomes available to
  163.   us. We would appreciate hearing from you if you find that
  164.   these programs work well on your non-IBM machine. We will use
  165.   the terms MS-DOS, PC-DOS and DOS interchangeably throughout
  166.   the manual.
  167.  
  168.   All of the utilities will run in a system with 128K bytes
  169.   available RAM. They are designed to take advantage of all
  170.   available RAM space. To get full performance out of the
  171.   programs that build large internal data structures (such as
  172.   DIFF), your system should have at least 192K bytes of RAM. If a
  173.   lot of your RAM space is consumed by print spoolers, RAM disks
  174.   and resident programs, you may need more RAM.
  175.  
  176.   Two double-sided disk drives are highly recommended unless you
  177.   have a hard disk, which is even better.
  178.  
  179.   -----------------------------------------------------------
  180.  
  181. 3. USING THE UTILITIES
  182.  
  183.   Most of the Utilities are designed so that you simply type the
  184.   command name and something useful will happen. Nevertheless,
  185.   it is worthwhile to do a little preparation before starting
  186.   out.
  187.  
  188.   The capacity of the Utilities has been set so that each can
  189.   easily handle the kinds of programs that a Turbo Pascal
  190.   programmer is likely to produce. This generally sets a limit
  191.   of 64K bytes per individual text file and several thousand
  192.   lines per program. Generally, the programs can take advantage
  193.   of increased RAM space, but in some cases an array size
  194.   hard-coded into the program will set an upper limit. All of
  195.   the utilities follow a consistent command format. If the name
  196.   of the utility is entered by itself, either the utility will
  197.   execute a default set of actions or it will prompt for
  198.   additional information. Optionally, each utility can be called
  199.   with command line arguments. For example:
  200.  
  201.     ROOT -T -F myfile.* >files.dat
  202.  
  203.   Each of the words -T and -F specifies a command option to the
  204.   utility. Every command option must begin with the hyphen - and
  205.   be followed immediately by one or more characters. Individual
  206.   options must be separated from one another by at least one
  207.   space or tab. The case (upper or lower) of the words typed on
  208.   the command line is generally not significant. Differing case
  209.   will be used in this manual for emphasis only. The fourth word
  210.   on the example command line above represents a file or set of
  211.   files on which the utility will operate. Depending on the
  212.   utility, there may be from 0 up to 3 files specified on the
  213.   command line. These files sometimes may contain wildcards as in
  214.   the example, and usually may contain MS-DOS pathnames. These
  215.   details are specified in the section on each utility.
  216.  
  217.   The final word on the example command line controls MS-DOS
  218.   output redirection. In this case the results of the command
  219.   will not be sent to the screen, but rather to the file named
  220.   FILES.DAT. If you do not know about the redirection features
  221.   of MS-DOS 2.0+, it is worth your time to study the DOS manual,
  222.   since redirection provides some very powerful capabilities.
  223.   Where it makes sense, the TurboPower Utilities support
  224.   input/output redirection.
  225.  
  226.   The discussion of each utility will include the following
  227.   format:
  228.  
  229.     ROOT [options] [file or directory] [I/O redir]
  230.  
  231.   Optional entries will always be enclosed in brackets. The
  232.   order of the entries does not matter except when explicitly
  233.   specified.
  234.  
  235.   Each of the Utilities that takes command line options has a
  236.   built-in help feature. Simply enter the name of the utility
  237.   followed by either -? or just ? to get a quick help screen
  238.   describing the options. For example,
  239.  
  240.     ROOT -?
  241.  
  242.   will show what options ROOT provides.
  243.  
  244.   The directly executable TurboPower utilities (SDIR, ROOT, REP,
  245.   DIFF, RPL) provide return codes after an abnormal exit from
  246.   the program. If the program is terminated by Ctrl-Break, it
  247.   returns a code of 1. If the program exits with an error, it
  248.   returns a code of 2. These codes can be accessed through the
  249.   MS-DOS batch ERRORLEVEL function or through MS-DOS function
  250.   call $4D.
  251.  
  252.   You can usually abort the operation of the utilities by typing
  253.   Ctrl-C or Ctrl-Break.
  254.  
  255.   -----------------------------------------------------------
  256.  
  257. 4. REFERENCES
  258.  
  259.   The PC-DOS manuals contain a wealth of information for both
  260.   beginners and advanced programmers. The following sections are
  261.   relevant to using the TurboPower Utilities.
  262.  
  263.   Subdirectories and Pathnames:
  264.  
  265.     Using Tree-Structured Directories. (Chapter 5 for either
  266.     MS-DOS 2.X or 3.0).
  267.  
  268.     PATH command. (Chapter 6 for 2.X, Chapter 7 for 3.0)
  269.  
  270.  
  271.   Redirection of Input and Output:
  272.  
  273.     Chapter 10 for 2.X, Chapter 6 for 3.0.
  274.  
  275.   -----------------------------------------------------------
  276.  
  277. 5. SDIR - Super Directory Utility
  278.  
  279. A. Purpose
  280.  
  281.   SDIR displays a file directory in various ways. It allows the
  282.   order in which the files are displayed to be sorted according
  283.   to name, extension, size and/or time. Hidden or subdirectory
  284.   entries optionally can be shown. Files older or newer than a
  285.   chosen date can be excluded from the listing. File names and
  286.   extensions may be specified using any combination of the
  287.   standard wild cards * and ?. Finally, the listing can be
  288.   printed in either of two formats, or displayed in any of
  289.   several formats.
  290.  
  291.   SDIR has been designed to work well with REP, the TurboPower
  292.   Command Repeater. Together, these utilities can save you a lot
  293.   of repetitive typing.
  294.  
  295.   SDIR does not modify the actual directory encoded on the disk.
  296.  
  297.  
  298. B. Usage
  299.  
  300.     SDIR [options] [directory] [output redir]
  301.  
  302.   Optional entries are enclosed in brackets [ ] here and
  303.   throughout this manual.
  304.  
  305.   The directory specifier follows normal DOS 2.0+ rules. If not
  306.   specified, the current drive and directory are used. If a
  307.   partial pathname (not beginning with \) is specified, this
  308.   pathname is appended to the current directory pathname. If a
  309.   pathname beginning with ..\ is specified, the remainder of the
  310.   specified pathname is appended to the pathname of the
  311.   directory above the current directory. If a pathname beginning
  312.   with just .. is specified, any file specification that follows
  313.   will refer to the contents of the directory above the current
  314.   directory.
  315.  
  316.   If only a drive is specified, the current default directory of
  317.   that drive is used. File specifiers (including wildcards) may
  318.   also be appended to the pathname.
  319.  
  320.   SDIR divides the directory output into columnar fields. When a
  321.   filename does not include an extension, the column for that
  322.   field will appear blank. It is NOT really blank, but is filled
  323.   with nulls (ASCII 0). This allows the REP parser to keep the
  324.   word count consistent between files with or without extensions
  325.   (that is, @3 in REP will always refer to file size).
  326.  
  327.   Each option must be specified individually, and separated from
  328.   other options by a space or tab. The order of the directory
  329.   and option entries is not important. The case (upper or lower)
  330.   of entries is not important.
  331.  
  332.   If output is being sent to the screen, and the screen has been
  333.   filled, SDIR will prompt "MORE?". Type <CR> (carriage return)
  334.   to get another single line of output, <space bar> or Y (for
  335.   Yes) to get another screenful, and any other key to quit
  336.   operation of SDIR.
  337.  
  338.   The maximum number of files SDIR will find in a given
  339.   directory is 512 (if you have more than this, you should
  340.   probably create some subdirectories).
  341.  
  342.   The output of SDIR can be redirected using the standard DOS
  343.   2.X techniques. These allow sending the output to a file, to
  344.   the printer, or to the input of another program. In the case
  345.   of the printer, it is recommended that you use one of the
  346.   print command options described below, as they provide print
  347.   formatting as well as redirection.
  348.  
  349.   Obtain a summary of SDIR options at any time by typing
  350.  
  351.   SDIR -?
  352.  
  353.  
  354. C. Sorting Options
  355.  
  356. -AN
  357.   Sort the listing by file Names in ascending (alphabetical)
  358.   order.
  359.  
  360. -AE
  361.   Sort the listing by file Extensions in ascending order.
  362.  
  363. -AS
  364.   Sort the listing by file Size in ascending order.
  365.  
  366. -AT
  367.   Sort the listing by file Time (combined date and time) in
  368.   ascending order.
  369.  
  370. -DN
  371. -DE
  372. -DS
  373. -DT
  374.   Sort the listing in descending order for any of the four
  375.   categories described above.
  376.  
  377.   Two different sort keys may be specified simultaneously. The
  378.   first key encountered on the command line becomes the primary
  379.   key, and the second the secondary. If no sort key is
  380.   specified, SDIR defaults to -AN -AE (files sorted first by
  381.   name, then by extension). If only one sort key is specified,
  382.   the second one defaults to a reasonable value. If more than
  383.   two sort keys are specified, all but the first two are
  384.   ignored.
  385.  
  386.  
  387. D. Filtering Options
  388.  
  389. -H[O]
  390.   Show Hidden files [Only] in the directory listing. SDIR finds
  391.   hidden, read-only, and system files using this search.
  392.  
  393. -S[O]
  394.   Show Subdirectories [Only] in the listing. SDIR will not show
  395.   the directory entries . and .. since they are (almost) always
  396.   there.
  397.  
  398. -M[n]
  399.   Show only files Modified since n days ago. If n is not
  400.   specified, it defaults to 0, and thus only those files
  401.   modified today are listed. n is an integer (0<=n<32768), and
  402.   must follow immediately after the letter M (without spaces).
  403.  
  404. -B[n]
  405.   Show only files last modified Before n days ago. If n is not
  406.   specified, it defaults to 0, and thus only those files NOT
  407.   modified today are listed. n meets the same constraints
  408.   specified for the M option.
  409.  
  410. -MB
  411.   Show only files Modified since last Backup. This uses the
  412.   modify bit supported by MS-DOS. This option can be used in
  413.   combination with any of the other options of SDIR.
  414.  
  415.  
  416. E. Listing Options
  417.  
  418. -T[O]
  419.   Include Titles [Only] in the directory listing. Titles include
  420.   an expanded version of the directory and wildcards specified,
  421.   the disk volume label, bytes remaining on the disk, number of
  422.   files found, and bytes used in the files found. By default,
  423.   titles are not output. This makes the response faster, and the
  424.   output is more easily used as input to other programs.
  425.  
  426. -Sn
  427.   Use a Sector size n (0<n<32768) when calculating total disk
  428.   space usage of a group of files. By default, SDIR uses a
  429.   sector size read from the disk. For a DSDD disk this creates
  430.   an effective sector size of 1024 bytes, and for a 10Mbyte hard
  431.   disk an effective sector size of 4096 bytes. File sizes
  432.   smaller than an exact sector size boundary are allocated the
  433.   full extra sector on the disk, thus using more space than you
  434.   might expect. You can use a non-default size to determine how
  435.   much space files will take when transferred to another disk.
  436.  
  437. -C
  438.   Output the directory in a Compressed format. Here only the
  439.   filename and extension are shown. The filenames are arranged
  440.   in 5 columns across the screen, so you can fit a lot of files
  441.   in a little space. The order of the display reads DOWN the
  442.   columns, which seems a more natural way to read than the DOS
  443.   DIR/W command provides. Subdirectory entries, if selected,
  444.   have the character \ appended.
  445.  
  446. -E
  447.   Precede each filename with the complete pathname to its
  448.   directory; otherwise SDIR output is normal. This option is
  449.   useful with REP.
  450.  
  451. -W
  452.   Include Whole pathname with each file found. No other file
  453.   information (such as size, date, etc.) is written out. This
  454.   option is useful when SDIR is to supply input to another
  455.   program such as the command repeater REP. If -W is specified,
  456.   the -T and -C options are overridden.
  457.  
  458. -P
  459.   Print the directory listing (at normal size) instead of
  460.   sending it to the display screen. When the printing options
  461.   are set, output redirection is not required in order to print
  462.   the data. Specifying -P will send form feeds to the printer in
  463.   order to avoid the perforations. Titles are included by
  464.   default when printing is specified. If -P is specified, the -W
  465.   and -C options are overridden.
  466.  
  467. -PT
  468.   Print the directory at Tiny size (on Epson or compatible
  469.   printers only). The size is such that the listing will fit
  470.   conveniently on a floppy disk or in its sleeve.
  471.  
  472.  
  473. F. File Attribute Codes
  474.  
  475. SDIR displays file attributes when the default display options
  476. are used. The codes for the attributes are:
  477.  
  478.   n - normal file
  479.   s - system file
  480.   d - directory
  481.   r - read-only file
  482.   h - hidden file
  483.   m - modified since backup
  484.  
  485.  
  486. G. Examples
  487.  
  488.     SDIR
  489.  
  490.   Displays all the normal files in the current directory, sorted
  491.   in alphabetical order by filename, then by extension.
  492.  
  493.     SDIR -t -dt -m5 c:\*.pas
  494.  
  495.   Displays all normal files in the root directory of drive C
  496.   having the extension .PAS, and which were modified within the
  497.   last 5 days. The listing will be presented in order of newest
  498.   file first. Titles are included in the output.
  499.  
  500.     SDIR -ae -ds mydir
  501.  
  502.   Displays all of the normal files in the subdirectory mydir of
  503.   your current directory. The listing will be sorted first by
  504.   extension, then by descending size.
  505.  
  506.     SDIR a: -pt
  507.  
  508.   Makes a tiny printout of the files on drive A.
  509.  
  510.     SDIR *tmp.exe
  511.  
  512.   Displays all .EXE files whose name ends in TMP. The DOS DIR
  513.   command will not give the proper answer here.
  514.  
  515.     SDIR >old.dir
  516.  
  517.   Saves the current directory listing in the file old.dir.
  518.  
  519.     SDIR \oldsrc\rpl*.pas -w | REP {type @0} -s
  520.  
  521.   Pipes the output of the SDIR command to the input of the REP
  522.   command. All the files matching rpl*.pas in the remote
  523.   directory specified are typed to the screen.
  524.  
  525.     SDIR ..\pascal\*.pas
  526.  
  527.   Looks at the subdirectory named pascal which is linked to the
  528.   directory above the current one.
  529.  
  530.   -----------------------------------------------------------
  531.  
  532. 6. ROOT - File Finder
  533.  
  534. A. Purpose
  535.  
  536.   ROOT serves several purposes. First, it will show the
  537.   subdirectory structure of a disk. This is similar to the DOS
  538.   TREE function but more powerful (and even readable!).
  539.  
  540.   Second, ROOT will find a file or files anywhere in the
  541.   subdirectory structure and then perform any of several
  542.   functions relative to the file.
  543.  
  544.   Third, ROOT is designed to work well with the command repeater
  545.   REP. By providing path and filename inputs to REP, ROOT helps
  546.   to automate many tedious tasks.
  547.  
  548.   ROOT has many options, which are described below.
  549.  
  550.  
  551. B. Usage
  552.  
  553.     ROOT [drive][pathname] [options] [output redir]
  554.  
  555.   Optional entries are here and throughout this manual enclosed
  556.   in brackets, [ ].
  557.  
  558.   Drive is a single letter followed by a colon (A:, B:, C:, ...,
  559.   to a maximum of H:). It indicates which drive is to be
  560.   searched. If not specified, the default drive is used.
  561.   Pathname can optionally follow drive. If provided, pathname
  562.   specifies the starting directory for searching. If not
  563.   specified, the current default directory is used. DOS pathname
  564.   shorthand is supported. If a new drive is specified, the
  565.   starting directory defaults to the root directory of that
  566.   drive.
  567.  
  568.   Each option must be specified individually, and separated from
  569.   other options  by a  space or tab. The order of the entries is
  570.   not important.  The case  (upper or  lower) of  entries is not
  571.   important.
  572.  
  573.   When you are displaying a subdirectory diagram and output is
  574.   going to the screen, ROOT will display the current directory
  575.   location in low intensity, while the rest of the
  576.   subdirectories are in high intensity.
  577.  
  578.   If output is being sent to the screen, and the screen has been
  579.   filled, ROOT will prompt "MORE?". Type <CR> (carriage return)
  580.   to get another single line of output, <space bar> or Y to get
  581.   another screenful, or any other key to quit operation of ROOT.
  582.  
  583.   The output of ROOT can be redirected using the standard MS-DOS
  584.   facilities. This allows the results of ROOT to be sent to a
  585.   file, the printer, or the input of another program. By
  586.   default, the output of ROOT is sent to the screen.
  587.  
  588.   Obtain a summary of ROOT options at any time by typing
  589.  
  590.     ROOT -?
  591.  
  592.  
  593. C. Command Options
  594.  
  595. -S
  596.   Show total Size (in bytes) used by files in each subdirectory;
  597.   otherwise size is not shown. Size is cluster-justified using a
  598.   cluster size read from the drive being searched.
  599.  
  600. -N
  601.   Do Not sort the subdirectory entries alphabetically. Otherwise
  602.   each level of the root structure is shown in alphabetical
  603.   order.
  604.  
  605. -W
  606.   Show Whole pathname for each subdirectory entry, otherwise
  607.   only the significant words of each pathname are shown.
  608.  
  609. -T
  610.   Start the subdirectory search at the Top level directory,
  611.   otherwise ROOT searches downward from the current default
  612.   directory. (This is equivalent to specifying a pathname of \).
  613.  
  614. -F filename
  615.   Find the file named filename. Wildcard characters accepted by
  616.   DOS (*, ?) are acceptable in filename. Filename must be
  617.   separated with a space from the -F flag, but must follow
  618.   immediately thereafter. -T is the only other option that has
  619.   meaning when -F is used. The search for filename will find a
  620.   maximum of 512 matching files in each directory, but will warn
  621.   when that limit is reached. The search is also limited to 6
  622.   levels of subdirectories below the starting directory. Again,
  623.   a warning will be issued when this limit is reached. When a
  624.   file matching filename is found, ROOT offers the following
  625.   commands:
  626.  
  627.   Q  Quit searching.
  628.   S  Search further.
  629.   T  Type the file to the screen.
  630.   P  Print the file on the default printer.
  631.   C  Copy the file to your current directory.
  632.   M  Move default directory to where file was found and quit.
  633.   D  Delete the file.
  634.   E  Execute the file and quit (.COM and .EXE files only).
  635.   I  Display full directory information regarding the file.
  636.   ?  Display a help message.
  637.  
  638.   You will be prompted to choose one of these commands.
  639.  
  640.   If the output of ROOT has been redirected to anywhere besides
  641.   the screen, interactive prompting will not occur. Instead, a
  642.   list of the matches found will be written to the redirected
  643.   output device. This list is comprised of a single line for
  644.   each match, where each line is a complete pathname and
  645.   filename.
  646.  
  647.  
  648. D. Examples
  649.  
  650.     ROOT
  651.  
  652.   Displays the subdirectory diagram of the default drive,
  653.   starting at the current directory, sorted alphabetically, on
  654.   the screen.
  655.  
  656.     ROOT c:\ -s -w >prn
  657.  
  658.   Prints the entire directory structure of disk C: including the
  659.   number of bytes used in each subdirectory, and the whole
  660.   pathname of each subdirectory.
  661.  
  662.     ROOT -t -f *.pas
  663.  
  664.   Searches the current drive, starting at the top level, for all
  665.   files with the extension .PAS. For each file found, ROOT will
  666.   offer the choices described at the end of the options section.
  667.  
  668.     ROOT -t -f *.pas >pasfiles.dat
  669.  
  670.   Writes a file pasfiles.dat containing the names and locations
  671.   of all files having the extension .PAS.
  672.  
  673.     ROOT -f *.bak | REP {del @0} -q
  674.  
  675.   Pipes the output of ROOT into REP, which then deletes all .BAK
  676.   files found in and below the current directory, after getting
  677.   user confirmation for each one.
  678.  
  679.     ROOT .. -n
  680.  
  681.   Shows all subdirectories attached to the parent of the current
  682.   directory, in the order that they are stored on the disk.
  683.  
  684.   -----------------------------------------------------------
  685.  
  686. 7. REP - Command Repeater
  687.  
  688. A. Purpose
  689.  
  690.   REP combines a programmable text parser with the ability to
  691.   execute any command allowed by MS-DOS. Programmers often want
  692.   to run the same program several times, with the only
  693.   difference being the data or files supplied as input to the
  694.   program. REP was developed specifically for this purpose, but
  695.   it offers a level of programmability that will make it
  696.   suitable for a wide range of applications.
  697.  
  698.   A few examples may illustrate REP's value. REP can
  699.   automatically:
  700.  
  701.    o  Delete all .BAK files older than 90 days in all
  702.       subdirectories.
  703.  
  704.    o  Copy files from all subdirectories of a diskette into a
  705.       single directory of a target drive.
  706.  
  707.    o  Print all the source files making up a program.
  708.  
  709.    o  Use RPL to find all instances of the variable XXX1 in all
  710.       source files of a program (and optionally replace it).
  711.  
  712.    o  Use DIFF to find differences between .BAK files and their
  713.       latest versions, and save the results to a single file.
  714.  
  715.    o  Print 107 copies of a disk label.
  716.  
  717.    o  Run a batch file and prompt for or provide the changing
  718.       input parameters to the batch file.
  719.  
  720.    o  Act as a general purpose (albeit slow) parser using the
  721.       ECHO statement.
  722.  
  723.   We will show how to implement these examples later in this
  724.   section.
  725.  
  726.   The basic operation of REP is straightforward, although it
  727.   offers so much power that you may initially be hesitant about
  728.   using it. REP reads one text line at a time from the standard
  729.   input. Using specified delimiters, REP then parses the text
  730.   line into words, and from those words and other options REP
  731.   builds a full command description. REP then executes the
  732.   command. When the command is finished, control is returned to
  733.   REP, which reads another text line from standard input and
  734.   repeats the process.
  735.  
  736.  
  737. B. Usage
  738.  
  739.   REP is called as follows:
  740.  
  741.     REP [options] {Command} [input redir]
  742.  
  743.   REP does not offer a prompted input mode, except to allow you
  744.   to specify a command tail if you have typed just REP.
  745.  
  746.   Command is any DOS internal, .COM, .EXE, or .BAT command along
  747.   with associated command line arguments. Command must be
  748.   surrounded by curly braces {}. It may contain spaces. The
  749.   command should be entered in just the same way as it is
  750.   usually entered at the DOS prompt, with two exceptions. First,
  751.   the Command name and its parameters or options may include
  752.   parser symbols, to be described below. Second, Command may not
  753.   directly specify input/output redirection. Redirection is
  754.   obtained using a REP option below. If I/O redirection were
  755.   specified within Command, MS-DOS would interpret it to mean
  756.   that we were redirecting the I/O of REP and not that of
  757.   Command.
  758.  
  759.   If you want Command to specify another call to REP (the DOS
  760.   equivalent of recursion), you must be careful. REP does not
  761.   support nesting of curly braces, so the second level Command
  762.   must be hidden using the REP -F option to be described below.
  763.   RAM space will also set a limit on this form of recursion.
  764.  
  765.   REP reads data lines from the standard input, which you may
  766.   wish to redirect so that they come from a file, or from the
  767.   output of another program. If REP input is not redirected, you
  768.   will be prompted to enter a data line at the keyboard. In that
  769.   case, you should terminate each data line with <carriage
  770.   return>. When you are done, enter <Ctrl-Z>.
  771.  
  772.   REP parses each input data line into words using a set of
  773.   delimiters. By default, the delimiters are space (ASCII 32)
  774.   and tab (ASCII 9). You may change the delimiter set using a
  775.   REP option. When parsing is complete, REP has a set of words
  776.   that may be used to perform substitutions into Command and
  777.   into other areas of the REP command line.
  778.  
  779.   The symbols by which you refer to the parsed words are as
  780.   follows:
  781.  
  782. @n
  783.   nth parsed word of input line (0<n<21).
  784.  
  785. @0
  786.   Entire input line (zero, not "oh").
  787.  
  788. @L
  789.   Last word of input line. (@l ok)
  790.  
  791. @P
  792.   All but last word of input line. (@p ok)
  793.  
  794. @B
  795.   Discretionary backslash. (@b ok)
  796.  
  797. @C(Start,Length)
  798.   Copies a substring of the standard input line starting at
  799.   position Start and extending for Length characters.
  800.  
  801.   For example, if the input data line is
  802.  
  803.   TEMPFILE DAT 32544 2-11-85 12:02
  804.  
  805.   then @1 refers to TEMPFILE, @3 refers to 32544, @L refers to
  806.   12:02, and @P refers to TEMPFILE DAT 32544 2-11-85
  807.  
  808.   Note that the delimiter characters themselves do not appear in
  809.   the parsed words, with the exception of the @0 and @P symbols.
  810.   For these symbols, all delimiters internal to the string
  811.   remain as in the input line.
  812.  
  813.   The @B symbol is introduced to work around a quirk of MS-DOS.
  814.   The pathname of the root directory ends in backslash \, but no
  815.   other subdirectory names end in backslash. When we want to
  816.   append a filename to a pathname, there must always be a
  817.   backslash between the pathname and filename. The discretionary
  818.   backslash symbol looks at the previous character of the
  819.   string. If it does not find a backslash, it adds one. If it
  820.   does find one, it doesn't add another one. In the Examples
  821.   section we illustrate the importance of this symbol.
  822.  
  823.   Parser symbols may be used anywhere in Command, Device, or
  824.   Path (see below for usage of Device and Path) in order to
  825.   customize the command for the particular data line read.
  826.  
  827.   @ is also used as an escape character, when a literal instance
  828.   of any of the special characters must be included. Special
  829.   characters are #,^,@,{, and }. Thus, to obtain a literal right
  830.   curly brace, you must enter @}.
  831.  
  832.  
  833. C. Command Options
  834.  
  835. 1. Redirecting Command Input and Output
  836.  
  837. -I Device
  838.   redirect Command Input.
  839.  
  840. -O Device
  841.   redirect Command Output.
  842.  
  843. -A Device
  844.   Append Command output.
  845.  
  846.   Device is any valid MS-DOS device (e.g. PRN, CON, NUL) or file
  847.   (including optional pathname). As in MS-DOS, using PRN (the
  848.   printer) as an input device is not acceptable. Only files are
  849.   meaningful when using the append option. These three command
  850.   options are the equivalent of the symbols <, >, and >>
  851.   respectively that normally are entered at the DOS prompt.
  852.   Device must be separated by a space from the option keyword,
  853.   but otherwise must immediately follow it. Device may include
  854.   parser symbols, which will be replaced by input data before
  855.   Command is executed.
  856.  
  857.   If you want command input to come from the keyboard and
  858.   command output to go to the screen, then there is no need to
  859.   specify these options. Note that standard input of Command is
  860.   redirected independently from the standard input of REP.
  861.  
  862.  
  863. 2.Changing Current Directory
  864.  
  865.   Some commands require that any files used be located in the
  866.   current default directory. REP offers the capability of
  867.   automatically changing directory before Command is executed,
  868.   by means of the following option:
  869.  
  870. -M Path
  871.   Move to directory Path before executing command.
  872.  
  873.   Path is any valid MS-DOS 2.X pathname. Path may contain parser
  874.   symbols, which will be replaced by input data before Command
  875.   is executed.
  876.  
  877.   You may wish to guarantee that you return to the initial
  878.   directory at the end of the REP run. This is specified with
  879.   the following option.
  880.  
  881. -H
  882.   Return to initial (Home) directory after executing all
  883.   commands.
  884.  
  885.  
  886. 3.Changing Delimiters Used by the Parser
  887.  
  888. As mentioned above, the data line parser uses space and tab as
  889. default delimiters. Sometimes you may wish to use other
  890. characters instead. This is specified with the following option:
  891.  
  892. -D Delims
  893.   Provide a new Delimiter set to the parser. When -D is
  894.   specified, the default delimiters are forgotten. Delims may
  895.   not contain any blank space and must be separated from the -D
  896.   keyword by at least a space. Each character in Delims is
  897.   significant. The new delimiters are simply typed one after the
  898.   other. Order of the delimiters is not important.
  899.  
  900. In some cases you may wish to specify non-printable or blank
  901. characters as delimiters. REP supports the following conventions
  902. for interpreting characters:
  903.  
  904. c
  905.   Any printable character c, if c has no special meaning.
  906.  
  907. #nnn
  908.   ASCII character nnn (0<=nnn<=255, must be terminated with
  909.   non-numeric character). For example, #13 is a carriage return.
  910.  
  911. ^c
  912.   Control character c (c must be a legal control character). For
  913.   example, ^I is a tab.
  914.  
  915. If you wish to use # or ^ as a literal delimiter, you must
  916. specify it indirectly, either with an escape symbol (e.g. @^) or
  917. using the ASCII sequence (e.g. ^ is #94).
  918.  
  919.  
  920. 4.Sending Keystrokes to the Command
  921.  
  922.   REP can supply a limited amount of interactive input to the
  923.   commands that it executes. For example, a program may require
  924.   that you answer a Yes/No prompt before it continues with the
  925.   rest of its activities. REP handles this by temporarily taking
  926.   over the keyboard interrupt handler. It requires IBM BIOS
  927.   compatibility to function correctly. The number of keystrokes
  928.   that REP can send to the command is not limited by the size of
  929.   the keyboard buffer. Key stuffing in REP is compatible with
  930.   Superkey and other programs which expand the keyboard buffer
  931.   size. You can specify up to 255 characters which REP will pass
  932.   along to the command being executed.
  933.  
  934.   REP also overrides the keyboard clearing operation that many
  935.   programs perform at startup. Certain programs may work around
  936.   the approved clearing technique, but REP works at least with
  937.   Turbo Pascal, WordStar and DOS commands such as FORMAT.
  938.  
  939.   To send keystrokes, use the following option:
  940.  
  941. -K Keys
  942.   Send Keys to the keyboard buffer before command begins.
  943.  
  944.   Specify Keys exactly the same way as Delims in the previous
  945.   option. In addition, you may use Parser Symbols within Keys.
  946.  
  947.   Some programs (PC-File III version 3 is an example) cannot
  948.   keep up with the speed of machine-generated keystroking. To
  949.   slow down the keystrokes for such programs, use the -Wn
  950.   option:
  951.  
  952.   -Wn
  953.     Wait n keystrokes.
  954.  
  955.   If it appears that your program cannot keep up, try -W2 or
  956.   larger. You can send function and <Alt> keys to your commands:
  957.   Simply use a #0 to start the <Alt> sequence and follow that by
  958.   the scan code of the character. For example, <Alt> A is #0#30,
  959.   function key <F1> is #0#59, and shift <F1> is #0#84. You can
  960.   find these scan codes in your BASIC manual or the Turbo Pascal
  961.   version 3.0 manual.
  962.  
  963.  
  964. 5.Double-Checking Commands
  965.  
  966.   You may be concerned that a command repeater could make an
  967.   error and run wild, deleting everything on your disk. This is
  968.   possible, but REP provides options to control the possibility.
  969.   It is especially important to use these control options when
  970.   you are developing a new REP application.
  971.  
  972. -Q
  973.   Query (Yes/No/Quit) before proceeding with each command.
  974.  
  975. -X
  976.   eXit after DOS errors (otherwise, the next data line is
  977.   attempted).
  978.  
  979. -W File
  980.   Write commands to File without executing them. You can check
  981.   the contents of this File to make sure it will do what you
  982.   intend. The file can then be executed as a batch file. Default
  983.   extension for File is .BAT. It may be preceded by optional
  984.   drive and pathname.
  985.  
  986.   Note that by default, REP does none of these.
  987.  
  988.   A DOS error is triggered if REP tries to move to a
  989.   non-existent directory, or tries to execute a non-existent
  990.   command, or tries to open a non-existent file as standard
  991.   input or output. Whenever these conditions are encountered,
  992.   the command line in question is not executed. However, when
  993.   the -X option is specified, REP gives up totally and does not
  994.   attempt any more data lines.
  995.  
  996.   REP cannot tell whether the command that was executed had its
  997.   own internal error unless that command sends back a return
  998.   code. Unfortunately, most programs do not provide return
  999.   codes, but REP tests them anyway, just in case. The TurboPower
  1000.   Utilities themselves provide return codes.
  1001.  
  1002.   If for some reason you need to abort the operation of REP, you
  1003.   should hold the <Ctrl> and <Break> keys down continuously
  1004.   until the program is stopped. REP checks for breaks in several
  1005.   ways, but because it can nest several levels of command
  1006.   interpreters it may take several breaks to stop all
  1007.   operations.
  1008.  
  1009.  
  1010. 6.REP Output Options
  1011.  
  1012.   You may wish to know where in a long list of commands REP
  1013.   currently is, or you may wish to include the command line in
  1014.   the output of the command being executed for later reference.
  1015.   These possibilities are specified as follows:
  1016.  
  1017. -C
  1018.   Append each Command line to command output before it is
  1019.   executed.
  1020.  
  1021. -S
  1022.   Write each command line to Screen before it is executed.
  1023.  
  1024.   The first option, -C, looks at the output destination of the
  1025.   command itself and appends the command line to that device or
  1026.   file.
  1027.  
  1028.   The second case writes the command to the screen, no matter
  1029.   where command output is going.
  1030.  
  1031.  
  1032. 7.Taking REP Command Line from a File
  1033.  
  1034.   You will probably not want to repeatedly type REP command
  1035.   lines once you have them figured out. There are two ways to
  1036.   avoid this. First, you can make the entire REP command part of
  1037.   a batch file, possibly with batch parameters passed into REP.
  1038.   Second, you can have REP read its command line from a file as
  1039.   specified by the following option:
  1040.  
  1041. -F File
  1042.   Read first line of File and include it into REP command line.
  1043.  
  1044. File is any valid DOS filename (including optional drive and
  1045. pathname). If no pathname is supplied, and the file is not found
  1046. in the current directory, REP searches the PATH environment to
  1047. find File. Note that only a single line of File is read. Other
  1048. lines may be used as comments. -F commands may be nested to
  1049. arbitrary depth. The default extension for File is .REP.
  1050.  
  1051. By means of -F options or batch commands, REP calls may be
  1052. nested to any depth, limited only by available RAM. Each time
  1053. REP is called, it reduces the amount of RAM available to a
  1054. called program by about 40K bytes.
  1055.  
  1056.  
  1057. 8.Miscellaneous Options
  1058.  
  1059. -B
  1060.   Beep after each command is completed.
  1061.  
  1062. -Rn
  1063.   Repeat command n times (0<n<32768). When the -R option is
  1064.   specified, REP will not read any data from the standard input,
  1065.   and thus will not supply any parsed words to the command. -R
  1066.   is meant for brute force repetition, such as the example of
  1067.   printing 107 disk labels.
  1068.  
  1069.  
  1070. D. Examples
  1071.  
  1072.   Many of the following examples are general purpose, and are
  1073.   best implemented as single line batch files. In the following,
  1074.   some commands have been split over two lines in order to fit
  1075.   the dimensions of the manual. They should of course be typed
  1076.   on a single line when you use them.
  1077.  
  1078.     root -t -f *.bak | REP {del @0} -q
  1079.  
  1080.   Finds all .BAK files (in all subdirectories of the default
  1081.   drive) and deletes them after first getting confirmation.
  1082.  
  1083.     root -t -w | REP {sdir @1 -b90 -dt} -a oldfiles.dat -c
  1084.  
  1085.   Makes a file OLDFILES.DAT containing all filenames whose
  1086.   contents were not modified in the last ninety days.
  1087.  
  1088.     root -t -w | REP {sdir @1@B*.bak -b90 -w} | REP {del @0}
  1089.  
  1090.   Deletes all  .BAK files  older than 90 days (no confirmation).
  1091.   Note the use of @B to append a backslash to the pathname.
  1092.  
  1093.     root -t -w | REP {sdir *.bak -b90 -w} -m @1 -h |
  1094.       REP {del @0} -w delfile.bat
  1095.  
  1096.   Illustrates another way of approaching the previous example,
  1097.   using the -m (move to directory) option and the -h (return
  1098.   home) option. This also illustrates the use of the write batch
  1099.   facility. This command does not execute any deletions. Instead
  1100.   it builds a batch file DELFILE.BAT that contains the deletion
  1101.   commands. You can then examine the batch file and execute if
  1102.   it is OK.
  1103.  
  1104.     root a: -w | REP {sdir @1 -w} | REP {copy @0 @L} -d \ -s
  1105.  
  1106.   Copies all files in all subdirectories of drive a: to the
  1107.   current default directory.
  1108.  
  1109.     root -w c: | REP {sdir -t @1} -o prn
  1110.  
  1111.   Prints a directory of every subdirectory on disk C:.
  1112.  
  1113.     sdir rpl*.inc | REP {print @1.@2}
  1114.  
  1115.   Prints all files in the current directory which match
  1116.   rpl*.inc. Note that a literal period . must be inserted into
  1117.   the output of SDIR to get a legal filename.
  1118.  
  1119.     REP {print dlabel.dat} -r107
  1120.  
  1121.   Prints 107 copies of dlabel.dat.
  1122.  
  1123.     REP {rpl -n -m lineval}
  1124.       -i @0 -a lineval.loc -c -s <make.rpl
  1125.  
  1126.   MAKE.RPL contains a line naming each source file that goes
  1127.   into making up the program RPL. This command then creates a
  1128.   file named LINEVAL.LOC that contains the name of the file,
  1129.   then each line number and program line containing the word
  1130.   lineval. In using RPL, your match patterns may not contain the
  1131.   characters {, }, # or ^ unless you hide them using the -F
  1132.   option of RPL, or "escape" them with the REP character @.
  1133.  
  1134.     REP {diff @1.@2 @1.BAK -c} -d . -a rpl.dif -c <make.rpl
  1135.  
  1136.   Runs DIFF on all files making up RPL and writes the number of
  1137.   differences between each file and its backup to RPL.DIF. Note
  1138.   the only parser delimiter is a period. If a .BAK file doesn't
  1139.   exist, REP will continue with the next input file.
  1140.  
  1141.     sdir | REP {ECHO @4 @3} -a sizedate.dat
  1142.  
  1143.   REP acts as a simple parser to put the date and size of each
  1144.   file in the current directory into the file sizedate.dat.
  1145.  
  1146.     root \ -w | REP {sdir @1 -mb -to -s1024} -a baksize.dat
  1147.  
  1148.   Builds a file baksize.dat that shows the size of files
  1149.   requiring backup in every directory of a disk. Sector rounding
  1150.   assumes that you will write backup to a DSDD floppy. See the
  1151.   supplied batch file BAKUP.BAT for a more sophisticated version
  1152.   of this function.
  1153.  
  1154.     REP {mybatfil @1 @2 2311 1266 6697} -q
  1155.  
  1156.   MYBATFIL is your own batch file requiring 5 parameters. REP
  1157.   waits for you to type the first two parameters followed by a
  1158.   <return>, then echoes the command line and gets you to confirm
  1159.   it before it runs the batch job.
  1160.  
  1161.   -----------------------------------------------------------
  1162.  
  1163. 8. DIFF - Text File Difference Finder
  1164.  
  1165. A. Purpose
  1166.  
  1167.   DIFF is used to compare the contents of two text files and
  1168.   then report any differences. It uses a sophisticated algorithm
  1169.   to regain synchronization after unmatched lines are found. It
  1170.   therefore can be used to compare files with an arbitrarily
  1171.   large number of differences, or files with a very small number
  1172.   of differences (including zero).
  1173.  
  1174.   DIFF offers a number of features that generalize the
  1175.   comparison process. By default, DIFF compares every character
  1176.   of each file. Optionally, certain types of differences can be
  1177.   ignored. These include the case (upper/lower) of characters,
  1178.   blanks and tabs, blank lines and formfeeds, arbitrary
  1179.   characters, and comments delimited as they are in Pascal.
  1180.  
  1181.   One application of DIFF is as an archival mechanism. To reduce
  1182.   archival storage space, only the differences between
  1183.   successive file versions need be stored. To support this
  1184.   application, DIFF offers an output format which is an EDLIN
  1185.   editor script. With this script, the previous version of a
  1186.   file can be automatically generated from the current version.
  1187.   Use of this script will be described in detail in the Examples
  1188.   section.
  1189.  
  1190.   DIFF also provides output formats meant to be read by humans.
  1191.   These are intended to answer the general questions, "Are these
  1192.   two files different? and (perhaps) where? and (perhaps) how?"
  1193.   The various options will be described below.
  1194.  
  1195.  
  1196. B. Usage
  1197.  
  1198.   Simply typing DIFF will initiate an interactive prompting
  1199.   session wherein DIFF asks about everything it needs to know.
  1200.   This is referred to as prompt mode. To fully understand the
  1201.   meaning of the prompts, it is worthwhile to study the options
  1202.   section below. To get started, however, you can just dive in
  1203.   and type DIFF.
  1204.  
  1205.   DIFF may also be called with command line arguments. In this
  1206.   case, the command line format is:
  1207.  
  1208.     DIFF [options] OrigFile ModFile [output redir]
  1209.  
  1210.   Options will be described in detail below. OrigFile and
  1211.   ModFile are any valid DOS filenames whose contents are ASCII
  1212.   text. Both files must be specified. There is no default
  1213.   extension. Files should be found in the current default
  1214.   directory unless preceded by an optional drive and pathname.
  1215.  
  1216.   DIFF sends its results to the standard output device. By
  1217.   default this is the screen. To send results to a file, to the
  1218.   printer, or to the input of another program use the MS-DOS 2.X
  1219.   redirection facilities.
  1220.  
  1221.   DIFF maintains a status line during execution showing its
  1222.   current location. This status information will NOT be
  1223.   redirected when the standard output is redirected.
  1224.  
  1225.   DIFF is designed to be used only with ASCII text files. Using
  1226.   it with binary files will probably overflow DIFF's input
  1227.   buffers and is sure to produce garbage for results. Each line
  1228.   of the ASCII text file must be terminated by at least a
  1229.   <carriage return> (ASCII character 13). Line feed characters
  1230.   (ASCII 10) are ignored. The longest line allowed is 1024
  1231.   characters. During the comparison, any line longer than 1024
  1232.   characters will be broken at 1024 and an extra <carriage
  1233.   return><linefeed> sequence inserted. This may lead to
  1234.   unexpected differences showing up in the output.
  1235.  
  1236.   DIFF contains an integral MORE filter. Whenever output is
  1237.   written to the screen (not redirected to a file or any other
  1238.   device), and 24 lines of output are written, DIFF will prompt
  1239.   "MORE?". Enter a space or a Y to get another screenful, a
  1240.   <return> to get another line, or any other key to quit.
  1241.  
  1242.   The largest files that DIFF can compare are limited by RAM
  1243.   space, and by the degree of dissimilarity of the two files.
  1244.   DIFF uses all available memory, up to a maximum of 128K bytes,
  1245.   for internal text string storage from the two files being
  1246.   compared. As a result, DIFF can generally compare two files
  1247.   each up to 64K bytes in size, but with no more than 3000 lines
  1248.   per file. However, if you have the source code this can be
  1249.   increased by looking at the constant declarations in DIFF.PAS.
  1250.   If two files bearing no relation to one another are compared,
  1251.   the maximum file size may be less. If any of the DIFF options
  1252.   which disregard text features are being used, the maximum file
  1253.   size is reduced by roughly half, since DIFF must internally
  1254.   store both the original and compressed text lines. If DIFF
  1255.   runs out of memory, it will complain and halt gracefully. If
  1256.   this happens you should divide your files into smaller pieces
  1257.   before running DIFF. DIFF can be interrupted by typing
  1258.   <Ctrl-Break> or <Ctrl-C>. Output can be temporarily stopped by
  1259.   typing <Ctrl-S> and then continued by typing <Ctrl-Q>.
  1260.  
  1261.  
  1262. C. Command Options
  1263.  
  1264. 1.Disregarding Differences
  1265.  
  1266.   By default, none of these options is active.
  1267.  
  1268. -DC
  1269.   Disregard Case of alphabetic characters. All characters are
  1270.   converted to upper case before comparison (this occurs
  1271.   internally to the program, and does not affect the input
  1272.   files, or the appearance of the output).
  1273.  
  1274. -DS
  1275.   Disregard Spacing. All blanks and tabs are removed from each
  1276.   text line before comparison. This includes leading blanks,
  1277.   trailing blanks, and blanks in the middle of the line.
  1278.  
  1279. -DB
  1280.   Disregard Blank lines. Any line consisting of only <CR>
  1281.   (carriage return), <CR><LF> (carriage return linefeed), or the
  1282.   combination of either of these with a formfeed <FF>, will be
  1283.   ignored. Please note that the line numbers reported by DIFF in
  1284.   this case count only the non-blank lines.
  1285.  
  1286. -DP
  1287.   Disregard Pascal comments. Any sequence of text that is
  1288.   properly delimited by the Pascal comment identifiers (which
  1289.   are { } (* *) ) will be ignored. Comments may extend across
  1290.   multiple lines and still be properly handled. Note that the
  1291.   appearance of these comment delimiters within Pascal literals
  1292.   (e.g., string assignments) will still cause DIFF to interpret
  1293.   the comment delimiters. Watch out for this!
  1294.  
  1295. -DK Keys
  1296.   Disregard any characters contained within the list Keys. Keys
  1297.   are specified just like Keys or Delims for the REP utility.
  1298.   You may specify up to 63 characters in the key list.
  1299.  
  1300.   Again, note that using the Disregard options will reduce
  1301.   DIFF's file capacity limits. The exact amount of reduction
  1302.   also depends on the extra degree of similarity gained by
  1303.   disregarding text features.
  1304.  
  1305.   If you wish to compare two Pascal files, one of which has been
  1306.   formatted by PF, and the other of which hasn't, you should use
  1307.   the two options -DC and -DS. Then DIFF reports only
  1308.   substantive differences.
  1309.  
  1310.  
  1311. 2.Formatting the Output of DIFF
  1312.  
  1313. -S
  1314.   Build an EDLIN Script. In this mode DIFF builds a list of
  1315.   editor commands which will automatically convert OrigFile into
  1316.   ModFile. We will describe how to run this script in the
  1317.   Examples section below. By default, Script mode is not active.
  1318.  
  1319.   When -S is selected, all Disregard options are ignored. Script
  1320.   mode is intended to produce an exact replica of ModFile, and
  1321.   therefore no text features can be disregarded. When -S is
  1322.   selected, none of the other Output Formatting options can be
  1323.   activated. -S is a self-contained option. However, the
  1324.   miscellaneous options described in section 3 below are still
  1325.   available.
  1326.  
  1327. -M
  1328.   Send Matched lines of the two files to the output. By default,
  1329.   this option is not active. If any of the Disregard options are
  1330.   active, the full versions of two lines may be different
  1331.   although they match after compression. In this case, DIFF will
  1332.   display the text line as it appears in ModFile.
  1333.  
  1334. -ND
  1335.   Do Not send Deleted lines to the output. Deleted lines are
  1336.   those that appear in OrigFile but do not appear (in the same
  1337.   relative order, at least) in ModFile. By default, all deleted
  1338.   lines are sent to the output.
  1339.  
  1340. -NI
  1341.   Do Not send Inserted lines to the output. Inserted lines are
  1342.   those not found in OrigFile that must be inserted (or
  1343.   appended) to create ModFile. By default, all inserted lines
  1344.   are sent to the output.
  1345.  
  1346. -NH
  1347.   Do Not send a Header line for each line sent to the output.
  1348.   The header line tells whether the text line following is
  1349.   matched, deleted, or inserted. It also gives the line number
  1350.   of the text line. The line number refers to position in
  1351.   OrigFile for deleted lines, and to the position in ModFile for
  1352.   inserted lines. For matched lines, the position in both
  1353.   OrigFile and ModFile is reported. By default, a header line is
  1354.   sent with each text line that goes to the output.
  1355.  
  1356. -B
  1357.   Use a Block format in reporting the output. In this mode, all
  1358.   consecutive instances of inserts (or deletes, or matches) are
  1359.   grouped into a continuous block of output, preceded by a
  1360.   single header line. In this case the header line reports the
  1361.   range of line numbers affected. This format is easier for
  1362.   humans to look at, but harder for machines to interpret. The
  1363.   -M, -ND, and -NI options may be applied in combination with
  1364.   block mode, but the headers cannot be turned off. By default,
  1365.   block mode is not active.
  1366.  
  1367. -C
  1368.   Count number of differing lines and send this number to the
  1369.   output. This mode turns off all other output formatting modes
  1370.   and produces just a single number. By default, this mode is
  1371.   not active.
  1372.  
  1373.  
  1374. 3.Miscellaneous Options
  1375.  
  1376. -Wn
  1377.   Write a maximum of n differences before quitting. n is an
  1378.   integer between 1 and 32767. By default, all differences are
  1379.   reported, no matter how many. n must immediately follow the W,
  1380.   with no spaces intervening.
  1381.  
  1382. -P
  1383.   Send Performance statistics to the screen when the run has
  1384.   been completed. Performance statistics include the amount of
  1385.   RAM space used and the processing rate (in lines per second).
  1386.   By default, performance statistics are not printed.
  1387.  
  1388. -?
  1389.   Display a help screen describing the command options. DIFF
  1390.   halts after displaying the help screen.
  1391.  
  1392.  
  1393. D. Using the Script Mode
  1394.  
  1395.     DIFF myfile.pas myfile.bak -s >myfile.s00
  1396.  
  1397.   Produces an EDLIN script that will convert myfile.pas into
  1398.   myfile.bak. The script is saved on a file named myfile.s00.
  1399.   Once the script has been created, the .BAK file can be
  1400.   deleted. A series of scripts having sequentially numbered
  1401.   extensions can be stored to represent the entire history of a
  1402.   file.
  1403.  
  1404.   To use the script of this example to recreate rev 00 of
  1405.   myfile, type
  1406.  
  1407.     COPY myfile.pas myfile.r00
  1408.     EDLIN myfile.r00 <myfile.s00
  1409.  
  1410.   As EDLIN executes, you will see a trace of its activities sent
  1411.   to the screen. When EDLIN finishes, myfile.r00 will be
  1412.   identical to what myfile.bak was when you started.
  1413.  
  1414.   If you do not wish to watch EDLIN's activities, call it as
  1415.   follows:
  1416.  
  1417.     EDLIN myfile.r00 <myfile.s00 >nul
  1418.  
  1419.   If you want to save the editing trace, call EDLIN as follows:
  1420.  
  1421.     EDLIN myfile.r00 <myfile.s00 >myfile.t00
  1422.  
  1423.   Myfile.t00 will contain the trace.
  1424.  
  1425.   If you have saved a series of scripts, and want to regenerate
  1426.   a version of the file that is more than one version out of
  1427.   date, then it is necessary to call EDLIN once for each script
  1428.   between the current file and the desired one.
  1429.  
  1430.   If you have edited the file since you created a script, and
  1431.   you wish to regenerate an old version, you must use the .BAK
  1432.   version of the file as a starting point, and not the most
  1433.   current version. To avoid confusion, it is better to keep two
  1434.   full versions of the file around at any time. One version is
  1435.   the last one which was archived using DIFF, and the other
  1436.   version is the current one. The previously archived version
  1437.   should be named as something besides *.BAK so that it isn't
  1438.   overwritten during editing.
  1439.  
  1440. E. Further Examples
  1441.  
  1442.     DIFF -B xxx.old xxx.new
  1443.  
  1444.   All differences between xxx.old and xxx.new will be sent to
  1445.   the screen in block format.
  1446.  
  1447.     DIFF -M -ND -NI -NH xxx.old xxx.new >xxx.mat
  1448.  
  1449.   All of the matched lines between xxx.old and xxx.new will be
  1450.   sent to the file xxx.mat. No header information, only the
  1451.   text, is included.
  1452.  
  1453.     DIFF -C -DC -DS -DB xxx.old xxx.new
  1454.  
  1455.   Reports the number of lines that differ between xxx.old and
  1456.   xxx.new after differences in case, spacing and blank lines are
  1457.   disregarded.
  1458.  
  1459.     DIFF -DK ;,.':()! -DC xxx.old xxx.new
  1460.  
  1461.   Reports the differences after case and common punctuation are
  1462.   disregarded.
  1463.  
  1464.   -----------------------------------------------------------
  1465.  
  1466. 9. RPL - Pattern Match and Replace
  1467.  
  1468. A. Purpose
  1469.  
  1470.   RPL is used to find occurrences of specified text patterns in
  1471.   a file and then optionally replace the matched text with other
  1472.   text. RPL provides much more flexibility in what can be
  1473.   matched and replaced than the typical replace command offered
  1474.   by a text editor.
  1475.  
  1476.   RPL is not an interactive program like an editor. It takes a
  1477.   set of patterns and files as an input, and produces lines of
  1478.   output based on all of the input. The input and output can be
  1479.   of any size, limited only by disk space and an individual line
  1480.   length of 1024 characters.
  1481.  
  1482.   RPL takes its input from the standard input device and writes
  1483.   its output to the standard output device. Because RPL is often
  1484.   used in pipelines (where the output of one program feeds the
  1485.   input of another program), the use of standard I/O is
  1486.   important and powerful.
  1487.  
  1488.   To specify match and replace patterns, RPL uses regular
  1489.   expressions in the style of the Unix operating system. If you
  1490.   haven't seen regular expressions before, you will probably
  1491.   think that a sparrow has been hopping on the top row of your
  1492.   keyboard when you see your first one. However, like the APL
  1493.   language, regular expressions carry a heavy load of meaning in
  1494.   a small amount of space.
  1495.  
  1496.   To get you started with RPL, about a dozen RPL application
  1497.   commands have been supplied. As you will see in the Examples
  1498.   section, these commands can handle some useful and complicated
  1499.   problems. Because RPL application commands are often general
  1500.   purpose and reusable, RPL is designed to provide convenient
  1501.   access to libraries of these commands.
  1502.  
  1503.   Those familiar with Unix text utilities will find that RPL is
  1504.   somewhere between EGREP and AWK with regard to the complexity
  1505.   of problems that it can solve. Several words of the regular
  1506.   expression syntax have been changed from their format in Unix
  1507.   in order to mesh well with MS-DOS.
  1508.  
  1509.  
  1510. B. Usage
  1511.  
  1512.   Simply typing RPL will initiate an interactive prompting
  1513.   session. To fully understand the meaning of the prompts, it is
  1514.   worthwhile to study the material below. If you have not used
  1515.   regular expressions before, you should definitely read the
  1516.   sections below.
  1517.  
  1518.   RPL may be called with command line arguments as follows:
  1519.  
  1520.     RPL [-F CommandFile] [options] [I/O redir]
  1521.  
  1522.   Options are described in detail below.
  1523.  
  1524.  
  1525. 1.Command Files
  1526.  
  1527.   The entry -F CommandFile specifies that RPL should read the
  1528.   first line of a text file named CommandFile and interpret it
  1529.   as part of the command line. To facilitate the use of
  1530.   libraries of command files, RPL will search the system PATH
  1531.   environment in order to find CommandFile (after checking the
  1532.   current default directory). This allows all command files to
  1533.   be kept in one place (e.g. on your utilities diskette, or in
  1534.   the top level directory of your hard disk) and accessed from
  1535.   anywhere on the system. The default extension of a command
  1536.   file is .PAT.
  1537.  
  1538.   Note that ONLY the first line of CommandFile is read and
  1539.   interpreted as a command line. This line may be up to 255
  1540.   characters long. The line read from CommandFile may also
  1541.   contain -F options, which allows nesting of command files to
  1542.   arbitrary depth. Since lines after the first are not
  1543.   interpreted, they may be used for comments describing the
  1544.   purpose of the command they follow.
  1545.  
  1546.   Any single command option or regular expression must be
  1547.   specified completely on a single line. See the Options section
  1548.   below.
  1549.  
  1550.  
  1551. 2.Specifying Input and Output
  1552.  
  1553.   If you call RPL with any options on the command line, you must
  1554.   specify an input file as part of the command line (or input
  1555.   must have been previously redirected). If you call RPL with
  1556.   nothing on the command line, you will be prompted for an input
  1557.   filename.
  1558.  
  1559.   The input file contains the text which will be read to find
  1560.   matches. Only a single input file may be specified (this
  1561.   differs from Unix, which allows multiple files). The file may
  1562.   be specified simply by name, or preceded by the MS-DOS input
  1563.   redirection character <. This file will be found in the
  1564.   current default directory, or can be preceded by a drive and
  1565.   pathname if you wish.
  1566.  
  1567.   RPL writes its output to the standard output device. By
  1568.   default this is the screen. You may redirect the output by
  1569.   using any of the MS-DOS 2.X techniques.
  1570.  
  1571.   You should NOT redirect the output to the same file from which
  1572.   the input is taken. Because line lengths may change
  1573.   significantly during transformation, this might write output
  1574.   over unread input.
  1575.  
  1576.  
  1577. 3.Behavior at Runtime
  1578.  
  1579.   If RPL cannot find a file, or if the syntax of a regular
  1580.   expression or command option is wrong, it will complain (in a
  1581.   somewhat helpful manner) and halt.
  1582.  
  1583.   You can obtain a summary of RPL syntax at any time by typing
  1584.   the command
  1585.  
  1586.     RPL -?
  1587.  
  1588.   RPL contains an integral MORE filter. Whenever output is
  1589.   written to the screen (not redirected to a file or other
  1590.   device) and 24 lines of output are written, the program will
  1591.   prompt "MORE?". Enter a space or a Y for another screenful, a
  1592.   <return> to get a single line, and any other key to quit. For
  1593.   some RPL patterns, the MORE filter may not be effective, since
  1594.   RPL can write one line containing many linefeeds.
  1595.  
  1596.   If RPL standard output is not writing to the screen, it will
  1597.   maintain a status indicator that shows the current line number
  1598.   within the input text file. The line processing rate of RPL
  1599.   varies significantly, depending on what patterns were
  1600.   specified and what the input text is. For the application
  1601.   commands supplied with RPL, the processing rate varies from
  1602.   about two lines per second to over fifty lines per second, so
  1603.   you may want some reassurance as to where RPL is.
  1604.  
  1605.  
  1606. C. Command Options
  1607.  
  1608.   RPL allows control over several independent aspects of the
  1609.   matching and replacing process. These aspects include
  1610.   specifying the regular expression patterns, deciding what
  1611.   types of lines to output, and miscellaneous formatting
  1612.   commands. These areas will be described one at a time.
  1613.  
  1614. 1.Specifying the Regular Expressions
  1615.  
  1616.   RPL allows up to three regular expressions to be applied
  1617.   during a single pass over a text file. The three types of
  1618.   expressions are Select/Avoid, Match, and Replace.
  1619.  
  1620.   A Select/Avoid expression is used exclusively to determine
  1621.   which lines of text are suitable for further processing. If a
  1622.   line of text does not meet the Select/Avoid criteria, no
  1623.   further matching or replacing will be done on that line.
  1624.   Whether that line is output or not comes under the control of
  1625.   the output options described in the next section. Generally, a
  1626.   Select/Avoid expression should be a relatively simple one to
  1627.   filter out lines that may waste a lot of time in more complex
  1628.   Match and Replace expressions.
  1629.  
  1630.   Use of a Select/Avoid expression is optional. Either a -S or a
  1631.   -V option may be specified, but not both. These expressions
  1632.   mean:
  1633.  
  1634. -S Select
  1635.   Use only lines from the input file that match the regular
  1636.   expression Select.
  1637.  
  1638. -V Select
  1639.   Use only lines from the input file that do NOT match Select.
  1640.  
  1641.   Select represents a regular expression in the format to be
  1642.   described. The regular expression must be separated from the
  1643.   option letter by at least one blank, but otherwise must
  1644.   immediately follow it on the command line. The option letter
  1645.   and the regular expression must be found on the same command
  1646.   line (in the same command file).
  1647.  
  1648.   A Match expression is also optional. However, you must provide
  1649.   at least one Select, Avoid, or Match expression, or RPL will
  1650.   have nothing to work with.
  1651.  
  1652.   The Match expression is the main workhorse of RPL. Replacement
  1653.   of text is based on what the Match expression finds. To
  1654.   specify a Match expression, use the following command option:
  1655.  
  1656. -M Match
  1657.   The syntax of this option is the same as for the Select/Avoid
  1658.   option.
  1659.  
  1660.   Finally, an optional Replace expression can be specified. This
  1661.   expression tells RPL how to go about replacing text that was
  1662.   matched. To specify a Replace expression, use the following
  1663.   command option:
  1664.  
  1665. -R Replace
  1666.   The syntax of this option is the same as for the Select/Avoid
  1667.   option (although the regular expression syntax is different,
  1668.   as you will see later).
  1669.  
  1670.  
  1671. 2.Deciding What Lines to Output
  1672.  
  1673.   Depending upon what regular expressions have been specified,
  1674.   there are many combinations of the input lines that we may
  1675.   want to output. We provide three additional command options to
  1676.   control the selection:
  1677.  
  1678. -US
  1679.   Output Un-Selected lines.
  1680.  
  1681. -OM
  1682.   Output Only Modified lines.
  1683.  
  1684. -OC
  1685.   Output only a Count of the lines that would otherwise have
  1686.   been written out.
  1687.  
  1688. In the following table we describe all of the combinations of
  1689. expressions, options and output behavior. 1 means the expression
  1690. or option has been specified. The -OC option is not shown in the
  1691. table. It always has the effect of forcing just a count of the
  1692. lines that would otherwise have been written out.
  1693.  
  1694.  
  1695. Output Combinations
  1696.  
  1697.       Expressions    Options
  1698.       S/V  M    R    US   OM   Lines Output
  1699.       ---  ---  ---  ---  ---  ------------------
  1700.       1    0    0    0    0    selected only
  1701.       0    1    0    0    0    matched only
  1702.       1    1    0    0    0    selected AND matched
  1703.       0    1    1    0    0    unmatched unchanged,
  1704.                                matched modified
  1705.       1    1    1    0    0    selected AND unmatched
  1706.                                unchanged, matched
  1707.                                modified
  1708.       1    1    1    1    0    unselected unchanged,
  1709.                                selected AND unmatched
  1710.                                unchanged, matched
  1711.                                modified
  1712.       0    1    1    0    1    matched modified
  1713.       1    1    1    0    1    selected AND matched
  1714.                                modified
  1715.       1    1    1    1    1    unselected unchanged,
  1716.                                selected AND matched
  1717.                                modified
  1718.  
  1719.   Combinations not shown will produce either an error or trivial
  1720.   results. Perhaps the best way to get the feel of these will be
  1721.   to study the examples provided.
  1722.  
  1723.   The operation of a find function in a typical editor is like
  1724.   that of the second row of the table.
  1725.  
  1726.   The operation of the replace function in a typical editor of
  1727.   like that of the fourth row of the table.
  1728.  
  1729.   The Select and Match expressions combine in a logical AND
  1730.   fashion. Text must match BOTH expressions to be considered for
  1731.   output.
  1732.  
  1733.   The Select/Avoid expression supports the additional function
  1734.   of "avoiding" text. Only text which does NOT match the
  1735.   expression will be considered for output or modification.
  1736.  
  1737.  
  1738. 3.Miscellaneous Formatting Commands
  1739.  
  1740.   RPL supports two additional formatting commands:
  1741.  
  1742. -N
  1743.   Write the line number (from the input text file) to the start
  1744.   of each output line.
  1745.  
  1746. -I
  1747.   Ignore case. All text is internally converted to upper case
  1748.   before matching proceeds. This does not affect the appearance
  1749.   of the output.
  1750.  
  1751.  
  1752. D. Select/Avoid and Match Expressions
  1753.  
  1754.   Regular expressions are combinations of normal text characters
  1755.   and special characters that are interpreted by RPL. A regular
  1756.   expression may be as simple as a fixed text string (e.g.,
  1757.   PROCEDURE will match all instances of the word PROCEDURE) or
  1758.   it may be extremely complicated and match a broad class of
  1759.   text strings.
  1760.  
  1761.   A Match expression operates on a single line of text at one
  1762.   time. No match can span multiple lines of text.
  1763.  
  1764.   Select/Avoid and Match regular expressions are composed of the
  1765.   following:
  1766.  
  1767.   A ? matches any single character except newline. A newline is
  1768.   really two characters in a specific order -- <carriage return>
  1769.   followed by <linefeed>. To match a newline, you must always
  1770.   explicitly specify a newline.
  1771.  
  1772.   A ^ matches at the beginning of a line only. A ^ occurring
  1773.   ANYWHERE in the match expression (except within a character
  1774.   class) is interpreted in this manner. This allows meaningful
  1775.   use of ^ in combination with grouping or alternation (see
  1776.   below).
  1777.  
  1778.   A $ matches at the end of a line only. As with ^ the $
  1779.   character retains its special meaning anywhere within the
  1780.   expression (except in a character class).
  1781.  
  1782.   A \ followed by a single character matches that character. In
  1783.   this way \* will match an asterisk, \\ will match a backslash,
  1784.   \$ will match a dollar sign, etc. However, the following
  1785.   sequences are special:
  1786.  
  1787.        \s      space (ASCII #32)
  1788.        \t      tab (ASCII #9)
  1789.        \b      backspace (ASCII #8)
  1790.        \r      return (ASCII #13)
  1791.        \l      linefeed (ASCII #10)
  1792.        \n      newline (#13 followed by #10)
  1793.        \i      input redirection <
  1794.        \o      output redirection >
  1795.        \p      pipe character |
  1796.        \w      word delimiter
  1797.                  Matches any of the following:
  1798.                    \t\s!"&()*+,-./:;<=>?@[\]^`{|}~
  1799.        \h      hex character
  1800.                  Matches any of 0123456789ABCDEF
  1801.  
  1802.   Case is ALWAYS significant when using the special characters.
  1803.   Thus \s will match a space while \S will match a capital
  1804.   letter S.
  1805.  
  1806.   When a regular expression is specified on a command line or in
  1807.   a command file, the regular expression may NOT contain any
  1808.   blank space. The special characters above should be used to
  1809.   produce instances of blanks and tabs.
  1810.  
  1811.   A single character not otherwise endowed with special meaning
  1812.   matches that character. Thus z matches a single instance of
  1813.   the letter z. Intuitive, huh?
  1814.  
  1815.   A string enclosed in brackets [] specifies a character class.
  1816.   Any single character in the string will be matched. For
  1817.   example, [abc] will match an a, b, or c. Ranges of ASCII
  1818.   letters and numbers may be abbreviated as, for example,
  1819.   [a-z0-9]. If the first symbol following the [ is ^ then a
  1820.   negative character class is specified. In this case, the
  1821.   string matches all characters EXCEPT those enclosed in the
  1822.   brackets. For example, [^a-z] matches everything except lower
  1823.   case characters (and newlines). The special characters defined
  1824.   above may be used inside of character classes with the
  1825.   exception of \n, \w and \h, which are shorthand for their own
  1826.   character classes. If the characters - or ] are to be used
  1827.   literally inside of a character class, they should be preceded
  1828.   by the escape character \. Note that *?+(){}!^$#& are not
  1829.   special characters when found inside a character class.
  1830.  
  1831.   A regular expression followed by * matches zero or more
  1832.   matches of the regular expression. This is referred to as a
  1833.   closure. Thus ba*b matches the string bb (no instances of a),
  1834.   bab (one instance), or baaaaaab (several instances).
  1835.  
  1836.   A regular expression followed by a + matches one or more
  1837.   matches of the regular expression. This is another type of
  1838.   closure. In this case ba+b will not match bb, but it will
  1839.   match bab, or baaaaaab.
  1840.  
  1841.   A regular expression followed by a ! matches zero or one
  1842.   matches of the regular expression. This is another closure.
  1843.   Here, ba!b will match bb or bab, but not baaaaaab.
  1844.  
  1845.   Two regular expressions concatenated match a match of the
  1846.   first followed by a match of the second. Thus (abc)(def)
  1847.   matches the string abcdef.
  1848.  
  1849.   Two regular expressions separated by # match either a match of
  1850.   the first or a match of the second. This is referred to as
  1851.   alternation. Any number of regular expressions can be strung
  1852.   together in this way. Alternation matches are tested in order
  1853.   from left to right, and the first match obtained is used. Then
  1854.   the remaining alternate expressions are skipped over. (Unix
  1855.   users note that we do not use a | character for alternation,
  1856.   since it unavoidably causes MS-DOS to start a pipeline.) See
  1857.   the next paragraph for an example.
  1858.  
  1859.   A regular expression enclosed in parentheses () matches a
  1860.   match of the regular expression. Parentheses are used to
  1861.   provide grouping, and may be nested to arbitrary depth. Open
  1862.   and close parentheses must be balanced. For example, the
  1863.   following two expressions are not equivalent, and the second
  1864.   probably expresses what was intended:
  1865.  
  1866.     PROCEDURE#FUNCTION
  1867.  
  1868.     (PROCEDURE)#(FUNCTION)
  1869.  
  1870.   The first expression is equivalent to PROCEDUR(E#F)UNCTION.
  1871.   The second expression matches either of the two well-known
  1872.   words.
  1873.  
  1874.   A regular expression enclosed in curly braces {} forms a
  1875.   tagged match word. Whatever was matched within the braces may
  1876.   be referred to by a Replace expression in a manner to be
  1877.   described. Tagged match words may NOT be nested. Open and
  1878.   close braces must be balanced. A maximum of nine tagged match
  1879.   words may be referenced by the Replace expression. Note that
  1880.   the use of curly braces in Select/Avoid expressions is
  1881.   meaningless. However, these expressions share an expression
  1882.   interpreter with the Match expressions, so no error will be
  1883.   flagged. As an example, consider the expression b{a*}b. If the
  1884.   string tested is bab, then the tagged match word will contain
  1885.   a single a. If the string tested is baaaaaab, then the tagged
  1886.   match word will contain aaaaaa. If the string tested is bb,
  1887.   then the tagged match word will be empty.
  1888.  
  1889.   Regular expressions are interpreted from left to right. The
  1890.   order of precedence of operators at the same parenthesis level
  1891.   is [] then *+! then # then concatenation.
  1892.  
  1893.   Tag braces are interpreted strictly from left to right and do
  1894.   not control precedence in any way. The first tagged match word
  1895.   found is given a tag of 1, the second a tag of 2, and so on up
  1896.   to a maximum tag of 9. The tag number that each word receives
  1897.   is based on when it is encountered in the line. If tags are
  1898.   skipped over as a result of alternation, then any remaining
  1899.   tags in a line will receive shifted tag numbers. For example,
  1900.   consider the expression:
  1901.  
  1902.     (FUNCTION)#({PROCEDURE})\s+{[^\s(]+}
  1903.  
  1904.   If a line contains the word PROCEDURE then the word following
  1905.   PROCEDURE will have a tag number of 2. If a line contains the
  1906.   word FUNCTION, then the word following FUNCTION will have a
  1907.   tag number of 1. It is up to the user to take advantage of
  1908.   this behavior. Generally, it is good practice to surround an
  1909.   entire set of alternates with tag markers:
  1910.  
  1911.     {(FUNCTION)#(PROCEDURE)}\s+{[^\s(]+}
  1912.  
  1913.  
  1914. E. Replace Regular Expressions
  1915.  
  1916.   Replace regular expressions are constructed the same way as
  1917.   Match regular expressions, but the number of operators is
  1918.   reducedi. The replacement process occurs in the following
  1919.   manner: any text of the input line that does not match the
  1920.   Match expression is sent to the output unchanged. The Match
  1921.   expression will find a string of text that starts at the
  1922.   leftmost position in the input line that matches, and
  1923.   continues to the rightmost position that matches. The string
  1924.   of matched text is operated upon by the Replace expression and
  1925.   output. The Match expression is then tried again on the input
  1926.   line, starting at the first position beyond the previous match
  1927.   string. This recurs until the end of line is found.
  1928.  
  1929.   Replace expressions are composed of the following:
  1930.  
  1931.   When a regular expression is specified on a command line or in
  1932.   a command file, the regular expression may NOT contain any
  1933.   blank space. The special characters below should be used to
  1934.   produce instances of blanks, tabs and the null expression.
  1935.  
  1936.   If a null Replace expression is desired, the -R keyword must
  1937.   either occupy the last position on its input line or use the
  1938.   special symbol \z to indicate a null expression. Null Replace
  1939.   expressions are used to delete text strings from a file.
  1940.  
  1941.   A single character not otherwise endowed with special meaning
  1942.   is sent to the output.
  1943.  
  1944.   A \ followed by a single character sends that character to the
  1945.   output. In this way a \& will write an ampersand and a \\ will
  1946.   write a backslash. However, the following sequences are
  1947.   special:
  1948.  
  1949.      \s      space (ASCII #32)
  1950.      \t      tab (ASCII #9)
  1951.      \b      backspace (ASCII #8)
  1952.      \r      return (ASCII #13)
  1953.      \l      linefeed (ASCII #10)
  1954.      \n      newline (#13 followed by #10)
  1955.      \i      input redirection <
  1956.      \o      output redirection >
  1957.      \p      pipe character |
  1958.      \z      null expression
  1959.  
  1960.   Unless a newline combination was explicitly matched in the
  1961.   Match expression, it is not necessary to explicitly specify
  1962.   newlines in the Replace expression. Each newline of the input
  1963.   text line will be written out in the unmatched category of
  1964.   output. Extra newlines may be added or separate lines may be
  1965.   combined by understanding this feature (see the examples).
  1966.  
  1967.   Another special case occurs when \ is followed by a single
  1968.   digit in the range of 1 through 9. In this case the tagged
  1969.   match word found by the Match expression is sent to the
  1970.   output. If a tagged match word for that tag number was not
  1971.   defined, or if the tagged match word didn't match anything,
  1972.   then nothing is output. The tagged match words may be output
  1973.   in any order and may be repeated any number of times.
  1974.  
  1975.   An & appearing in the Replace expression causes all text
  1976.   matched by the match expression to be sent to the output. &
  1977.   may appear in the Replace expression as many times as desired.
  1978.  
  1979.  
  1980. F. Examples
  1981.  
  1982.   We will start with some simple examples and work up to
  1983.   complicated ones. Some of the example commands are split onto
  1984.   two lines of the manual. When you actually use them, they
  1985.   should be typed on a single line.
  1986.  
  1987.     RPL -N -M PROCEDURE <myfile.pas
  1988.  
  1989.   Finds all lines containing the word PROCEDURE in the file
  1990.   myfile.pas and writes them to the screen, preceded by their
  1991.   line number.
  1992.  
  1993.     RPL -I -N -M (PROCEDURE)#(FUNCTION) <myfile.pas
  1994.  
  1995.   Does the same thing as the example above, but also shows lines
  1996.   containing the word FUNCTION. The matching is not
  1997.   case-sensitive.
  1998.  
  1999.     RPL -M oldvariable -R newvariable <myfile.pas >myfile.new
  2000.  
  2001.   Replaces all instances of the word oldvariable with the word
  2002.   newvariable in myfile.pas. The modified text is written to the
  2003.   file myfile.new.
  2004.  
  2005.     RPL -M ^{?+[^\s]}\s* -R \1 <myfile.txt >myfile.cln
  2006.  
  2007.   Strips trailing blanks from each line of the file myfile.txt.
  2008.   Output is sent to the file myfile.cln. The Match expression
  2009.   can be explained as follows:
  2010.  
  2011.     Anchor at the beginning of the line ^
  2012.     Start a tag word {
  2013.     Match one or more instances of any character ?+
  2014.     Match one instance of any character but a space [^\s]
  2015.     End the tag word }
  2016.     Match any and all trailing spaces \s*
  2017.  
  2018.   The Replace expression then outputs the tagged word, which
  2019.   contains the entire line up to the last non-blank character.
  2020.  
  2021.   Empty lines and lines consisting entirely of blanks are output
  2022.   unchanged. Leading blanks are output as in the input file. A
  2023.   more complex expression could be used to remove blanks from
  2024.   all-blank lines as well.
  2025.  
  2026.     RPL -M ? -OC <longfile.pas
  2027.  
  2028.   Counts the number of non-empty lines in longfile.pas. The
  2029.   match command -M ? matches any line containing at least one
  2030.   character (besides a <CR><LF>). The -OC option says to present
  2031.   just a count of the result.
  2032.  
  2033.     RPL -I -M \w*{['$#A-Z0-9]+}\w* -R \1\n <file1 >file2
  2034.  
  2035.   Strips word delimiters and puts one word per line into file2.
  2036.   The Match expression can be explained as follows:
  2037.  
  2038.     Find zero or more instances of any word delimiter \w*
  2039.     Start a tag word {
  2040.     Match one or more instances of any character that might
  2041.        reasonably form part of a capitalized word ['$#A-Z0-9]+
  2042.     End the tag word }
  2043.     Find zero or more instances of any word delimiter \w*
  2044.  
  2045.   The Replace expression then writes the tagged word and adds a
  2046.   newline to put each word on a separate line.
  2047.  
  2048.   This command will create empty lines mixed in with the lines
  2049.   containing a single word. The blank lines may be removed with
  2050.   the expressions of the previous example, or they may be
  2051.   removed using a supplied application command as follows.
  2052.  
  2053.     RPL -F rmblines <file2 >file2.cln
  2054.  
  2055.   Calls the command file RMBLINES.PAT to remove all blank lines
  2056.   from file2 and write the result to file2.cln.
  2057.  
  2058.  
  2059.   If you intend to use an RPL application repeatedly, it will be
  2060.   worthwhile to spend some time optimizing it for performance.
  2061.   Regular expressions producing the same result can vary
  2062.   significantly in processing speed. The following list
  2063.   describes the relative performance of various RPL capabilities
  2064.   (listed fastest to slowest):
  2065.  
  2066.     fixed text strings anchored to the beginning of line
  2067.  
  2068.     fixed text strings not anchored to the beginning of line
  2069.  
  2070.     expressions including character classes, alternation or
  2071.     grouping
  2072.  
  2073.     expressions including closures (especially * and +)
  2074.  
  2075.   In general, the longer the expression, the slower will be the
  2076.   response.
  2077.