home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <errno.h>
- #include <fido.h>
- #include <qdos.h>
- #include <ctype.h>
- #include <time.h>
- #include <dirent.h>
-
- typedef unsigned char u_char;
- typedef unsigned short int u_short;
- typedef unsigned long int u_long;
- typedef unsigned int u_int;
-
- /*
- du.c 1.00 copyleft 1992 Erik Slagter (v882022@si.hhs.nl)
- This source may be distributed and modified freely if this message stays
- intact.
-
- compile with c68k 2.00 or higher.
-
- usage: ex du;"[-[sabkm]] {directory}"
-
- flags:
-
- -s short; do not output directory names
- -a all ; output all file names and sizes
- -b bytes; output in bytes
- -k kbyte; output in kilobytes
- -m mega ; output in megabytes
-
- multiple file and directory names and wildcards may be supplied
-
- extremely useful in conjunction with harddisk or level II device driver.
-
- Modification history of du
-
- 1.00: 920410: First version
-
- */
-
- static u_char format = 10;
- static u_char which = 1;
- char _prog_name[] = "du";
- long _mneed = 16384;
- static u_char *_version = "1.00";
- static u_char *sccs = "(#)du.c 1.01 920327 Qdos Minerva C68 2.00\n";
-
- #define oops(s) (perror(s), exit(ERR_BP))
-
- u_int count(dir)
- u_char *dir;
- {
- chanid_t chanid;
- struct qdirect qd;
- u_char tmp[1024];
- u_char file[1024];
- u_int total = 0;
-
- sprintf(tmp, "%s*", dir);
-
- chanid = open_qdir(dir);
- while(read_qdir(chanid, tmp, file, &qd, 0))
- if(qd.d_type == QF_DIR_TYPE)
- total += count(file);
- io_close(chanid);
-
- chanid = open_qdir(dir);
- while(read_qdir(chanid, tmp, file, &qd, 0))
- if(qd.d_type != QF_DIR_TYPE)
- {
- total += qd.d_length;
- if(which > 1)
- printf("%5d %s\n", qd.d_length >> format, file);
- }
- io_close(chanid);
-
- if(which)
- printf("%5d %s\n", total >> format, *dir ? dir : ".");
-
- return(total);
- }
-
- long main(argc, argv)
- int argc;
- char **argv;
- {
- u_int total = 0;
- u_int dirs = 0;
-
- while(*++argv)
- if(argv[0][0] == '-')
- switch(argv[0][1])
- {
- case('s'):
- which = 0; break;
- case('a'):
- which = 2; break;
- case('b'):
- format = 0; break;
- case('k'):
- format = 10; break;
- case('m'):
- format = 20; break;
- default:
- fprintf(stderr, "usage: %s [-[sabkm]] {directory}\n", _prog_name);
- exit(ERR_BP);
- }
- else
- total += count(*argv), dirs++;
-
- if(!dirs)
- total = count("");
-
- if((dirs > 1) || !which)
- printf("Total %5d\n", total >> format);
- }
-
-