home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / OLS / Os2 / LHA2P205 / LHA2P205.LZH / lha2-2.05pre / source.lzh / src / list.c < prev    next >
C/C++ Source or Header  |  1995-10-15  |  3KB  |  148 lines

  1. /*
  2.  * list.c --- list files in archive
  3.  *   Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
  4.  *   Copyright (C) 1991-1995, Satoshi HIRAMATSU (OS/2 HPFS version)
  5.  *
  6.  * $Log$
  7.  */
  8.  
  9.  
  10. #include <sys/types.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include "typedef.h"
  15. #include "port2.h"
  16. #include "lh.h"
  17. #include "header.h"
  18.  
  19.  
  20. static int filecount;
  21. static long originalsize, packedsize;
  22.  
  23.  
  24. void
  25. initlist(void)
  26. {
  27.   filecount = originalsize = packedsize = 0;
  28.   if(flg_n == 0)
  29.     {
  30.       printf("  Name          Original    Packed  Ratio"
  31.          "   Date     Time   Attr Type  CRC\n");
  32.       printf("--------------  --------  -------- ------"
  33.          " -------- -------- ---- ----- ----\n");
  34.     }
  35. }
  36.  
  37.  
  38. static void
  39. expanddate(char *buf, time_t t, ulong org, ulong pac)
  40. {
  41.   struct tm *tm;
  42.   int rt;
  43.  
  44.   tm = localtime(&t);
  45.   rt = ratio(pac, org, 3);
  46.   sprintf(buf + 14, "%10lu%10lu %3d.%1d%% "
  47.       "%02d-%02d-%02d %02d:%02d:%02d",
  48.       org, pac, rt / 10, rt % 10,
  49.       tm -> tm_year % 100,
  50.       tm -> tm_mon + 1,
  51.       tm -> tm_mday,
  52.       tm -> tm_hour,
  53.       tm -> tm_min,
  54.       tm -> tm_sec);
  55. }
  56.  
  57.  
  58. void
  59. list(void)
  60. {
  61.   char buf[79], *p, *q;
  62.   static char attr[7] = "ohs--a";
  63.   int i, j, k;
  64.   static char __directory__[7] = " <DIR>";
  65.  
  66.   p = hpb.filename;
  67.   q = hpb.pathname;
  68.   if(flg_n == 0)
  69.     {
  70.       memset(buf, ' ', 14);
  71.       expanddate(buf, hpb.mtime, hpb.original, hpb.packed);
  72.       sprintf(buf + 59, " ---w       %04X", hpb.filecrc);
  73.       memcpy(&buf[65], hpb.method, 5);
  74.       for(i = 0, j = 1; i < 6; i++, j <<= 1) /* attributes */
  75.     if(hpb.attr & (uint)j)
  76.       {
  77.         k = attr[i];
  78.         if(i <= 2)
  79.           buf[63 - i] = k;
  80.         else
  81.           buf[60] = k;
  82.       }
  83.  
  84.       if(hpb.level < 0)
  85.     memset(&buf[71], '*', 4); /* if no CRC suppoted */
  86.  
  87.       if(flg_x)
  88.     puts(q);        /* display in 2 lines */
  89.       else
  90.     {
  91.       if(p != q)        /* display in one line */
  92.         *buf = '+';
  93.  
  94.       if(hpb.namelen)
  95.         {
  96.           if(hpb.namelen <= 12)
  97.           memcpy(&buf[2], p, hpb.namelen);
  98.           else
  99.         {
  100.           memcpy(&buf[2], p, 12); /* HFPS long filename */
  101.           if(*buf == '+')
  102.             *buf = '*';
  103.           else
  104.             *buf = '=';
  105.         }
  106.         }
  107.       else
  108.         {
  109.           /* for UNIX version LHA directory archives.  */
  110.           if(*(hpb.pathname + hpb.pathlen - 1) == DELIM)
  111.         memcpy(&buf[2], __directory__, strlen(__directory__));
  112.         }
  113.     }
  114.       puts(buf);
  115.       filecount ++;
  116.       originalsize += hpb.original;
  117.       packedsize += hpb.packed;
  118.     }
  119.   else
  120.     {
  121.       if(flg_x)
  122.     puts(q);
  123.       else
  124.     puts(p);
  125.     }
  126. }
  127.  
  128.  
  129. void
  130. endlist(time_t arctime)
  131. {
  132.   char buf[79];
  133.  
  134.   if(flg_n == 0)
  135.     {
  136.       if(filecount)
  137.     {
  138.       printf("--------------  --------  -------- ------"
  139.          " -------- --------\n");
  140.       sprintf(buf, "   %3d files  ", filecount);
  141.       expanddate(buf, arctime, originalsize, packedsize);
  142.       puts(buf);
  143.     }
  144.       else
  145.     printf("  no file\n");
  146.     }
  147. }
  148.