2020-09-06 05:43:07 -07:00

54 lines
1.6 KiB
C

// /bin/dev/_rm.c
// from the Dead Souls Mudlib
// the command to rm files (wild cards without prompt!!!!, be careful)
// created by Descartes of Borg 02 august 1993
#include <lib.h>
inherit LIB_DAEMON;
int cmd(string str) {
string *files;
string tmp;
object ob;
int i;
if(!str) {
notify_fail("Correct syntax: <rm [file]>\n");
return 0;
}
if((ob=previous_object())->GetForced()) {
write("Someone attempted to force you to rm "+str+".");
return 1;
}
tmp = absolute_path(ob->query_cwd(), str);
if(!archp(ob) || !sizeof(files = wild_card(tmp)))
files = ({ tmp });
if(!(i=sizeof(files))) {
message("system", "File "+tmp+" does not exist.", this_player());
return 1;
}
while(i--) {
switch(file_size(files[i])) {
case -1: message("system", "File "+files[i]+" does not exist.",
this_player()); break;
case -2: message("system", files[i]+" is a directory.",
this_player()); break;
default: message("system", rm(files[i]) ? files[i]+": Ok." :
files[i]+": Permission denied.", this_player());
break;
}
}
return 1;
}
string GetHelp(){
string ret = "Syntax: rm [file]\n\n"
"The command deletes the file named. Once deleted, the file "
"cannot be recovered. Seriously.";
if(archp(this_player()))
ret += "Note for arches: wild cards work with this command, "
"but there is no prompt, so be VERY CAREFULL!!!!";
return ret;
}