/* mtd.c - DECUS C list empty directory files on RSX */

/*
 *	B U G S
 *
 *	It will break on:
 *
 *		named directories
 *		node names (foo::)
 *		nested directories
 *		long file names
 */

/*
 *	E D I T   H I S T O R Y
 *
 * 24jul85 DLE	Add [0,0] to file specs.
 *
 */

#include <stdio.h>
#include <algol68.h>

FILE *	file;
extern int $$ferr;
int	dirbuf[8];
#define ENTSIZ 16
char	nambuf[100];
char *	p;

panic(s)
char *	s;
BEGIN
	error("\7$$ferr=%oo %s",$$ferr,s);
END

main()
BEGIN
register int used;
register int count;

	IF	( ! (file=fwild("[0,0]*.dir;*","rnu")) )
	THEN	panic("can't understand wild string");
	FI
	WHILE	(fnext(file))
	DO	used = FALSE;
		count = 0;
		WHILE	(fget(dirbuf,ENTSIZ,file))
		DO	count++;
			IF	(*dirbuf)
			THEN	used = TRUE;
				break;
			FI
		OD
		IF	( ! feof(file) )	/* only error allowed is EOF */
		THEN	count = 0;
		FI
		IF	(   ( ! used )   &&   count   )
		THEN	fgetname(file,nambuf);
			p = strchr(nambuf,':');
			IF	(!p)
			THEN	error("\7no ':'");
			FI
			*p = 0;
			printf("%s:[0,0]%s\n",nambuf,++p);
		FI
	OD
END

/* end: mtd.c */
