inherit COMMAND_BASE;
#include <creator.h>
mapping globals = ([]), files = ([]), ret = ([]);
#define tp globals[fd]
#define FILE files[fd]
#define RET ret[fd]
mixed cmd(string arg) {
int fd, num = 0;
string last = "";
if(!arg)
arg = "";
else {
string bit, *bits = explode(arg, " ");
arg = "";
bits -= ({""});
foreach(bit in bits){
mixed *st;
if (bit[0] == '-'){
continue;
}
bit = this_player()->get_path(bit)[1..];
if (bit == "")
return notify_fail("Your wombles just expired.\n");
if (!master()->valid_read(bit, this_player(), 0))
return notify_fail("Permission denied: " + bit + " .\n");
if(sizeof(st = unguarded((:stat, bit:)))){
if(stringp(st[0]))
return notify_fail("Can't use diff on directories.\n");
}
arg += " " + last;
last = bit;
num ++;
}
}
if (num == 2)
arg += " " + last;
last = "/" + last;
if (num > 3)
return notify_fail("Can't compare more than two files");
if (num == 3 && file_size(last) > 0)
return notify_fail("File " + last + " exists.\n");
fd = external_start(7, arg, "read_call_back", "write_call_back",
"close_call_back");
if (fd == -1)
return notify_fail("diff failed somehow.\n");
tp = this_player();
if (num == 3 && master()->valid_write(last, this_player(), 0))
FILE = last;
RET = "";
return 1;
}
void read_call_back(int fd, mixed mess) {
mess = replace(mess, "/usr/bin/", "");
RET += mess;
}
void write_call_back(int fd) {
tell_object(tp, "diff: Whoops! fatal error.\n");
}
void close_call_back(int fd) {
if (FILE)
write_file(FILE, RET);
else {
if(RET == "")
RET = "those files are the same";
tp->more_string(RET);
}
map_delete(ret, fd);
map_delete(files, fd);
map_delete(globals, fd);
}