[net.sources] Hard disk space reporter for IBM-PC under PC-DOS in DeSmet C

bet@ecsvax.UUCP (07/03/84)

: This is a shar archieve.  Extract with sh, not csh.
: The rest of this file will extract:
: README dirio.c disktype.h diskuse.bat makefile.dat report.c
echo extracting - README
sed 's/^X//' > README << '/*EOF'
XThis program prints a report of disk space used on a tree-structured hard
Xdisk. All spaces are totals. If it isn't exactly accurate, please feel
Xfree to figure out why. If you do, I'd like to know. It *is* close.
X
XThis program is for DeSmet C. Porting to another compiler will require
Xchanging some in-stream assembler, at the very least. If you want the
Xready-to-run executable, let me know.
X
X					Bennett Todd
X					...{decvax,ihnp4,akgua}!mcnc!ecsvax!bet
/*EOF
echo extracting - dirio.c
sed 's/^X//' > dirio.c << '/*EOF'
X/*
X * interface routines for directory manipulation
X */
X
X#include <stdio.h>
X#include <disktype.h>
X
X/* sets disk transfer area to <addr> in current dseg */
Xset_dta(addr)
XDTA *addr;
X{
X#asm
X	mov		dx,[bp+4]
X	mov		ah,1ah
X	int		21h
X#
X}
X
X/* finds first name matching <name>, returns TRUE iff successful */
Xfind_first(name)
Xchar *name;
X{
X#asm
X	mov		dx,[bp+4]	; file name pattern
X	mov		cx,16h		; attribute byte for hidden+system+directory
X	mov		ah,4eh
X	int		21h
X	jc		find_first_error
X#
X	return(TRUE);
X
X#asm
Xfind_first_error:
X#
X	return(FALSE);
X}
X
X/* finds next; returns FALSE when there are no more */
Xfind_next()
X{
X#asm
X	mov		ah,4fh
X	int		21h
X	jc		find_next_error
X#
X	return(TRUE);
X
X#asm
Xfind_next_error:
X#
X	return(FALSE);
X}
/*EOF
echo extracting - disktype.h
sed 's/^X//' > disktype.h << '/*EOF'
X/*
X * type and constant defines for use of dirio routines
X */
X
Xtypedef struct {
X	char reserved[21],
X		 attrib;
X	int time,
X		date;
X	long size;
X	char name[13];
X	char padding[85];
X} DTA;
X
X#define ATR_RO	1
X#define ATR_HID	2
X#define ATR_SYS	4
X#define ATR_VOL	8
X#define ATR_DIR	16
X#define ATR_AR	32
/*EOF
echo extracting - diskuse.bat
sed 's/^X//' > diskuse.bat << '/*EOF'
Xpause prepare printer
Xreport | sort /+9 > prn:
/*EOF
echo extracting - makefile.dat
sed 's/^X//' > makefile.dat << '/*EOF'
Xreport.exe report.o dirio.o
X	bind.exe report dirio
Xreport.o report.c stdio.h disktype.h
X	c88.exe report
Xdirio.o dirio.c stdio.h disktype.h
X	c88.exe dirio
Xclean
X	command.com /c=erase report.o
X	command.com /c=erase dirio.o
/*EOF
echo extracting - report.c
sed 's/^X//' > report.c << '/*EOF'
X/*
X * report [path] ...
X * report gives actual disk space used by each directory,
X * including space taken by all files in that directory
X *
X * Bennett Todd
X * Duke Computation Center
X * Durham, NC 27706
X * (919) 684-3183
X * ...{decvax,ihnp4,akgua}!mcnc!ecsvax!bet
X */
X
X#include <stdio.h>
X#include <disktype.h>
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X	long space();
X
X	int i;
X
X	/*
X	 * space("<directory>"); will recursively do the entire job for that
X	 * directory. Do it for every argument; default to the current directory.
X	 */
X
X	if(argc==1)
X		space(".");
X	else
X		for(i=1; i<argc; i++)
X			space(argv[i]);
X}
X
X/*
X * space returns the total spaced used by dir
X * side effect: dta is left corrupted, set to a local variable.
X */
X
Xlong
Xspace(dir)
Xchar *dir;
X{
X	char tempname[64];
X	long total,
X		 normalize();
X	DTA dta;
X
X	set_dta(dta);
X	total = 0;
X	/*
X	 * about the following: a directory *is* a file; the question is,
X	 * does its directory entry contain the *size* of the directory itself?
X	 * If so then the following two lines should include that size.
X	 * If not ....
X	 */
X	if (find_first(dir))
X		total = normalize(dta.size);
X
X	sprintf(tempname,"%s\\*.*",dir);
X	if (find_first(tempname))
X		do
X			if ((dta.attrib & ATR_DIR) != NULL) {
X				if (dta.name[0] != '.') { /* "hidden" files */
X					sprintf(tempname, "%s\\%s", dir, dta.name);
X					total += space(tempname);
X					set_dta(dta);
X				}
X			} else
X				total += normalize(dta.size);
X		while (find_next());
X	printf("%8ld %-s\n", total, dir);
X	return(total);
X}
X
X/* normalize rounds up to next multiple of 4K -- I hope */
Xlong
Xnormalize(val)
Xlong val;
X{
X	return((val+4095)&(~4095));
X}
/*EOF