%%s 6/6/165 %%d D 1.2 15-Jun-83 12:27:37 sventek 2 1 %%c Removed trailing periods from quoted strings, as they are no longer needed. %%s 0/0/0 %%d D 1.1 25-Mar-82 12:15:35 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- trsym 103 asc 25-mar-82 08:57:32 v1.1 (sw-tools v1.1) ## definitions for TR tool # put on a file named 'trsym' # used only by tr define(MAXSET,100) %%D 2 #-h- tr.r 2320 asc 25-mar-82 08:57:34 v1.1 (sw-tools v1.1) #-h- main 1421 asc 25-mar-82 08:57:14 v1.1 (sw-tools v1.1) %%E 2 %%I 2 #-h- tr.r 2320 asc 15-jun-83 12:27:19 sventek (joseph sventek) #-h- main 1417 asc 15-jun-83 12:27:01 sventek (joseph sventek) %%E 2 ## tr - transliterate characters on a file include trsym DRIVER(tr) character getc character arg(MAXLINE), c, from(MAXSET), to(MAXSET) integer getarg, length, makset, xindex integer allbut, collap, i, lastto %%D 2 string usestr "usage: tr from [to]." %%E 2 %%I 2 string usestr "usage: tr from [to]" %%E 2 call query(usestr) if (getarg(1, arg, MAXLINE) == EOF) call error(usestr) else if (arg(1) == NOT) { allbut = YES if (makset(arg, 2, from, MAXSET) == NO) %%D 2 call error("from: too large.") %%E 2 %%I 2 call error("from: too large") %%E 2 } else { allbut = NO if (makset(arg, 1, from, MAXSET) == NO) %%D 2 call error("from: too large.") %%E 2 %%I 2 call error("from: too large") %%E 2 } if (getarg(2, arg, MAXLINE) == EOF) to(1) = EOS else if (makset(arg, 1, to, MAXSET) == NO) %%D 2 call error("to: too large.") %%E 2 %%I 2 call error("to: too large") %%E 2 lastto = length(to) if (length(from) > lastto | allbut == YES) collap = YES else collap = NO repeat { i = xindex(from, getc(c), allbut, lastto) if (collap == YES & i >= lastto & lastto > 0) { # collapse call putc(to(lastto)) repeat i = xindex(from, getc(c), allbut, lastto) until (i < lastto) } if (c == EOF) break if (i > 0 & lastto > 0) # translate call putc(to(i)) else if (i == 0) # copy call putc(c) # else delete } #*** DRETURN end #-h- makset 301 asc 25-mar-82 08:57:16 v1.1 (sw-tools v1.1) ## makset - make set from array(k) in set integer function makset(array, k, set, size) integer addset integer i, j, k, size character array(ARB), set(size) i = k j = 1 call filset(EOS, array, i, set, j, size) makset = addset(EOS, set, j, size) return end #-h- xindex 379 asc 25-mar-82 08:57:17 v1.1 (sw-tools v1.1) ## xindex - invert condition returned by index integer function xindex(array, c, allbut, lastto) character array(ARB), c integer index integer allbut, lastto if (c == EOF) xindex = 0 else if (allbut == NO) xindex = index(array, c) else if (index(array, c) > 0) xindex = 0 else xindex = lastto + 1 return end #-h- tr.fmt 2301 asc 25-mar-82 08:57:37 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Tr (1) 6-Jul-78 transliterate characters .sy tr from [to] .ds tr copies the standard input to the standard output with substitution or deletion of selected characters. Input characters found in `from' are mapped into the corresponding characters of `to'. Ranges of characters may be specified by separating the extremes by a dash. For example, a-z stands for the string of characters whose ascii codes run from character a through character z. If the number of characters in `from' is the same as in `to', a one to one corresponding translation will be performed on all occurrences of the characters in `from'. If the number of characters in `from' is more than in `to', the implication is that the last character in the `to' string is to be replicated as often as necessary to make a string as long as the `from' string, and that this replicated character should be collapsed into only one. If the `to' string is missing or empty, "TR" will take this condition as a request to delete all occurrences of characters in the `from' string. .sp 1 "TR" differs from the tool "CH" since it deals only with single characters or ranges of characters, while "CH" deals with character strings. For example tr xy yx would change all x's into y's and all y's into x's, whereas ch xy yx change all the patterns "xy" into "yx". .sp 1 One of the most common functions of "TR" is to translate upper case letters to lower case, and vice versa. Thus, .ce tr A-Z a-z would map all upper case letters to lower case. Users of systems which cannot pass both upper and lower case characters on a command line should remember to include the appropriate escape flags. .fl none .sa .nf Tools "find" and "ch". The "Software Tools" book, p.51-61. The "UNIX Programmer's Manual", p. TR(I). .fi .di "usage: tr from [to]." .br .in +5 The command line passed to transit is in error. .br .in -5 "from: too large." .br .in +5 The string for "from" is too large. Current limit is 100 characters including E0S. .br .in -5 "to: too large." .br .in +5 The string for "to" is too large. Current limit is 100 characters including EOS. .in -5 .au Original code from Kernighan and Plaugers's "Software Tools", with modifications by Debbie Scherrer. .bu %%E 1