#include <unistd.h>
#include <stdio.h>
#define appname "d's rm"
#define appversion "0.3"
int rm(char file[]) {
unlink(file);
}
int main(int argc, char *argv[]) {
int opt;
int verbose = 0;
int recursive = 0;
int force = 0;
int interactive = 0;
char response;
while ((opt = getopt(argc, argv, "rvRif")) != -1) {
switch(opt) {
case 'r':
case 'R':
printf("Option 'recursive' not implemented yet\n"); recursive = 1; break;
case 'i': interactive = 1; break;
case 'v': verbose = 1; break;
case 'f': printf("Option 'force' not implemented yet\n"); force = 1; break;
}
}
if (interactive == 1) {
for (; optind < argc; optind++) {
printf("rm: remove %s ('y' or 'n')? ", argv[optind]);
do {
response = getchar();
}
while (response == '\n');
if (response == 'y' || response == 'Y')
rm(argv[optind]);
}
} else {
for (; optind < argc; optind++) {
if (verbose == 1) {
printf("removed '%s'\n", argv[optind]);
}
rm(argv[optind]);
}
}
exit(0);
}
syntax highlighted by Code2HTML, v. 0.9.1