9 extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
15 if (memcmp(h->method, "-lhd-", sizeof(h->method)) == 0) {
17 if (mkdir(h->filename, 0777) == -1) {
19 error("cannot make directory \"%s\"", opts.outdir);
24 if (file_exists(h->filename)) {
25 if (!opts.force_extract) {
26 message("'%s' has been already exist. skip", h->filename);
31 while ((outfile = fopen(h->filename, "wb")) == NULL) {
32 fprintf(stderr, "Can't open %s\nNew filename: ", h->filename);
33 if (get_line(h->filename, sizeof(h->filename)) == 0) {
34 fprintf(stderr, "Not extracted\n");
38 h->namelen = strlen(h->filename);
42 printf("Extracting %s ", h->filename);
47 printf("===== %s =====\n", h->filename);
50 opts.method = which_method(h->method);
51 if (opts.method == NULL) {
52 fprintf(stderr, "Unknown method: %.5s\n", h->method);
57 unsigned int slide_off = 0;
59 unsigned long remainder = h->origsize;
62 if (opts.method->dicbit != 0)
64 while (remainder != 0) {
65 uint n = (uint)MIN(remainder, MAXDICSIZ);
66 if (opts.method->dicbit != 0)
67 decode(rp, n, buf, &slide_off, &slide_len);
70 if (fread(buf, 1, n, rp->fp) != n)
73 fwrite_crc(buf, n, outfile, &crc);
74 if (outfile != stdout && opts.quiet < 1) {
81 if ((crc ^ INIT_CRC) != h->file_crc)
85 fprintf(stdout, "\n");
91 ut.actime = ut.modtime = h->mtime;
92 utime(h->filename, &ut);