コード例 #1
0
mixed cmd(string str) {
  /* call fish(x,y,z) object */
  mixed *args, file, f;
  mixed retobj;
  string *s, s1, s2;
  string fn,os, obvarname;
  string *argv;
  object *ov;
  object fish, shad, ob;

  notify_fail("USAGE : call [obvar=]lfun(arg[,arg[,arg...]]) object[s]\n");
  if (!str)
    return 0;
  obvarname = (string)0;
  sscanf(str, "%s=%s", obvarname, str);
  s = explode("&"+str+"&", ")");
  if (sizeof(s) < 2 || sscanf(s[0], "%s(%s", s1, s2) != 2)
    return 0;
  fn = replace(s1[1..], " ", "");
  s[0] = s2;
  args = PARSER->parse_args(implode(s, ")"), ")");
  if (!args) return 1;
  argv = args[0];
  os = args[1][0..<2];
  while (strlen(os) && os[0] == ' ')
    os = os[1..];
  notify_fail("Can't find object "+os+".\n");
  ov = WIZ_PRESENT->wiz_present(os, this_player());
  
  ov = filter( ov, (: reference_allowed( $1, $( this_player() ) ) :) );  

  if (!sizeof(ov)) return 0;

  if (sizeof(argv) < 6) argv += allocate(6 - sizeof(argv));

  foreach (ob in ov) {
    fish = ob;
    while (shad = shadow(fish, 0)) {
      fish = shad;
      if (f = function_exists(fn, fish)) file = f;
    }
    if (!file) file = function_exists(fn, ob);
    if (file) {
  if ( ( ob != this_player() && ob->query_property( "player" ) ) ) {
        unguarded((: write_file,
                   (LMASTER->query_member(this_player()->query_name()) ?
                    "/d/admin/log/CALL_LIAISONS.log" :
                    "/d/admin/log/CALL_CREATORS.log" ),
                   sprintf("%s: %s (%O) called %s(%s) on %s (%O)\n",
                           ctime(time()),
                           this_player()->query_name(), this_player(),
                           fn, implode(argv - ({0}), ", "),
        ob->query_name(), ob) :));
        user_event("inform", sprintf("%s called %s(%s) on %s",
            this_player()->query_name(), fn, implode(argv - ({0}), ", "),
コード例 #2
0
int cmd(string arg, mixed thing, int silent) {
  class message mess;
  string words,
    word;
  string them_mess,
    extra;
  string *ok_string;
  string *prop;
  object *obs;
  object *net_dead;
  object *multiple_earmuffed;
  object *cannot_see;
  object *ok;
  object *fail;
  object *earmuffed;           /* These people have ear muffed tells */
  object *roleplaying;
  mixed busy;
  
  if (pointerp(thing)) {
    words = arg;
    thing -= ({ 0 });
    if (TP && environment(TP) &&
        function_exists("trap_tell", environment(TP)) &&
        member_array(this_object(), previous_object(-1)) == -1) {
      return (int) environment(TP)->trap_tell(words, thing, 0);
    }
  } else if (!objectp(thing)) {
コード例 #3
0
ファイル: faircombat.c プロジェクト: xxx/cdlib
/*
 * Function name: check_arm
 * Description:   Check that a armour is all right.
 * Arguments:	  arm - The armour in question and takes neccesary actions to
			modify what is wrong.
 * Returns:       Correct armour class.
 */
nomask int
check_arm(object arm)
{
    if (function_exists("check_armour", arm) != "/std/armour")
	return 0;

    return 1;
}
コード例 #4
0
ファイル: faircombat.c プロジェクト: xxx/cdlib
/*
 * Function name: check_wep
 * Description:   Check that a weapon is all right.
 * Arguments:	  wep - The weapon in question and takes neccesary actions to
			modify what is wrong.
 * Returns:       Correct weapon class.
 */
nomask int
check_wep(object wep)
{
    if (function_exists("check_weapon", wep) != "/std/weapon")
	return 0;

    return 1;
}
コード例 #5
0
ファイル: fbody.c プロジェクト: shentino/simud
// Ok, this isn't going to work until we get 3.3.x online.
// Rats. Will look at it later. -- Acius.
int main( string param ) {
   string obname, fname;
   object ob;
   string obfile;
   string curr, buf;
   int line, i;

   if( !param || sscanf(param, "%s->%s", obname, fname) != 2 ) {
      notify_fail( query_verb() + " obj->func\n" );
      return 0;
   }

   ob = find_thing( obname );
   if( !ob ) {
      notify_fail( "Can't find object: " + obname + "\n" );
      return 0;
   }

   obfile = function_exists( fname, ob, FEXISTS_FILENAME );
   line = function_exists( fname, ob, FEXISTS_LINENO );

   if( !obfile || !line ) {
      notify_fail("Can't find the function.\n");
      return 0;
   }

   buf = read_file( obfile, line, 1 );
   for( i = 1; i < 40 && line - i > 0; i++ ) {
      curr = read_file( obfile, line - i );
      if( curr[0..2] == "/**" || curr[0..2] == "///" || curr[0..1] == " *" || curr[0..1] == " */" )
         buf = curr + buf;
      else break;
   }

   buf += read_file( obfile, line+1, 40 );
   i = strstr(buf, "\n}\n", 0);
   if( i > 0 ) buf = buf[..i+2];
   msg("Function " + fname + " in file " + obfile + ":\n" + buf );

   return 1;
}
コード例 #6
0
int cmd( object* things) {
   int i, bonus;
   object form;
   mapping map;
 
   for ( i = 0; i < sizeof( things ); i++ ) {
      if ( !function_exists( "query_artifact_type", things[ i ] ) ) {
         write( "You cannot duplicate "+  things[ i ]->the_short() +".\n" );
         continue;
      }
      if ( (int)this_player()->query_specific_gp( "crafts" ) < COST ) {
         write( "You don't have enough guild points to duplicate "+
               things[ i ]->the_short() +".\n" );
         continue;
      }
      switch( (string)things[ i ]->query_artifact_type() ) {
       case "wand" :
         bonus = (int)this_player()->query_skill_bonus( TURNING );
         break;
       default :
         write( "Oops, something went wrong with "+ things[ i ]->the_short() +
               ".  Please contact a creator.\n" );
        continue;
      }
      if ( bonus < LEVEL ) {
         write( "Your skill is insufficient to make a form from "+
               things[ i ]->the_short() +".\n" );
         continue;
      }
      this_player()->adjust_gp( -COST );
      switch ( (string)things[ i ]->query_artifact_type() ) {
       case "wand" :
         form = clone_object( "/obj/weapon" );
         break;
      }
      map = (mapping)things[ i ]->query_static_auto_load();
      if ( !m_sizeof( map ) ) {
         map = (mapping)things[ i ]->int_query_static_auto_load();
         form->init_static_arg( map );
      } else
      form->init_static_arg( map[ "::" ] );
      map = (mapping)things[ i ]->query_dynamic_auto_load();
      form->init_dynamic_arg( map[ "::" ] );
      form->set_enchant( 0 );
      form->set_value_info( "artifact", 0 );
      if ( bonus < LEVEL + random( LEVEL ) )
         form->remove_property( "artifact form" );
      write( "You duplicate a form from "+ things[ i ]->the_short() +".\n" );
      if ( (int)form->move( this_player() ) != MOVE_OK )
         form->move( environment( this_player() ) );
   }
   return 1;
} /* cmd() */
コード例 #7
0
string query_os_type(){
    string config_file, s1, s2, s3;
    if(function_exists("architecture",load_object("/secure/sefun/sefun"))){
        string arch = lower_case(architecture());
        if(grepp(arch,"windows") || grepp(arch,"cygwin")) return "windows";
        else return "unix";
    }
    if(!file_exists("/secure/cfg/mudos.cfg")) return "unknown";
    config_file = read_matching_line("/secure/cfg/mudos.cfg","mudlib directory :");
    if(!config_file) return "";
    if(sscanf(config_file,"%s:%s:%s",s1,s2,s3) == 3){
        return "windows";
    }
    else return "unix";
}
コード例 #8
0
void display_doc(string docfile) {
    object tmp_ob;

    if (file_exists(sprintf("%s.c", docfile))) {
        if ((tmp_ob = find_object(docfile)) || (tmp_ob = load_object(docfile))) {
            if (function_exists("help", tmp_ob)) {
                tmp_ob->help();
            }
            else {
                printf("A command %s exists, but it has no help.\n", docfile);
            }
        }
    }
    this_player()->more(docfile);
}
コード例 #9
0
ファイル: _identity.c プロジェクト: ehershey/pd
int cmd_identity(string str) {
  string cmd, args, func;

  if (!str)
    SYNTAX;

  if (sscanf(str, "%s %s", cmd, args) != 2)
    cmd = str;

  func = "cmd_identity_"+cmd;

  if (!function_exists(func, this_object()))
    SYNTAX;


  return call_other(this_object(), func, args);
}
コード例 #10
0
ファイル: ff.c プロジェクト: mudchina/fy4
int main(object me, string arg)
{
        object ob;
        string dest, func, file; 
        if(!arg || sscanf(arg, "%s %s", dest, func)!=2 )
                return notify_fail("指令格式:ff <物件> <函数名称>\n"); 
        if( dest=="me" ) ob = me;
        else if( dest=="here" ) ob = environment(me);
        else ob = present(dest, me); 
        if( !ob ) ob = present(dest, environment(me));
        if( !ob ) ob = find_object(resolve_path(me->query("cwd"), dest));
        if( !ob ) return notify_fail("这里没有「" + dest + "」。\n"); 
        file = function_exists(func, ob);
        if(!file)
                printf("物件 %O 并没有定义 %s 这个函数。\n", ob, func);
        else
                printf("物件 %O 的 %s 函数定义在 %s.c。\n", ob, func, file );
        return 1;
} 
コード例 #11
0
ファイル: nocscript_expr_test.cpp プロジェクト: ilovezfs/uhd
    expression::type_t get_type(
            const std::string &name,
            const expression_function::argtype_list_type &arg_types
    ) const {
        if (not function_exists(name, arg_types)) {
            throw uhd::syntax_error(str(
                boost::format("[EXPR_TEXT] get_type(): Unknown function: %s, %d arguments")
                % name % arg_types.size()
            ));
        }

        if (name == "XOR" or name == "AND") {
            return expression::TYPE_BOOL;
        }
        if (name == "ADD") {
            return arg_types[0];
        }
        UHD_THROW_INVALID_CODE_PATH();
    }
コード例 #12
0
mixed cmd(string arg) {
  string word, cur_lang, group;
  object ob, *members, *earmuffed;

  return notify_fail( "This command is no longer used.  Please "
   "use \"group say\" instead.\n" );
   
  /* Don't allow someone with gchat ear muffed to use the command. */
  if( TP->check_earmuffs( "gchat" ) )
     return notify_fail( "You have gchat ear muffed.\n" );

  group = TEAM_HANDLER->query_group(this_player());
  if(!group)
    return notify_fail("You are not a member of any group.\n");
  
  if(!arg)
    return notify_fail("Syntax: gchat <message>\n");

  cur_lang = TP->query_current_language();
  
  if (!LANGUAGE_HAND->query_language_spoken(cur_lang))
    return notify_fail(capitalize(cur_lang)+" is not a spoken language.\n");
  
  if (!LANGUAGE_HAND->query_language_distance(cur_lang))
    return notify_fail(capitalize(cur_lang)+" is not able to spoken at a "
                       "distance.\n");
  
  word = query_word_type(arg, "");
  if (word != "")
    word = word + "ing";
  
  if (TP->query_volume(D_ALCOHOL))
    arg = drunk_speech(arg);
  
  if(function_exists("mangle_tell", environment(TP)))
    arg = environment(TP)->mangle_tell(arg, ob, 0);
  
  /* Who's a member of the group? */
  members = TEAM_HANDLER->query_members(group);
  members -= ({ this_player() });
コード例 #13
0
static int report_function_metadata(const wchar_t *funcname, bool verbose, io_streams_t &streams,
                                    bool metadata_as_comments) {
    const wchar_t *path = L"n/a";
    const wchar_t *autoloaded = L"n/a";
    const wchar_t *shadows_scope = L"n/a";
    wcstring description = L"n/a";
    int line_number = 0;

    if (function_exists(funcname)) {
        auto props = function_get_properties(funcname);
        path = function_get_definition_file(funcname);
        if (path) {
            autoloaded = function_is_autoloaded(funcname) ? L"autoloaded" : L"not-autoloaded";
            line_number = function_get_definition_lineno(funcname);
        } else {
            path = L"stdin";
        }
        shadows_scope = props->shadow_scope ? L"scope-shadowing" : L"no-scope-shadowing";
        function_get_desc(funcname, description);
        description = escape_string(description, ESCAPE_NO_QUOTED);
    }

    if (metadata_as_comments) {
        if (std::wcscmp(path, L"stdin")) {
            streams.out.append_format(L"# Defined in %ls @ line %d\n", path, line_number);
        }
    } else {
        streams.out.append_format(L"%ls\n", path);
        if (verbose) {
            streams.out.append_format(L"%ls\n", autoloaded);
            streams.out.append_format(L"%d\n", line_number);
            streams.out.append_format(L"%ls\n", shadows_scope);
            streams.out.append_format(L"%ls\n", description.c_str());
        }
    }

    return STATUS_CMD_OK;
}
コード例 #14
0
ファイル: ff.c プロジェクト: huangleon/fy2005
int main(object me, string arg)
{
	object ob;
	string dest, func, file;

	if(!arg || sscanf(arg, "%s %s", dest, func)!=2 )
		return notify_fail("╓╕┴ю╕ё╩╜г║ff <╬я╝■> <║п╩¤├√│╞>\n");

	if( dest=="me" ) ob = me;
	else if( dest=="here" ) ob = environment(me);
	else ob = present(dest, me);

	if( !ob ) ob = present(dest, environment(me));
	if( !ob ) ob = find_object(resolve_path(me->query("cwd"), dest));
	if( !ob ) return notify_fail("╒т└я├╗╙╨б╕" + dest + "б╣бг\n");

	file = function_exists(func, ob);
	if(!file)
		printf("╬я╝■ %O ▓в├╗╙╨╢и╥х %s ╒т╕Ў║п╩¤бг\n", ob, func);
	else
		printf("╬я╝■ %O ╡─ %s ║п╩¤╢и╥х╘┌ %s.cбг\n", ob,	func, file );
	return 1;
}
コード例 #15
0
int cmd_help(string topic) {
  string *search_path;
  string *list;
  string arg,name ;
  int i, ii;
  object ob, act_ob;
  string bin, bintopic ;
  
  act_ob = this_player();
  
  if(!topic || topic == "") {
      this_player()->more(STD_HELP, 0 ,1);
      return 1;
    }
 
  topic = lower_case (topic);
 
  switch(topic) {

	case "properties" :	write("[Property document files]\n\n");
				this_player()->force_me("ls " + PROPH_DIR);
				return 1;
				break;
	case "efun"	:
	case "efuns"	:	write("[Efun document files]\n\n");
				this_player()->force_me("ls " + EFUN_DIR);
				return 1;
				break;
	case "lfun"	:
	case "lfuns"	: 	write("[Lfun document files]\n\n");
				this_player()->force_me("ls " + LFUN_DIR);
				return 1; 
				break;
	case "wizhelp"	:	write("[Wizhelp document files]\n\n");
				this_player()->force_me("ls " + WIZH_DIR);
				return 1;
				break;
	case "simul_efuns" :	
	case "simul_efun"  :	write("[Simul_efun document files]\n\n");
				this_player()->force_me("ls " + SE_DIR);
				return 1;
				break;
	case "applies"	:	write("[Applies document files]\n\n");
				this_player()->force_me("ls " + APPLY_DIR);
				return 1; 
				break;
	case "lpc" 	:	write("[LPC document files]\n\n");
				this_player()->force_me("ls " + LPCH_DIR);
				return 1;
				break;
	case "concepts"	:	write("[Concepts document files]\n\n");
				this_player()->force_me("ls " + CONCEPT_DIR);
				return 1;
				break;

   }


    list = DOC_D->get_docs_on(topic, explode((string)this_player()->query("PATH"), ":"));
    if (sizeof(list)) {
        if (sizeof(list)==2) {
            printf("%s: %s\n", list[1], list[0]);
            display_doc(list[1]);
            return 1;
        }
        for (ii=0;ii<sizeof(list);ii+=2) {
            printf("[%d] %s: %s", ii/2+1, list[ii+1], list[ii]);
        }
        printf("Which doc [1-%d,q]? ", sizeof(list)/2);
        input_to("which_doc", 0, list);
        return 1;
    }
  
  if ((ob = present(topic,act_ob)) ||
      (environment(act_ob) && (ob = present(topic,environment(act_ob)))))
    {
      if(function_exists("help",ob))
	{
	  write ("---------------------------------------------------\n");
	  write ("Help for "+topic+" (Object Help)\n");
	  write ("---------------------------------------------------\n");
	  ob->help();
	  return 1;
	}
    }
  write("There is no help available on that topic.\n");
  return 1;
}
コード例 #16
0
/// The functions builtin, used for listing and erasing functions.
int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
    const wchar_t *cmd = argv[0];
    int argc = builtin_count_args(argv);
    functions_cmd_opts_t opts;

    int optind;
    int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
    if (retval != STATUS_CMD_OK) return retval;

    if (opts.print_help) {
        builtin_print_help(parser, streams, cmd, streams.out);
        return STATUS_CMD_OK;
    }

    // Erase, desc, query, copy and list are mutually exclusive.
    bool describe = opts.description ? true : false;
    if (describe + opts.erase + opts.list + opts.query + opts.copy > 1) {
        streams.err.append_format(_(L"%ls: Invalid combination of options\n"), cmd);
        builtin_print_error_trailer(parser, streams.err, cmd);
        return STATUS_INVALID_ARGS;
    }

    if (opts.erase) {
        for (int i = optind; i < argc; i++) function_remove(argv[i]);
        return STATUS_CMD_OK;
    }

    if (opts.description) {
        wchar_t *func;

        if (argc - optind != 1) {
            streams.err.append_format(_(L"%ls: Expected exactly one function name\n"), cmd);
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_INVALID_ARGS;
        }

        func = argv[optind];
        if (!function_exists(func)) {
            streams.err.append_format(_(L"%ls: Function '%ls' does not exist\n"), cmd, func);
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_CMD_ERROR;
        }

        function_set_desc(func, opts.description);
        return STATUS_CMD_OK;
    }

    if (opts.report_metadata) {
        if (argc - optind != 1) {
            streams.err.append_format(_(L"%ls: Expected exactly one function name for --details\n"),
                                      cmd);
            return STATUS_INVALID_ARGS;
        }

        const wchar_t *funcname = argv[optind];
        return report_function_metadata(funcname, opts.verbose, streams, false);
    }

    if (opts.handlers) {
        maybe_t<event_type_t> type_filter;
        if (opts.handlers_type) {
            type_filter = event_type_for_name(opts.handlers_type);
            if (! type_filter) {
                streams.err.append_format(_(L"%ls: Expected generic | variable | signal | exit | job-id for --handlers-type\n"),
                        cmd);
                return STATUS_INVALID_ARGS;
            }
        }
        event_print(streams, type_filter);
        return STATUS_CMD_OK;
    }

    // If we query with no argument, just return false.
    if (opts.query && argc == optind) {
        return STATUS_CMD_ERROR;
    }

    if (opts.list || argc == optind) {
        wcstring_list_t names = function_get_names(opts.show_hidden);
        std::sort(names.begin(), names.end());
        bool is_screen = !streams.out_is_redirected && isatty(STDOUT_FILENO);
        if (is_screen) {
            wcstring buff;
            for (size_t i = 0; i < names.size(); i++) {
                buff.append(names.at(i));
                buff.append(L", ");
            }
            streams.out.append(reformat_for_screen(buff));
        } else {
            for (size_t i = 0; i < names.size(); i++) {
                streams.out.append(names.at(i).c_str());
                streams.out.append(L"\n");
            }
        }

        return STATUS_CMD_OK;
    }

    if (opts.copy) {
        wcstring current_func;
        wcstring new_func;

        if (argc - optind != 2) {
            streams.err.append_format(_(L"%ls: Expected exactly two names (current function name, "
                                        L"and new function name)\n"),
                                      cmd);
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_INVALID_ARGS;
        }
        current_func = argv[optind];
        new_func = argv[optind + 1];

        if (!function_exists(current_func)) {
            streams.err.append_format(_(L"%ls: Function '%ls' does not exist\n"), cmd,
                                      current_func.c_str());
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_CMD_ERROR;
        }

        if (!valid_func_name(new_func) || parser_keywords_is_reserved(new_func)) {
            streams.err.append_format(_(L"%ls: Illegal function name '%ls'\n"), cmd,
                                      new_func.c_str());
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_INVALID_ARGS;
        }

        // Keep things simple: don't allow existing names to be copy targets.
        if (function_exists(new_func)) {
            streams.err.append_format(
                _(L"%ls: Function '%ls' already exists. Cannot create copy '%ls'\n"), cmd,
                new_func.c_str(), current_func.c_str());
            builtin_print_error_trailer(parser, streams.err, cmd);
            return STATUS_CMD_ERROR;
        }

        if (function_copy(current_func, new_func)) return STATUS_CMD_OK;
        return STATUS_CMD_ERROR;
    }

    int res = STATUS_CMD_OK;
    for (int i = optind; i < argc; i++) {
        if (!function_exists(argv[i])) {
            res++;
        } else {
            if (!opts.query) {
                if (i != optind) streams.out.append(L"\n");
                const wchar_t *funcname = argv[optind];
                report_function_metadata(funcname, opts.verbose, streams, true);
                streams.out.append(functions_def(funcname));
            }
        }
    }

    return res;
}
コード例 #17
0
ファイル: MQ2DataAPI.cpp プロジェクト: Xackery/macroquest2
bool EvaluateDataExpression(MQ2TYPEVAR& Result, PCHAR pStart, PCHAR pIndex, bool function_allowed = false)
{
	if (!Result.Type)
	{
		if (!gWarning) {//if they have warnings turned on in the macro, we will disregard checking the map
			if (gUndeclaredVars.find(pStart) != gUndeclaredVars.end())
				return false;//its a undefined variable no point in moving on further.
		}
		if (PMQ2DATAITEM DataItem = FindMQ2Data(pStart))
		{
			if (!DataItem->Function(pIndex, Result))
			{
				return false;
			}
		}
		else if (PDATAVAR DataVar = FindMQ2DataVariable(pStart))
		{
			if (pIndex[0])
			{
				if (DataVar->Var.Type == pArrayType)
				{
					if (!((CDataArray*)DataVar->Var.Ptr)->GetElement(pIndex, Result))
					{
						return false;
					}
				}
			}
			else
				Result = DataVar->Var;
		}
		else if (function_allowed && function_exists(pStart))
		{
			if (!call_function(pStart, pIndex))
				return false;
			strcpy_s(DataTypeTemp, gMacroStack->Return);
			Result.Ptr = &DataTypeTemp[0];
			Result.Type = pStringType;
		}
		else
		{
			if (gMacroBlock) {
				if (gWarning) {
					DumpWarning(pStart,gMacroBlock->CurrIndex);
				}
				gUndeclaredVars[pStart] = gMacroBlock->CurrIndex;
			}
			return false;
		}
	}
	else
	{
		int result = FindMacroDataMember(Result.Type, Result, pStart, pIndex);
		if (result < 0)
		{
			MQ2DataError("No such '%s' member '%s'", Result.Type->GetName(), pStart);
		}
		if (result <= 0)
			return false;
	}
	return true;
}
コード例 #18
0
ファイル: complete.c プロジェクト: brentdax/fishfish
/**
   Complete the specified command name. Search for executables in the
   path, executables defined using an absolute path, functions,
   builtins and directories for implicit cd commands.

   \param cmd the command string to find completions for

   \param comp the list to add all completions to
*/
static void complete_cmd( const wchar_t *cmd,
						  array_list_t *comp,
						  int use_function,
						  int use_builtin,
						  int use_command )
{
	wchar_t *path;
	wchar_t *path_cpy;
	wchar_t *nxt_path;
	wchar_t *state;
	array_list_t possible_comp;
	wchar_t *nxt_completion;

	wchar_t *cdpath = env_get(L"CDPATH");
	wchar_t *cdpath_cpy = wcsdup( cdpath?cdpath:L"." );

	if( (wcschr( cmd, L'/') != 0) || (cmd[0] == L'~' ) )
	{

		if( use_command )
		{

			if( expand_string( 0,
							   wcsdup(cmd),
							   comp,
							   ACCEPT_INCOMPLETE | EXECUTABLES_ONLY ) != EXPAND_ERROR )
			{
				complete_cmd_desc( cmd, comp );
			}
		}
	}
	else
	{
		if( use_command )
		{

			path = env_get(L"PATH");
			if( path )
			{

				path_cpy = wcsdup( path );

				for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
				     nxt_path != 0;
				     nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
				{
					int prev_count;
					int i;
					int path_len = wcslen(nxt_path);
					int add_slash;

					if( !path_len )
					{
						continue;
					}

					add_slash = nxt_path[path_len-1]!=L'/';
					nxt_completion = wcsdupcat( nxt_path,
												add_slash?L"/":L"",
												cmd );
					if( ! nxt_completion )
						continue;

					prev_count = al_get_count( comp );

					if( expand_string( 0,
									   nxt_completion,
									   comp,
									   ACCEPT_INCOMPLETE |
									   EXECUTABLES_ONLY ) != EXPAND_ERROR )
					{
						for( i=prev_count; i<al_get_count( comp ); i++ )
						{
							completion_t *c = (completion_t *)al_get( comp, i );
							if(c->flags & COMPLETE_NO_CASE )
							{
								c->completion = halloc_wcsdup( comp, c->completion + path_len + add_slash );
							}
						}
					}
				}
				free( path_cpy );
				complete_cmd_desc( cmd, comp );
			}
		}

		/*
		  These return the original strings - don't free them
		*/

		al_init( &possible_comp );

		if( use_function )
		{
			function_get_names( &possible_comp, cmd[0] == L'_' );
			complete_strings( comp, cmd, 0, &complete_function_desc, &possible_comp, 0 );
		}

		al_truncate( &possible_comp, 0 );

		if( use_builtin )
		{
			builtin_get_names( &possible_comp );
			complete_strings( comp, cmd, 0, &builtin_get_desc, &possible_comp, 0 );
		}
		al_destroy( &possible_comp );

	}

	if( use_builtin || (use_function && function_exists( L"cd") ) )
	{
		/*
		  Tab complete implicit cd for directories in CDPATH
		*/
		if( cmd[0] != L'/' && ( wcsncmp( cmd, L"./", 2 )!=0) )
		{
			for( nxt_path = wcstok( cdpath_cpy, ARRAY_SEP_STR, &state );
				 nxt_path != 0;
				 nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
			{
				wchar_t *nxt_completion=
					wcsdupcat( nxt_path,
							   (nxt_path[wcslen(nxt_path)-1]==L'/'?L"":L"/"),
							   cmd );
				if( ! nxt_completion )
				{
					continue;
				}

				if( expand_string( 0,
								   nxt_completion,
								   comp,
								   ACCEPT_INCOMPLETE | DIRECTORIES_ONLY ) != EXPAND_ERROR )
				{
				}
			}
		}
	}

	free( cdpath_cpy );
}
コード例 #19
0
ファイル: ext_function.cpp プロジェクト: scottmac/hiphop-dev
bool f_function_exists(CStrRef function_name) {
  return function_exists(function_name);
}
コード例 #20
0
ファイル: builtin-functions.cpp プロジェクト: 2bj/hhvm
/**
 * invokeHandler returns true if any autoload handlers were executed,
 * false otherwise. When this function returns true, it is the caller's
 * responsibility to check if the given class or interface exists.
 */
bool AutoloadHandler::invokeHandler(const String& className,
                                    bool forceSplStack /* = false */) {

  if (className.empty()) {
    return false;
  }

  if (!m_map.isNull()) {
    ClassExistsChecker ce;
    Result res = loadFromMap(className, s_class, true, ce);
    if (res == ContinueAutoloading) {
      if (ce(className)) return true;
    } else {
      if (res != Failure) return res == Success;
    }
  }
  // If we end up in a recursive autoload loop where we try to load the
  // same class twice, just fail the load to mimic PHP as many frameworks
  // rely on it unless we are forcing a restart (due to spl_autoload_call)
  // in which case autoload is allowed to be reentrant.
  if (!forceSplStack) {
    if (m_loading.exists(className)) { return false; }
    m_loading.add(className, className);
  } else {
    // We can still overflow the stack if there is a loop when using
    // spl_autoload_call directly, but this behavior matches the reference
    // implementation.
    m_loading.append(className);
  }

  // Make sure state is cleaned up from this load; autoloading of arbitrary
  // code below can throw
  SCOPE_EXIT {
    String l_className = m_loading.pop();
    assert(l_className == className);
  };

  Array params = PackedArrayInit(1).append(className).toArray();
  if (!m_spl_stack_inited && !forceSplStack) {
    if (function_exists(s___autoload)) {
      invoke(s___autoload, params, -1, true, false);
      return true;
    }
    return false;
  }
  if (!m_spl_stack_inited || m_handlers.empty()) {
    return false;
  }
  Object autoloadException;
  for (const HandlerBundle& hb : m_handlers) {
    try {
      vm_call_user_func_cufiter(*hb.m_cufIter, params);
    } catch (Object& ex) {
      assert(ex.instanceof(SystemLib::s_ExceptionClass));
      if (autoloadException.isNull()) {
        autoloadException = ex;
      } else {
        Object cur = ex;
        Variant next = cur->o_get(s_previous, false, s_exception);
        while (next.isObject()) {
          cur = next.toObject();
          next = cur->o_get(s_previous, false, s_exception);
        }
        cur->o_set(s_previous, autoloadException, s_exception);
        autoloadException = ex;
      }
    }
    if (Unit::lookupClass(className.get()) != nullptr) {
      break;
    }
  }
  if (!autoloadException.isNull()) {
    throw autoloadException;
  }
  return true;
}
コード例 #21
0
ファイル: wizard.c プロジェクト: shentino/simud
/** A highly unusual function that lets you generate and execute a snippet of code
 * that will execute. Just pass in the snippet. Warning: This can't handle recursive
 * calls; the old call will be trashed by the new.
 *
 * \return The return value of the call, converted to a string.
 */
string exec_call(string code) {
   string buf;
   string obj, func, func_name, err;
   mixed param, ret;
   string fname;

   if( !this_player() )
      raise_error("exec_call must have a valid this_player() using it");

   fname = this_player()->make_path_absolute( EXEC_OBJ );

   if( ret = find_object(fname) ) destruct(ret);
   if( file_exists(fname + ".c") && !rm( fname + ".c" ) )
      return "Unable to clear out the old "+fname+" to execute the call (uid="+getuid(this_object())+").";

   buf = HEADER + EXEC_MACROS + "\ndo_call() {\n";

   if( sscanf(code, "%s->%s", obj, func) == 2 ) {
      func_name = func;
      if( sscanf(func, "%~s(%~s)") != 2 ) {
         code = func;
         if( sscanf( code, "%s %d", func, param) == 2)
            func = (func_name = func) + "( " + param + " );";
         else
         if( sscanf( code, "%s %s", func, param) == 2)
            func = (func_name = func) + "( \"" + param + "\" );";
         else
            func = (func_name = code) + "();";
      }
      else sscanf( func_name, "%s(%~s)", func_name );
   }
   else if( sscanf(code, "%s %s(%s)%~s", obj, func, param) == 4 && member(func, ' ') < 0 )
      func = (func_name = func) + "( " + param +" );";
   else if( sscanf(code, "%s %s %d", obj, func, param) == 3 )
      func = (func_name = func) + "( " + param + " );";
   else if( sscanf(code, "%s %s %s", obj, func, param) == 3 )
      func = (func_name = func) + "( \"" + param + "\" );";
   else if( sscanf(code, "%s %s", obj, func) == 2 )
      func = (func_name = func) + "();";
   else raise_error("Ill formatted exec_call");

   if( !find_thing(obj) ) return "No such object: "+obj;
   if( !function_exists(func_name, find_thing(obj)) && !function_exists("catch_call", find_thing(obj)) )
      return "No such function: "+obj+"->"+func_name+"()";

//   if( sscanf(func, "%s(%s)%s", ret, ret, ret) != 3 ) func += "();";

   if( func[<1] != ';' ) func += ";";
   buf += "   object ob;\n";
   buf += "   ob = find_thing(\""+obj+"\");\n";
   buf += "   if( !ob ) return \"Could not find object "+obj+"!\";\n";
   buf += "   return ob->"+func+"\n}\n";

   write_file( fname + ".c", buf );
   err = catch(ret = load_object( fname ));
   if( err ) {
      msg("==> [Call Error] "+err);
      return "<Invalid>";
   }

   seteuid( getuid(this_player()) );
   export_uid( ret );
   seteuid( getuid(this_object()) );
   err = catch(ret = fname->do_call());
   if( err ) {
      msg("==> [Call Runtime Error] "+err);
      return "<Invalid>";
   }

   return as_lpc(ret);
}