comparison f-demime/qpdec.c @ 0:7e0d08176f32

f-demime starting code
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 06:14:03 +0000
parents
children 05651a1b8ba8
comparison
equal deleted inserted replaced
-1:000000000000 0:7e0d08176f32
1 /*
2 * This module implements quoted-printable decoding.
3 */
4
5 #include <ctype.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "defs.h"
11
12 extern void (*dec_outf)();
13
14 int qpdec_err_flag;
15
16 static void
17 strip_trailing_lwsp(line)
18 char *line;
19 {
20 char *cp;
21
22 cp = index(line, '\0');
23 while (cp > line && isspace(cp[-1])
24 cp--;
25 *cp = '\0';
26 }
27
28 static int
29 decode_hex_digit(c)
30 {
31 if (isdigit(c))
32 return(c - '0');
33 else if (isupper(c))
34 return(c - 'A' + 10);
35 else
36 return(c - 'a' + 10);
37 }
38
39 static int
40 decode_hex_byte(cp)
41 char *cp;
42 {
43 int u, l;
44
45 u = decode_hex_digit(cp[0]);
46 l = decode_hex_digit(cp[1]);
47 return (u << 4) | l;
48 }
49
50 void
51 qpdec_input_line(line)
52 char *line;
53 {
54 char *cp;
55 int c;
56
57 strip_trailing_lwsp(line);
58 for (cp = line; *cp; ) {
59 c = *cp++ & 0xFF;
60 if (c != '=') {
61 dec_outf(c);
62 continue;
63 }
64 if (!*cp)
65 return;
66 if (isxdigit(cp[0]) && isxdigit(cp[1])) {
67 c = decode_hex_byte(cp);
68 cp += 2;
69 dec_outf(c);
70 continue;
71 }
72 qpdec_err_flag = 1;
73 dec_outf('=');
74 }
75 dec_outf('\n');
76 }