home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 December
/
VPR9712A.ISO
/
OLS
/
OS2
/
LHA2P205
/
LHA2P205.LZH
/
lha2-2.05pre
/
source.lzh
/
src
/
lzh2c.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-15
|
2KB
|
107 lines
/*
* lzh2c.c --- archive file to C code transelator
* Copyright (C) 1988-1992, Haruyasu YOSHIZAKI (lzh2asm.c)
* Copyright (C) 1991-1995, Satoshi HIRAMATSU
*
* $Log$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "typedef.h"
struct hdr
{
uchar size;
uchar sum;
uchar method[6];
ulong packed;
ulong original;
ulong time;
ushort attr;
uchar fnlen;
uchar fname[256];
ushort crc;
uchar *ext;
} header;
FILE *f0, *f1;
char title[] = "char NAM_X[] = {\n";
char foot[] = "\n};\n";
int
main(int argc, char *argv[])
{
int i, c, d;
char *p;
f0 = fopen(argv[1], "rb");
if(f0 == NULL)
exit(1);
f1 = fopen(argv[2], "w");
if(f1 == NULL)
exit(1);
fread(&header, 1, 2, f0);
fread(header.method, 1, 5, f0);
fread(&header.packed, 4, 1, f0);
fread(&header.original, 4, 1, f0);
fread(&header.time, 4, 1, f0);
fread(&header.attr, 2, 1, f0);
fread(&header.fnlen, 1, 1, f0);
fread(header.fname, 1, header.fnlen, f0);
fread(&header.crc, 2, 1, f0);
header.ext = (uchar *) malloc(i = header.size - (header.fnlen + 22));
fread(header.ext, 1, i, f0);
free(header.ext);
header.method[5] = '\0';
#ifdef DEBUG
printf("\n=== LZH header info. =================\n");
printf(" header size is %10u byte(s).\n",header.size);
printf(" compression method is \"%s\".\n",header.method);
printf(" packed size is %10lu byte(s).\n", header.packed);
printf(" original size is %10lu byte(s).\n", header.original);
printf(" crc is %10xH.\n", header.crc, header.crc);
printf("======================================\n\n");
#endif
do
{
p = strstr(title, "NAM_X");
if(p)
strncpy(p, argv[1], 5);
}
while(p);
fprintf(f1, "%s", title);
fprintf(f1,
"\t0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
header.packed & 0xff, (header.packed >> 8) & 0xff,
(header.packed >> 16) & 0xff, (header.packed >> 24) & 0xff,
header.original & 0xff, (header.original >> 8) & 0xff,
(header.original >> 16) & 0xff, (header.original >> 24) & 0xff);
d = getc(f0);
for(i = 0; (c = getc(f0)) != EOF; ++i)
{
if(i == 8)
{
fprintf(f1, ",\n\t");
i = 0;
}
else
{
fputc(',', f1);
fputc(' ', f1);
}
fprintf(f1, "0x%02x", d);
d = c;
}
fprintf(f1, "%s", foot);
fclose(f1);
return 0;
}