home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / sysutl / fdk.arc / FDK.DOC < prev    next >
Text File  |  1988-05-24  |  13KB  |  270 lines

  1.  
  2.                           Filter Development Kit
  3.                         (C) 1988 -- Chris E. Greer
  4.  
  5.  
  6. NOTICE: This software may be used and freely copied for personal use only. 
  7.         Any commercial or business use requires permission of the author.
  8.         The author makes no guarantees about the operation of the software,
  9.         and cannot be held liable for any problems or loss resulting from
  10.         the use or misuse of this software.
  11.  
  12.  
  13.  
  14.  
  15.                                 Overview
  16.  
  17.    The Filter Development Kit is a project that grew out of my desire to
  18. try out my new copy of Turbo C, and to learn the C language in general. 
  19. What it consists of, essentially, is two separate programs that can be used
  20. to create many different kinds of DOS filters.  By a filter, I refer to a
  21. program that takes a stream of characters as input, changes them in some
  22. way, and outputs the changed stream.  An example of a filter is a program
  23. that strips off the high bit of all the characters in a stream.  A filter
  24. may also change lowercase characters to uppercase, or strip all the form
  25. feeds from a stream.  All these types of filters can be created with FDK.
  26.  
  27.    Although filters can be pretty complex, such as the SORT, FIND, and MORE
  28. filters supplied with DOS, the filters created by the FDK are primarily
  29. substitution filters.  A swap table is maintained by the filter, and any
  30. character can be mapped to any other character, or simply removed from the
  31. stream altogether.  In other words, you can set up the filter so that every
  32. time an 'A' is encountered on the input stream, an 'a' is substituted for
  33. it.  This would have the effect of changing all uppercase A's to lowercase.
  34.  
  35.     In addition to character substitution, the FDK also gives you the
  36. option of completely removing NULLs, or characters with a value of 0, from
  37. the stream.  Thus, by mapping any unwanted character or characters to NULL,
  38. and then stripping NULLs from the stream, you can delete unwanted
  39. characters from the stream.
  40.  
  41.     The final option available is the expansion of tabs into spaces.  Tab
  42. 'stops' can be set at any interval you want, and any tabs encountered in
  43. the input stream would be turned into spaces up to the next tab stop.
  44.  
  45.  
  46.  
  47.                             Creating a Filter
  48.  
  49.    The two files needed to create a filter are FDK.EXE and FILTER.EXE. 
  50. FDK.EXE is the program that allows you to modify the swap table and set the
  51. NULL and TAB options for your new filter.  FILTER.EXE is the template
  52. filter; actually, it is a 'non-filter' - nothing has been remapped in the
  53. swap table, and NULLs and TABs are passed through unaffected, but it still
  54. is a working filter.  Although you can use any filter created by FDK as a
  55. template filter, it's still best to keep this one around when you need to
  56. start from scratch.
  57.  
  58.    Using FDK is fairly simple.  To create a filter, make sure FDK.EXE and
  59. the template filter are in the same directory, or at least that the
  60. template filter is in the current directory and FDK.EXE is available
  61. through the current PATH setting.  Enter the following at the DOS prompt:
  62.  
  63.     FDK <template> <newfilter>
  64.  
  65. where <template> is the name of an existing filter created by FDK, and
  66. <newfilter> is the name of the new filter you are creating.  Both must be
  67. valid DOS file names, both must have the extension .EXE, and they cannot be
  68. the same name (i.e., the command: FDK filter.exe filter.exe will generate
  69. an error.  For example, to use FILTER.EXE as the template, and to create a
  70. filter named UPPER.EXE, enter the following:
  71.  
  72.     FDK filter.exe upper.exe
  73.     
  74. The template filter is read, and the current settings for the low-order
  75. bytes of the swap table will be displayed.  Each column has two numbers;
  76. the left one is the input value, which can't be changed.  The right number
  77. is the substitution character and can be changed to any one-byte value you
  78. choose (00-FF).  You can move through the table using the following editing
  79. keys, and remap any character as desired.
  80.  
  81.       Editing Keys:
  82.  
  83.         Arrow keys        move in the direction of the arrows
  84.  
  85.         Tab, Shift-Tab        move right or left one column
  86.  
  87.         PgUp, PgDn        move to top or bottom of current
  88.                     column
  89.  
  90.         Home, End        move to upper left and lower right
  91.                     characters of the displayed table
  92.  
  93.         F1            toggles between low-order charac-
  94.                     ters (00 - 7F) and high-order
  95.                     characters (80 - FF)
  96.  
  97.         F10            toggles between fast and slow
  98.                     screen updates.  Fast is the
  99.                     default, use this toggle only if
  100.                                         you get snow on your monitor
  101.  
  102.         ESC            exits the swap table
  103.  
  104.  
  105. All values in the swap table must be entered as a hex value ranging from 00
  106. to FF.  The original character and its mapped character are shown at the
  107. bottom of the screen.  This line also displays the two or three letter
  108. abbreviation for the ASCII control codes (these are the first 31 characters
  109. of the ASCII character set, from 00 - 1F hex).
  110.  
  111.    After setting up the swap table for your new filter, you will be shown
  112. the current status of the NULL handler.  Use the space bar to toggle
  113. between keeping and stripping NULLs, and hit Enter to accept the new
  114. setting.  You will then be shown the current status of the TAB handler, and
  115. can use the space bar to toggle between expanding them or passing them
  116. through.  If you want to expand the tabs, you will be prompted for a number
  117. to use to create the tab stops.  Enter a new value or press Enter to accept
  118. the current setting.  That's all there is to it; the new filter will be
  119. written to disk and you will be returned to DOS.
  120.  
  121.  
  122.  
  123.  
  124.                             Using your Filter
  125.  
  126.    These filters work by taking advantage of redirection and pipes in DOS. 
  127. All the references to character streams so far may be a little confusing,
  128. so here's a brief explanation.  DOS treats all files as streams of bytes. 
  129. DOS also treats keyboard input, or stdin,  and console output, or stdout,
  130. as files.  Redirection takes advantage of this fact, and remaps stdin or
  131. stdout to point to a regular file instead of the keyboard or monitor.  To
  132. redirect input, add a left arrow (Shift ,) to the name of the file you want
  133. to use as an input file.  To redirect stdout, add a right arrow (Shift .)
  134. to a valid DOS filename.  That file will be created and output intended for
  135. stdout will go there rather than to the monitor.
  136.  
  137.    The filters created with FDK take advantage of DOS redirection.  They
  138. actually get their input from stdin, and output the changed stream to
  139. stdout.  You can verify this by running the filter called CAPS.EXE supplied
  140. with the FDK.  If you run CAPS with no argument, the program will accept
  141. anything you type at the keyboard as input, and will change any lowercase
  142. letters to uppercase every time you press Enter (try it if you want; stop
  143. the program with a Ctrl-C).  By using redirection, you can use any DOS file
  144. as an input, and place the output in a new file.  If you have not used
  145. redirection before, try using it to change sample text file provided with
  146. the FDK to all caps.  Enter the following at the DOS prompt:
  147.  
  148.       CAPS <lower.txt >upper.txt
  149.  
  150. LOWER.TXT is a text file containing all lowercase characters.  After
  151. running LOWER through the filter CAPS, all the letters will be changed to
  152. uppercase and placed in the file UPPER.TXT.  LOWER.TXT itself is unchanged.
  153. Any filter you create with FDK can be used in the same way.
  154.  
  155.     There is also one other way to use these filters - through the use of
  156. pipes.  Pipes take their input from the output of another program.  Pipes
  157. are specified by using the vertical bar (|) before the name of the program
  158. that is to receive the output.  You can try out an FDK filter using a pipe
  159. by entering the following at the DOS prompt:
  160.  
  161.       TYPE lower.txt |caps
  162.  
  163. The result is the same as in the previous example, except that the
  164. transformed file is displayed on the monitor rather than saved to a file. 
  165. Using your filter with pipes is useful for viewing files that would
  166. normally be unreadable.  You can also chain pipes, by placing them one
  167. after the other on the command line.  Try entering the following:
  168.  
  169.     TYPE fdk.doc |caps |more
  170.  
  171. This will display this documentation file on the screen in all caps,
  172. pausing after each screenful to wait for a keypress (more.com and caps.exe
  173. need to be in the current directory or on the current PATH).
  174.  
  175.     For an example of the usefulness of a filter, suppose you have a
  176. document created by your favorite word processor, and you want to take a
  177. quick look at it.  Most word processors insert formatting characters into
  178. the file, creating lots of garbage characters if you try to view the
  179. document using the DOS type command.  Using FDK, you can create a filter
  180. that either strips the high bit off of the control bytes, or removes them
  181. altogether.  This way you can view any file created by your word processor
  182. without loading the whole program.  The ASCII.EXE filter included with FDK
  183. is an extreme form of this kind of filter.  It removes every non-ASCII
  184. character, and also all non-printing ASCII control codes except for CR, LF,
  185. FF, and SUB (Ctrl-Z, the DOS end-of-file character), from the input stream. 
  186. If you want to see how this filter was set up, start FDK using ASCII.EXE as
  187. the template filter.
  188.  
  189.  
  190.  
  191.  
  192.                                   Etc.
  193.  
  194.  
  195.    The last filter supplied with FDK is one that remaps seldom used
  196. characters in the ASCII set to single-line box drawing characters from the
  197. IBM high-order character set.  This is useful for someone whose word
  198. processor doesn't allow the high-order set to be used in a document.  Draw
  199. the box using the characters below, and print the file to disk.  If your
  200. program won't allow you to print to disk, use one of the utilities found in
  201. the software libraries of most BBS and commercial computer services such as
  202. GEnie, that automatically capture printer output and save it to disk.  Use
  203. BOX.EXE to remap the characters to box characters, and use the DOS print
  204. utility to print the new file.
  205.  
  206.       Box drawing characters:
  207.  
  208.         {        upper left corner
  209.  
  210.         }        upper right corner
  211.  
  212.         [        lower left corner
  213.  
  214.         ]        lower right corner
  215.  
  216.         |        vertical line
  217.  
  218.         \        horizontal line
  219.  
  220.         ~        left intersection
  221.  
  222.         `        right intersection
  223.  
  224. To verify this, enter:
  225.  
  226.     TYPE fdk.doc |box |more
  227.  
  228. Be sure that more.com and box.exe are either in the current directory or in
  229. the current PATH.  Press any key until this table comes on the screen. 
  230. Now, instead of the ASCII characters, you'll see the box characters next to
  231. their descriptions.  Of course, you can use FDK to change the character
  232. assignments to any character you want, or to change them to double line
  233. characters.  Also, you may have to experiment as to which characters can
  234. be used to create boxes since printer control sequences will be imbedded in
  235. the print image file.  If one of the above characters is part of a printer
  236. control sequence, remapping it to a graphics character can cause the
  237. printer to choke.  There is one potential conflict in the above characters
  238. for an Epson printer - the \ character used for horizontal lines is part of
  239. the control string used to set relative printhead position (ESC \).  This
  240. will probably not cause a conflict, but if it does, try using the caret
  241. (Shift 6) instead.  You'll need to check your printer documentation if you
  242. encounter a problem.
  243.  
  244.  
  245.  
  246.    There are a lot of uses for filters, and it can be a pain to code an
  247. entire program to create a special filter for one or two uses.  Since the
  248. vast majority of filters are just simple substitution-type filters, FDK can
  249. really save a lot of time and aggravation.  The examples shown are just a
  250. scratch on the surface of the problems that can be solved using these kinds
  251. of filters.
  252.  
  253.    If you have any questions or comments, or find any bugs, I can be
  254. reached via my mailbox on GEnie (send mail to C.Greer).  I'm not very
  255. consistent at logging onto GEnie, so it might take a week or so for me to
  256. respond to a letter.  This never has been intended to be commercial
  257. software or shareware or anything like that, just a way to learn the C
  258. language, so feel free to use it or share it with friends (just don't
  259. charge anyone for it).  The only thing I ask is that you keep the DOC file
  260. and sample filters together with FDK.EXE, since FDK.EXE is less than
  261. useless without a template filter.
  262.  
  263.     Whew!  Writing documentation is harder than I thought it would be.  I
  264. hope someone finds this program useful like I did.  One last note:  I want
  265. to give credit where credit is due.  The filter itself is based on a sample
  266. filter in the book "Advanced MSDOS" by Ray Duncan.  I took his code and
  267. modified it to use a swap table, strip or keep NULLs, and keep or expand
  268. TABs (his expanded tabs all the time).  This is an excellent reference book
  269. for experienced or inquisitive computerphiles (I'm the latter), and is
  270. highly recommended.