~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to src/tiff/contrib/mac-mpw/mactrans.c

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}