home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / util / egutil53.lbr / FINREP.DZC / FINREP.DOC
Encoding:
Text File  |  1993-06-09  |  14.5 KB  |  324 lines

  1. ;;01-06-88
  2.                      FINREP.DOC  Version 2.7
  3.                             02/24/88
  4.  
  5. Eric Gans
  6. French Department, UCLA
  7. Los Angeles, CA 90024
  8.  
  9.    * MS-DOS users: FINREP now exists for DOS. MS-DOS v2.6 is *
  10.    * (more or less) equivalent to CP/M v2.7.                 *
  11.  
  12. Version 2.7
  13. Corrects  a bug introduced in v2.6 that cut the output file short 
  14. in certain cases.
  15.  
  16. Version 2.6
  17. Corrected a bug in reading words across sectors.
  18.  
  19. Version 2.5
  20. Corrected a bug in the wild-card file routine (thanks to faithful 
  21. FINREP user John Stensvaag).  Improved verify routine (as per DOS 
  22. version); reduced program size.
  23.  
  24. Version 2.4
  25. The  search routines have been extensively revised and  debugged.  
  26. FINREP  should now find just about any string,  however perverse.  
  27.  
  28. Version 2.3
  29. Fixed  bug  that  made verification  incompatible  with  multiple 
  30. (wildcard)  files.   Allow wildcard (?,  not *) at end of  search 
  31. string.
  32.  
  33. Version 2.2
  34. Added  "V"  flag  to allow user verification  ("Replace  (y/n)?") 
  35. before replacement in text files; a few minor improvements.
  36.  
  37. Version 2.1
  38. Fixed bug that treated wildcard filetypes as single files.  Added 
  39. a couple of clarifications to DOC file.
  40.  
  41. Version 2.0
  42. Allows wildcard searches (various options),  wildcard  filetypes. 
  43. Easier entry of caps (!string!  instead of !s!t!r!i!n!g).  Allows 
  44. control characters other than letters (e.g., ^[,^@).
  45.  
  46.                               *****
  47.  
  48.      FINREP is a search/replace program that remedies most of the
  49. deficiencies of Wordstar's ^QA and other similar commands.  Aside
  50. from being faster, it has important additional features:
  51.  
  52.      - allows wildcards in search string (v2.0)
  53.      - allows wildcard filename (find/replace in groups of files)
  54.      - command-line entry allows batch processing by SUBMIT, etc.
  55.      - allows entry of control or hex characters (0-FF)
  56.      - can be used with object files (e.g., COM files)
  57.      - sets  capitalization (first letter or whole word) and high
  58.        bit of the last character according to the old string
  59.  
  60. This last feature means that,  for example,  if you are writing a 
  61. scenario where the characters' names appear sometimes in CAPS and 
  62. sometimes just Capitalized, you don't need two search/replaces to 
  63. replace one name with another: JOE will be replaced by HARRY, Joe 
  64. by Harry, and even joe by harry.  
  65.  
  66.                               *****
  67.  
  68. Format: finrep [d:]fn [newfn] /[switches]/ oldstring [newstring]
  69.  
  70. (Enter "finrep" alone for a brief command summary.)
  71.  
  72. If a second filename is given, the changes will be placed in that
  73. file;  if  not,  the  old filename will hold the changes and  the
  74. original  file will be changed from fn.ft to fn.BAK  (unless  the
  75. "B" switch is used).
  76.  
  77. Wildcards  (*,?) may be used anywhere in the filename;  if  there 
  78. are  wildcards in the filetype (after the ".") the B switch  will
  79. be  set  automatically  to suppress creation  of  BAK  files.  If 
  80. wildcards are used,  a second filename cannot be entered.  If you 
  81. enter:
  82.  
  83. A>finrep urk*.doc // "blurk" "zap"
  84.  
  85. the files urk01.doc,  urk33.doc,  urktty.doc would be modified as 
  86. expected and files urk01.bak, urk33.bak etc. would be created.
  87.  
  88. The characters "//" must be entered even if no switches are used.
  89.  
  90. The switches are as follows:
  91.  
  92. B  =  no BAK file.  This switch disables making a BAK  file;  the 
  93. original  file  will be lost.  (Use only if you did not  enter  a 
  94. second filename.)
  95.  
  96. Q = allow wildcards in search string. (The program runs faster if 
  97. this  switch is not used.)  The various options for this  command 
  98. are described below.
  99.  
  100. V = verify replacement.   If this switch is used,  the context of 
  101. the search string will be displayed on the screen and you will be 
  102. queried  re replacement.   This switch cannot be used along  with 
  103. the O or H switches (see below).
  104.  
  105. O = Object file.  If this switch is used, the program will ignore 
  106. end-of-file  markers (1AH),  as in PIP's "o"  command.   Use  for 
  107. search/replace in non-text files.   WARNING: if you don't use "O" 
  108. with  a  non-text  file it will be cut off after the  first  1AH. 
  109. That's why FINREP makes BAK files!
  110.  
  111. H  =  keep High bit.  With this switch,  all bytes  are  searched 
  112. exactly  as they are;  letters with the high bit set will not  be 
  113. identified  with their standard ASCII  counterparts.  
  114.  
  115. W = no Whole-word search.  This switch is used to search a string 
  116. whether  or not it is a whole word;  with it,  a search for "the" 
  117. will find "other", "their" etc.
  118.  
  119. NB  - The  program  defines a "word"  as  anything  preceded  and 
  120. followed  by  something other than a letter  (space,  punctuation 
  121. mark,  number, control character, beginning or end of file). Thus 
  122. this  switch  is not needed if the search string is a  series  of 
  123. words,  a  word  preceded  by a control  character  that  is  not 
  124. contiguous to another word, etc.
  125.  
  126. C  = respect case.  This switch allows you to distinguish capital 
  127. from lower-case letters: in a search for "the", "The" will not be 
  128. found/replaced.  (NB: Upper case letters cannot be entered within 
  129. quotes; see below.)
  130.  
  131.  
  132. In normal operation (with no switches),  the search will  include 
  133. whole words only; it will ignore case and high bits, but will set 
  134. the  new  string  to  correspond  to the  old  in  this  respect, 
  135. capitalizing the first letter or the whole string and setting the 
  136. high  bit  of the last as required.  This last  feature  is  only 
  137. useful if the replacement string is one word long; if it contains 
  138. more than one word,  you may set the high bits when you enter the 
  139. string,  or let your word-processor (e.g. Wordstar) do it. If you 
  140. include  capitals  in  your  replacement  string,  they  will  be 
  141. respected even if the find string is not capitalized.
  142.  
  143. If  you want to search for a capitalized word,  you must use  the 
  144. "C"  switch (or the "H" or "O" switch);  FINREP will give you  an 
  145. error message if you don't. 
  146.  
  147. The last four switches are in the relation O > H > C       
  148.                                                  > W  ; 
  149. the "higher" switch includes the smaller.  Thus if the "H" switch 
  150. is used,  capitals and lower case will be distinguished,  and the 
  151. search will not be limited to whole words.
  152.  
  153. *****************************************************************
  154.  
  155. String entry:
  156.  
  157. The  find  and replace strings must be separated by a space  from 
  158. the switch entry and from each other.  Strings should be  entered 
  159. as follows:
  160.  
  161. ASCII     - in quotes: "blurk", "54%**90er @"
  162.  
  163. The following characters must NOT be placed between quotes:
  164.  
  165. HEX       - separate by commas: d,1A,cd,10,ff,3 
  166. CAPITALS  - between !!: !A!,!hello!          [NEW IN V2.0] 
  167. CONTROL CHARACTERS - preceded by ^: ^M,^m^j,^c,^C,^[,^^
  168. WILDCARDS - ????, ?n (1 <= n <= 9) or ?* (indeterminate)
  169.      The  "|" character is used to display a break in the replace 
  170. string (see below).
  171.  
  172. All ascii letters entered within quotes will be treated as  LOWER 
  173. CASE.  If  you  want  to search upper case letters with  the  "C" 
  174. switch,  or to put upper case letters in the replace string,  you 
  175. must  surround  them  with "!!",  unless you enter  them  as  hex 
  176. characters:  (A = 41, B = 42 ...). Sorry about this, but the CP/M 
  177. command line cannot distinguish upper from lower case.
  178.  
  179. Any  combination  of characters is  valid;  for  clarity,  groups 
  180. should  be separated by commas,  although this is only  necessary 
  181. for individual hex characters: !h!"ello",^m^j,e5,?7,32,!blurk!,^q 
  182. Quotes and !..!  must be closed.  To search/replace the quotation 
  183. mark,  enter it as a hex character ("=22h).   You can search  for 
  184. "!" if you keep it between quotes.
  185.  
  186. The  length  of the find/replace strings is limited to 30  bytes; 
  187. this  length  applies to the strings themselves and  not  to  the 
  188. keyboard entry,  which cannot exceed 127 bytes in all (blame CP/M 
  189. for  this).  Thus  ^j,cd,ff,3d is 4 bytes long.   In the case  of 
  190. indeterminate  wildcards,  up to 255 bytes are allowed,  but  the 
  191. limit of 30 still stands for the find/replace strings themselves.
  192.  
  193. If  you do not enter a replace string,  the  searched-for  string 
  194. will be replaced by nothing, i.e., deleted.
  195.  
  196. WILDCARDS 
  197.  
  198. The wildcard search has a great deal of flexibility.  For obvious 
  199. reasons,  wildcards  cannot appear at the beginning of the search 
  200. string.  (In versions below 2.3 they can't be at the end  either.  
  201. For  some  not-so-obvious reason this seemed a bad thing  at  the 
  202. time.)  The options are as follows:
  203.  
  204. 1. Simple wildcard search: all bytes of the search string will be 
  205. replaced.
  206.  
  207. finrep  zz.txt  /q/ "d"?2"e" "xxyz" will replace all  words  like 
  208. "done", "dare", "dove" etc. by "xxyz"  A maximum of four wildcard 
  209. groups are allowed in this form: thus "a"?"cd"?4"ijk"??"nopq"?"s" 
  210. is a permissible search string
  211.  
  212. 2.  Simple wildcard search with break. Only one wildcard group is 
  213. allowed;  the  replace string is divided in two,  with the  first 
  214. part  replacing  what precedes the wildcards and the second  what 
  215. follows;  the  intermediate bytes are left alone.   The break CAN 
  216. appear at the beginning or end of the replace string to  indicate 
  217. that  the corresponding part of the find string is to be deleted.  
  218. A blank replace string (entered simply as: | ) will delete both.
  219.  
  220. finrep  xx.txt /qw/ "d"?2"e" "xx"|"yzz" will replace the  "d"  in 
  221. this  pattern  with "xx" and the "e" with "yzz";  "done"  becomes 
  222. "xxonyyz", "madame" -> "maxxamyxx", etc.  (This last example only 
  223. works if the "W" switch is used.)
  224.  
  225. 3.  Indeterminate  wildcard  search/replace.   The  indeterminate 
  226. wildcard "?*" must be the only wildcard in the search string.  In 
  227. this  option  the  whole  string from the  beginning  to  end  is 
  228. replaced.   A  maximum of 255 characters will be allowed  in  the 
  229. search string; longer strings will not be found.
  230.  
  231. finrep  blurk.let  /qw/  "xy"?*"zq" "garbage"  will  replace  all 
  232. strings   beginning  and  ending  with  the  indicated   letters: 
  233. "xyrwerwerzq",  "xyuu  is  the nbrzq",  "xy ^C^Yzq" will  all  be 
  234. replaced by "garbage"
  235.  
  236. NB - Since FINREP only looks for one thing at a time, it will not 
  237. find nested pairs of strings,  and will appear to miss some pairs 
  238. where the second half of the search string is over 255 bytes away 
  239. from  the point at which the search began.   (FINREP checks  this 
  240. only every 128 bytes.)  Thus if you are looking for  "the"?*"of", 
  241. FINREP  will  sometimes  miss the apparent "hit" in a  text  like 
  242. this:  ... the [ ... the ... ] of ...
  243. where the [] contain over 255 bytes.   This is not a bug,  but  a 
  244. limitation of the program. 
  245.  
  246. 4.  Indeterminate  wildcard with break.  This is a very  powerful 
  247. option  that allows you,  for example,  to replace  PerfectWriter 
  248. "fences" with WordStar control toggles (& vice versa). Here again 
  249. only  one  wildcard group is allowed in the  search  string;  the 
  250. intermediate bytes are left unchanged.
  251.  
  252. finrep   zap.kkk   /qw/   "123"?*"45"  "6"|"789"   will   replace 
  253. "zz123blurk blurk xxxc oo45rr" by "zz6blurk blurk xxxc oo789rr";
  254. finrep  perf.wri /qwc/ "@"!ux!"{"?*"}" ^s|^s will replace the  PW 
  255. underline fence @UX{ ...  } by WS's ^S ...  ^S  Note that the "C" 
  256. flag is used here to search for caps; if l.c. as well as caps are 
  257. acceptable,  it  could be omitted and the search  string  written 
  258. "@ux{"?*"}".   You  can delete the fences altogether by replacing 
  259. the ^s|^s by | in the last example.
  260.  
  261. One  user thought the word "break" was misleading and  should  be 
  262. replaced  by  "save," since the "|" in the replace  string  means 
  263. that  you  preserve the wildcard part of the  search  string.  In 
  264. other words:  finrep zap.txt /qw/ "<<"?*">>" will kill everything 
  265. between  the "<<..>>" whereas:  finrep zap.txt /qw/ "<<"?*">>"  | 
  266. will just kill the "<<>>" and "save" their contents.  
  267.  
  268. FINREP  can be aborted at any time by typing <ESC> (=1B  HEX).  I 
  269. preferred this to ^C since an extra ^C will be read by CP/M as  a 
  270. Warm Boot.
  271.  
  272. Except when the "V" switch is used, the only screen output is the 
  273. number of strings replaced and, if you use wildcards, the names & 
  274. total  number  of  files  processed.  If  you  want  to  see  the 
  275. replacement procedure in action, use a word-processor!
  276.  
  277. Notes:
  278.  
  279. 1.  FINREP  will modify files of any length;  it uses the  entire 
  280. memory  below the CCP as its buffer,  and writes to disk whenever 
  281. the  buffer  fills up.  Since it doesn't overwrite  the  CCP,  it 
  282. doesn't have to end with a Warm Boot.
  283.  
  284. 2.  There  is no intrinsic limit on the number of  files  allowed 
  285. under the wildcard filename option;  for sanity's sake,  you will 
  286. get an error message if there are more than 255.
  287.  
  288. 3.  If  you want to create a version of FINREP with some  of  the 
  289. switches preset,  run the program without a filename:      finrep 
  290. /[sw1][sw2]../  After  it  returns to the CP/M  prompt,  save  13
  291. finrep1.com  will  keep  the switches  as  you  like  them.  This 
  292. procedure  is  NOT  REVERSIBLE,  so  keep  your  original  FINREP 
  293. unchanged.
  294.  
  295. 4.  In deciding whether to capitalize a whole word/string, FINREP 
  296. looks  at the first two letters.  If the find string has only one 
  297. letter,  only the first letter of the replacement string will  be 
  298. capitalized.   If   the   word  to  be   replaced   has   unusual 
  299. captalization (e.g.  BBrrOOOmm),  use the "C" switch and/or enter 
  300. separate replacement strings for different variants.
  301.  
  302. 5.  In  using  indeterminate wildcards,  you should use  the  "W" 
  303. switch  unless BOTH HALVES of the search string begin and end  on 
  304. word boundaries. 
  305.  
  306. 6.  Re  speed,  FINREP  is  somewhat faster than  Wordstar's  ^QA 
  307. command.  But  if all you want to do is replace a string,  it  is 
  308. over  three  times faster,  since its time includes  loading  and 
  309. saving the file.  Measured on a long (84 K) file,  FINREP took 27 
  310. seconds and WS 34 for a typical search/replace.  But WS needs  at 
  311. least  10 seconds to load and a good minute to save the file  and 
  312. exit.  With a little practice, the command line can be entered as 
  313. fast  as  WS's,  and  it  can  be included  in  SUBMIT  files  or 
  314. reproduced by programs like SYNONYM or my SYN.COM.
  315.  
  316.                               *****
  317.  
  318. FINREP  was  written  at the request of  John-Mark  Stensvaag  of 
  319. Vanderbilt University.   At first I couldn't see the use for  it, 
  320. but  he  convinced me (he is a professor of  Law).  The  wildcard 
  321. features  added  in  v1.1  and  v2.0  were  also  his  idea;  the 
  322. verification  feature  in  v2.2 was ssuggested  by  J.  Olsen  of 
  323. Chicago.  I would appreciate hearing from you about (a) bugs  and 
  324. (b) suggestions for further enhancements.