home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff374.lzh / Mat / Examples.DOC < prev    next >
Text File  |  1990-10-08  |  12KB  |  288 lines

  1.                   Example Command Scripts using Mat
  2.                   _________________________________
  3.  
  4. Included in this package are some example Shell scripts that demonstrate
  5. some of the ways in which Mat can be useful.  You might even want to put
  6. some of them -- or variants thereof -- into your own S: directory.
  7. I've  had to omit one or two of the ones I use most, because they're
  8. rather too dependent on ny own environment to be portable (or of interest
  9. to anyone but me!).
  10.  
  11. There are scripts that emulate (with advantages) the AmigaDOS commands
  12. PrintFiles and Search, one that does almost any kind of multiple file
  13. renaming you might want, a utility for file counting, and so on.
  14.  
  15. Following are descriptions of the scripts and instructions for their use.
  16. Look at the scripts themselves as well to see how they work.  Most of them
  17. are fairly commented.
  18.  
  19. I will assume you are using the (AmigaDOS 1.3) Shell (or equivalent) to
  20. execute the scripts as commands.  They all have the "Script" bit set.
  21.  
  22.  
  23. PR      --  Print files with matching names
  24.  
  25.     This is a simple script that is in some ways more versatile than the
  26.     PRINTFILES program supplied with the Workbench in that you can use
  27.     pattern specifiers as well as plain file names (though -- unlike
  28.     PRINTFILES -- you can only run it from the shell).  It runs in the
  29.     background, sending the specified files to the printer (PRT:),
  30.     separated by form-feeds.
  31.  
  32.     For example, to print all .DOC files in the current directory:
  33.  
  34.                 PR #?.doc
  35.  
  36.     You can include up to five filename specifiers in the command line.
  37.     These can include directory paths which in turn can contain patterns.
  38.     To look through all the directories at the top level of df1: and print
  39.     any files with DOC or README in their name:
  40.  
  41.                 PR df1:#?/#?(doc|readme)#?
  42.  
  43.  
  44.     Let's use this PR script to demonstrate some of the added features of
  45.     Mat pattern matching.  (All these remarks and cautions about patterns
  46.     and file specifiers apply to the other scripts as well.)  For a start,
  47.     if you prefer "*" to "#?", Mat allows that instead (provided it is not
  48.     inside quotes, where EXECUTE will misunderstand its meaning):
  49.  
  50.                 PR *.doc
  51.  
  52.     If you want to print out all the files in the current directory that
  53.     are NOT .INFO files, use:
  54.  
  55.                 PR #?~(.info)
  56.  
  57.  
  58. SCH     --  Search Text files for strings
  59.  
  60.     This script is a reasonable facsimile of the AmigaDOS SEARCH, except
  61.     that it is much faster!  (The difference isn't quite as great as if
  62.     you used Mat directly, due to the overhead of script decoding, but
  63.     it is still usually a factor of two on reasonably long files -- the
  64.     difference may be overwhelmed by disk access on shorter ones.)  It
  65.     doesn't have all the switch options of the 1.3 SEARCH command, but it
  66.     does attempt to reproduce the 'ALL' switch; the format of the output is
  67.     different, though, and it can only handle five levels of directories.
  68.     Note the use of the redirection character '>' as an option argument;
  69.     unlike shell redirection, though, you MUST have a space between the
  70.     character and the destination filename.
  71.  
  72.                 SCH #?.DOC something
  73.  
  74.                 SCH > result SEARCH something FROM df0: ALL
  75.  
  76.  
  77. REF     --  Search Text files for strings
  78.  
  79.     REF is a slightly different approach to the SEARCH concept: the matched
  80.     strings are highlighted. It runs in the background, and prints out
  81.     everything at once when done.  [The script as supplied writes to a
  82.     temporary file 'T:Ref_List'; you can look at this again with 'MORE' or
  83.     something, but you could also easily change the script to make a more
  84.     permanent record.]
  85.  
  86.     REF expects a simple string as the argument it is to search for (not a
  87.     pattern).  You can use patterns in your file specifier to specify which
  88.     are to be searched (as in SCH); up to three specifiers are allowed.
  89.     All lines found that include the string anywhere within them are
  90.     displayed, with the actual match section highlighted.  It assumes no
  91.     upper/lower case distinctions are wanted. If you want different
  92.     assumptions, use Mat directly (or rewrite REF). Don't forget to put
  93.     quotes around your string if it contains spaces.
  94.  
  95.             REF "string search" #?.DOC
  96.  
  97.     would highlight all occurrences of the words "string search" in all
  98.     the .DOC files in this directory.
  99.  
  100.  
  101. MREF     --  Search Text files for patterns
  102.  
  103.     This is exactly the same script as REF, except that the string-search
  104.     argument to Mat is omitted.  This means a) it can search for patterns
  105.     as well as simple strings, and b) it is VERY slow!
  106.  
  107.     One example out of the endless possibilities should suffice:
  108.  
  109.             MREF "(pattern|string) match" #?.doc
  110.  
  111.     will find all the lines that contain "pattern match" or "string match"
  112.     in all the .DOC files in this directory.
  113.  
  114.     Remember that the difference in speed between REF and MREF is due
  115.     to the "triage" that the first one does with a string search for
  116.     candidate lines, before matching and slicing.  You can write your own
  117.     variant to suit your needs; for example you could have more flexibility
  118.     by allowing separate string and pattern arguments, or you could add
  119.     line numbers to the output.
  120.  
  121.  
  122. REN     --  Global rename with pattern matching.
  123.  
  124.     This script I use a lot, but it needs more knowledge of Mat's pattern
  125.     matching features than the previous ones.  The thing is that when you
  126.     have the freedom AmigaDOS gives you in naming files (compared to
  127.     certain operating systems on certain other machines that we will
  128.     ignore...) you need much more than the "ren *.c *.bak" convention
  129.     that suffices for those primitive systems; we have no "root names" and
  130.     "extensions" to be treated as indivisible units.  To provide a general
  131.     renaming facility we have to introduce concepts like "slices" and
  132.     "templates".
  133.  
  134.     As an example, suppose I have some text files that all end in '.txt',
  135.     and I want to rename these to, say, '--.txt_OLD'.  It happens though
  136.     that they all have associated icons '--.txt.info' which will have to be
  137.     renamed too, and if they are to remain WorkBench-accessible the ".info"
  138.     string must stay at the end of the name.  So, how do we do this with
  139.     REN?  Like this:
  140.  
  141.             REN #?.txt^#? AS ^0_OLD^1
  142.  
  143.     Yipes!  Whad'all'dat?
  144.  
  145.     OK.  So I jumped in at the deep end.  Be brave.  Let's look at the
  146.     pattern first: it's fairly standard except for the little "^" that
  147.     crept in after "txt"; this is a "slice mark" that indicates where we
  148.     want to split up the matched string.  Each resulting match can be
  149.     referenced in two parts: 1) everything up to ".txt", and 2) everything
  150.     after that (this could be empty).  By the way, that mark is NOT
  151.     produced with the CTRL key: all references to "^" here mean the actual
  152.     caret character (aka "circumflex" or "hat") -- "SHIFT-6" on your
  153.     keyboard.
  154.  
  155.     Then there's that very strange second command argument (the keyword
  156.     "AS" is optional); those slice marks seem to crop up here again.  Only
  157.     -- sorry -- this time they're not slice marks: this is a "template",
  158.     and they -- with the character immediately following -- are
  159.     "selectors".  The template indicates exactly how the matched string is
  160.     to be rearranged (the script itself extends this considerably to do the
  161.     actual renaming job, but don't worry about that here).  Breaking the
  162.     template up, the first two characters are "^0"; this means "use the
  163.     part of the match before the slice mark". Following this, "_OLD" is the
  164.     literal string we want inserted at that point. Finally, "^1" means "use
  165.     the rest of the match".
  166.  
  167.     As a result of this command, then, we would see this sort of renaming:
  168.  
  169.         myfile.txt          becomes     myfile.txt_OLD
  170.         myfile.txt.info        "        myfile.txt_OLD.info
  171.         any other.txt          "        any other.txt_OLD
  172.         any other.txt_oops     "        any other.txt_OLD_oops
  173.  
  174.     That last renaming operation mightn't be part what we wanted, so in
  175.     that case we would extend the previous command:
  176.  
  177.             REN #?.txt^(%|.info) ^0_OLD^1
  178.  
  179.     which would ONLY rename files that ENDED either with '.txt' or with
  180.     '.txt.info'.
  181.  
  182.     Another common sort of renaming is not to add, but to change, a segment
  183.     of the name:
  184.  
  185.         myfile.txt          -->     myfile.OLD
  186.         myfile.txt.info     -->     myfile.OLD.info
  187.         ...and so on
  188.  
  189.     For this, we need TWO slice marks:
  190.  
  191.             REN #?.^txt^#?  ^0OLD^2
  192.  
  193.     In this case "^0" refers to the match up to the ".".  "^1" is the piece
  194.     between the first and second slice marks -- i.e. "txt".  It doesn't
  195.     appear in the template this time -- it is discarded and replaced by
  196.     "OLD".  "^2" is now the remainder of the match following the second
  197.     slice.
  198.  
  199.     Of course the renaming job is often simpler than this.  For example to
  200.     move all your '.c' files to an existing subdirectory 'old', just use:
  201.  
  202.             REN #?.c old/^F
  203.  
  204.     "^F" is the selector for the original file name, so this just prefixes
  205.     "old/" to it.  And you can always reduce to the basics:
  206.  
  207.             REN myfile yourfile
  208.  
  209.     (The script detects that there are no template markers, and simply
  210.     calls the RENAME command.)
  211.  
  212.     All simple now?  ..It gets easy with a little practice.  For the whole
  213.     story on slicing and templates, read Mat.DOC.
  214.  
  215.  
  216. FILECOUNT
  217.  
  218.     This script will either count all the files matching a specifier:
  219.  
  220.                 FILECOUNT work:test/#?.c
  221.  
  222.     or -- with the first argument representing a selection pattern --
  223.     count both the number of files matching the selection pattern and
  224.     the total number of files searched:
  225.  
  226.                 FILECOUNT #?.c work:test/#?.(c|h)
  227.  
  228.     In this second mode (but not in the first, because of key identification
  229.     problems) you're allowed up to five specifiers.
  230.  
  231.  
  232. LINECOUNT
  233.  
  234.     This reports the number of lines in each file matching the spec.
  235.     (It uses a bit of a kluge -- a nonsense pattern that should never
  236.     match -- to do it.) Again you can have up to five specifiers.
  237.  
  238.                 LINECOUNT work:test/#?.c
  239.  
  240.  
  241. PATHS
  242.  
  243.     "Path Save"  -- Creates an executable script file (by default named
  244.     "re-path"; a parameter to the command will be used as the name if
  245.     supplied) that when invoked will reset the path to what it was when
  246.     PATHS was executed.  This script also uses a PIPE: (though it could
  247.     work only slightly less conveniently with a temporary file).  Notice
  248.     how Mat's negated match ability is used to prevent unwanted addition of
  249.     "C:" and "Current Directory".
  250.  
  251.  
  252. SASS
  253.  
  254.     "Save Assigns" -- creates a script file that will re-assign all
  255.     NON-System Assigned Devices to what they were when SASS was executed.
  256.     (Any existing, non-conflicting assignments are left undisturbed when
  257.     the script "re-assign" is executed.)  Normal system assigns -- like
  258.     "SYS:" and "C:" will not be recorded in the script (again managed by
  259.     Mat's negated match).  Again too this uses PIPE:s, but also is the only
  260.     script that requires an auxiliary program, "ElideS", to be on the path.
  261.     This program is a trivial space compactor that lets us bypass Mat's
  262.     difficulty with variable spaces.  For your own interest you might want
  263.     to convert this into a script that UN-Assigns all non-system
  264.     assignments (left as the proverbial "exercise for the reader"...).
  265.  
  266.  
  267. MAKEDEP
  268.  
  269.     You may find this one useful if you write C programs.  It scans
  270. through the set of source files represented by the specifier, and creates
  271. a set of target dependencies (for the headers included in each file) in
  272. the form usually required by the "make" utility.  It is not as smart as
  273. some of the custom programs that do the same job, in that it won't look
  274. at "includes of includes" -- you'd have to do that bit by hand -- but
  275. it's adequate for a lot of needs.  Like SCH, it uses the redirection
  276. character '>' as a keyword argument to redirect the output to the
  277. appropriate file (it just displays it if omitted).  It assumes that all
  278. the files it is to search have names ending in ".c"; you can leave the
  279. extension part off if you like, and it will be added:
  280.  
  281.                 MAKEDEP > makebase my#?.c
  282.  
  283.                 MAKEDEP > makebase my#?
  284.  
  285.  
  286.                             %%%%%%%%%%%%%%%%%
  287.  
  288.