~ubuntu-branches/ubuntu/vivid/macutils/vivid

« back to all changes in this revision

Viewing changes to mixed/macbinary.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Sharkey
  • Date: 2001-10-27 15:22:18 UTC
  • Revision ID: james.westby@ubuntu.com-20011027152218-oikhfgiaja3hjf5f
Tags: upstream-2.0b3
ImportĀ upstreamĀ versionĀ 2.0b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "globals.h"
 
2
#include "../fileio/machdr.h"
 
3
#include "../fileio/kind.h"
 
4
#include "../util/util.h"
 
5
 
 
6
extern void dir();
 
7
extern void mcb();
 
8
extern void do_indent();
 
9
 
 
10
static void skip_file();
 
11
#ifdef SCAN
 
12
static void get_idf();
 
13
#endif /* SCAN */
 
14
 
 
15
void macbinary()
 
16
{
 
17
    char header[INFOBYTES];
 
18
    int c;
 
19
 
 
20
    while(1) {
 
21
        if((c = fgetc(infp)) == EOF) {
 
22
            break;
 
23
        }
 
24
        (void)ungetc(c, infp);
 
25
        if(fread(header, 1, INFOBYTES, infp) != INFOBYTES) {
 
26
            (void)fprintf(stderr, "Can't read MacBinary header.\n");
 
27
            exit(1);
 
28
        }
 
29
        if(header[I_NAMEOFF] & 0x80) {
 
30
            dir(header);
 
31
            continue;
 
32
        }
 
33
        in_data_size = get4(header + I_DLENOFF);
 
34
        in_rsrc_size = get4(header + I_RLENOFF);
 
35
        in_ds = (((in_data_size + 127) >> 7) << 7);
 
36
        in_rs = (((in_rsrc_size + 127) >> 7) << 7);
 
37
        ds_skip = in_ds - in_data_size;
 
38
        rs_skip = in_rs - in_rsrc_size;
 
39
        if(dir_skip != 0) {
 
40
            skip_file(in_ds + in_rs);
 
41
            continue;
 
42
        }
 
43
#ifdef SCAN
 
44
        if(header[I_NAMEOFF] == 0) {
 
45
            get_idf((int)header[I_NAMEOFF + 1]);
 
46
            skip_file(ds_skip + in_rs);
 
47
            continue;
 
48
        }
 
49
#endif /* SCAN */
 
50
        if(header[0] == 0 /* MORE CHECKS HERE! */) {
 
51
            mcb(header, (unsigned long)in_rsrc_size,
 
52
                        (unsigned long)in_data_size, in_ds + in_rs);
 
53
            continue;
 
54
        } else {
 
55
            (void)fprintf(stderr, "Unrecognized header.\n");
 
56
            exit(1);
 
57
        }
 
58
    }
 
59
}
 
60
 
 
61
static void skip_file(skip)
 
62
    int skip;
 
63
{
 
64
    char buff[1024];
 
65
    int n;
 
66
 
 
67
    while(skip > 0) {
 
68
        n = (skip < 1024 ? skip : 1024);
 
69
        if(fread(buff, 1, n, infp) != n) {
 
70
            (void)fprintf(stderr, "Incomplete file.\n");
 
71
            exit(1);
 
72
        }
 
73
        skip -= n;
 
74
    }
 
75
}
 
76
 
 
77
#ifdef SCAN
 
78
static void get_idf(kind)
 
79
    int kind;
 
80
{
 
81
    char filename[1024], filename1[255];
 
82
 
 
83
    if(fread(filename, 1, in_data_size, infp) != in_data_size) {
 
84
        (void)fprintf(stderr, "Incomplete file.\n");
 
85
        exit(1);
 
86
    }
 
87
    filename[in_data_size] = 0;
 
88
    if(list) {
 
89
        do_indent(indent);
 
90
        switch(kind) {
 
91
        case UNIX_NAME:
 
92
            (void)fprintf(stderr, "Unix filename: \"%s\"\n", filename);
 
93
            break;
 
94
        case PACK_NAME:
 
95
            transname(filename, filename1, in_data_size);
 
96
            (void)fprintf(stderr, "Packed filename: \"%s\"\n", filename1);
 
97
            break;
 
98
        case ARCH_NAME:
 
99
            transname(filename, filename1, in_data_size);
 
100
            (void)fprintf(stderr, "Archive name: \"%s\"\n", filename1);
 
101
            break;
 
102
        case UNKNOWN:
 
103
            (void)fprintf(stderr, "Unknown method detected\n");
 
104
            break;
 
105
        case ERROR:
 
106
            (void)fprintf(stderr, "Error detected\n");
 
107
            break;
 
108
        case PROTECTED:
 
109
            (void)fprintf(stderr, "Protected file detected\n");
 
110
            break;
 
111
        case COPY:
 
112
            (void)fprintf(stderr, "Copied file found\n");
 
113
            break;
 
114
        default:
 
115
            (void)fprintf(stderr, "Do not understand this identification\n");
 
116
            exit(1);
 
117
        }
 
118
    }
 
119
}
 
120
#endif /* SCAN */
 
121