// 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;
}
varargs string identify( mixed a )
{
int i, s;
string ret;
mapping RealMap;
if( undefinedp( a ) ) return "UNDEFINED";
if( nullp( a ) ) return "0";
if( intp( a ) ) return "" + a;
if( floatp( a ) ) return "" + a;
if( objectp( a ) )
{
if( ret = a-> GetKeyName() ) ret += " ";
else ret = "";
return "OBJ(" + ret + file_name( a ) + ")";
}
if( stringp( a ) )
{
a = replace_string( a, "\"", "\\\"" );
a = "\"" + a + "\"";
a = replace_string( a, "\\", "\\\\" );
a = replace_string( a, "\\\"", "\"" );
a = replace_string( a, "\n", "\\n" );
a = replace_string( a, "\t", "\\t" );
return a;
}
if( pointerp( a ) )
{
ret = "({ ";
s = sizeof( a );
for( i = 0 ; i < s ; i++ )
{
if( i ) ret += ", ";
ret += identify( a[i] );
}
return ret + ( s ? " " : "" ) + "})";
}
if( mapp( a ) )
{
ret = "([ ";
RealMap = (mapping)(a);
a = keys( RealMap );
s = sizeof( a );
for( i = 0 ; i < s ; i++ )
{
if( i ) ret += ", ";
ret += identify( a[i] ) + " : " + identify( RealMap[a[i]] );
}
return ret + ( s ? " " : "" ) + "])";
}
if(functionp(a)) return sprintf("%O", a);
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() {}
string convert_name(string str) {
string a, b, ret;
if(!str || str == "") return "";
if(strsrch(str,"@") != -1){
str = replace_string(str, " ", "");
str = replace_string(str, "'", "");
return lower_case(replace_string(str, "-", ""));
}
if(sscanf(str, "%s@%s", a, b) == 2 &&
ret = INTERMUD_D->GetMudName(b)) return a+"@"+ret;
else return str;
}
varargs string get_stack( int x) {
int i, s;
string list = "";
string *stack0 = call_stack(0);
string *stack1 = call_stack(1);
string *stack2 = call_stack(2);
for(i = 0, s = sizeof(stack1); i < s; i++){
list +="\n"+i+":"+identify(stack2[i])+"."+identify(stack1[i])+"."+identify(stack2[i]);
}
if(x){
list += "\n"+ identify(previous_object(-1));
}
return list;
}
void tc(string mess){
object crat = find_player("cratylus");
string sauce = base_name((previous_object() || this_object()));
if(crat) tell_object(crat, sauce +": "+mess+"\n");
//if(crat) crat->receive_private_msg(sauce+": "+mess, PRIVATE_MSG);
debug_message(sauce +": "+mess);
flush_messages();
}