summaryrefslogtreecommitdiff
path: root/tiff/contrib/mac-mpw/mactrans.c
blob: d35373e079f494990f37ca457b82273ccd86f8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 *  mactrans.c  -- Hack filter used to generate MPW files 
 *    with special characters from pure ASCII, denoted "%nn" 
 *    where nn is hex. (except for "%%", which is literal '%').
 *
 *  calling sequence:
 *
 *    catenate file | mactrans [-toascii | -fromascii] > output
 *
 *    Written by: Niles Ritter.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

void to_ascii(void);
void from_ascii(void);

main(int argc, char *argv[])
{
	if (argc<2 || argv[1][1]=='f') from_ascii();
	else to_ascii();
	exit (0);
}

void from_ascii(void)
{
    char c;
    int d;
    while ((c=getchar())!=EOF)
    {
    	if (c!='%' || (c=getchar())=='%') putchar(c);
	else
	{
		ungetc(c,stdin);
		scanf("%2x",&d);
		*((unsigned char *)&c) = d;
		putchar(c);
	}
    }
}

void to_ascii(void)
{
    char c;
    int d;
    while ((c=getchar())!=EOF)
    {
    	if (isascii(c)) putchar (c);
	else
	{
		d = *((unsigned char *)&c);
		printf("%%%2x",d);
	}
    }
}
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 8
 * fill-column: 78
 * End:
 */