home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / star / list.c < prev    next >
C/C++ Source or Header  |  2001-04-07  |  6KB  |  277 lines

  1. /* @(#)list.c    1.30 01/04/07 Copyright 1985, 1995 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)list.c    1.30 01/04/07 Copyright 1985, 1995 J. Schilling";
  5. #endif
  6. /*
  7.  *    List the content of an archive
  8.  *
  9.  *    Copyright (c) 1985, 1995 J. Schilling
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #include <mconfig.h>
  28. #include <stdio.h>
  29. #include "star.h"
  30. #include "table.h"
  31. #include <dirdefs.h>
  32. #include <standard.h>
  33. #include <strdefs.h>
  34. #include <schily.h>
  35. #include "starsubs.h"
  36.  
  37. extern    FILE    *tarf;
  38. extern    FILE    *vpr;
  39. extern    char    *listfile;
  40.  
  41. extern    BOOL    havepat;
  42. extern    BOOL    verbose;
  43. extern    BOOL    tpath;
  44. extern    BOOL    numeric;
  45. extern    BOOL    verbose;
  46. extern    BOOL    cflag;
  47. extern    BOOL    xflag;
  48. extern    BOOL    interactive;
  49.  
  50. extern    BOOL    acctime;
  51. extern    BOOL    Ctime;
  52.  
  53. extern    BOOL    listnew;
  54. extern    BOOL    listnewf;
  55.  
  56. EXPORT    void    list        __PR((void));
  57. LOCAL    void    modstr        __PR((FINFO * info, char* s, Ulong  mode));
  58. EXPORT    void    list_file    __PR((FINFO * info));
  59. EXPORT    void    vprint        __PR((FINFO * info));
  60.  
  61. EXPORT void
  62. list()
  63. {
  64.         FINFO    finfo;
  65.         FINFO    newinfo;
  66.         TCB    tb;
  67.         TCB    newtb;
  68.         char    name[PATH_MAX+1];
  69.         char    newname[PATH_MAX+1];
  70.         char    newlname[PATH_MAX+1];
  71.     register TCB     *ptb = &tb;
  72.  
  73.     fillbytes((char *)&finfo, sizeof(finfo), '\0');
  74.     fillbytes((char *)&newinfo, sizeof(newinfo), '\0');
  75.  
  76.     finfo.f_tcb = ptb;
  77.     for (;;) {
  78.         if (get_tcb(ptb) == EOF)
  79.             break;
  80.         finfo.f_name = name;
  81.         if (tcb_to_info(ptb, &finfo) == EOF)
  82.             return;
  83.         if (listnew || listnewf) {
  84.             /*
  85.              * XXX nsec beachten wenn im Archiv!
  86.              */
  87.             if (finfo.f_mtime > newinfo.f_mtime &&
  88.                     (!listnewf || is_file(&finfo))) {
  89.                 movebytes(&finfo, &newinfo, sizeof(finfo));
  90.                 movebytes(&tb, &newtb, sizeof(tb));
  91.                 /*
  92.                  * Paranoia.....
  93.                  */
  94.                 strncpy(newname, name, PATH_MAX);
  95.                 newname[PATH_MAX] = '\0';
  96.                 newinfo.f_name = newname;
  97.                 if (newinfo.f_lname[0] != '\0') {
  98.                     /*
  99.                      * Paranoia.....
  100.                      */
  101.                     strncpy(newlname, newinfo.f_lname,
  102.                                 PATH_MAX);
  103.                     newlname[PATH_MAX] = '\0';
  104.                     newinfo.f_lname = newlname;
  105.                 }
  106.                 newinfo.f_flags |= F_HAS_NAME;
  107.             }
  108.         } else if (listfile) {
  109.             if (hash_lookup(finfo.f_name))
  110.                 list_file(&finfo);
  111.         } else if (!havepat || match(finfo.f_name))
  112.             list_file(&finfo);
  113.  
  114.         void_file(&finfo);
  115.     }
  116.     if ((listnew || listnewf) && newinfo.f_mtime != 0L) {
  117.         /* XXX
  118.          * XXX Achtung!!! tcb_to_info zerst÷rt t_name[NAMSIZ]
  119.          * XXX und t_linkname[NAMSIZ].
  120.          */
  121.         tcb_to_info(&newtb, &newinfo);
  122.         list_file(&newinfo);
  123.     }
  124. }
  125.  
  126. #ifdef    OLD
  127. static char *typetab[] = 
  128. {"S","-","l","d","","","","", };
  129. #endif
  130.  
  131. LOCAL void
  132. modstr(info, s, mode)
  133.         FINFO    *info;
  134.          char    *s;
  135.     register Ulong    mode;
  136. {
  137.     register char    *mstr = "xwrxwrxwr";
  138.     register char    *str = s;
  139.     register int    i;
  140.  
  141.     for (i=9; --i >= 0;) {
  142.         if (mode & (1 << i))
  143.             *str++ = mstr[i];
  144.         else
  145.             *str++ = '-';
  146.     }
  147.     *str = '\0';
  148.     str = s;
  149.     if (mode & 01000) {
  150.         if (mode & 01)
  151.             str[8] = 't';
  152.         else
  153.             str[8] = 'T';
  154.     }
  155.     if (mode & 02000) {
  156.         if (mode & 010) {
  157.             str[5] = 's';
  158.         } else {
  159.             if (is_dir(info))
  160.                 str[5] = 'S';
  161.             else
  162.                 str[5] = 'l';
  163.         }
  164.     }
  165.     if (mode & 04000) {
  166.         if (mode & 0100)
  167.             str[2] = 's';
  168.         else
  169.             str[2] = 'S';
  170.     }
  171. }
  172.  
  173. EXPORT void
  174. list_file(info)
  175.     register FINFO    *info;
  176. {
  177.         FILE    *f;
  178.         time_t    *tp;
  179.         char    *tstr;
  180.         char    mstr[10];
  181.     static    char    nuid[11];
  182.     static    char    ngid[11];
  183.  
  184.     f = vpr;
  185.     if (verbose) {
  186. /*        tp = (time_t *) (acctime ? &info->f_atime :*/
  187. /*                (Ctime ? &info->f_ctime : &info->f_mtime));*/
  188.         tp = acctime ? &info->f_atime :
  189.                 (Ctime ? &info->f_ctime : &info->f_mtime);
  190.         tstr = ctime(tp);
  191.         if (numeric || info->f_uname == NULL) {
  192.             sprintf(nuid, "%lu", info->f_uid);
  193.             info->f_uname = nuid;
  194.             info->f_umaxlen = sizeof(nuid)-1;
  195.         }
  196.         if (numeric || info->f_gname == NULL) {
  197.             sprintf(ngid, "%lu", info->f_gid);
  198.             info->f_gname = ngid;
  199.             info->f_gmaxlen = sizeof(ngid)-1;
  200.         }
  201.  
  202.         if (is_special(info))
  203.             fprintf(f, "%3lu %3lu",
  204.                 info->f_rdevmaj, info->f_rdevmin);
  205.         else
  206.             fprintf(f, "%7lu", info->f_size);
  207.         modstr(info, mstr, info->f_mode);
  208.  
  209. /*
  210.  * XXX ▄bergangsweise, bis die neue Filetypenomenklatur sauber eingebaut ist.
  211.  */
  212. if (info->f_xftype == 0) {
  213.     info->f_xftype = IFTOXT(info->f_type);
  214.     errmsgno(EX_BAD, "XXXXX xftype == 0\n");
  215. }
  216.         fprintf(f,
  217.             " %s%s %3.*s/%-3.*s %.12s %4.4s ",
  218. #ifdef    OLD
  219.             typetab[info->f_filetype & 07],
  220. #else
  221.             XTTOSTR(info->f_xftype),
  222. #endif
  223.             mstr,
  224.             (int)info->f_umaxlen, info->f_uname,
  225.             (int)info->f_gmaxlen, info->f_gname,
  226.             &tstr[4], &tstr[20]);
  227.     }
  228.     fprintf(f, "%s", info->f_name);
  229.     if(tpath) {
  230.         fprintf(f, "\n");
  231.         return;
  232.     }
  233.     if (is_link(info))
  234.         fprintf(f, " link to %s", info->f_lname);
  235.     if (is_symlink(info))
  236.         fprintf(f, " -> %s", info->f_lname);
  237.     if (is_volhdr(info))
  238.         fprintf(f, " --Volume Header--");
  239.     if (is_multivol(info))
  240.         fprintf(f, " --Continued at byte %ld--", info->f_offset);
  241.     fprintf(f, "\n");
  242. }
  243.  
  244. EXPORT void
  245. vprint(info)
  246.     FINFO    *info;
  247. {
  248.         FILE    *f;
  249.     char    *mode;
  250.  
  251.     if (verbose || interactive) {
  252.         f = vpr;
  253.  
  254.         if (cflag)
  255.             mode = "a ";
  256.         else if (xflag)
  257.             mode = "x ";
  258.         else
  259.             mode = "";
  260.         if (is_dir(info)) {
  261.             fprintf(f, "%s%s directory\n", mode, info->f_name);
  262.         } else if (is_link(info)) {
  263.             fprintf(f, "%s%s link to %s\n",
  264.                 mode, info->f_name, info->f_lname);
  265.         } else if (is_symlink(info)) {
  266.             fprintf(f, "%s%s symbolic link to %s\n",
  267.                 mode, info->f_name, info->f_lname);
  268.         } else if (is_special(info)) {
  269.             fprintf(f, "%s%s special\n", mode, info->f_name);
  270.         } else {
  271.             fprintf(f, "%s%s %ld bytes, %ld tape blocks\n",
  272.                 mode, info->f_name, info->f_size,
  273.                 tarblocks(info->f_rsize));
  274.         }
  275.     }
  276. }
  277.