home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / ZOOEXT.C < prev    next >
C/C++ Source or Header  |  1991-07-11  |  23KB  |  659 lines

  1. #ifndef LINT
  2. /* derived from: zooext.c 2.21 88/08/24 02:39:04 */
  3. /*$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $*/
  4. /*$Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $*/
  5. static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $\n\
  6. $Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $";
  7. #endif /* LINT */
  8.  
  9. /*
  10. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  11. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  12. (C) Copyright 1991 Rahul Dhesi -- All rights reserved
  13. */
  14. /* Extract file from archive.  Extracts files specified in parameter-list
  15.    from archive zoo_path.  If none specified, extracts all files from
  16.    archive. */
  17.  
  18. #include "options.h"
  19. #include "zoo.h"
  20. #include "parse.h"      /* defines struct for parse() */
  21.  
  22. #include "portable.h"   /* portable I/O definitions */
  23. #include "machine.h"    /* machine-specific declarations */
  24.  
  25. #include "zooio.h"
  26. #include "various.h"
  27.  
  28. #ifndef NOSIGNAL
  29. #include <signal.h>
  30. #endif
  31.  
  32. #include "zoofns.h"
  33.  
  34. #ifdef MODE_BIN        /* will need fileno() from stdio.h */
  35. # include <stdio.h>
  36. #endif
  37.  
  38. void makepath PARMS((char *));
  39. int needed PARMS((char *, struct direntry *, struct zoo_header *));
  40. void putstr PARMS((char *));
  41.  
  42. #ifdef FATTR
  43. int setfattr PARMS ((char *, unsigned long));
  44. #endif /* FATTR */
  45.  
  46. extern int quiet;
  47.  
  48. #include "errors.i"
  49.  
  50. /* Following two are used by ctrl_c() also, hence declared here */
  51. char extfname[LFNAMESIZE];             /* filename of extracted file */
  52. char prtfname[LFNAMESIZE];             /* name of extracted file on screen */
  53. static ZOOFILE this_file;              /* file to extract */
  54.  
  55. static int tofile;                     /* true if not pipe or null device */
  56. extern unsigned int crccode;
  57. extern char *out_buf_adr;              /* address of output buffer */
  58.  
  59. void zooext(zoo_path, option)
  60. char *zoo_path, *option;
  61. {
  62. char *whichname;                          /* which name to extract */
  63. char matchname[PATHSIZE];                 /* for pattern matching only */
  64. #ifndef NOSIGNAL
  65. T_SIGNAL (*oldsignal)();        /* to save previous SIGINT handler */
  66. #endif
  67. ZOOFILE zoo_file;                         /* open archive */
  68. long next_ptr;                            /* pointer to within archive */
  69. struct zoo_header zoo_header;             /* header for archive */
  70. int status;                               /* error status */
  71. int exit_status = 0;                                /* exit status */
  72. int error_message;                                /* Whether to give error message */
  73. unsigned long disk_space;                 /* disk space left */
  74. int matched = 0;                          /* Any files matched? */
  75. int overwrite = 0;                        /* force overwrite of files? */
  76. int supersede = 0;                                /* supersede newer files? */
  77. int needdel = 0;                          /* extract deleted files too */
  78. int usepath = 2;                          /* use path for extraction */
  79. int todot = 0;                            /* extract relative to . */
  80. int badcrc_count = 0;                     /* how many files with bad CRC */
  81. int bad_header = 0;                       /* to avoid spurious messages later */
  82. long fiz_ofs = 0;                         /* offset where to start */
  83. long dat_ofs = 0;                                    /* .. and offset of file data */
  84. int pipe = 0;                             /* are we piping output? */
  85. int null_device = 0;                      /* are we sending to null device? */
  86. #ifndef PORTABLE
  87. int fast_ext = 0;                         /* fast extract as *.?Z? */
  88. int alloc_size;                           /* disk allocation unit size */
  89. #endif
  90. struct direntry direntry;                 /* directory entry */
  91. int first_dir = 1;                                /* first dir entry seen? */
  92.  
  93. static char extract_ver[] = "Zoo %d.%d is needed to extract %s.\n";
  94. static char no_space[] = "Insufficient disk space to extract %s.\n";
  95.  
  96. while (*option) {
  97.    switch (*option) {
  98. #ifndef PORTABLE
  99.       case 'z': fast_ext++; break;
  100. #endif
  101.       case 'x':
  102.       case 'e': break;
  103.       case 'N': null_device++; break;
  104.       case 'O': overwrite += 2; break;
  105.       case 'o': overwrite++; break;
  106.       case 'p': pipe++; break;
  107.         case 'S': supersede++; break;
  108.       case 'd': needdel++; break;
  109.       case 'q': quiet++; break;
  110.         case ':': usepath = 0; break;
  111.       case '/': usepath++; break;
  112.       case '.': todot++; break;
  113.       case '@':     /* if @m,n specified, fiz_ofs = m, dat_ofs = n */
  114.             {
  115.                 char *comma_pos;
  116.                 ++option;
  117.                 comma_pos = strchr(option, ',');
  118.                 if (comma_pos != NULL) {
  119.                     dat_ofs = calc_ofs (comma_pos + 1);
  120.                     *comma_pos = '\0';
  121.                 }
  122.                 fiz_ofs = calc_ofs(option);
  123.                 goto no_more;
  124.             }
  125.       default:
  126.          prterror ('f', inv_option, *option);
  127.          /* break; */
  128.    }
  129.    option++;
  130. }
  131.  
  132. no_more: /* come from exit in while loop above */
  133.  
  134.  
  135. if (overwrite == 1)                 /* must be at least 2 to begin with */
  136.    overwrite--;
  137.  
  138. if (null_device && pipe) {
  139.    prterror ('f', inv_option, 'p');
  140.    pipe = 0;
  141. }
  142.  
  143. if (overwrite && pipe)
  144.    prterror ('w', option_ignored, 'O');
  145.  
  146. #ifndef PORTABLE
  147. if (null_device && fast_ext) {
  148.    prterror ('w', inv_option, 'N');
  149.    null_device = 0;
  150. }
  151. #endif
  152.  
  153. tofile = !pipe && !null_device;     /* sending to actual file */
  154.  
  155. zoo_file = zooopen(zoo_path, Z_READ);
  156.  
  157. if (zoo_file == NOFILE)
  158.    prterror ('f', could_not_open, zoo_path);
  159.  
  160. if (fiz_ofs != 0L) {                /* if offset specified, start there */
  161.     prterror ('m', start_ofs, fiz_ofs, dat_ofs);
  162.    zooseek (zoo_file, fiz_ofs, 0);
  163. } else {
  164.    /* read header */
  165.    frd_zooh (&zoo_header, zoo_file);
  166.    if ((zoo_header.zoo_start + zoo_header.zoo_minus) != 0L) {
  167.       prterror ('w', failed_consistency);
  168.       bad_header++;
  169.         exit_status = 1;
  170.    }
  171.    zooseek (zoo_file, zoo_header.zoo_start, 0); /* seek to where data begins */
  172. }
  173.  
  174. #ifndef PORTABLE
  175. disk_space = space (0, &alloc_size);         /* remember disk space left */
  176. #else
  177. disk_space = MAXLONG;              /* infinite disk space */
  178. #endif
  179.  
  180. /* if piping output we open the output device just once */
  181. if (null_device) {
  182.    this_file = NULLFILE;
  183. } else if (pipe)
  184.    this_file = STDOUT;    /* standard output */
  185.  
  186. while (1) {
  187.    frd_dir (&direntry, zoo_file);
  188.    if (direntry.zoo_tag != ZOO_TAG) {
  189.       long currpos, zoolength;
  190.         prterror ('F', invalid_header);
  191.  
  192.         /* Note:  if header was bad, there's no point trying to find
  193.             how many more bytes aren't processed -- our seek position is
  194.             likely very wrong */
  195.  
  196.         if (!bad_header)
  197.             if ((currpos = zootell (zoo_file)) != -1L)
  198.                 if (zooseek (zoo_file, 0L, 2) != -1)
  199.                     if ((zoolength = zootell (zoo_file)) != -1L)
  200.                         printf (cant_process, zoolength - currpos);
  201.         zooexit (1);
  202.    }
  203.    if (direntry.next == 0L) {                /* END OF CHAIN */
  204.       break;                                 /* EXIT on end of chain */
  205.    }
  206.     /* when first direntry read, change dat_ofs from abs. pos. to rel. offset */
  207.     if (first_dir && dat_ofs != 0) {
  208.         dat_ofs -= direntry.offset;
  209.         first_dir = 0;
  210.     }
  211.    next_ptr = direntry.next + dat_ofs;       /* ptr to next dir entry */
  212.  
  213.    whichname = choosefname(&direntry);       /* which filename */
  214.     whichname = str_dup(whichname);                /* bug fix */
  215.    fixfname(whichname);                      /* fix syntax */
  216.     strcpy (matchname, fullpath (&direntry));    /* get full pathname */
  217.     if (zoo_header.vdata & VFL_ON)
  218.         add_version (matchname, &direntry);        /* add version suffix */
  219.  
  220. /* if extraction to subtree rooted at curr dir, modify pathname */
  221. #if 0
  222. #ifdef DIR_LBRACK
  223.    if (todot && direntry.dirname[0] == *DIR_LBRACK &&
  224.                 direntry.dirname[1] != *CUR_DIR)      {
  225.       char tmpstr[PATHSIZE];
  226.       strcpy (tmpstr, DIR_LBRACK);
  227.       strcat (tmpstr, CUR_DIR);
  228.       strcat (tmpstr, &direntry.dirname[1]);
  229.       strcpy (direntry.dirname, tmpstr);
  230.    }
  231. #endif
  232. #endif
  233.  
  234.    /* hard-coded '/' should be eventually removed */
  235.    if (todot && *direntry.dirname == '/') {
  236.       char tmpstr[PATHSIZE];
  237.       strcpy(tmpstr, direntry.dirname);
  238.       strcpy(direntry.dirname,CUR_DIR);
  239.       strcat(direntry.dirname, tmpstr);
  240.    }
  241.  
  242.    /* matchname now holds the full pathname for pattern matching */
  243.  
  244.    if ( ( (needdel && direntry.deleted) ||
  245.             (needdel < 2 && !direntry.deleted)
  246.         ) && needed(matchname, &direntry, &zoo_header)) {
  247.       matched++;           /* update count of files extracted */
  248.  
  249.       if (direntry.major_ver > MAJOR_LZH_VER ||
  250.          (direntry.major_ver == MAJOR_LZH_VER &&
  251.             direntry.minor_ver > MINOR_LZH_VER)) {
  252.             prterror ('e', extract_ver, direntry.major_ver,
  253.                            direntry.minor_ver, whichname);
  254.                 exit_status = 1;
  255.             goto loop_again;
  256.       }
  257.  
  258.       /*
  259.       If extracting to null device, or if user requested extraction
  260.       of entire path, include any directory name in filename.
  261.       If extraction to current directory requested, and if extfname
  262.       begins with path separator, fix it */
  263.  
  264.       strcpy (extfname, whichname);
  265.       if ((usepath || null_device) && direntry.dirlen != 0) {
  266.          combine(extfname, direntry.dirname, whichname);
  267.          if (usepath > 1 && !null_device)
  268.             makepath(direntry.dirname);         /* make dir prefix */
  269.       }
  270.  
  271.         strcpy(prtfname, extfname);
  272.         if (zoo_header.vdata & VFL_ON)
  273.             add_version (prtfname, &direntry);
  274.  
  275.       if (tofile) {
  276.          int present = 0;
  277.  
  278. #ifndef PORTABLE
  279.          /*
  280.          if Z format (fast) extraction, extension is created as
  281.          follows:  for no current extension, new extension is "zzz";
  282.          for current extension "a", new extension is "azz";  for
  283.          current extension "ab", new extension is "azb";  and for
  284.          current extension "abc", new extension is "azc".
  285.          */
  286.  
  287.          if (fast_ext) {
  288.             int length;
  289.             struct path_st path_st;
  290.             parse (&path_st, extfname);         /* split filename */
  291.             strcpy (extfname, path_st.fname);   /* just root filename */
  292.             length = strlen (path_st.ext);
  293.             strcat (extfname, ".");
  294.             if (length == 0)
  295.                strcat (extfname, "zzz");        /* no ext -> .zzz */
  296.             else if (length == 1) {
  297.                strcat (extfname, path_st.ext);
  298.                strcat (extfname, "zz");         /* *.?    -> *.?zz */
  299.             } else { /* length is 2 or 3 */
  300.                if (length == 2)                 /* allow .aa, .ab, etc. */
  301.                   path_st.ext[2] = path_st.ext[1];
  302.                path_st.ext[1] = 'z';
  303.                strcat (extfname, path_st.ext);  /* *.??   -> *.?z? */
  304.             }
  305.                 strcpy(prtfname, direntry.fname);
  306.                 add_version (prtfname, &direntry);
  307.          }
  308. #endif   /* ifndef PORTABLE */
  309.  
  310.             /* don't extract if archived file is older than disk copy */
  311.             if (!supersede && exists(extfname)) {
  312.                 unsigned int ddate, dtime;
  313. #ifdef GETUTIME
  314.                 getutime (extfname, &ddate, &dtime);
  315. #else
  316.                 ZOOFILE tfile;
  317.                 ddate = dtime = 0xffff;                    /* assume maximum */
  318.                 tfile = zooopen(extfname, Z_READ);
  319.                 if (tfile == NOFILE)
  320.                     goto loop_again;
  321.                 gettime (tfile, &ddate, &dtime);
  322.                 zooclose (tfile);
  323. #endif
  324.                 if (cmpnum (direntry.date, direntry.time, ddate, dtime) <= 0) {
  325.                     prterror ('m', "%-14s -- skipped\n", prtfname);
  326.                     goto loop_again;
  327.                 }
  328.             }
  329.  
  330.          if (overwrite) {
  331.             this_file = zoocreate (extfname);
  332. #ifdef FATTR
  333.                 /* if can't open file, and OO option, make it writable first */
  334.                 if (this_file == NOFILE && overwrite >= 4 &&
  335.                         (direntry.fattr >> 22) == 1 && exists(extfname)) {
  336.                     setfattr (extfname, (unsigned long) (1L << 7) | direntry.fattr);
  337.                     this_file = zoocreate (extfname);
  338.                 }
  339. #endif /* FATTR */
  340.          } else {
  341.             if (exists (extfname)) {
  342.                present = 1;
  343.                this_file = NOFILE;
  344.             } else
  345.                this_file = zoocreate (extfname);
  346.          }
  347.             error_message = 1;
  348.          if (this_file == NOFILE) {
  349.             if (present == 1) {      /* if file exists already */
  350.                     char ans[20];          /* answer to "Overwrite?" */
  351.                do {
  352. #ifdef EXT_ANYWAY
  353.                   printf ("%s exists; extract anyway? [Yes/No/All] ",
  354.                            extfname);
  355. #else
  356.                   printf ("Overwrite %s (Yes/No/All)? ", extfname);
  357. #endif
  358.                   fflush (stdin);
  359.                   fgets (ans, sizeof(ans), stdin);
  360.                   str_lwr (ans);
  361.                } while (*ans != 'y' && *ans != 'n' && *ans != 'a');
  362.  
  363.                if (*ans == 'a')
  364.                   overwrite++;
  365.                if (*ans == 'y' || *ans == 'a') {
  366.                   this_file = zoocreate(extfname);
  367.                   error_message = 1; /* give error message if open fails */
  368.                } else {
  369.                   error_message = 0; /* user said 'n', so no error message */
  370.                }
  371.             } else {
  372.                error_message = 1;   /* Real error -- give error message */
  373.             }
  374.          } /* end if */
  375.       } /* end if */
  376.  
  377.       if (this_file == NOFILE) {         /* file couldn't be opened */
  378.          if (error_message == 1) {
  379.             prterror ('e', "Can't open %s for output.\n", extfname);
  380.                 exit_status = 1;
  381.  
  382. #ifndef PORTABLE
  383.             /* if error was due to full disk, abort */
  384.             if (space(0, &alloc_size) < alloc_size)
  385.                prterror ('f', disk_full);
  386. #endif
  387.  
  388.          }
  389.       } else if (zooseek (zoo_file, (direntry.offset + dat_ofs), 0) == -1L) {
  390.          prterror ('e', "Could not seek to file data.\n");
  391.             exit_status = 1;
  392.          close_file (this_file);
  393.       } else {
  394. #ifndef PORTABLE
  395.          /* check msdos's free disk space if we seem to be running low
  396.             (within 1 cluster of being full) */
  397.          if (tofile && disk_space < direntry.org_size + alloc_size) {
  398.             disk_space = space (0, &alloc_size);
  399.             if (disk_space < alloc_size) {
  400.                close_file (this_file);
  401.                unlink (extfname);
  402.                prterror ('f', disk_full);
  403.             }
  404.          }
  405. #endif
  406.          if (tofile && disk_space < direntry.org_size) {
  407. #ifdef PORTABLE
  408.             ;
  409. #else
  410.                 prterror ('e', no_space, prtfname);
  411.             unlink (extfname);               /* delete any created file */
  412. #endif   /* portable */
  413.  
  414.          } else {
  415.  
  416. #ifndef PORTABLE
  417.             if (fast_ext) {            /* fast ext -> create header */
  418.                void make_tnh PARMS((struct tiny_header *, struct direntry *));
  419.                struct tiny_header tiny_header;
  420.                make_tnh(&tiny_header, &direntry);
  421.                zoowrite (this_file, (char *) &tiny_header, sizeof(tiny_header));
  422.  
  423.                if (direntry.cmt_size != 0) { /* copy comment */
  424.                   long save_pos;
  425.                   save_pos = zootell (zoo_file);
  426.                   zooseek (zoo_file, direntry.comment, 0);
  427.                   getfile (zoo_file, this_file,
  428.                           (long) direntry.cmt_size, 0);
  429.                   zooseek (zoo_file, save_pos, 0);
  430.                }
  431.             }
  432. #endif /* ifndef PORTABLE */
  433.  
  434.             crccode = 0;      /* Initialize CRC before extraction */
  435.                if (!pipe) {
  436. #ifdef PORTABLE
  437.                   prterror ('m', "%-14s -- ", prtfname);
  438. #else
  439.                   if (fast_ext)
  440.                      prterror ('m', "%-12s ==> %-12s -- ",
  441.                         prtfname,  extfname);
  442.                   else
  443.                      prterror ('m', "%-12s -- ", prtfname);
  444. #endif /* PORTABLE */
  445.  
  446.                } else {            /* must be pipe */
  447.                   prterror ('M',"\n\n********\n%s\n********\n",prtfname);
  448.  
  449. #ifdef SETMODE
  450.                   MODE_BIN(this_file);           /* make std output binary so
  451.                                                    ^Z won't cause error */
  452. #endif
  453.                }
  454. #ifndef NOSIGNAL
  455.             if (tofile)
  456.                {
  457.                   oldsignal = signal (SIGINT, SIG_IGN);
  458.                   if (oldsignal != SIG_IGN)
  459.                      signal (SIGINT, ctrl_c); /* Trap ^C & erase partial file */
  460.                }
  461. #endif /* not NOSIGNAL */
  462.  
  463.             if (direntry.packing_method == 0)
  464.                /* 4th param 1 means CRC update */
  465.                status = getfile (zoo_file, this_file, direntry.size_now, 1);
  466.  
  467. #ifndef PORTABLE
  468.             else if (fast_ext)
  469.                /* 4th param 0 means no CRC update */
  470.                status = getfile (zoo_file, this_file, direntry.size_now, 0);
  471. #endif
  472.  
  473.             else if (direntry.packing_method == 1) {
  474. #ifdef UNBUF_IO
  475. #include "ERROR"
  476.                     /* NOT PORTABLE -- DO NOT TRY THIS AT HOME */
  477.                     long lseek PARMS ((int, long, int));
  478.                     long tell PARMS ((int));
  479.                     int this_fd, zoo_fd;
  480.  
  481.                     /* get file descriptors */
  482.                     this_fd = null_device ? -2 : fileno (this_file);
  483.                     zoo_fd = fileno (zoo_file);
  484.  
  485.                     zooseek (zoo_file, zootell (zoo_file), 0);    /* synch */
  486.                     lseek (zoo_fd, zootell (zoo_file), 0);            /* ..again */
  487.                     if (!null_device) {
  488.                         zooseek (this_file, zootell (this_file), 0);    /* synch */
  489.                         lseek (this_fd, zootell (this_file), 0);        /* ..again */
  490.                     }
  491.                   status = lzd(zoo_fd, this_fd);            /* uncompress */
  492.                     zooseek (zoo_file, tell (zoo_fd), 0);    /* resynch    */
  493.                     if (!null_device)
  494.                         zooseek (this_file, tell (this_fd), 0);/* resynch    */
  495. #else
  496.                status = lzd (zoo_file, this_file);     /* uncompress */
  497. #endif
  498.                 } else if (direntry.packing_method == 2) {
  499.                status = lzh_decode (zoo_file, this_file);
  500.             } else {
  501.                prterror ('e', "File %s:  impossible packing method.\n",
  502.                   whichname);
  503.                   unlink(extfname);
  504.                   goto loop_again;
  505.             }
  506.  
  507.  
  508. #ifndef NOSIGNAL
  509.             if (tofile)
  510.                signal (SIGINT, oldsignal);
  511. #endif /* not NOSIGNAL */
  512.  
  513. #ifdef SETMODE
  514.             if (pipe)
  515.                MODE_TEXT(this_file);          /* restore text mode */
  516. #endif
  517.  
  518.             if (tofile) {
  519.                /* set date/time of file being extracted */
  520. #ifdef GETTZ
  521.                     void tzadj();
  522.                     /* adjust for original timezone */
  523.                     tzadj (&direntry);
  524. #endif
  525. #ifdef NIXTIME
  526.                close_file (this_file);
  527.                setutime (extfname, direntry.date, direntry.time);
  528. #else
  529.                settime (this_file, direntry.date, direntry.time);
  530.                close_file (this_file);
  531. #endif
  532. #ifdef FATTR
  533. /* Restore file attributes. Bit 23==1 means system-specific; we currently
  534. don't recognize this.  Bit 23==0 means use portable format, in which case
  535. bit 22==0 means ignore attributes.  Thus attributes are ignored if both
  536. bits 23 and 22 are zero, which is the effect of a zero-filled file
  537. attribute field.  Currently we restore file attributes if and only if
  538. bit 23==0 and bit 22==1. */
  539.  
  540.                     if ((direntry.fattr >> 22) == 1) {
  541.                         setfattr (extfname, direntry.fattr);
  542.                     }
  543. #endif /* FATTR */
  544.             } /* end of if (tofile) ... */
  545.             if (status != 0) {
  546.                     exit_status = 1;
  547.                if (tofile)
  548.                   unlink (extfname);
  549.                if (status == 2) {    /* was 1 (wrong) */
  550.                   memerr(0);
  551.                /* To avoid spurious errors due to ^Z being sent to screen,
  552.                   we don't check for I/O error if output was piped */
  553.                } else if (!pipe && (status == 2 || status == 3)) {
  554.                      prterror ('e', no_space, prtfname);
  555.                }
  556.             } else {
  557.                /* file extracted, so update disk space.  */
  558.                /* we subtract the original size of the file, rounded
  559.                   UP to the nearest multiple of the disk allocation
  560.                   size. */
  561. #ifndef PORTABLE
  562.                {
  563.                   unsigned long temp;
  564.                   temp = (direntry.org_size + alloc_size) / alloc_size;
  565.                   disk_space -= temp * alloc_size;
  566.                }
  567. #endif
  568.  
  569.                if (
  570. #ifndef PORTABLE
  571.                           !fast_ext &&
  572. #endif
  573.                             direntry.file_crc != crccode
  574.                         ) {
  575.                   badcrc_count++;
  576.                         exit_status = 1;
  577.                   if (!pipe) {
  578.                      if (!null_device)
  579.                         prterror ('M', "extracted   ");
  580.                      prterror ('w', bad_crc, prtfname);
  581.                   }
  582.                   else {   /* duplicate to standard error */
  583.                      static char stars[] = "\n******\n";
  584.                      putstr (stars);
  585.                      prterror ('w', bad_crc, prtfname);
  586.                      putstr (stars);
  587.                      fprintf (stderr, "WARNING:  ");
  588.                      fprintf (stderr, bad_crc, prtfname);
  589.                   }
  590.                } else
  591.                   if (!pipe)
  592.                      prterror ('M', null_device ? "OK\n" : "extracted\n");
  593.  
  594.             } /* end if */
  595.          } /* end if */
  596.       } /* end if */
  597.    } /* end if */
  598.  
  599. loop_again:
  600.    zooseek (zoo_file, next_ptr, 0); /* ..seek to next dir entry */
  601. } /* end while */
  602.  
  603. close_file (zoo_file);
  604. if (!matched)
  605.    putstr (no_match);
  606.  
  607. if (badcrc_count) {
  608.    prterror ('w', "%d File(s) with bad CRC.\n", badcrc_count);
  609. } else if (null_device)
  610.    prterror ('m', "Archive seems OK.\n");
  611.  
  612. zooexit (exit_status);
  613.  
  614. } /* end zooext */
  615.  
  616. /* close_file() */
  617. /* closes a file if and only if we aren't sending output to
  618.    a pipe or to the null device */
  619.  
  620. void close_file (file)
  621. ZOOFILE file;
  622. {
  623.    if (tofile)
  624.       zooclose (file);
  625. }
  626.  
  627. /* Ctrl_c() is called if ^C is hit while a file is being extracted.
  628.    It closes the files, deletes it, and exits. */
  629. T_SIGNAL ctrl_c()
  630. {
  631. #ifndef NOSIGNAL
  632.    signal (SIGINT, SIG_IGN);     /* ignore any more */
  633. #endif
  634.    zooclose (this_file);
  635.    unlink (extfname);
  636.    zooexit (1);
  637. }
  638.  
  639. #ifndef PORTABLE
  640. /* make_tnh copies creates a tiny_header */
  641. void make_tnh (tiny_header, direntry)
  642. struct tiny_header *tiny_header;
  643. struct direntry *direntry;
  644. {
  645.    tiny_header->tinytag = TINYTAG;
  646.    tiny_header->type = 1;
  647.    tiny_header->packing_method = direntry->packing_method;
  648.    tiny_header->date = direntry->date;
  649.    tiny_header->time = direntry->time;
  650.    tiny_header->file_crc = direntry->file_crc;
  651.    tiny_header->org_size = direntry->org_size;
  652.    tiny_header->size_now = direntry->size_now;
  653.    tiny_header->major_ver = direntry->major_ver;
  654.    tiny_header->minor_ver = direntry->minor_ver;
  655.    tiny_header->cmt_size = direntry->cmt_size;
  656.    strcpy (tiny_header->fname, direntry->fname);
  657. }
  658. #endif /* ifndef PORTABLE */
  659.