home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / dirgt.c < prev    next >
Text File  |  1985-10-29  |  4KB  |  113 lines

  1. /***********************************************************************/
  2.    DIRGT.C
  3.    by Thomas E. Link for the LATTICE COMPILER
  4.    11-25-84
  5. /***********************************************************************/
  6.  
  7.  
  8. #include "stdio.h"
  9.  
  10. #define  FALSE     0
  11. #define  TRUE      1
  12.  
  13. struct  dirrect {
  14.     char           fname[12];
  15.     unsigned int   ftime;
  16.     unsigned int   fdate;
  17.     long           flen;
  18. } dir_rec[112];
  19. char    lookst[41];
  20. char    volst[14];
  21. char    ds[9],ts[9];
  22. int     count,m;
  23. long    total;
  24.  
  25. /*     this was the PASCAL definition of the external procedure:
  26. procedure DIRGET(var looks:lookst; var dir_rec:dirrect;
  27.                  var vols:volst; var count:word);extern;
  28. */
  29.  
  30.  
  31. main( argc, argv )
  32. int     argc;
  33. char    **argv;
  34. {
  35.         if (argc == 1){         /* no arguments on command line */
  36.             printf(" Input file specifier : ");
  37.             getnc(40,lookst);   /* get max 40 characters */
  38.         }
  39.         else                    /* Copy command line argument   */
  40.             strcpy(lookst,argv[1]);
  41.         volst[0] = '*';         /* initialize volume string     */
  42.         total = 0;              /*        and total bytes       */
  43.         dirget(&count,volst,&dir_rec[0],lookst);  /* external call */
  44.                                 /* if volst has changed there's a label*/
  45.         if (volst[0]!='*') printf(" The diskette is labeled %s\n",volst);
  46.         putchar('\n');          /* newline in any case          */
  47.                                 /* go through list and print entries   */
  48.         for(m = 0 ; m < count ; ++m ){
  49.                 printnme(dir_rec[m].fname);     /* print 12 chars      */
  50.                 getdate(dir_rec[m].fdate,ds);   /* convert int to date */
  51.                 gettime(dir_rec[m].ftime,ts);   /* convert int to time */
  52.                 printf("  %6ld  %s  %s\n",dir_rec[m].flen,ds,ts);
  53.                 total += dir_rec[m].flen;       /* get running total   */
  54.         };
  55.         printf("\n  %ld bytes used in %d files.\n",total,count);
  56. }
  57.  
  58. getdate(sysnumber,pstring)
  59. unsigned int sysnumber;
  60. char *pstring;
  61. {
  62.         int     day,month,year;
  63.         day    = (sysnumber & 31);      /* day is bottom 5 bits        */
  64.         month  = (sysnumber >> 5) & 15; /* month is middle 4 bits      */
  65.         year   = (sysnumber >> 9) + 80; /* year is top 7 bits          */
  66.         pstring[0] = (char)((month / 10) + '0');
  67.         pstring[1] = (char)((month % 10) + '0');
  68.         pstring[2] = '/';
  69.         pstring[3] = (char)((day / 10) + '0');
  70.         pstring[4] = (char)((day % 10) + '0');
  71.         pstring[5] = '/';
  72.         pstring[6] = (char)((year / 10) + '0');
  73.         pstring[7] = (char)((year % 10) + '0');
  74.         pstring[8] = '\0';
  75. }
  76.  
  77. gettime(sysnumber,pstring)
  78. unsigned int sysnumber;
  79. char *pstring;
  80. {
  81.         int     hour,minute,second;
  82.         second  = (sysnumber & 31) * 2; /* second/2 is bottom 5 bits   */
  83.         minute  = (sysnumber >> 5) & 63;/* minute is middle 6 bits     */
  84.         hour    = (sysnumber >> 11);    /* hour is top 5 bits          */
  85.         pstring[0] = (char)((hour / 10) + '0');
  86.         pstring[1] = (char)((hour % 10) + '0');
  87.         pstring[2] = ':';
  88.         pstring[3] = (char)((minute / 10) + '0');
  89.         pstring[4] = (char)((minute % 10) + '0');
  90.         pstring[5] = ':';
  91.         pstring[6] = (char)((second / 10) + '0');
  92.         pstring[7] = (char)((second % 10) + '0');
  93.         pstring[8] = '\0';
  94. }
  95.  
  96.  
  97. printnme(pstring)
  98. char    *pstring;               /* print 12 characters in name         */
  99. {
  100.         int     m;
  101.         for(m=0 ; m<=11 ; putchar(pstring[m++]));
  102. }
  103.  
  104.  
  105. getnc(lent,istring)
  106. int     lent;                   /* get maximum LENT characters and put */
  107. char    *istring;               /*     into istring                    */
  108. {
  109.         int     m;
  110.         for(m=0; (m<=lent) && ((istring[m]=getchar())!='\n'); m++);
  111.         istring[m]='\0';
  112. }
  113.