/* * somewhat stupid rm program, just to keep from extreme * dos (and os/2) confusion */ #include #include #include #include #include #include /* for DosSetFileMode() */ #include "glob.h" void die(); extern int getopt(); extern int optind, opterr; extern int optopt; char inquire=0; /* ask before deleting */ char verbose=1; /* chatter about things */ char recursive=0; /* remove subdirectories */ char force=0; /* force removal of files */ struct glob_t dta; /* interesting information about the file to kill */ /* * lf, in the flesh */ main(argc, argv) char **argv; { register i; register char *p, *base; opterr = 1; while ((i=getopt(argc, argv, "rfi")) != -1) switch (i) { case 'r': recursive=1; break; case 'i': inquire=1; break; case 'f': inquire=0; verbose=0; force=1; break; default: fprintf(stderr, "usage: rm [-rfi] file [...]\n"); exit(1); } if (argc <= optind) { fprintf(stderr, "usage: rm [-rfi] file [...]\n"); exit(1); } for (i=optind; i= 0; i--) if (rmdir(drlist[i]) != 0) perror(drlist[i]); } /* execute_deathrow */ /* * appeal() asks if you really wish to kill the file in question */ appeal(file, p, inquire) char *file; struct glob_t *p; { register ask_for_mode; register char *ans; char line[80]; ask_for_mode = (force == 0) && (p->attrib & (F_RDONLY|F_HIDDEN|F_SYSTEM)); while (inquire || ask_for_mode) { if (ask_for_mode) fprintf(stderr, "override mode %02x for %s? ", p->attrib & F_AMASK, file); else fprintf(stderr, "rm %s? ", file); fflush(stderr); gets(line); for (ans=line; *ans && isspace(*ans); ++ans) ; if ((*ans = tolower(*ans)) == 'y') break; else if (*ans == 'q') exit(0); else return 1; } /* Okay to kill the file, so we'll make it killable. */ if (p->attrib & F_RDONLY) DosSetFileMode(file, p->attrib & ~F_RDONLY, 0L); return 0; } /* appeal() */ /* * die() buries a file */ void die(p, dta) char *p; struct glob_t *dta; { if (appeal(p, dta, inquire) == 0) if (dta->attrib & F_DIRECT) { if (recursive) deathrow(p); else if (verbose) fprintf(stderr, "%s: is a directory\n", p); } else if (remove(p) != 0 && verbose) perror(p); } /* die */ /* * mapslash() converts backslashes into forward slashes */ mapslash(p) register char *p; { for (; *p; p++) if (*p == '\\') *p = '/'; else if (isupper(*p)) *p = tolower(*p); } /* mapslash */