5
/* translate C-like escape sequences
7
/* #include <stringops.h>
9
/* VSTRING *unescape(result, input)
13
/* unescape() translates C-like escape sequences in the null-terminated
14
/* string \fIinput\fR and places the result in \fIresult\fR. The result
15
/* is null-terminated.
17
/* Escape sequences and their translations:
21
/* Backspace character.
23
/* formfeed character.
27
/* Carriage-return character.
29
/* Horizontal tab character.
31
/* Vertical tab character.
33
/* Backslash character.
35
/* 8-bit character whose ASCII value is the 1..3 digit
36
/* octal number \fInum\fR.
38
/* The backslash character is discarded.
42
/* The Secure Mailer license must be distributed with this software.
45
/* IBM T.J. Watson Research
47
/* Yorktown Heights, NY 10598, USA
55
/* Utility library. */
58
#include <stringops.h>
60
/* unescape - process escape sequences */
62
VSTRING *unescape(VSTRING *result, const char *data)
68
#define UCHAR(cp) ((unsigned char *) (cp))
69
#define ISOCTAL(ch) (ISDIGIT(ch) && (ch) != '8' && (ch) != '9')
71
VSTRING_RESET(result);
73
while ((ch = *UCHAR(data++)) != 0) {
75
if ((ch = *UCHAR(data++)) == 0)
78
case 'a': /* \a -> audible bell */
81
case 'b': /* \b -> backspace */
84
case 'f': /* \f -> formfeed */
87
case 'n': /* \n -> newline */
90
case 'r': /* \r -> carriagereturn */
93
case 't': /* \t -> horizontal tab */
96
case 'v': /* \v -> vertical tab */
99
case '0': /* \nnn -> ASCII value */
107
for (oval = ch - '0', i = 0;
108
i < 2 && (ch = *UCHAR(data)) != 0 && ISOCTAL(ch);
110
oval = (oval << 3) | (ch - '0');
114
default: /* \any -> any */
118
VSTRING_ADDCH(result, ch);
120
VSTRING_TERMINATE(result);
126
#include <vstring_vstream.h>
128
int main(int unused_argc, char **unused_argv)
130
VSTRING *in = vstring_alloc(10);
131
VSTRING *out = vstring_alloc(10);
133
while (vstring_fgets_nonl(in, VSTREAM_IN)) {
134
unescape(out, vstring_str(in));
135
vstream_fwrite(VSTREAM_OUT, vstring_str(out), VSTRING_LEN(out));
137
vstream_fflush(VSTREAM_OUT);