}
static int
+read_header_lv0(FILE *fp, char *buf, struct lzh_header *h)
+{
+ int headersize;
+ int headersum;
+ int ext_headersize;
+
+ headersize = get_byte(&buf[0]);
+ headersum = get_byte(&buf[1]);
+
+ fread_crc(buf + 21, headersize - (21 - 2), fp); /* CRC not used */
+
+ buf += 2;
+
+ if (calc_headersum(buf, headersize) != headersum)
+ error("Header sum error");
+
+ get_char(&buf[0], h->method, 5);
+ h->compsize = get_dword(&buf[5]);
+ h->origsize = get_dword(&buf[9]);
+ h->ftime = get_dword(&buf[13]);
+ /* attrib = get_byte(&buf[17]); */
+ h->level = get_byte(&buf[18]); /* header level */
+ h->namelen = get_byte(&buf[19]);
+ get_char(&buf[20], h->filename, h->namelen);
+ h->filename[h->namelen] = 0;
+ h->file_crc = get_word(&buf[20+h->namelen]);
+ h->os_id = 0; /* generic */
+
+ return 1; /* success */
+}
+
+static int
read_header_lv1(FILE *fp, char *buf, struct lzh_header *h)
{
int headersize;
fread_crc(buf + 1, 21 - 1, fp);
switch (buf[20]) {
case 0:
+ return read_header_lv0(fp, buf, h);
break;
case 1:
return read_header_lv1(fp, buf, h);
void
write_header_lv0(FILE *fp, struct lzh_header *h)
{
+ char buf[4096], *p = buf;
+ int sum;
+ int headersize;
+
+ headersize = 22 + h->namelen;
+
+ put_byte(&buf[0], 0); /* dummy */
+ put_byte(&buf[1], 0); /* dummy */
+ put_char(&buf[2], h->method, 5);
+ put_dword(&buf[7], h->compsize); /* packed size */
+ put_dword(&buf[11], h->origsize); /* original size */
+ put_dword(&buf[15], h->ftime); /* ftime */
+ put_byte(&buf[19], 0x20); /* attribute */
+ put_byte(&buf[20], 0); /* level */
+ put_byte(&buf[21], h->namelen); /* length of pathname */
+ put_char(&buf[22], h->filename, h->namelen);
+ put_word(&buf[22+h->namelen], h->file_crc);
+
+ headersize += 0; /* size of ext-header (old style) */
+ put_byte(&buf[0], headersize);
+
+ sum = calc_headersum(buf+2, headersize);
+ put_byte(&buf[1], sum);
+
+ fwrite_crc(buf, headersize+2, fp);
}
void
headersize = 25 + h->namelen;
put_byte(&buf[0], headersize);
- put_byte(&buf[1], 0); /* dummy */
+ put_byte(&buf[1], 0); /* dummy */
put_char(&buf[2], h->method, 5);
- put_dword(&buf[7], h->compsize); /* packed size */
+ put_dword(&buf[7], h->compsize); /* packed size */
put_dword(&buf[11], h->origsize); /* original size */
- put_dword(&buf[15], h->ftime); /* ftime */
- put_byte(&buf[19], 0x20); /* attribute */
- put_byte(&buf[20], 1); /* level */
- put_byte(&buf[21], h->namelen); /* length of pathname */
+ put_dword(&buf[15], h->ftime); /* ftime */
+ put_byte(&buf[19], 0x20); /* attribute */
+ put_byte(&buf[20], 1); /* level */
+ put_byte(&buf[21], h->namelen); /* length of pathname */
put_char(&buf[22], h->filename, h->namelen);
put_word(&buf[22+h->namelen], h->file_crc);
put_byte(&buf[22+h->namelen+2], 'M');
list_start(void)
{
if (opts.quiet < 2)
- printf("Filename Original Compressed Ratio CRC Method\n");
+ printf("Filename Original Compressed Ratio CRC Method Lv\n");
}
static void
if (h->namelen > 14)
printf("\n ");
r = ratio(h->compsize, h->origsize);
- printf(" %10lu %10lu %u.%03u %04X %5.5s\n",
- h->origsize, h->compsize, r / 1000, r % 1000, h->file_crc, h->method);
+ printf(" %10lu %10lu %u.%03u %04X %5.5s [%d]\n",
+ h->origsize,
+ h->compsize,
+ r / 1000,
+ r % 1000,
+ h->file_crc,
+ h->method,
+ h->level);
}
static int