4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 /* tr - transliterate data stream */
52 struct string
{ int last
, max
; char *p
; } string1
, string2
;
55 main(int argc
, char **argv
)
63 string1
.last
= string2
.last
= 0;
64 string1
.max
= string2
.max
= 0;
65 string1
.p
= string2
.p
= "";
69 if(*argv
[0]=='-'&&argv
[0][1]!=0) {
86 if(argc
>0) string1
.p
= argv
[0];
87 if(argc
>1) string2
.p
= argv
[1];
89 code
[i
] = vect
[i
] = 0;
91 while(c
= next(&string1
))
95 if(vect
[i
]==0) vect
[j
++] = i
;
103 if(cflag
) c
= *compl++;
104 else c
= next(&string1
);
110 code
[c
&0377] = dflag
?1:d
;
112 while(d
= next(&string2
))
116 if(code
[i
]==0) code
[i
] = i
;
117 else if(dflag
) code
[i
] = 0;
121 while((c
=getc(stdin
)) != EOF
) {
123 if(c
= code
[c
&0377]&0377)
124 if(!sflag
|| c
!=save
|| !squeez
[c
&0377]) {
125 (void)putchar(save
= c
);
134 next(struct string
*s
)
139 if(s
->last
++ < s
->max
)
141 s
->max
= s
->last
= 0;
143 if(s
->last
&& *s
->p
=='-') {
150 if(s
->max
< s
->last
) {
156 return(s
->last
= nextc(s
));
160 nextc(struct string
*s
)
167 while(i
<3 && (c
= *s
->p
)>='0' && c
<='7') {
175 if(c
==0) *--s
->p
= 0;