home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / compress / zoosrc20.zoo / zooext.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  22KB  |  657 lines

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