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
|
#include "hexbin.h"
#ifdef DL
#include "globals.h"
#include "crc.h"
#include "readline.h"
#include "../fileio/machdr.h"
#include "../fileio/wrfile.h"
#include "../util/util.h"
#include "buffer.h"
#include "printhdr.h"
extern void exit();
static long dl_fork();
static int nchar();
static int nextc();
static char *icp = &line[0];
/* oldest format -- process .dl files */
void dl(macname, filename)
char *macname, *filename;
{
int n;
if(listmode) {
(void)fprintf(stderr, "This file is in \"dl\" format.\n");
}
for(n = 0; n < INFOBYTES; n++) {
info[n] = 0;
}
/* set up for Mac name */
if(macname[0] == '\0') {
/* strip directories */
macname = search_last(filename, '/');
if(macname == NULL) {
macname = filename;
} else {
macname++;
}
/* strip extension */
n = strlen(macname);
if(n > 3) {
n -= 3;
if(!strncmp(macname + n, ".dl", 3)) {
macname[n] = '\0';
}
}
}
n = strlen(macname);
if(n > F_NAMELEN) {
n = F_NAMELEN;
}
(void)strncpy(mh.m_name, macname, n);
(void)strncpy(mh.m_type, "APPL", 4);
(void)strncpy(mh.m_author, "????", 4);
mh.m_name[n] = '\0';
transname(mh.m_name, trname, n);
define_name(trname);
print_header0(0);
print_header1(0, 0);
set_put(1);
mh.m_datalen = 0;
set_put(0);
mh.m_rsrclen = dl_fork();
info[I_NAMEOFF] = n;
(void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
(void)strncpy(info + I_TYPEOFF, mh.m_type, 4);
(void)strncpy(info + I_AUTHOFF, mh.m_author, 4);
put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
print_header2(0);
end_put();
}
static long dl_fork()
{
register unsigned long i, v, c;
register unsigned long n, bytes;
n = 0;
bytes = 0;
v = 0;
crc = 0;
while((i = nchar()) != '|') {
if(i < '@' || i > 'O') {
continue;
}
v = (v << 4) | (i & 0xF);
if((++n & 1) == 0) {
put_byte((char)v);
crc += v;
v = 0;
bytes++;
}
}
c = 0;
for(i = 0 ; i < 8 ; i++) {
c = (c << 4) | (nchar() & 0xF);
}
verify_crc(bytes + crc, c);
return bytes;
}
static int nchar()
{
int i;
if((i = nextc()) == EOF) {
(void)fprintf(stderr, "Premature EOF\n");
#ifdef SCAN
do_error("hexbin: Premature EOF");
#endif /* SCAN */
exit(1);
}
return i & 0177;
}
static int nextc()
{
while(*icp == 0) {
if(readline() == 0) {
return EOF;
}
icp = &line[0];
}
return *icp++;
}
#else /* DL */
int dl; /* keep lint and some compilers happy */
#endif /* DL */
|