#include <sys/types.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> int main(int argc, char *argv[]) { FILE *zin; int text,all; int i,ch,dodelete=0; float percent; extern int errno; if (argc<2) { printf("Usage: istext [-d] filename ...\n"); exit(1); } if (!strcmp(argv[1],"-d")) { dodelete=1; argc--; argv++; } for (i=1;i<argc;i++) { zin = fopen(argv[i], "r"); if (zin == NULL) { printf("Could not open %s: %s\n", argv[i], strerror(errno)); continue; } all=0;text=0; while (!feof(zin)) { ch=fgetc(zin); if (ch==-1) break; all++; if (isprint(ch)) { text++; continue; } if ((ch=='\t') || (ch=='\r') || (ch=='\n') || (ch=='\b')) { text++; continue; } } fclose(zin); if (all==0) all=1; percent= (float)text/(float)all; if (percent<0.9) { if (dodelete) unlink(argv[i]); else printf("remove %s: %3.3f\n",argv[i],100.0 * percent); } } exit(0); }