home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
pc
/
source
/
spaceuse.arc
/
SPACEUSE.C
next >
Wrap
Text File
|
1988-08-14
|
3KB
|
112 lines
/* SPACEUSE.C by Erkki Vanninen */
#include <stdio.h>
#include <dir.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <ctype.h>
int hind = 0;
struct {
long size;
char hakem[100];
} hakem_taulu[200];
int eind = 0;
struct {
long size;
char ext[4];
} ext_taulu[500];
long tutki_hakem (char *hakem);
int vertaa (long *luku1, long *luku2);
main (int argc, char *argv[])
{
char *paahakem = "C:\\";
int i;
if (argc > 1)
*paahakem = toupper(*argv[1]);
if (*paahakem < 'A' || *paahakem > 'Z')
exit(printf("Format : SPACEUSE [d:] [>LPT1:]"));
tutki_hakem(paahakem);
qsort(hakem_taulu, hind, sizeof(*hakem_taulu), vertaa);
qsort(ext_taulu, eind, sizeof(*ext_taulu), vertaa);
printf("Space used Directory\n"
"========== ===========================================\n");
for (i = 0; i < hind; i++)
printf("%9ld %s\n", hakem_taulu[i].size, hakem_taulu[i].hakem);
printf("\n\nSpace used Extent\n"
"========== ======\n");
for (i = 0; i < eind; i++)
printf("%9ld .%s\n", ext_taulu[i].size, ext_taulu[i].ext);
}
long tutki_hakem (char *hakem)
{
struct ffblk ffblk;
long dirsize = 0;
long subdirsize = 0;
int loppu;
char ffhakem[100];
char alihakem[100];
char *extptr;
int i;
for (loppu = findfirst (strcat (strcpy (ffhakem, hakem), "*.*"), &ffblk, FA_DIREC); !loppu; loppu = findnext(&ffblk))
if (strcmp (ffblk.ff_name, ".") && strcmp (ffblk.ff_name, ".."))
if (ffblk.ff_attrib & FA_DIREC)
subdirsize += tutki_hakem (strcat (strcat (strcpy (alihakem, hakem), ffblk.ff_name), "\\"));
else{
dirsize += ffblk.ff_fsize;
extptr = strchr (ffblk.ff_name, '.');
if (extptr == NULL)
extptr = "";
else
extptr ++;
for (i = 0; i < eind && strcmp ( ext_taulu[i].ext, extptr);
i++);
if (i < eind)
ext_taulu[i].size += ffblk.ff_fsize;
else {
ext_taulu[eind].size = ffblk.ff_fsize;
strcpy(ext_taulu[eind++].ext, extptr);
}
}
strcpy(hakem_taulu[hind].hakem, hakem);
hakem_taulu[hind++].size = dirsize;
if (subdirsize > 0) {
strcat (strcpy (hakem_taulu[hind].hakem, hakem), "...");
hakem_taulu[hind++].size = subdirsize + dirsize;
}
return(subdirsize + dirsize);
}
int vertaa (long *luku1, long *luku2)
{
if (*luku1 < *luku2)
return (1);
else
if (*luku1 == *luku2)
return (0);
else
return (-1);
}