[net.sources] Removing files w/ unprintable names

bob (02/16/83)

/*	Remove unprintable files from the current directory
The following two files can be compiled together to produce
an interactive file remover for files with unprintable control
characters in their names.  It is safer than 'rm -ri directory'
which will acheive the same effect.
Note that the directory structure is vanilla-flavored.
*/
!!!!!!!!!!!!!file name is "rmup.c"
#include <stdio.h>
#include <ctype.h>

#define NFILES 250
char filelist[NFILES][16];

main()
{
	int i, j, nfiles;

	nfiles = ls(".",filelist,NFILES);
	for ( i = 0; i < nfiles; i++ ) {
		for ( j = 0; j < 14; j ++ ) {
			if ( filelist[i][j] == '\0' )
				break;
			if ( filelist[i][j] & 0x80 ) {
				if ( filequery(filelist[i]) ) {
					unlink(filelist[i]);
				}
				break;
			}
		}
	}
	exit(0);
}

filequery(file)
char *file;
{
	char line[50];

	printf("Remove: ");
	while ( *file ) {
		if ( isprint(*file) ) {
			printf("%c",(*file & 0377));
		}
		else {
			printf(" %04o ",(*file & 0377));
		}
		file++;
	}
	printf("? ");
	fgets(line, sizeof line, stdin);
	if ( line[0] == 'y' || line[0] == 'Y' )
		return 1;
	return 0;
}
!!!!!!!!!!!!!file name is "ls.c"
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>

ls(dirname,files,nfiles)
	char *dirname,		/* name of the directory to be listed */
		files[][16];	/* repository */
	int nfiles;		/* max length of repository */
{
	FILE *dir;
	struct direct file;
	int i;

	if ((dir = fopen(dirname,"r")) == NULL)
		return 0;

	for ( i = 0; i < nfiles; )
		if (fread(&file,sizeof file,1,dir))
		{
			if (file.d_ino) {
				strncpy(files[i],file.d_name,DIRSIZ);
				files[i][DIRSIZ] = '\0';
				i++;
			}
		} else
			break;
	fclose(dir);
	return i;
}