TransDoc.tioga
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
R. Nix, April 12, 1984 6:59:40 pm PST
Swinehart, May 17, 1985 10:38:24 am PDT
Bertrand Serlet April 2, 1987 10:29:03 pm PST
Bloomenthal, May 8, 1989 12:20:52 pm PDT
Trans
CEDAR 7.0 — FOR INTERNAL XEROX USE ONLY
Trans
Pattern Substitution
Dan Swinehart <Swinehart.pa>
Abstract: Trans does a pattern-directed global substitution to a group of files. Trans has a subset of the functionality of the EditTool's substitute command; however, it is better suited to the task of performing different global substitutions to several files. Trans's main shortcoming is that it cannot deal with Tioga node structure. See TransTioga, below, regarding Tioga documents.
Created by: Dan Swinehart
Maintained by: Dan Swinehart <Swinehart.pa>
Keywords: Regular Expression, Text, Replace, Substitution, Text Replace, Grep, Pattern Searching
XEROX Xerox Corporation
Palo Alto Research Center
3333 Coyote Hill Road
Palo Alto, California 94304
For Internal Xerox Use Only
1. Trans
Description
Trans [switches] [pattern replacement] fileNames
Trans does a pattern-directed global substitution to a group of files. Trans has a subset of the functionality of the EditTool's substitute command; however, it is better suited to the task of performing different global substitutions to several files.
Trans's main shortcoming is that it cannot deal with Tioga node structure. It's not that it deals with nodes badly -- it doesn't deal with them at all. C'est la vie; somebody should write a Streams-like or Rope-like interface to editing Tioga documents in order to make such things easier.
Trans may be viewed as transforming files filled with records; the pattern is used to specify the format of the records to be transformed. The replacement is used to specify how you want the record to change.
The pattern syntax is given in RegularExpressionDoc.tioga. You delimit the fields of the record using the <> notation, e.g. the pattern ``<lastName>, <firstName>\n'' might match a list of names. The replacement syntax is similar to the EditTool's, in that the replacement expression ``<firstName> <lastName>\n'' will interchange the order of names in the text matched by the pattern. Note that apostrophe, ``''', is the quote-character, in case you want to stick a ``<'' in a replacement. There are special purpose hacks for changing field capitalization: ``<lastName:u>'' would capitalize the ``<lastName>'' field, ``<lastName:l>'' would make it be all lower case.
Switches
-pattern (-p)
By default, Trans interprets the pattern as a regular expression using the syntax described in RegularExpressionDoc.tioga.
-literal (-l)
If this switch is given, then Trans interprets patterns as literal text.
-caseSensitive (-c)
Capitalization is significant in matching the pattern agains the text.
-ignoreCase (-i)
By default, Trans ignores capitalization differences when matching the pattern against the text.
-wordMatch (-w)
Match text only on word boundaries.
-matchAnywhere (-m)
By default, Trans will match the pattern anywhere.
-deleteMatched (-d)
If the -d switch is given, then no replacement expression should be given, and Trans will delete all text that matches the pattern. This switch is necessary because the CommandTool's command line parser doesn't parse "" as a token.
-selectMatched (-s)
If this switch is given, then Trans will delete all text that doesn't match the pattern, and will apply the given replacement to the text that does match the pattern.
-replaceMatched (-t)
By default, Trans replaces text that matches the pattern with the text determined by the replacement expression, copying the text that doesn't match the pattern over into the output.
-appendFile (-a)
This switch takes an argument, which is the name of a file to which all output will be appended. Normally when a list of file names is given, each file is processed separately, and output is written to a new generation of each file. This switch is useful, in conjunction with the -s switch, for doing something like collecting the names of all procedures defined in a set of files.
-filePatterns (-f)
This is how you tell Trans to do more than one pattern => replacement transformation. This switch takes an argument, which is the name of a file. Each line of the file should be a Trans command line, without file names, but including any switches that you'd like to be in effect (including other -f switches). Trans will apply each of the commands in the file to each of the files specified on the command line. Switch settings are dynamically scoped, e.g. the switch settings given on the command line specify the defaults for each pattern-replacement line in the file, but each pattern-replacement line can override those defaults.
Bugs
Trans knows nothing about Tioga formatting.
2. TransTioga
TransTioga <key> <replacement> <file1> . . . <fileN>
This replaces key with replacement for each of the named files while maintaining Tioga formatting. TransTioga does not, however, perform sophisticated pattern replacement. The default files are highest version only, unless a specific version, !*, or !L is specified.