9 extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
16 if (memcmp(h->method, "-lhd-", sizeof(h->method)) == 0) {
18 if (mkdir(h->filename, 0777) == -1) {
20 error("cannot make directory \"%s\"", opts.outdir);
25 if (file_exists(h->filename)) {
26 if (!opts.force_extract) {
27 message("'%s' has been already exist. skip", h->filename);
32 while ((outfile = fopen(h->filename, "wb")) == NULL) {
33 fprintf(stderr, "Can't open %s\nNew filename: ", h->filename);
34 if (get_line(h->filename, sizeof(h->filename)) == 0) {
35 fprintf(stderr, "Not extracted\n");
39 h->namelen = strlen(h->filename);
43 printf("Extracting %s ", h->filename);
48 printf("===== %s =====\n", h->filename);
51 opts.method = which_method(h->method);
52 if (opts.method == NULL) {
53 fprintf(stderr, "Unknown method: %.5s\n", h->method);
58 unsigned int slide_off = 0;
60 unsigned long remainder = h->origsize;
63 if (opts.method->dicbit != 0)
65 while (remainder != 0) {
66 uint n = (uint)MIN(remainder, MAXDICSIZ);
67 if (opts.method->dicbit != 0)
68 decode(&huf, rp, n, buf, &slide_off, &slide_len);
71 if (fread(buf, 1, n, rp->fp) != n)
74 fwrite_crc(buf, n, outfile, &crc);
75 if (outfile != stdout && opts.quiet < 1) {
82 if ((crc ^ INIT_CRC) != h->file_crc)
86 fprintf(stdout, "\n");
92 ut.actime = ut.modtime = h->mtime;
93 utime(h->filename, &ut);