示例#1
0
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 {
示例#2
0
nomask void set_list(string list, object * ptr) {
  if(KERNEL()) {
    argcheck( list, 1, "string" );
    argcheck( ptr, 2, "array" );

    if(!ltable) ltable = ([ ]);
    ltable[list] = ptr;
  }
}
示例#3
0
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 = ( { } );
示例#4
0
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);
}
示例#5
0
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;
}
示例#6
0
void subscribe_event(string name) {
   argcheck(name, 1, "string");

   if (events && events[name]) {
      events[name][previous_object()] = 1;
   }
}
示例#7
0
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];
      }
   }
示例#8
0
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);
   }
}
示例#9
0
/* 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))];
}
示例#10
0
/*
 * 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];
}
示例#11
0
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);
}
示例#12
0
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);
    }
}
示例#13
0
文件: HMLEdit.c 项目: komh/hanedit2
int main(int argc, char *argv[], char *envp[])
{
    _envargs(&argc,&argv,"HANEDIT2OPT");
    argcheck(argc,argv);
#ifdef DEBUG
    morph();
#endif
    winmain();

    return 0;
}
示例#14
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;
}
示例#15
0
/* 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;
}
示例#16
0
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;
  }
示例#17
0
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 -= ({ "" });
示例#18
0
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];
      }
   }
示例#19
0
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;
}
示例#20
0
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 ) ;
}
示例#21
0
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);
}
示例#22
0
文件: write.c 项目: Lundex/gurbalib
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);
   }
}
示例#23
0
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 );

}
示例#24
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 );
  }
}
示例#25
0
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;
}
示例#26
0
/* 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;
}
示例#27
0
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
}
示例#29
0
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;
}
示例#30
0
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);
}