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