home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 308.lha / treewalk / treewalk.doc < prev    next >
Encoding:
Text File  |  1980-12-05  |  12.3 KB  |  292 lines

  1. SYNOPSIS:
  2.  
  3. Treewalk - visit all the files in a directory tree.
  4.  
  5. usage: treewalk [<options>] [[command] <CLI command>]
  6.  
  7. options are: post, both, dir <directory>, verbose, single, filter <expression>
  8.  
  9. options and "command" are only checked in the first 3 characters.
  10.  
  11. DESCRIPTION:
  12.  
  13. Treewalk is a command for visiting all the files of a subtree of an
  14. AmigaDOS file system. It's designed to be reasonably fast, robust, and
  15. not use a lot of stack space - or any other critical resources. About
  16. the only thing you're liable to run out of is memory.  (Note: "all the
  17. files of a subtree" doesn't include the directory that's the root. So
  18. if you do something to every directory in the subtree, it won't do it
  19. to the root directory.
  20.  
  21. The normal behavior of the command is to test every file in the
  22. specified subtree against a user "filter" expression, and if the file
  23. passes through the filter, to issue the user supplied command with
  24. that file as one of the arguments.
  25.  
  26. Any argument that isn't an option starts the user supplied command.
  27. All arguments after the first command argument are concatenated
  28. together, with a single space between them, to make up the command. As
  29. each file is visited, its full path name enclosed in '"''s (so that
  30. things like RAM DISK: will work) is concatenated to the end of the
  31. command. When the last file is visited, or the command line becomes to
  32. long for the system, it is issued to the cli. The current working
  33. directory of the command is the directory in which the treewalk
  34. command was started, not the directory being visited or the directory
  35. that is the root of the tree being walked. The command is run as many
  36. times as needed so that all files are visited.
  37.  
  38. The "command" keyword indicates that the next argument is the start of
  39. the command, whether or not it looks like a keyword. This is useful if
  40. the command you wish to run on the starts with a valid keyword. If
  41. there is no command, treewalk will print out the names of all files
  42. that pass through the filter.
  43.  
  44. The "verbose" option causes treewalk to print the text of every
  45. command before issuing it.
  46.  
  47. The "ignore" option causes treewalk to not print anything on error
  48. returns from the command.
  49.  
  50. The "single" option defeats the stacking of files on the command line,
  51. and the command is run once for every file. This is useful if the
  52. command in question only accepts one filename.  For instance, "list
  53. nohead" should be done this way.
  54.  
  55. The "dir" option is followed by the name of a directory. That
  56. directory will then be used as the root of the tree, instead of the
  57. current directory.
  58.  
  59. Normally, treewalk will visit a directory before it visits any of
  60. it's children. This is a "preorder" treewalk, "pre" because it
  61. visits parents first. You can change this with the following
  62. options.
  63.  
  64. The "post" option causes treewalk to visit all the children of a
  65. directory before it visits that directory.
  66.  
  67. The "both" option causes treewalk to visit a directory both before and
  68. after it visits all the children of that directory. If the directory
  69. has no subdirectories, then it will list all the files of that
  70. directory twice, one listing following immediately after another.
  71.  
  72. The "filter" option is used to specify the filter expression. If no
  73. filter is provided, all files in the subtree will pass.
  74.  
  75. The filter expression is similar to a C language expression, Like a C
  76. expression, it is false if it evaluates to 0, and true otherwise. The
  77. only variables in the expression are parts of the FileInfoBlock of the
  78. file being evaluated. They are:
  79.  
  80. diskkey        - for gurus only
  81. direntrytype    - ditto
  82. entrytype    - ditto
  83. filename    - the name of the file in this directory (string value)
  84. name        - the full path name of the file (string value)
  85. protection    - the protection mask
  86. size        - the number of bytes in the file
  87. numblocks    - the number of blocks in the file
  88. date        - date the file was last changed
  89. day        - day the file was last changed
  90. comment        - comment associated with the file (string value)
  91.  
  92. The "day" version of date ignores the minutes of the day of creation,
  93. so that it will compare equal to a day with no time specified via the
  94. "`" construct.  I.e., "day == `yesterday`" matches files created
  95. yesterday.
  96.  
  97. Note to purists: The "date" value is the number of minutes since
  98. midnight, January 1, 1978. It's called "date" instead of "datestamp"
  99. because it's not a real datestamp.  The protection bits `rewd` are
  100. inverted on output, as they have inverted meaning: the `r` bit being
  101. on means you _can't_ read the file. List prints a `r` when you can
  102. read the file. These bits are inverted to prevent the user from having
  103. to remember this.
  104.  
  105. The FileInfoBlock values can also be gotten for other files. The same names
  106. as above are used, preceded by a file name and a '.'. For instance,
  107. main.c.size is the size of the file "main.c" in the directory treewalk
  108. was started in. Such expressions are evaluated at startup time, and
  109. are constant throughout the execution of treewalk.
  110.  
  111. The other valid constants in filter expressions are:
  112.  
  113. true        - longhand for 1
  114. false        - longhand for 0
  115. integers    - The same as C:
  116.             starting with a '0' indicates octal
  117.             starting with a '0x' indicates hex
  118.             otherwise, it's decimal
  119. "string"    - a text string
  120. 'string'    - ditto
  121.  
  122. In addition any string surrounded by "`"'s is an integer constant, of
  123. one of two forms. If it consists of a string of characters from the
  124. set "rwdespah", then the appropriate bits will be turned on to match
  125. the protection of the file.
  126.  
  127. Otherwise, this may be a date and time specifier. These are of the
  128. form "day minute". Day is either a fully specified numeric date of the
  129. form "month/day/year", a day of the week, "yesterday", or not
  130. specified. The "month/day/year" form uses a two-digit year between
  131. 1978 & 1999. The day of the week refers to the previous day of that
  132. name. If the day is not specified, then today is used.
  133.  
  134. Time is either "noon", hour:minute on a 24-hour clock, or
  135. missing. If the time is missing, then midnight is assumed.  If
  136. the day specified is today, and the time is later than the
  137. current time, then yesterday is assumed - even if you specify
  138. the day explicitly.
  139.  
  140. There are some operands that depends on the file currently being
  141. filtered, or on the user. They are:
  142.  
  143. dir    - true if the current file is a directory, else false
  144. file    - the opposite of dir
  145. name    - the full path name of the file (string value)
  146. user    - name is printed on the console, followed by a ?, and a line
  147.         is read. If the first character of the line is 'y' or
  148.         'Y', then true, otherwise false.
  149.  
  150. Finally, any non-string not recognized is assumed to be an ARexx macro
  151. name. The extension used in searching for the macro is "ftw".  This
  152. macro will be invoked as a function with pathname of the directory as
  153. it's first argument, and the file name as it's second.  The pathname
  154. will be in a form such that "arg(1) || arg(2)" will be the full
  155. pathname. The expression the macro returns should be an integer, and
  156. will be used as the value of the macro token in the expression.
  157.  
  158. The macro may issue "commands" back to the running treewalk. The
  159. commands are treated as filters, and the current file is sent through
  160. them, and the result returned. What the result is depends on whether
  161. you have specified "options results". If this is not on, the rc is 0
  162. if the filter returns "true", and 1 if the filter returns "false". If
  163. the results option is on, and no errors occured, rc is always 0, and
  164. the result string is the value, formated as four bytes of hex. You can
  165. then use x2c() and import() to extract strings, if the value returned
  166. was a string (i.e. - you issued the command 'comment'). In either
  167. case, return codes greater than 1 indicate a real error - usually in
  168. the filter expression, sometimes that you're out of memory.
  169.  
  170. As a suggestion for writing ftw macros, I recommend following the rule
  171. that if the macro uses the file name, it returns a 1, and if it
  172. rejects the file name, it returns a 0. This allows treewalk to print
  173. the names of the files used by the macro by 'treewalk filter macro',
  174. or to not print the names by 'treewalk filter "macro & false"'. Of
  175. course, if the macro is just a filter itself, then it should return
  176. either 0 or 1.
  177.  
  178. To combine these, there are the operators. All but four are from C,
  179. and the precedence of the operators is the same as C. They are:
  180.  
  181. !    - unary logical not;        ~            - unary bitwise not
  182. &    - bitwise and
  183. %    - bitwise exclusive or
  184. |    - bitwise or
  185. =*, =#, !*, !# - string compares    <, >, <=, >=, ==    - integer comparisons
  186. &&    - logical and, short circuiting
  187. ||    - logical or, short circuiting
  188.  
  189. (, )    - parens for grouping
  190.  
  191.  
  192. The only four operators not found in C are =*, =#, !* and !#. These
  193. are pattern matching operators for use on strings (file names or
  194. comments). The left-hand operand is a string, the right-hand operand
  195. is a pattern. =* and !* provides Unix-like regular expressions, with
  196. '*' and '?' having special meaning. =# and !# provides AmigaDOS like
  197. regular expressions, with '#' and '?' having special meanings. =* and
  198. =# are true if the comparisons match, and !* and !# are true if the
  199. comparisons don't match.
  200.  
  201. The rest of the operators behave as one would expect them to. The
  202. only thing that needs to be pointed out is that logical and (or)
  203. short circuits. So if the left-hand operand is false (true), the
  204. right-hand operand is never evaluated. This allows a limited form of
  205. flow control in the filter expression.
  206.  
  207. Like C, it is legal to apply the logical operators to non-boolean
  208. ints, and to apply the comparison operators to booleans. Unlike C,
  209. strings can not have their addresses extracted, and ints cannot be
  210. used for string addresses. Strings may only appear, and are all that
  211. may appear, as the operands of the pattern matching operators.
  212.  
  213. As a final suggestion on filters, unless the filter is a single token,
  214. it's probably best to surround it in '"''s, as that will cause the
  215. magic characters in the expression (&, |, <, > come to mind) to not
  216. be interpreted by whatever CLI you are running.
  217.  
  218. EXAMPLES:
  219.  
  220. List all the directories in src:
  221.  
  222.     treewalk dir src: filter dir
  223.  
  224. Delete the subtree x:
  225.  
  226.     treewalk dir x post single delete
  227.  
  228. This isn't really very useful, as "delete all" is faster. However, it
  229. illustrates several points. First, "delete" is broken, as it has a
  230. limited number of arguments. Second, this requires the postorder
  231. treewalk, so that all the files in a directory will be deleted before
  232. the directory is deleted.
  233.  
  234. Delete all .o files in the current subtree:
  235.  
  236.     treewalk filter "filename =# '#?.o'" single delete
  237.  
  238. List all files newer than :last-backup.
  239.  
  240.     treewalk filter "date > :last-backup.date"
  241.  
  242. Find all files on the current device older than :last-backup using
  243. over 20 blocks, that don't have the execute bit on, and compress them.
  244.  
  245.     treewalk dir : filter "date < :last-backup.date &&
  246.         numblocks > 20 && !(protection & `e`)" compress
  247.  
  248. Same as above, except we also don't compress .o files in the subtree at
  249. :go and we only compress if the user wants us to.
  250.  
  251.     treewalk dir : filter "name !* '*:go/*' &&
  252.         date < :last-backup.date && numblocks > 20 &&
  253.         !(protection & `e`) && user" compress
  254.  
  255. This last might more efficiently be done as a Rexx macro that decides
  256. whether or not the file will be compressed, and then asks the user.
  257. Let's assume we've got a macro "munchp.ftw" that does the name, mode
  258. and size checking. You could then do:
  259.  
  260.     treewalk dir : filter "date < :last-backup.date && munchp
  261.         && user" compress
  262.         
  263. As an alternative, suppose that instead of compressing them, you
  264. wanted to save them to an archive somewhere, and had a rexx script to
  265. do that. Further, suppose that the Rexx script (archive.ftw) return 1
  266. if it did the archive, and 0 if it didn't. Then you might do:
  267.  
  268.     treewalk dir : filter "date < :last-backup.date && munchp
  269.         && archive && false"
  270.  
  271. To quietly do the archiving. Or you might do:
  272.  
  273.     treewalk >logs:archive.log dir :
  274.         filter "date < :last-backup.date && munchp && archive"
  275.  
  276. To list the archived files to logs:archive.log.
  277.  
  278.     Copyright (C) 1989  Mike Meyer
  279.  
  280.     This file is free documentation; you can redistribute it and/or modify
  281.     it under the terms of the GNU General Public License as published by
  282.     the Free Software Foundation; either version 1, or any later version.
  283.  
  284.     This program is distributed in the hope that it will be useful,
  285.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  286.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  287.     GNU General Public License for more details.
  288.  
  289.     You should have received a copy of the GNU General Public License
  290.     along with this program; if not, write to the Free Software
  291.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  292.