home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / list.c < prev    next >
C/C++ Source or Header  |  1992-10-31  |  21KB  |  831 lines

  1. /*****************************************************************************
  2.  * $Id: list.c,v 1.10 1992/10/31 06:54:55 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: list.c,v $
  5.  * Revision 1.10  1992/10/31  06:54:55  ak
  6.  * Modified -G (again) to specify the generation of increment.
  7.  *
  8.  * Revision 1.9  1992/10/25  10:20:28  ak
  9.  * Don't archive/extract ctime+atime if a single -p or --same-perm is
  10.  * specified. It make trouble on incremental backups and file transfers.
  11.  * Added an option --all-timestamps or twice -p to archive/extract
  12.  * ctime+atime.
  13.  *
  14.  * Revision 1.8  1992/09/29  09:55:47  ak
  15.  * K.U.R., once again :-)
  16.  * - removed a dup() in buffer.c
  17.  * - EMX opendir with hidden/system test in gnu.c (...dotdot)
  18.  *
  19.  * Revision 1.7  1992/09/26  08:32:05  ak
  20.  * *** empty log message ***
  21.  *
  22.  * Revision 1.6  1992/09/21  08:06:07  ak
  23.  * K.U.R.'s fix for --checkpoints
  24.  *
  25.  * Revision 1.5  1992/09/20  07:47:03  ak
  26.  * Fixes from Kai Uwe Rommel
  27.  *   --checkpoints instead of --semi-verbose (1.11)
  28.  *   -g filenames
  29.  *
  30.  * Revision 1.4  1992/09/12  15:57:33  ak
  31.  * - Usenet patches for GNU TAR 1.10
  32.  * - Bugfixes and patches of Kai Uwe Rommel:
  33.  *         filename conversion for FAT
  34.  *         EMX 0.8e
  35.  *         -0..1 alias for a: b:
  36.  *         -2..7 alias for +++TAPE$x
  37.  *
  38.  * Revision 1.3  1992/09/09  14:25:51  ak
  39.  * K.U.R: save atime/mtime when -p is given
  40.  *
  41.  * Revision 1.2  1992/09/02  20:08:13  ak
  42.  * Version AK200
  43.  * - Tape access
  44.  * - Quick file access
  45.  * - OS/2 extended attributes
  46.  * - Some OS/2 fixes
  47.  * - Some fixes of Kai Uwe Rommel
  48.  *
  49.  * Revision 1.1.1.1  1992/09/02  19:21:51  ak
  50.  * Original GNU Tar 1.10 with some filenames changed for FAT compatibility.
  51.  *
  52.  * Revision 1.1  1992/09/02  19:21:49  ak
  53.  * Initial revision
  54.  *
  55.  *****************************************************************************/
  56.  
  57. static char *rcsid = "$Id: list.c,v 1.10 1992/10/31 06:54:55 ak Exp $";
  58.  
  59. /*
  60.  * Modified by Andreas Kaiser July 92.
  61.  * See CHANGES.AK for info.
  62.  */
  63.  
  64. /* List a tar archive.
  65.    Copyright (C) 1988 Free Software Foundation
  66.  
  67. This file is part of GNU Tar.
  68.  
  69. GNU Tar is free software; you can redistribute it and/or modify
  70. it under the terms of the GNU General Public License as published by
  71. the Free Software Foundation; either version 1, or (at your option)
  72. any later version.
  73.  
  74. GNU Tar is distributed in the hope that it will be useful,
  75. but WITHOUT ANY WARRANTY; without even the implied warranty of
  76. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  77. GNU General Public License for more details.
  78.  
  79. You should have received a copy of the GNU General Public License
  80. along with GNU Tar; see the file COPYING.  If not, write to
  81. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  82.  
  83. /*
  84.  * List a tar archive.
  85.  *
  86.  * Also includes support routines for reading a tar archive.
  87.  *
  88.  * this version written 26 Aug 1985 by John Gilmore (ihnp4!hoptoad!gnu).
  89.  *
  90.  * @(#)list.c 1.31 11/5/87 - gnu
  91.  */
  92. #include <stdio.h>
  93. #include <string.h>
  94. #include <ctype.h>
  95. #include <sys/types.h>
  96. #include <sys/stat.h>
  97. #ifndef    MSDOS
  98. #include <sys/file.h>
  99. #endif    /* MSDOS */
  100.  
  101. #ifdef USG
  102. #include <sys/sysmacros.h>    /* major() and minor() defined here */
  103. #endif
  104.  
  105. char *ctime();                /* From libc.a */
  106.  
  107. #define    isodigit(c)    ( ((c) >= '0') && ((c) <= '7') )
  108.  
  109. #include "tar.h"
  110. #include "port.h"
  111.  
  112. extern FILE *msg_file;
  113.  
  114. long from_oct();            /* Decode octal number */
  115. void demode();                /* Print file mode */
  116.  
  117. union record *head;            /* Points to current archive header */
  118. struct stat hstat;            /* Stat struct corresponding */
  119. int head_standard;            /* Tape header is in ANSI format */
  120.  
  121. void print_header();
  122. void skip_file();
  123. void skip_extended_headers();
  124.  
  125. extern char *quote_copy_string();
  126.  
  127.  
  128. /*
  129.  * Main loop for reading an archive.
  130.  */
  131. void
  132. read_and(do_something)
  133.     void (*do_something)();
  134. {
  135.     int status = 3;            /* Initial status at start of archive */
  136.     int prev_status;
  137.     extern time_t new_time;
  138.     char save_linkflag;
  139.     
  140.     name_gather();            /* Gather all the names */
  141.     open_archive(1);        /* Open for reading */
  142.  
  143.     for(;;) {
  144.         prev_status = status;
  145.         status = read_header();
  146.         switch (status) {
  147.  
  148.         case 1:            /* Valid header */
  149.             /* We should decode next field (mode) first... */
  150.             /* Ensure incoming names are null terminated. */
  151.             head->header.name[NAMSIZ-1] = '\0';
  152.  
  153.             if (   !name_match(head->header.name)
  154.                  || (f_new_files && hstat.st_mtime<new_time)
  155.                  || (f_exclude && check_exclude(head->header.name))) {
  156.  
  157.                 int isextended = 0;
  158.  
  159.                 if(   head->header.linkflag==LF_VOLHDR
  160.                     || head->header.linkflag==LF_MULTIVOL
  161.                    || head->header.linkflag==LF_NAMES) {
  162.                     (*do_something)();
  163.                     continue;
  164.                 }
  165.  
  166.                                 /* If we're showing verbose non-progress
  167.                                    reports, print the name.  */
  168.                                 if (f_show_omitted_dirs
  169.                                     && head->header.linkflag == LF_DIR)
  170.                                   printf ("Omitting %s\n", head->header.name);
  171.  
  172.                 /* Skip past it in the archive */
  173.                 if (head->header.isextended)
  174.                     isextended = 1;
  175.                 save_linkflag = head->header.linkflag;
  176.                 userec(head);
  177.                 if (isextended) {
  178. /*                    register union record *exhdr;
  179.  
  180.                     for (;;) {
  181.                         exhdr = findrec();
  182.                         if (!exhdr->ext_hdr.isextended) {
  183.                             userec(exhdr);
  184.                             break;
  185.                         }
  186.                     }
  187.                     userec(exhdr);*/
  188.                     skip_extended_headers();
  189.                 }
  190.                 /* Skip to the next header on the archive */
  191.                 if(save_linkflag != LF_DIR)
  192.                     skip_file((long)hstat.st_size);
  193.                 continue;
  194.  
  195.             }
  196.  
  197.             (*do_something)();
  198.             continue;
  199.  
  200.             /*
  201.              * If the previous header was good, tell them
  202.              * that we are skipping bad ones.
  203.              */
  204.         case 0:            /* Invalid header */
  205.             userec(head);
  206.             switch (prev_status) {
  207.             case 3:        /* Error on first record */
  208.                 msg("Hmm, this doesn't look like a tar archive.");
  209.                 /* FALL THRU */
  210.             case 2:        /* Error after record of zeroes */
  211.             case 1:        /* Error after header rec */
  212.                 msg("Skipping to next file header...");
  213.             case 0:        /* Error after error */
  214.                 break;
  215.             }
  216.             continue;
  217.  
  218.         case 2:            /* Record of zeroes */
  219.             userec(head);
  220.             status = prev_status;    /* If error after 0's */
  221.             if (f_ignorez)    
  222.                 continue;
  223.             /* FALL THRU */
  224.         case EOF:        /* End of archive */
  225.             break;
  226.         }
  227.         break;
  228.     };
  229.  
  230.     close_archive();
  231.     names_notfound();        /* Print names not found */
  232. }        
  233.  
  234.  
  235. /*
  236.  * Print a header record, based on tar options.
  237.  */
  238. void
  239. list_archive()
  240. {
  241.     extern char *save_name;
  242.     int    isextended = 0; /* Flag to remember if head is extended */
  243.     
  244.     /* Save the record */
  245.     saverec(&head);
  246.  
  247.     /* Print the header record */
  248.     if (f_verbose) {
  249.         if (f_verbose > 1 || f_map_file)
  250.             decode_header(head, &hstat, &head_standard, 0);
  251.         print_header();
  252.     }
  253.  
  254.     if(f_gnudump && head->header.linkflag==LF_DUMPDIR) {
  255.         size_t    size, written, check;
  256.         char    *data;
  257.         extern int errno;
  258.         extern long save_totsize;
  259.         extern long save_sizeleft;
  260.  
  261.         userec(head);
  262.         if(f_multivol) {
  263.             save_name = head->header.name;
  264.             save_totsize=hstat.st_size;
  265.         }
  266.         for(size = hstat.st_size;size>0;size-=written) {
  267.             if(f_multivol)
  268.                 save_sizeleft=size;
  269.             data = findrec()->charptr;
  270.             if(data==NULL) {
  271.                 msg("EOF in archive file?");
  272.                 break;
  273.             }
  274.             written = endofrecs()->charptr - data;
  275.             if(written>size)
  276.                 written=size;
  277.             errno=0;
  278.             check=fwrite(data,sizeof(char), written, msg_file);
  279.             userec((union record *)(data+written - 1));
  280.             if(check!=written) {
  281.                 msg_perror("only wrote %ld of %ld bytes to file %s",check, written,head->header.name);
  282.                 skip_file((long)(size)-written);
  283.                 break;
  284.             }
  285.         }
  286.         if(f_multivol)
  287.             save_name = 0;
  288.         saverec((union record **) 0);    /* Unsave it */
  289.         fputc('\n',msg_file);
  290.         fflush(msg_file);
  291.         return;
  292.  
  293.     }
  294.     saverec((union record **) 0);    /* Unsave it */
  295.     /* Check to see if we have an extended header to skip over also */
  296.     if (head->header.isextended) 
  297.         isextended = 1;
  298.         
  299.     /* Skip past the header in the archive */
  300.     userec(head);
  301.  
  302.     /*
  303.       * If we needed to skip any extended headers, do so now, by
  304.       * reading extended headers and skipping past them in the 
  305.      * archive.
  306.      */
  307.     if (isextended) {
  308. /*        register union record *exhdr;
  309.  
  310.         for (;;) {
  311.             exhdr = findrec();
  312.  
  313.             if (!exhdr->ext_hdr.isextended) {
  314.                 userec(exhdr);
  315.                 break;
  316.             }
  317.             userec(exhdr);
  318.         }*/
  319.         skip_extended_headers();
  320.     }
  321.             
  322.     if(f_multivol)
  323.         save_name=head->header.name;
  324.     /* Skip to the next header on the archive */
  325.         
  326.     skip_file((long) hstat.st_size);
  327.         
  328.     if(f_multivol)
  329.         save_name = 0;
  330. }
  331.  
  332.  
  333. /*
  334.  * Read a record that's supposed to be a header record.
  335.  * Return its address in "head", and if it is good, the file's
  336.  * size in hstat.st_size.
  337.  *
  338.  * Return 1 for success, 0 if the checksum is bad, EOF on eof,
  339.  * 2 for a record full of zeros (EOF marker).
  340.  *
  341.  * You must always userec(head) to skip past the header which this
  342.  * routine reads.
  343.  */
  344. int
  345. read_header()
  346. {
  347.     register int    i;
  348.     register long    sum, recsum;
  349.     register char    *p;
  350.     register union record *header;
  351.     long    from_oct();
  352.  
  353.     header = findrec();
  354.     head = header;        /* This is our current header */
  355.     if (NULL == header)
  356.         return EOF;
  357.  
  358.     recsum = from_oct(8,  header->header.chksum);
  359.  
  360.     sum = 0;
  361.     p = header->charptr;
  362.     for (i = sizeof(*header); --i >= 0;) {
  363.         /*
  364.          * We can't use unsigned char here because of old compilers,
  365.          * e.g. V7.
  366.          */
  367.         sum += 0xFF & *p++;
  368.     }
  369.  
  370.     /* Adjust checksum to count the "chksum" field as blanks. */
  371.     for (i = sizeof(header->header.chksum); --i >= 0;)
  372.         sum -= 0xFF & header->header.chksum[i];
  373.     sum += ' '* sizeof header->header.chksum;    
  374.  
  375.     if (sum == recsum) {
  376.         /*
  377.          * Good record.  Decode file size and return.
  378.          */
  379.         if (header->header.linkflag == LF_LINK)
  380.             hstat.st_size = 0;    /* Links 0 size on tape */
  381.         else
  382.             hstat.st_size = from_oct(1+12, header->header.size);
  383.         return 1;
  384.     }
  385.  
  386.     if (sum == 8*' ') {
  387.         /*
  388.          * This is a zeroed record...whole record is 0's except
  389.          * for the 8 blanks we faked for the checksum field.
  390.          */
  391.         return 2;
  392.     }
  393.  
  394.     return 0;
  395. }
  396.  
  397.  
  398. /* 
  399.  * Decode things from a file header record into a "struct stat".
  400.  * Also set "*stdp" to !=0 or ==0 depending whether header record is "Unix
  401.  * Standard" tar format or regular old tar format.
  402.  *
  403.  * read_header() has already decoded the checksum and length, so we don't.
  404.  *
  405.  * If wantug != 0, we want the uid/group info decoded from Unix Standard
  406.  * tapes (for extraction).  If == 0, we are just printing anyway, so save time.
  407.  *
  408.  * decode_header should NOT be called twice for the same record, since the
  409.  * two calls might use different "wantug" values and thus might end up with
  410.  * different uid/gid for the two calls.  If anybody wants the uid/gid they
  411.  * should decode it first, and other callers should decode it without uid/gid
  412.  * before calling a routine, e.g. print_header, that assumes decoded data.
  413.  */
  414. decode_header(header, st, stdp, wantug)
  415.     register union record    *header;
  416.     register struct stat    *st;
  417.     int    *stdp;
  418.     int    wantug;
  419. {
  420.  
  421.     long from_oct();
  422.  
  423.     st->st_mode = from_oct(8,  header->header.mode);
  424.     st->st_mtime = from_oct(1+12, header->header.mtime);
  425. #ifdef OS2
  426.     if(f_gnudump || f_all_timestamps) {
  427. #else
  428.     if(f_gnudump) {
  429. #endif
  430.         st->st_atime = from_oct(1+12, header->header.atime);
  431.         st->st_ctime = from_oct(1+12, header->header.ctime);
  432.     }
  433.     
  434. /*    if (0==strcmp(header->header.magic, TMAGIC)) {        */
  435.     if (0==strncmp(header->header.magic, TMAGIC, 5)) {
  436.         /* Unix Standard tar archive */
  437.         *stdp = 1;
  438.         if (wantug) {
  439. #ifdef NONAMES
  440.             st->st_uid = from_oct(8,  header->header.uid);
  441.             st->st_gid = from_oct(8,  header->header.gid);
  442. #else
  443.             st->st_uid = finduid(header->header.uname);
  444.             st->st_gid = findgid(header->header.gname);
  445. #endif
  446.         }
  447.         switch (header->header.linkflag) {
  448.         case LF_BLK: case LF_CHR:
  449.             st->st_rdev = makedev(from_oct(8, header->header.devmajor),
  450.                        from_oct(8, header->header.devminor));
  451.         }
  452.     } else {
  453.         /* Old fashioned tar archive */
  454.         *stdp = 0;
  455.         st->st_uid = from_oct(8,  header->header.uid);
  456.         st->st_gid = from_oct(8,  header->header.gid);
  457.         st->st_rdev = 0;
  458.     }
  459. }
  460.  
  461.  
  462. /*
  463.  * Quick and dirty octal conversion.
  464.  *
  465.  * Result is -1 if the field is invalid (all blank, or nonoctal).
  466.  */
  467. long
  468. from_oct(digs, where)
  469.     register int    digs;
  470.     register char    *where;
  471. {
  472.     register unsigned long    value;
  473.  
  474.     while (isspace(*where)) {        /* Skip spaces */
  475.         where++;
  476.         if (--digs <= 0)
  477.             return -1;        /* All blank field */
  478.     }
  479.     value = 0;
  480.     while (digs > 0 && isodigit(*where)) {    /* Scan til nonoctal */
  481.         value = (value << 3) | (*where++ - '0');
  482.         --digs;
  483.     }
  484.  
  485.     if (digs > 0 && *where && !isspace(*where))
  486.         return -1;            /* Ended on non-space/nul */
  487.  
  488.     return value;
  489. }
  490.  
  491.  
  492. /* print checkpoint */
  493. void
  494. print_checkpoint()
  495. {
  496.     static char where[FILENAME_MAX];
  497.     char *new = head->header.name;
  498.     char *slash = strrchr(new, '/');
  499.     if (slash && slash[1] && strncmp(where, new, slash - new)) {
  500.         strncpy(where, new, slash - new);
  501.         where[slash - new] = 0;
  502.         msg("Processing %s/", where);
  503.     }
  504. }
  505.  
  506. /*
  507.  * Actually print it.
  508.  *
  509.  * Plain and fancy file header block logging.
  510.  * Non-verbose just prints the name, e.g. for "tar t" or "tar x".
  511.  * This should just contain file names, so it can be fed back into tar
  512.  * with xargs or the "-T" option.  The verbose option can give a bunch
  513.  * of info, one line per file.  I doubt anybody tries to parse its
  514.  * format, or if they do, they shouldn't.  Unix tar is pretty random here
  515.  * anyway.
  516.  *
  517.  * Note that print_header uses the globals <head>, <hstat>, and
  518.  * <head_standard>, which must be set up in advance.  This is not very clean
  519.  * and should be cleaned up.  FIXME.
  520.  */
  521. #define    UGSWIDTH    11        /* min width of User, group, size */
  522. #define    DATEWIDTH    19        /* Last mod date */
  523. static int    ugswidth = UGSWIDTH;    /* Max width encountered so far */
  524.  
  525. void
  526. print_header()
  527. {
  528.     char modes[11];
  529.     char *timestamp;
  530.     char uform[11], gform[11];    /* These hold formatted ints */
  531.     char *user, *group;
  532.     char size[24];        /* Holds a formatted long or maj, min */
  533.     long longie;        /* To make ctime() call portable */
  534.     int    pad;
  535.     char *name;
  536.     extern long baserec;
  537.  
  538.     if(f_sayblock)
  539.         fprintf(msg_file,"rec %10d: ",baserec + (ar_record - ar_block));
  540.     /* annofile(msg_file, (char *)NULL); */
  541.  
  542.     if (f_checkpoints > 0) {
  543.         print_checkpoint();
  544.           return;
  545.     }
  546.  
  547.     if (f_verbose <= 1) {
  548.         /* Just the fax, mam. */
  549.         char *name;
  550.  
  551.         name=quote_copy_string(head->header.name);
  552.         if(name==0)
  553.             name=head->header.name;
  554.         fprintf(msg_file, "%s\n", name);
  555.         if(name!=head->header.name)
  556.             free(name);
  557.     } else {
  558.         /* File type and modes */
  559.         modes[0] = '?';
  560.         switch (head->header.linkflag) {
  561.         case LF_VOLHDR:
  562.             modes[0]='V';
  563.             break;
  564.  
  565.         case LF_MULTIVOL:
  566.             modes[0]='M';
  567.             break;
  568.  
  569.         case LF_NAMES:
  570.             modes[0]='N';
  571.             break;
  572.  
  573.         case LF_SPARSE:
  574.         case LF_NORMAL:
  575.         case LF_OLDNORMAL:
  576.         case LF_LINK:
  577.                 modes[0] = '-'; 
  578.                 if ('/' == head->header.name[strlen(head->header.name)-1])
  579.                     modes[0] = 'd';
  580.                 break;
  581.         case LF_DUMPDIR:modes[0] = 'd'; break;
  582.         case LF_DIR:    modes[0] = 'd'; break;
  583.         case LF_SYMLINK:modes[0] = 'l'; break;
  584.         case LF_BLK:    modes[0] = 'b'; break;
  585.         case LF_CHR:    modes[0] = 'c'; break;
  586.         case LF_FIFO:    modes[0] = 'p'; break;    
  587.         case LF_CONTIG:    modes[0] = 'C'; break;
  588.         case LF_EATTR:    modes[0] = 'A'; break;
  589.         }
  590.  
  591.         demode((unsigned)hstat.st_mode, modes+1);
  592.  
  593.         /* Timestamp */
  594.         longie = hstat.st_mtime;
  595.         timestamp = ctime(&longie);
  596.                 if (timestamp==NULL)
  597.                   timestamp="--- --- -- --:--:-- ----\n";
  598.         if (timestamp) {
  599.             timestamp[16] = '\0';
  600.             timestamp[24] = '\0';
  601.         }
  602.  
  603.         /* User and group names */
  604.         if (*head->header.uname && head_standard) {
  605.             user  = head->header.uname;
  606.         } else {
  607.             user = uform;
  608.             (void)sprintf(uform, "%d", (int)hstat.st_uid);
  609.         }
  610.         if (*head->header.gname && head_standard) {
  611.             group = head->header.gname;
  612.         } else {
  613.             group = gform;
  614.             (void)sprintf(gform, "%d", (int)hstat.st_gid);
  615.         }
  616.  
  617.         /* Format the file size or major/minor device numbers */
  618.         switch (head->header.linkflag) {
  619.         case LF_CHR:
  620.         case LF_BLK:
  621.             (void)sprintf(size, "%d,%d",
  622.                     major(hstat.st_rdev),
  623.                     minor(hstat.st_rdev));
  624.             break;
  625.         case LF_SPARSE:
  626.             (void)sprintf(size, "%ld",
  627.                  from_oct(1+12, head->header.realsize));
  628.             break;
  629.         case LF_EATTR:
  630.             (void)sprintf(size, "%ld", 
  631.                     from_oct(1+12, head->header.size));
  632.             break;
  633.         default:
  634.             (void)sprintf(size, "%ld", (long)hstat.st_size);
  635.         }
  636.  
  637.         /* Figure out padding and print the whole line. */
  638.         pad = strlen(user) + strlen(group) + strlen(size) + 1;
  639.         if (pad > ugswidth) ugswidth = pad;
  640.  
  641.         name = quote_copy_string(head->header.name);
  642.         if(!name)
  643.             name=head->header.name;
  644.         fprintf(msg_file, "%s %s/%s %*s%s %s %s %.*s",
  645.             modes,
  646.             user,
  647.             group,
  648.             ugswidth - pad,
  649.             "",
  650.             size,
  651.             timestamp ? timestamp+4  : "-",
  652.             timestamp ? timestamp+20 : "-",
  653.             sizeof(head->header.name),
  654.             name);
  655.  
  656.         if(name!=head->header.name)
  657.             free(name);
  658.         switch (head->header.linkflag) {
  659.         case LF_SYMLINK:
  660.             name=quote_copy_string(head->header.linkname);
  661.             if(!name)
  662.                 name=head->header.linkname;
  663.             fprintf(msg_file, " -> %s\n", name);
  664.             if(name!=head->header.linkname)
  665.                 free(name);
  666.             break;
  667.  
  668.         case LF_LINK:
  669.             name=quote_copy_string(head->header.linkname);
  670.             if(!name)
  671.                 name=head->header.linkname;
  672.             fprintf(msg_file, " link to %s\n", head->header.linkname);
  673.             if(name!=head->header.linkname)
  674.                 free(name);
  675.             break;
  676.  
  677.         default:
  678.             fprintf(msg_file, " unknown file type '%c'\n",
  679.                 head->header.linkflag);
  680.             break;
  681.  
  682.         case LF_OLDNORMAL:
  683.         case LF_NORMAL:
  684.         case LF_SPARSE:
  685.         case LF_CHR:
  686.         case LF_BLK:
  687.         case LF_DIR:
  688.         case LF_FIFO:
  689.         case LF_CONTIG:
  690.         case LF_DUMPDIR:
  691.             putc('\n', msg_file);
  692.             break;
  693.  
  694.         case LF_VOLHDR:
  695.             fprintf(msg_file, "--Volume Header--\n");
  696.             break;
  697.             
  698.         case LF_MULTIVOL:
  699.             fprintf(msg_file, "--Continued at byte %ld--\n",from_oct(1+12,head->header.offset));
  700.             break;
  701.  
  702.         case LF_NAMES:
  703.             fprintf(msg_file,"--Mangled file names--\n");
  704.             break;
  705.  
  706.         case LF_EATTR:
  707.             fprintf(msg_file, " (EA)\n");
  708.             break;
  709.         }
  710.     }
  711.     fflush(msg_file);
  712. }
  713.  
  714. /*
  715.  * Print a similar line when we make a directory automatically.
  716.  */
  717. void
  718. pr_mkdir(pathname, length, mode)
  719.     char *pathname;
  720.     int length;
  721.     int mode;
  722. {
  723.     char modes[11];
  724.     char *name;
  725.     extern long baserec;
  726.  
  727.     if (f_verbose > 1) {
  728.         /* File type and modes */
  729.         modes[0] = 'd';
  730.         demode((unsigned)mode, modes+1);
  731.  
  732.         if(f_sayblock)
  733.             fprintf(msg_file,"rec %10d: ",baserec + (ar_record - ar_block));
  734.         /* annofile(msg_file, (char *)NULL); */
  735.         name=quote_copy_string(pathname);
  736.         if(!name)
  737.             name=pathname;
  738.         fprintf(msg_file, "%s %*s %.*s\n",
  739.             modes,
  740.             ugswidth+DATEWIDTH,
  741.             "Creating directory:",
  742.             length,
  743.             pathname);
  744.         if(name!=pathname)
  745.             free(name);
  746.     }
  747. }
  748.  
  749.  
  750. /*
  751.  * Skip over <size> bytes of data in records in the archive.
  752.  */
  753. void
  754. skip_file(size)
  755.     register long size;
  756. {
  757.     union record *x;
  758.     extern long save_totsize;
  759.     extern long save_sizeleft;
  760.  
  761.     if(f_multivol) {
  762.         save_totsize=size;
  763.         save_sizeleft=size;
  764.     }
  765.  
  766.     while (size > 0) {
  767.         x = findrec();
  768.         if (x == NULL) {    /* Check it... */
  769.             msg("Unexpected EOF on archive file");
  770.             exit(EX_BADARCH);
  771.         }
  772.         userec(x);
  773.         size -= RECORDSIZE;
  774.         if(f_multivol)
  775.             save_sizeleft-=RECORDSIZE;
  776.     }
  777. }
  778.  
  779. void
  780. skip_extended_headers()
  781. {
  782.     register union record *exhdr;
  783.  
  784.     for (;;) {
  785.         exhdr = findrec();
  786.         if (!exhdr->ext_hdr.isextended) {
  787.             userec(exhdr);
  788.             break;
  789.         }
  790.         userec (exhdr);
  791.     }
  792. }
  793.  
  794. /*
  795.  * Decode the mode string from a stat entry into a 9-char string and a null.
  796.  */
  797. void
  798. demode(mode, string)
  799.     register unsigned mode;
  800.     register char *string;
  801. {
  802.     register unsigned mask;
  803.     register char *rwx = "rwxrwxrwx";
  804.  
  805.     for (mask = 0400; mask != 0; mask >>= 1) {
  806.         if (mode & mask)
  807.             *string++ = *rwx++;
  808.         else {
  809.             *string++ = '-';
  810.             rwx++;
  811.         }
  812.     }
  813.  
  814.     if (mode & S_ISUID)
  815.         if (string[-7] == 'x')
  816.             string[-7] = 's';
  817.         else
  818.             string[-7] = 'S';
  819.     if (mode & S_ISGID)
  820.         if (string[-4] == 'x')
  821.             string[-4] = 's';
  822.         else
  823.             string[-4] = 'S';
  824.     if (mode & S_ISVTX)
  825.         if (string[-1] == 'x')
  826.             string[-1] = 't';
  827.         else
  828.             string[-1] = 'T';
  829.     *string = '\0';
  830. }
  831.