7 /* transliterate characters
9 /* #include <stringops.h>
11 /* char *translit(buf, original, replacement)
16 /* translit() takes a null-terminated string, and replaces characters
17 /* given in its \fIoriginal\fR argument by the corresponding characters
18 /* in the \fIreplacement\fR string. The result value is the \fIbuf\fR
21 /* Cannot replace null characters.
25 /* The Secure Mailer license must be distributed with this software.
28 /* IBM T.J. Watson Research
30 /* Yorktown Heights, NY 10598, USA
38 /* Utility library. */
40 #include "stringops.h"
42 char *translit(char *string
, const char *original
, const char *replacement
)
48 * For large inputs, should use a lookup table.
50 for (cp
= string
; *cp
!= 0; cp
++) {
51 for (op
= original
; *op
!= 0; op
++) {
53 *cp
= replacement
[op
- original
];
64 * Usage: translit string1 string2
66 * test program to perform the most basic operation of the UNIX tr command.
71 #include <vstring_vstream.h>
73 #define STR vstring_str
75 int main(int argc
, char **argv
)
77 VSTRING
*buf
= vstring_alloc(100);
80 msg_fatal("usage: %s string1 string2", argv
[0]);
81 while (vstring_fgets(buf
, VSTREAM_IN
))
82 vstream_fputs(translit(STR(buf
), argv
[1], argv
[2]), VSTREAM_OUT
);
83 vstream_fflush(VSTREAM_OUT
);