1 /*$Id: decodeQ.c,v 1.3 1998/10/29 21:48:24 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
9 /* takes a string pointed to by cpfrom and adds the next 'n' bytes to */
10 /* outdata, replacing any Quoted-Printable codes with the real characters. */
11 /* NUL and LF in the input are allowed, but anything that decodes to these */
12 /* values is ignored. */
14 static char char16table
[128] = {
15 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
16 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
17 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
18 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1,
19 -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
20 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
21 -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
22 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
25 #define char16enc(c) (((c) & 0x80) ? -1 : char16table[(c)])
27 static void die_nomem(fatal
)
30 strerr_die2x(111,fatal
,ERR_NOMEM
);
33 void decodeQ(cpfrom
,n
,outdata
,fatal
)
38 /* does Q decoding of the string pointed to by cpfrom up to the character */
39 /* before the one pointed to by cpnext, and appends the results to mimeline*/
41 char *cp
,*cpnext
,*cpmore
;
43 char ch1
,ch2
; /* need to be signed */
48 if (!stralloc_readyplus(outdata
,n
)) die_nomem(fatal
);
51 if (*cp
== '_') *cp
= ' '; /* '_' -> space */
52 else if (*cp
== '=') { /* "=F8" -> '\xF8' */
53 /* copy stuff before */
54 if (!stralloc_catb(outdata
,cpmore
,cp
-cpmore
)) die_nomem(fatal
);
57 if (*cp
== '\n') { /* skip soft line break */
66 if (ch1
>= 0 && ch2
>= 0) { /* ignore illegals */
67 holdch
[0] = (ch1
<< 4 | ch2
) & 0xff;
68 if (!stralloc_catb(outdata
,holdch
,1)) die_nomem(fatal
);
73 } /* copy stuff after */
74 if (!stralloc_catb(outdata
,cpmore
,cpnext
-cpmore
)) die_nomem(fatal
);