]> git.saurik.com Git - wxWidgets.git/blob - src/tiff/contrib/mac-mpw/mactrans.c
adding more infos, links
[wxWidgets.git] / src / tiff / contrib / mac-mpw / mactrans.c
1 /*
2 * mactrans.c -- Hack filter used to generate MPW files
3 * with special characters from pure ASCII, denoted "%nn"
4 * where nn is hex. (except for "%%", which is literal '%').
5 *
6 * calling sequence:
7 *
8 * catenate file | mactrans [-toascii | -fromascii] > output
9 *
10 * Written by: Niles Ritter.
11 */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <ctype.h>
15
16 void to_ascii(void);
17 void from_ascii(void);
18
19 main(int argc, char *argv[])
20 {
21 if (argc<2 || argv[1][1]=='f') from_ascii();
22 else to_ascii();
23 exit (0);
24 }
25
26 void from_ascii(void)
27 {
28 char c;
29 int d;
30 while ((c=getchar())!=EOF)
31 {
32 if (c!='%' || (c=getchar())=='%') putchar(c);
33 else
34 {
35 ungetc(c,stdin);
36 scanf("%2x",&d);
37 *((unsigned char *)&c) = d;
38 putchar(c);
39 }
40 }
41 }
42
43 void to_ascii(void)
44 {
45 char c;
46 int d;
47 while ((c=getchar())!=EOF)
48 {
49 if (isascii(c)) putchar (c);
50 else
51 {
52 d = *((unsigned char *)&c);
53 printf("%%%2x",d);
54 }
55 }
56 }