home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / FILES202.ZIP / FILES.C next >
C/C++ Source or Header  |  1989-03-23  |  3KB  |  139 lines

  1. /* files.c
  2. **
  3. ** Copyright (c) 1988-89, Christopher Laforet
  4. ** All Rights Reserved
  5. **
  6. ** The Programmer's Oasis
  7. ** (919) 226-6957
  8. ** 9600HST,2400,1200,300-N-8-1
  9. **
  10. ** (v1.xx) for Turbo-C
  11. ** (v2.xx) for OS/2 - CML 2-89
  12. **
  13. */
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <os2.h>
  20. #include "files.h"
  21.  
  22.  
  23.  
  24. unsigned short total_files = 0;
  25. unsigned long total_bytes = 0L;
  26. int verbose_flag = 0;
  27. int directory_flag = 0;
  28. int current_flag = 0;
  29. int modified_flag = 0;
  30. int sort_flag = 1;
  31. int pattern_flag = 0;
  32.  
  33.  
  34. main(argc,argv)
  35. int argc;
  36. char *argv[];
  37.     {
  38.     short count;
  39.     unsigned char pattern[20];
  40.     unsigned char start[100];
  41.     unsigned short drive;
  42.     unsigned long drivemap;
  43.  
  44.     fprintf(stdout,"FILES (v %u.%02u of %s): A File/Directory Listing Utility\n",MAJOR_VERSION,MINOR_VERSION,__DATE__);
  45.     fprintf(stdout,"Copyright (c) 1988-89, Christopher Laforet.  All Rights Reserved.\n");
  46.     fprintf(stdout,"Released into the Public Domain 1988.\n\n");
  47.     strcpy(pattern,"*.*");
  48.     strcpy(start,"");
  49.     if (argc > 1)
  50.         {
  51.         for (count = 1; count < argc; count++)
  52.             {
  53.             if (*argv[count] == '+')
  54.                 {
  55.                 switch (argv[count][1])
  56.                     {
  57.                     case 'd':
  58.                         ++directory_flag;
  59.                         break;
  60.                     case 'c':
  61.                         ++current_flag;
  62.                         break;
  63.                     case 'v':
  64.                         ++verbose_flag;
  65.                         break;
  66.                     default:
  67.                         fprintf(stderr,"Unknown option +%c\n",argv[count][1]);
  68.                         break;
  69.                     }
  70.                 }
  71.             else if (*argv[count] == '-')
  72.                 {
  73.                 switch (argv[count][1])
  74.                     {
  75.                     case 's':
  76.                         sort_flag = 0;
  77.                         break;
  78.                     case 'h':
  79.                     case '?':
  80.                         usage();
  81.                         break;
  82.                     default:
  83.                         fprintf(stderr,"Unknown option -%c\n",argv[count][1]);
  84.                         break;
  85.                     }
  86.                 }
  87.             else if (!(strncmp(argv[count],"p=",2)))
  88.                 {
  89.                 strcpy(pattern,&argv[count][2]);
  90.                 ++pattern_flag;
  91.                 }
  92.             else if (*argv[count] == '?')
  93.                 {
  94.                 usage();
  95.                 }
  96.             else if (count == 1)
  97.                 {
  98.                 strcpy(start,argv[1]);
  99.                 if ((strlen(start) == 1) && (start[0] == '\\'))
  100.                     {
  101.                     if (!DosQCurDisk(&drive,&drivemap))
  102.                         {
  103.                         sprintf(start,"%c:",'A' + (drive - 1));
  104.                         }
  105.                     }
  106.                 else if (start[strlen(start) - 1] == '\\')
  107.                     {
  108.                     start[strlen(start) - 1] = 0;
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.     if (verbose_flag)
  114.         {
  115.         fprintf(stdout,"Attrib  FileSize  Date         Time   Name\n\n");
  116.         }
  117.     else
  118.         {
  119.         fprintf(stdout,"FileSize  Date         Time   Name\n\n");
  120.         }
  121.     getfile(start,pattern);
  122.     fprintf(stdout,"\nTotal Files Found: %u\nTotal Bytes in Files: %lu\nTotal Free Space on Disk: %lu\n\n",total_files,total_bytes,get_disk_space(start));
  123.     return(0);
  124.     }
  125.  
  126.  
  127.  
  128. void usage()
  129.     {
  130.     fprintf(stdout,"Usage is: files [start-directory] [options]\n");
  131.     fprintf(stdout,"   where \"options\" are:\n");
  132.     fprintf(stdout,"\t+c - current directory only\n");
  133.     fprintf(stdout,"\t+d - list directories only\n");
  134.     fprintf(stdout,"\t-s - do not sort listings\n");
  135.     fprintf(stdout,"\t+v - verbose listing (include attributes)\n");
  136.     fprintf(stdout,"\t p=pattern where pattern can include * and ?\n\n");
  137.     exit(1);
  138.     }
  139.