static mixed *map_array(mixed * arr, mixed fun, varargs mixed arg...) { mixed *extra; mixed *result; object obj; int i, sz; argcheck(arrayp(arr), 1, "array"); #ifdef CLOSURES_EXTENSION argcheck(stringp(fun) || functionp(fun), 2, "function or string"); #else argcheck(stringp(fun), 2, "string"); #endif if (sizeof(arg)) { #ifdef CLOSURES_EXTENSION if (functionp(fun)) { extra = arg; } else #endif if (objectp(arg[0])) { obj = arg[0]; } else if (stringp(arg[0])) { obj = find_object(arg[0]); } if (!extra) { argcheck(objectp(obj), 3, "object or string"); extra = arg[1..]; } } else {
nomask void set_list(string list, object * ptr) { if(KERNEL()) { argcheck( list, 1, "string" ); argcheck( ptr, 2, "array" ); if(!ltable) ltable = ([ ]); ltable[list] = ptr; } }
mixed *filter_array(mixed * arr, string fun, varargs object obj, mixed extra ...) { mixed *res; int i, sz; argcheck(arrayp(arr), 1, "array"); argcheck(stringp(fun), 2, "string"); if (!objectp(obj)) { obj = this_object(); } res = ( { } );
int strstr(string search, string what) { int i, lw, ls; argcheck(search, 1, "string"); argcheck(what, 2, "string"); ls = strlen(search); lw = strlen(what) - 1; for (i = 0; i < (ls - lw); i++) { if (search[i..(i + lw)] == what) return i; } return (-1); }
static mixed * map_array(mixed * arr, string fun, object ob, varargs mixed extra ) { mixed * result; int i, sz; argcheck( arrayp( arr ), 1, "array" ); argcheck( stringp( fun ), 2, "string" ); sz = sizeof( arr ); result = allocate(sz); for( i = 0; i < sz; i++ ) { result[i] = call_other( ob, fun, arr[i] ); } return result; }
void subscribe_event(string name) { argcheck(name, 1, "string"); if (events && events[name]) { events[name][previous_object()] = 1; } }
static object clone_object(string path) { object ob, ed; string trace, cloner; argcheck(path, 1, "string"); ed = find_object(ERROR_D); /* * yeah.. calling the error_d to get a formatted runtime trace.. * no, we aren't * reporting an error here, just using one of its * nice utility functions to get a nicely formatted trace */ if (ed) { trace = ed->format_runtime_error("Clone calltrace", ::call_trace(), 0, 0, 0); } else { trace = "No clone calltrace available\n"; } if (this_object()->is_player() && this_object()->query_name()) { cloner = this_object()->query_name(); } else if ((sscanf(object_name(this_object()), "/cmds/wiz/%*s") == 1) && this_user()) { cloner = this_user()->query_name(); } else { cloner = _owner; } if (strlen(path) > 2) { if ((path[strlen(path) - 2] == '.') && (path[strlen(path) - 1] == 'c')) { path = path[..strlen(path) - 3]; } }
object compile_object(string path, string code ...) { argcheck(path, 1, "string"); if (!KERNEL() && !SYSTEM() ) { #ifdef SECURITY_COMPILER_RW if (!valid_write(path)) { error("Permission denied."); } #endif if (code && sizeof(code)) { if (!valid_write(path)) { error("Permission denied"); } } else { if (!valid_read(path)) { error("Permission denied"); } } } if (strlen(path) > 2) { if (path[strlen(path) - 2] == '.' && path[strlen(path) - 1] == 'c') path = path[..strlen(path) - 3]; } if (find_object(COMPILER_D)) { path = COMPILER_D->allow_object(path); } if (code && sizeof(code)) { return driver->compile_object(path, code...); } else { return driver->compile_object(path); } }
/* Returns random element from the given array. Returns nil if array is empty. */ mixed random_element( mixed *arr ) { argcheck( arr, 1, "array" ); if (sizeof(arr) < 1) return nil; return arr[random(sizeof(arr))]; }
/* * Get the value for a tls 'super global'. * * By Aidil@Way of the Force * * This code is in the public domain. */ static mixed get_tlvar(string name) { mapping vars; argcheck(stringp(name), 1, "string"); vars = DRIVER->get_tlvar(TLS_UVARS); if (vars) return vars[name]; }
void out_unmod(string str) { argcheck(str, 1, "string"); if (!this_user()) return; this_user()->put_original(str); if (this_player()->is_snooped()) this_player()->do_snoop(str); }
nomask void destruct_object(object ob) { argcheck(ob, 1, "object"); if (find_object(COMPILER_D) && COMPILER_D->allow_object(ob->base_name())) { ob->_F_destruct(); } else { console_msg("WARNING: destruct_object() used on an inheritable: " + ob->base_name() + "\n"); ::destruct_object(ob); } }
int main(int argc, char *argv[], char *envp[]) { _envargs(&argc,&argv,"HANEDIT2OPT"); argcheck(argc,argv); #ifdef DEBUG morph(); #endif winmain(); return 0; }
string lowercase(string str) { int i, sz; argcheck(str, 1, "string"); for (i = 0, sz = strlen(str); i < sz; i++) { if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A'; } return str; }
/* reversible explode string */ static string *rexplode(string str, string sep) { string dummy; string *result; argcheck(stringp(str), 1, "non empty string"); argcheck(stringp(sep), 2, "non empty string"); if (!strlen(sep)) { dummy = "!"; } else { dummy = sep[0] != '!' ? "!" : "?"; } str = dummy + str + dummy; result = explode(str, sep); result[0] = result[0][1..]; result[sizeof(result) - 1] = result[sizeof(result) - 1][..strlen(result[sizeof(result) - 1]) - 2]; return result; }
static void set_otlvar(string name, mixed value) { mapping vars; int save; argcheck(stringp(name), 1, "string"); vars = DRIVER->get_tlvar(TLS_OVARS); if(!vars) { vars = ([ ]); save = 1; }
string trim_str(string str) { string* parsed; argcheck(str, 1, "string"); if (nilp(str) || str == "") { return ""; } parsed = parse_string("whitespace = /[\n\b\r\t ]+/ " + "word = /[^\n\b\r\t ]+/ S: word S: S word", str); parsed -= ({ "" });
static int compile_library(string path, string code ...) { object ob, tmp; string **depends; int i, sz; mapping queue; argcheck(path, 1, "string"); if (strlen(path) > 2) { if (path[strlen(path) - 2] == '.' && path[strlen(path) - 1] == 'c') { path = path[..strlen(path) - 3]; } }
int member_array(mixed item, mixed * arr) { int i, sz; argcheck(arr, 2, "array"); sz = sizeof(arr); for (i = 0; i < sz; i++) { if (arr[i] == item) { return i; } } return -1; }
int query_admin(mixed player) { if(objectp(player)) { if( !player<-"/sys/lib/player" ) { return 0; } player = player->query_name(); } else { argcheck( stringp( player ), 1, "player object or string" ); } return SECURE_D->query_admin( player ) ; }
nomask int query_mortal(mixed player) { if (objectp(player)) { if (!player <-"/sys/obj/player") { return 0; } player = player->query_name(); } else { argcheck(stringp(player), 1, "player object or string"); } return !query_wizard(player); }
void write(string str) { argcheck(str, 1, "string"); if (!this_player()) { return; } this_player()->message(str); if (this_player()->is_snooped()) { this_player()->do_snoop(str); } }
int member_map( mixed item, mapping map ) { mixed *arr; argcheck( map, 2, "mapping" ); arr = map_indices( map ); if( member_array( item, arr ) > -1 ) return( 1 ); arr = map_values( map ); if( member_array( item, arr ) > -1 ) return( 1 ); return( 0 ); }
void event( string name, varargs mixed args... ) { object *obs; int i; argcheck( name, 1, "string" ); if(!events[name]) return; obs = map_indices(events[name]); for( i = 0; i < sizeof( obs ); i++ ) { if( obs[i] ) call_other( obs[i], "event_" + name, args ); } }
static object clone_object( string path ) { object ob, ed; string trace; string cloner; argcheck( path, 1, "string" ); ed = find_object(ERROR_D); /* * yeah.. calling the error_d to get a formatted runtime trace.. no, we aren't * reporting an error here, just using one of its nice utility functions to get * a nicely formatted trace * */ if(ed) trace = ed->format_runtime_error("Clone calltrace",::call_trace(),0,0,0); else trace = "No clone calltrace available\n"; if(this_object()->is_player() && this_object()->query_name()) { cloner = this_object()->query_name(); } else if(sscanf(object_name(this_object()),"/cmds/wiz/%*s") == 1 && this_user()) { cloner = this_user()->query_name(); } else { cloner = _owner; } if( strlen(path) > 2 ) { if( path[strlen(path)-2] == '.' && path[strlen(path)-1] == 'c' ) path = path[..strlen(path)-3]; } if(find_object(COMPILER_D)) { path = COMPILER_D->allow_object( path ); } if( !(ob = find_object( path ) ) ) { ob = compile_object( path ); call_other(ob,"???"); } ob = ::clone_object( ob ); ob->_F_set_cloner(cloner,trace); ob->_F_create(); return ob; }
/* get the size of all files in a directory */ int dir_size(string file) { mixed **info; int *sizes, size, i, sz; argcheck(file, 1, "string"); info = get_dir(file + "/*"); sizes = info[1]; size = 1; /* 1K for directory itself */ i = sizeof(sizes); while (--i >= 0) { sz = sizes[i]; size += (sz > 0) ? (sz + 1023) >> 10 : (sz == 0) ? 1 : dir_size(file + "/" + info[0][i]); } return size; }
static int file_exists(string str) { mixed *val; int *sizes; argcheck(str, 1, "string"); val = get_dir(str); sizes = val[1]; if (!sizes || sizeof(sizes) == 0) { return 0; } if (sizes[0] == -2) { return -1; } return 1; }
int main(int argc, char **argv) { argcheck(argc, argv); // Setup connection char nPORT[7]; // port to connect to char * HOST = new char[DEFAULT_BUFLEN]; // host to connect to SOCKET serverSocket = INVALID_SOCKET; bool success = setupConnection(argc, argv, nPORT, HOST); // if connection setup was successful, continue with socket setup if (success) { //initialize socket SOCKET listenSocket = setupListenSocket(nPORT, argv); if (listenSocket == INVALID_SOCKET) { fprintf(stderr, "error: INVALID_SOCKET, quitting."); //LogF.writetolog("error: INVALID_SOCKET, quitting."); exit(0); } // if the socket setup was successful, continue with testing interface else { // Create server object server = new Client(listenSocket); // testing interface with server try { connectToServerSubsystem(); } catch (ServerException& e) { printf(e.sendEr()); } } } // if connection setup failed, exit else { printf("connection setup failed, exiting"); //LogF.writetolog("connection setup failed."); exit(0); } return 0; // exit }
int cat_file(string filename) { int i, sz; string *lines; argcheck(filename, 1, "string"); i = file_exists(filename); if (!i) { write("No such file.\n"); return 0; } if (i == -1) { write("Unable to cat directories.\n"); return 0; } lines = explode(read_file(filename), "\n"); for (i = 0, sz = sizeof(lines); i < sz; i++) { out_unmod(lines[i] + "\n"); } return 1; }
int treat_core(char **core, int argnb) { int i; int ct; i = 1; ct = 1; if (core[0] == NULL) return (0); while (i < argnb) { if (core[i][0] == '-') { ct = argcheck(core[i], ct); if (ct < 0) return (-1); } else return (ct); i++; } return (ct); }