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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "../fileio/machdr.h"
#include "../fileio/rdfile.h"
#include "../fileio/rdfileopt.h"
#include "../util/patchlevel.h"
#include "../util/util.h"
extern void dofile(void);
#define LOCALOPT "RilqVH"
static void usage();
static char options[128];
static char *dir_stack;
static int dir_ptr = -64;
static int dir_max;
int dorep = 1;
int main(argc, argv)
int argc;
char **argv;
{
int c, i, j, n;
extern int optind;
extern char *optarg;
int errflg;
char text[32], ftype[5], fauth[5];
int dir_skip = 0, write_it, query = 0, list = 0, info_only = 0;
int indent = 0;
(void)strcat(options, get_rdfileopt());
(void)strcat(options, LOCALOPT);
errflg = 0;
while((c = getopt(argc, argv, options)) != EOF) {
if(!rdfileopt((char)c)) {
switch(c) {
case 'R':
dorep = 0;
break;
case 'l':
list++;
break;
case 'q':
query++;
break;
case 'i':
info_only++;
break;
case '?':
errflg++;
break;
case 'H':
give_rdfileopt();
(void)fprintf(stderr, "Binhex specific options:\n");
(void)fprintf(stderr, "-r:\tdo not use run length encoding\n");
(void)fprintf(stderr,
"-i:\tgive information only, do not write\n");
(void)fprintf(stderr, "-l:\tgive listing\n");
(void)fprintf(stderr,
"-q:\tquery for every file/folder before writing\n");
(void)fprintf(stderr,
"-V:\tgive information about this version\n");
(void)fprintf(stderr, "-H:\tthis message\n");
(void)fprintf(stderr, "Default is silent writing\n");
exit(0);
case 'V':
(void)fprintf(stderr, "Version %s, ", VERSION);
(void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
(void)fprintf(stderr, "%s.\n", get_minb());
exit(0);
}
}
}
if(errflg) {
usage();
exit(1);
}
if(info_only || query) {
list++;
}
setup(argc - optind, argv + optind);
while((i = nextfile()) != ISATEND) {
if(dir_skip) {
if(i == ISDIR) {
dir_skip++;
} else if(i == ENDDIR) {
dir_skip--;
}
continue;
}
write_it = 1;
n = file_info[I_NAMEOFF] & 0x7f;
transname(file_info + I_NAMEOFF + 1, text, n);
if(i == ISFILE) {
transname(file_info + I_TYPEOFF, ftype, 4);
transname(file_info + I_AUTHOFF, fauth, 4);
}
if(list) {
if(i == ISFILE) {
do_indent(indent);
(void)fprintf(stderr,
"name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
text, ftype, fauth, (long)data_size, (long)rsrc_size);
} else if(i == ISDIR) {
do_indent(indent);
dir_ptr += 64;
if(dir_ptr == dir_max) {
if(dir_max == 0) {
dir_stack = malloc(64);
} else {
dir_stack = realloc(dir_stack, (unsigned)dir_max + 64);
}
dir_max += 64;
if(dir_stack == NULL) {
(void)fprintf(stderr, "Insufficient memory\n");
exit(1);
}
}
for(j = 0; j <= n; j++) {
dir_stack[dir_ptr + j] = text[j];
}
(void)fprintf(stderr, "folder=\"%s\"", text);
indent++;
} else {
indent--;
do_indent(indent);
(void)fprintf(stderr, "leaving folder \"%s\"",
dir_stack + dir_ptr);
dir_ptr -= 64;
}
if(info_only) {
write_it = 0;
}
if(query) {
if(i != ENDDIR) {
write_it = do_query();
} else {
(void)fputc('\n', stderr);
}
if(!write_it && i == ISDIR) {
dir_skip = 1;
indent--;
dir_ptr -= 64;
}
} else {
(void)fputc('\n', stderr);
}
}
if(write_it) {
if(i == ISFILE) {
dofile();
}
}
}
exit(0);
/* NOTREACHED */
}
static void usage()
{
(void)fprintf(stderr, "Usage: binhex [-%s] [files]\n", options);
(void)fprintf(stderr, "Use \"binhex -H\" for help.\n");
}
|