* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / qpdecode.c
1 /*
2  * $Id$ 
3  *
4  * Convert "quoted printable" encoding to binary (stdin to stdout)
5  * Copyright (C) 1999 by Art Cancro
6  * Distributed under the terms of the GNU General Public License.
7  */
8
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #include <string.h>
14
15 int main(int argc, char *argv[]) {
16         char buf[80];
17         int soft_line_break = 0;
18         int ch;
19
20         while (fgets(buf, 80, stdin) != NULL) {
21                 while (isspace(buf[strlen(buf)-1]))
22                         buf[strlen(buf)-1] = 0;
23                 soft_line_break = 0;
24
25                 while (strlen(buf) > 0) {
26                         if (!strcmp(buf, "=")) {
27                                 soft_line_break = 1;
28                                 strcpy(buf, "");
29                         } else if ( (strlen(buf)>=3) && (buf[0]=='=') ) {
30                                 sscanf(&buf[1], "%02x", &ch);
31                                 putc(ch, stdout);
32                                 strcpy(buf, &buf[3]);
33                         } else {
34                                 putc(buf[0], stdout);
35                                 strcpy(buf, &buf[1]);
36                         }
37                 }
38                 if (soft_line_break == 0) printf("\r\n");
39         }
40         exit(0);
41 }