home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / TEXT / UTILITY / TDS_V10.ZIP / TDS.DOC < prev    next >
Encoding:
Text File  |  1990-12-26  |  13.8 KB  |  359 lines

  1. TDS -- Transliteration, Deletion, and Squeeze filter         23Dec1990
  2.  
  3. INVOCATION (some of all the myriad ways)
  4.  
  5.      tds [-cds] [SearchChars [ReplacementChars]] <inputfile
  6.  
  7.      tds [-cds] [SearchChars [ReplacementChars]] <inputfile >outputfile
  8.  
  9.      tds [-cds] [SearchChars [ReplacementChars]] <inputfile | outputstream
  10.  
  11.      inputstream | tds [-cds] [SearchChars [ReplacementChars]]
  12.  
  13.      inputstream | tds [-cds] [SearchChars [ReplacementChars]] >outputfile
  14.  
  15.      inputstream | tds [-cds] [SearchChars [ReplacementChars]] | outputstream
  16.  
  17.      Option switches may be anywhere within the scope of the 
  18.      invocation except inside the SearchChars or ReplacementChars 
  19.      strings, also known as s1 and s2 in the source code.
  20.  
  21. DESCRIPTION
  22.  
  23.      The TDS filter is a fast superset of the standard Unix (tm) 
  24.      System V "tr" program.  Improvements of TDS over TR are an 
  25.      increased flexibility in the interpretation of escape code and 
  26.      character ranges, an increase in the number of descriptive error 
  27.      messages, and a speed increase in most cases due to its buffering 
  28.      scheme and speed-optimal code.  You can expect a 100% to 900% 
  29.      speed increase with files larger than 100KB.  TDS also corrects a 
  30.      deficiency of the TR program in its inability to process NULL 
  31.      characters, (char)0.
  32.  
  33.      To get started quickly, skip ahead to the EXAMPLES section.
  34.  
  35.      TDS was written as a programming exercise that involved reverse 
  36.      engineering, automated program testing, fast file processing, 
  37.      some expression parsing and error handling, and filter program 
  38.      writing.  By reverse engineering, I refer in this case to the 
  39.      process of writing a program that is functionally equivalent to 
  40.      and perhaps even better than an existing program without ever 
  41.      consulting the existing program's source code.
  42.  
  43.      The original TR program seems to be one of the first filter 
  44.      programs ever written for the Unix (tm) operating system and one 
  45.      of the most sparsely documented programs in the online MANual.  
  46.      It also seems, from viewing its nondescriptive name, that TR was 
  47.      originally designed to be just a TRansliterator filter that would 
  48.      (1) scan an input stream for any character matching a character 
  49.      in SearchChars, (2) replace the input stream character with the 
  50.      corresponding character in ReplacementChars, and (3) output the 
  51.      result.  Any input stream characters not matching any of the 
  52.      characters in SearchChars would get passed unchanged into the 
  53.      output stream.  The delete and squeeze functions were probably 
  54.      added later, reducing the mnemonic value of "TR[ransliterator]".
  55.  
  56.      Like the TR program, invoking TDS without any option switches 
  57.      causes it to act as a transliteration filter.  In almost all 
  58.      practical cases, you will want TDS to be part of an explicit 
  59.      pipeline or for TDS to be given an inputfile as a source of 
  60.      data.  If you invoke TDS from the command line like this:
  61.  
  62.           tds
  63.  
  64.      Then the program will just sit there and wait for data from the 
  65.      standard input stream -- in this case, the keyboard or terminal 
  66.      -- exactly like TR.  Again, you probably will not want this and 
  67.      will instead want to invoke TDS in one of the forms listed above 
  68.      in the INVOCATION section.
  69.  
  70.      Setting the -d switch makes TDS act as a d)eletion filter. In 
  71.      this mode, TDS scans the input stream for characters that match 
  72.      the characters in SearchChars and then prevents the matching 
  73.      characters from reaching the output stream.  For example, the 
  74.      following invocation will cause TDS to get data from inputfile 
  75.      and stop any spaces (octal code \040) from reaching the 
  76.      outputfile:
  77.  
  78.           tds -d \040 <inputfile >outputfile
  79.  
  80.                or
  81.  
  82.           tds -d \\040 <inputfile >outputfile     (for some shells)
  83.  
  84.      Setting the -c option makes TDS c)omplement SearchChars so that 
  85.      it becomes the set of characters that SearchChars presently is 
  86.      NOT.  For instance, if you want to specify SearchChars as the set 
  87.      of all characters EXCEPT the letters AB, then you can specify 
  88.      SearchChars as AB and activate the -c)omplement switch:
  89.  
  90.           tds -d -c AB <inputfile >outputfile
  91.  
  92.      In this example, all of the characters in the inputfile EXCEPT 
  93.      the letters A and B get blocked from appearing in the outputfile.  
  94.      The -c switch is simply a labor-saving feature that saves you the 
  95.      trouble of directly specifying a lot of characters.  In other 
  96.      words, the -c switch lets you indirectly specify a lot of 
  97.      characters in a concise manner; it can be interpreted as the word 
  98.      "NOT" that affects only the first string, SearchChars.
  99.  
  100.      TR interprets the -c in "-d -c" as SearchChars while TDS 
  101.      interprets the -c as an option switch.  It is recommended that 
  102.      you use a backslash (or two, for Unix shells) before the minus 
  103.      sign if you want TDS to treat the minus as an actual minus 
  104.      character instead of as an option switch indicator.
  105.  
  106.      Setting the -s option makes TDS s)queeze consecutively duplicate 
  107.      characters into one character.  With this option set, TDS first 
  108.      performs transliteration.  It then scans the input stream for 
  109.      duplicate, consecutive characters that match any of the 
  110.      characters in ReplacementChars.  If any such duplicate, 
  111.      consecutive characters are found, they appear as one "squeezed" 
  112.      character in the output stream.  Ex.:
  113.  
  114.           tds -s \t \d32 <textfile
  115.  
  116.                or
  117.  
  118.           tds -s \\t \\d32 <textfile              (for some shells)
  119.  
  120.      In this example, TABs are first converted to spaces.  Immediately 
  121.      afterwards, duplicate and contiguous spaces are s)queezed into 
  122.      one space in the processing stream.  The -s switch only affects 
  123.      the characters in ReplacementChars that are found in the 
  124.      processing stream.  If you invoke TDS like the following:
  125.  
  126.           tds -s \d32 <textfile
  127.  
  128.                or
  129.  
  130.           tds -s \\d32 <textfile
  131.  
  132.      it is equivalent to:
  133.  
  134.           tds -s \d32 \d32 <textfile
  135.  
  136.                or
  137.  
  138.           tds -s \\d32 \\d32 <textfile
  139.  
  140.      So, you see, the -s option still only affects the characters in 
  141.      ReplacementChars that are found in the processing stream.
  142.  
  143.      For the convenience of people who do not have reference manuals 
  144.      listing character codes in OCTAL (base-8) format, TDS can also 
  145.      accept DECIMAL (base-10) and HEXADECIMAL (base-16) escape codes.
  146.  
  147.      The format of a DECIMAL escape code is \dNNN, where the \d prefix 
  148.      (in upper or lower case) indicates that a DECIMAL escape code 
  149.      follows and NNN is a DECIMAL integer from 0 to 255.  Ex:
  150.  
  151.           tds -s \d32 <file
  152.  
  153.             or
  154.  
  155.           tds -s \\d32 <file   (The extra \ is needed for some shells.)
  156.  
  157.      The above command causes TDS to read the contents of the file and 
  158.      s)queeze all duplicate and consecutive SPACEs into one SPACE.  
  159.      \d32 is the DECIMAL number code for the SPACE character in the 
  160.      American Standard Code for Information Interchange (ASCII).
  161.  
  162.      The format of a HEXADECIMAL escape code is \hNN or \xNN, where 
  163.      the \h or \x prefix (in upper or lower case) informs TDS that a 
  164.      HEXADECIMAL escape code follows and NN is a HEXADECIMAL number 
  165.      from 00 to FF.  Ex:
  166.  
  167.           tds -s \x20 <file
  168.  
  169.             or
  170.  
  171.           tds -s \\x20 <file   (The extra \ is needed for some shells.)
  172.  
  173.      The above command also causes TDS to read the contents of the 
  174.      file and s)queeze all duplicate SPACEs from the output 
  175.      stream.  \x20 is the HEXADECIMAL escape code for the ASCII 
  176.      SPACE character.
  177.  
  178.      Whether you use OCTAL or DECIMAL or HEXADECIMAL escape codes 
  179.      depends on your notational preference or the availability of 
  180.      of an ASCII table.
  181.  
  182.      The length of an escape code can affect its meaning:
  183.  
  184.           \d032 does NOT mean the same thing as \d0032,
  185.           which is in fact equivalent to 2\d003 to TDS.
  186.  
  187.      In order to eliminate possible notational problems when using TDS 
  188.      escape codes, it is recommended that you always remove any zeros 
  189.      at the beginning of an escape code except when you want to 
  190.      specify the NULL character, e.g. \0 (recommended), \d0, \h0 or 
  191.      \x0.
  192.  
  193.      In addition to accepting numeric escape codes in different bases, 
  194.      TDS also accepts mnemonic escape codes in upper or lower case for 
  195.      your convenience, unlike TR:
  196.  
  197.           MNEMONIC                    DECIMAL
  198.            ESCAPE                      ASCII
  199.             CODE     MEANING           CODE
  200.  
  201.              \a      Audible bell        7
  202.              \b      Backspace           8
  203.              \t      Tab                 9
  204.              \n      Newline            10
  205.              \v      Vertical tab       11
  206.              \f      Formfeed           12
  207.              \r      carriage Return    13
  208.              \s      Space              32
  209.              \\      backslash          92
  210.  
  211.      Ex.:
  212.  
  213.           tds \r \n <inputfile >outputfile
  214.  
  215.             or
  216.  
  217.           tds \\r \\n <inputfile >outputfile     (for some shells)
  218.  
  219.      In the above example, TDS converts any Carriage Return in the 
  220.      inputfile into a n)ewline (Line Feed) and then puts the result in 
  221.      outputfile.  This may be handy for converting some text files 
  222.      into Unix (tm) format.
  223.  
  224.      Two other notational conveniences absent from TR are TDS's 
  225.      ability to understand descending as well as ascending character 
  226.      ranges, e.g. [a-z][Z-A], and the ability to specify multiple 
  227.      character ranges within the same pair of brackets, e.g. [a-zZ-A] 
  228.      (recommended).
  229.  
  230.      TDS recognizes TR's "*" character multiplier operator in 
  231.      ReplacementChars.  An "*" (asterisk) after a character within 
  232.      brackets indicates that the preceding character is to be 
  233.      repeated.  For example:
  234.  
  235.           tds acegik [z*] <inputfile
  236.  
  237.           tds acegik '[z*]' <inputfile
  238.  
  239.                or
  240.  
  241.           tds acegik [z*6] <inputfile
  242.  
  243.           tds acegik '[z*6]' <inputfile
  244.  
  245.      The above makes all a, c, e, g, i and k characters read from the 
  246.      inputfile appear as z characters.
  247.  
  248.      When no decimal number is specified after a character multiplier, 
  249.      256 minus the current length of ReplacementChars is assumed as 
  250.      the number of repetitions.  When ReplacementChars is null in 
  251.      length, ReplacementChars is made identical to SearchChars.
  252.  
  253.  
  254. PROGRAM INVOCATION EXAMPLES
  255.  
  256.      Output a list of words taken from a file:
  257.  
  258.           tds -sc [a-zZ-A] [\n*] <inputfile        (recommended)
  259.  
  260.           tds -sc '[a-zZ-A]' '[\n*]' <inputfile    (recommended)
  261.  
  262.                     versus
  263.  
  264.           tr  -sc [a-z][A-Z] [\012*] <inputfile
  265.           ~~~
  266.           tr  -sc "[a-z][A-Z]" "[\012*]" <inputfile
  267.           ~~~
  268.      A word in the case above is a set of contiguous alphabetic 
  269.      characters.
  270.  
  271.      Capitalize all letters in inputfile and send the result to 
  272.      outputfile:
  273.  
  274.           tds [a-z] [A-Z] <inputfile >outputfile
  275.  
  276.           tds '[a-z]' '[A-Z]' <inputfile >outputfile  (quotes for some shells)
  277.  
  278.      Uncapitalize all letters in inputfile and send the result to 
  279.      outputfile:
  280.  
  281.           tds [A-Z] [a-z] <inputfile >outputfile
  282.  
  283.           tds '[A-Z]' '[a-z]' <inputfile >outputfile
  284.  
  285.      Squeeze multiple, contiguous spaces in inputfile into just one 
  286.      space and output the result to outputfile:
  287.  
  288.           tds -s \d32 <inputfile >outputfile
  289.  
  290.           tds -s \\d32 <inputfile >outputfile  (extra \ for some shells)
  291.  
  292.           tds -s \s  <inputfile >outputfile    (recommended)
  293.  
  294.           tds -s \\s <inputfile >outputfile    (recommended)
  295.  
  296.      The above may be used before or after obfuscating C code to make 
  297.      the code perhaps more unreadable; or, before beautifying code to 
  298.      make the code more readable.
  299.  
  300.      Read a text file with minimized spacing:
  301.  
  302.           tds -s \t \d32 <inputfile | more
  303.  
  304.           tds -s \\t \\d32 <inputfile | more   (extra \ for some shells)
  305.  
  306.           tds -s \t \s <inputfile | more       (recommended)          
  307.  
  308.           tds -s \\t \\s <inputfile | more     (recommended)
  309.  
  310.      Act as a Rot13 encryption filter:
  311.  
  312.           tds [a-zA-Z] [n-za-mN-ZA-M] <inputfile >outputfile
  313.  
  314.           tds '[a-zA-Z]' '[n-za-mN-ZA-M]' <inputfile >outputfile
  315.  
  316.      Act as a Rot13 decryption filter:
  317.  
  318.           tds [n-za-mN-ZA-M] [a-zA-Z] <inputfile >outputfile
  319.  
  320.           tds '[n-za-mN-ZA-M]' '[a-zA-Z]' <inputfile >outputfile
  321.  
  322.      Convert a Carriage Return(CR)-terminated inputfile into a 
  323.      Line Feed(LF, NewLine)-terminated file:
  324.  
  325.           tds \r \n <inputfile >outputfile
  326.  
  327.           tds \\r \\n <inputfile >outputfile
  328.  
  329.      The above is handy for converting some NON-Unix text files into 
  330.      Unix text files.  The following is handy for doing the reverse:
  331.  
  332.           tds \n \r <inputfile >outputfile
  333.  
  334.           tds \\n \\r <inputfile >outputfile
  335.  
  336. TRADEMARKS
  337.  
  338.      Unix is a trademark of AT&T.
  339.  
  340. AUTHOR & PROGRAM LICENSE
  341.  
  342.      The TDS program and this documentation are Copyright 1990 by 
  343.      Edward Lee.  You may not charge more than the cost of storage 
  344.      media for providing a copy of TDS to another.  You may not make a 
  345.      profit from providing others with a copy or copies of TDS.  You 
  346.      may, however, use the TDS executable file in personal or 
  347.      commercial environments to develop other products with the 
  348.      understanding that you, the user of TDS, accept any damage 
  349.      incurred from the use or misuse of TDS.  This documentation in 
  350.      its entirety must accompany distributed copies of the TDS source 
  351.      file.
  352.  
  353.      You can consider this program and documentation as part of my
  354.      resume.
  355.  
  356.      edlee@chinet.chi.il.us
  357.  
  358. -Ed L
  359.