// Petrarch
// Merentha Lib 1.0
// sefun.c
#pragma show_error_context
#include <lpctypes.h>
#include "files.c"
#include "logs.c"
#include "math.c"
#include "money.c"
#include "mud_config.c"
#include "numbers.c"
#include "objects.c"
#include "player_funs.c"
#include "preds.c"
#include "strings.c"
#include "time.c"
int same(mixed x, mixed y) {
if (typeof(x) != typeof(y)) return 0;
switch (typeof(x)) {
case INT:
case STRING:
case OBJECT:
case FLOAT:
return x == y;
case MAPPING:
if (x == y) return 1; // speed up this case
if (sizeof(x) != sizeof(y)) return 0;
if (!same(keys(x), keys(y))) return 0;
if (!same(values(x), values(y))) return 0;
return 1;
case ARRAY:
if (x == y) return 1; // speed up this case
if (sizeof(x) != sizeof(y)) return 0;
for (int i = 0; i < sizeof(x); i++) {
if (!same(x[i], y[i])) return 0;
}
return 1;
case FUNCTION:
error("Not implemented.");
}
}
void cat(string file) {
message("sefun", read_file(file), this_player());
}
varargs int getoid(object ob) {
int id;
sscanf(file_name(ob || previous_object()), "%*s#%d", id);
return id;
}
string user_cwd(string name) {
return ("/realms/" + name[0..0] + "/" + name);
}
string user_path(string name) {
return (user_cwd(name) + "/");
}
string file_owner(string file) {
string temp, junk;
if (file[0] != '/') file = "/" + file;
if (sscanf(file, "/realms/%s/%s", temp, junk) == 2) {
return temp;
}
return 0;
}
string identify(mixed arg) {
string rtn;
mixed x, y;
switch(typeof(arg)){
case OBJECT: return "("+file_name(arg)+")";
case STRING: return "\""+arg+"\"";
case INT: return ""+arg;
case ARRAY: {
rtn = "({ ";
foreach (y in arg)
rtn += identify(y)+", ";
return rtn+"})";
}
case MAPPING: {
rtn = "([ " +
implode(values(map_mapping(arg,(: sprintf("%s : %s", identify($1),identify($2)) :))),", ");
return rtn+"])";
}
case FUNCTION:
case FLOAT: {
return sprintf("%O\n", arg);
}
return "UNKNOWN";
}
}
string resolve_path(string curr, string newer) {
int i, j, size;
string *tmp;
switch(newer){
case 0:
case ".":
return curr;
case "here":
return file_name(environment())+".c";
default:
if (newer[0..1] == "~/") newer = user_path((string)this_player()->query_name()) + newer[2..];
else {
switch(newer[0]){
case '~': {
i = strsrch(newer, '/');
if (i < 0) newer = user_path(newer[1..]);
else newer = user_path(newer[1..i-1]) + newer[i..];
break;
}
case '/': break;
default: newer[<0..<1] = curr + "/";
}
}
if (newer[<1] != '/') newer += "/";
size = sizeof(tmp = regexp(explode(newer, "/"), "."));
i = j = 0;
while (i < size){
switch(tmp[i]){
case "..":
if (j){
while (j-- && !tmp[j]);
if (j >= 0) tmp[j] = 0;
else j++;
}
case ".":
tmp[i++] = 0;
break;
default:
j = ++i;
break;
}
}
return "/"+implode(tmp, "/");
}
}
string domain_file(string) {
return "Root";
}
string creator_file(string) {
return "Root";
}
string author_file(string) {
return "Root";
}
void simul() {}