/* file: pbs-erase.c G. Moody 26 February 2012 Erase files named in the argument list and remove them from the index The index, "index.html", must be in the same directory as the first file named. Files to be deleted must appear in the index in the same order as in the argument list! The first four characters in each argument (normally, "/ptmp") are assumed not to appear in the index. */ #include #include #include #include main(int argc, char **argv) { FILE *ifile, *ofile; int i = 1; static char buf[2048], command[256], indexname[64], indexback[64], *p; if (argc < 2) exit(0); strcpy(indexname, argv[1]); p = indexname + strlen(indexname) - 1; while (p > indexname && *p != '/') p--; strcpy(p+1, "index.html"); sprintf(indexback, "%s~", indexname); sprintf(command, "cp -p %s %s", indexname, indexback); system(command); ifile = fopen(indexback, "r"); ofile = fopen(indexname, "w"); while (fgets(buf, sizeof(buf), ifile)) { if (i < argc && strstr(buf, argv[i]+5)) unlink(argv[i++]); else fputs(buf, ofile); } }