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

  1. #include "stdio.h"
  2. #include <search.h>
  3. #include <string.h>
  4.  
  5. #define  FALSE     0
  6. #define  TRUE      1
  7.  
  8. int compare();
  9.  
  10. struct  dirrect {
  11.     char           fname[12];
  12.     unsigned int   ftime;
  13.     unsigned int   fdate;
  14.     long           flen;
  15. } dir_rec[112];
  16. char    lookst[41];
  17. char    volst[14];
  18. char    ds[9],ts[9];
  19. int     count,m;
  20. long    total;
  21.  
  22. /*     this was the PASCAL definition of the external procedure:
  23. procedure DIRGET(var looks:lookst; var dir_rec:dirrect;
  24.                  var vols:volst; var count:word);extern;
  25. */
  26.  
  27.  
  28. main( argc, argv )
  29. int     argc;
  30. char    **argv;
  31. {
  32.         if (argc == 1){         /* no arguments on command line */
  33.             printf(" Input file specifier : ");
  34.             getnc(40,lookst);   /* get max 40 characters */
  35.         }
  36.         else                    /* Copy command line argument   */
  37.             strcpy(lookst,argv[1]);
  38.         volst[0] = '*';         /* initialize volume string     */
  39.         total = 0;              /*        and total bytes       */
  40.         dirget(&count,volst,&dir_rec[0],lookst);  /* external call */
  41.                                 /* if volst has changed there's a label*/
  42.         if (volst[0]!='*') printf(" The diskette is labeled %s\n",volst);
  43.         putchar('\n');          /* newline in any case          */
  44.                                 /* go through list and print entries   */
  45.  
  46.         qsort(dir_rec, count, sizeof(struct dirrect), compare);
  47.  
  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.  
  114. int compare(arg1, arg2)
  115. struct dirrect *arg1, *arg2;
  116. {
  117.  
  118.    return strcmp((*arg1).fname, (*arg2).fname);
  119.  
  120. }
  121.