home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / spaceuse.arc / SPACEUSE.C next >
Text File  |  1988-08-14  |  3KB  |  112 lines

  1. /* SPACEUSE.C by Erkki Vanninen */
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <dir.h>
  6. #include <string.h>
  7. #include <dos.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10.  
  11. int    hind = 0;
  12. struct    {
  13.     long size;
  14.     char hakem[100];
  15.     } hakem_taulu[200];
  16.  
  17. int    eind = 0;
  18. struct {
  19.     long size;
  20.     char ext[4];
  21.     } ext_taulu[500];
  22.  
  23. long tutki_hakem (char *hakem);
  24. int  vertaa      (long *luku1, long *luku2);
  25.  
  26. main (int argc, char *argv[])
  27. {
  28.     char *paahakem = "C:\\";
  29.     int  i;
  30.  
  31.     if (argc > 1)
  32.         *paahakem = toupper(*argv[1]);
  33.     if (*paahakem < 'A' || *paahakem > 'Z')
  34.             exit(printf("Format : SPACEUSE [d:] [>LPT1:]"));
  35.  
  36.     tutki_hakem(paahakem);
  37.  
  38.     qsort(hakem_taulu, hind, sizeof(*hakem_taulu), vertaa);
  39.     qsort(ext_taulu, eind, sizeof(*ext_taulu), vertaa);
  40.  
  41.     printf("Space used  Directory\n"
  42.            "==========  ===========================================\n");
  43.         for (i = 0; i < hind; i++)
  44.             printf("%9ld   %s\n", hakem_taulu[i].size, hakem_taulu[i].hakem);
  45.  
  46.     printf("\n\nSpace used Extent\n"
  47.                "========== ======\n");
  48.     for (i = 0; i < eind; i++)
  49.         printf("%9ld   .%s\n", ext_taulu[i].size, ext_taulu[i].ext);
  50. }
  51.  
  52. long tutki_hakem (char *hakem)
  53. {
  54.     struct ffblk ffblk;
  55.  
  56.     long    dirsize = 0;
  57.     long    subdirsize = 0;
  58.     int    loppu;
  59.     char    ffhakem[100];
  60.     char    alihakem[100];
  61.     char    *extptr;
  62.     int    i;
  63.  
  64.     for (loppu = findfirst (strcat (strcpy (ffhakem, hakem), "*.*"), &ffblk, FA_DIREC); !loppu; loppu = findnext(&ffblk))
  65.  
  66.         if (strcmp (ffblk.ff_name, ".") && strcmp (ffblk.ff_name, ".."))
  67.             if (ffblk.ff_attrib & FA_DIREC)
  68.                 subdirsize += tutki_hakem (strcat (strcat (strcpy (alihakem, hakem), ffblk.ff_name), "\\"));
  69.         else{
  70.             dirsize += ffblk.ff_fsize;
  71.             extptr = strchr (ffblk.ff_name, '.');
  72.         
  73.             if (extptr == NULL)
  74.                 extptr = "";
  75.               else
  76.                 extptr ++;
  77.  
  78.             for (i = 0; i < eind && strcmp ( ext_taulu[i].ext, extptr);
  79.              i++);
  80.         
  81.             if (i < eind)
  82.             ext_taulu[i].size += ffblk.ff_fsize;
  83.             else {
  84.             ext_taulu[eind].size = ffblk.ff_fsize;
  85.             strcpy(ext_taulu[eind++].ext, extptr);
  86.             }
  87.         }
  88.  
  89.     strcpy(hakem_taulu[hind].hakem, hakem);
  90.     hakem_taulu[hind++].size = dirsize;
  91.  
  92.     if (subdirsize > 0) {
  93.         strcat (strcpy (hakem_taulu[hind].hakem, hakem), "...");
  94.         hakem_taulu[hind++].size = subdirsize + dirsize;
  95.     }
  96.     return(subdirsize + dirsize);
  97. }
  98.  
  99. int vertaa (long *luku1, long *luku2)
  100. {
  101.     if (*luku1 < *luku2)
  102.         return (1);
  103.     else
  104.             if (*luku1 == *luku2)
  105.                 return (0);
  106.             else
  107.                 return (-1);
  108. }
  109.  
  110.     
  111.     
  112.