Exemplo n.º 1
0
void testing_$CHOICE_expand(bool verbose)
{
	if (verbose) {
		fprintf( stdout, "\n----- testing_$CHOICE_expand ----\n\n");
	}

	REQUIRE( expand("$CHOICE(0,AA,BB,CC,DD)") == "AA" );
	REQUIRE( expand("$CHOICE(1,AA,BB,CC,DD)") == "BB" );
	REQUIRE( expand("$CHOICE(2,AA,BB,CC,DD)") == "CC" );
	REQUIRE( expand("$CHOICE(3,AA,BB,CC,DD)") == "DD" );
	//REQUIRE( expand("$CHOICE(4,AA,BB,CC,DD)") == "" );

	REQUIRE( expand("$CHOICE(0,List6c)") == "aa" );
	REQUIRE( expand("$CHOICE(2,List6c)") == "cc" );
	REQUIRE( expand("$CHOICE(3,List6c)") == "dd" );
	REQUIRE( expand("$CHOICE(5,List6c)") == "ff" );

	REQUIRE( expand("$CHOICE(VANILLA,List6c)") == "ff" );
	REQUIRE( expand_as("MASTER", "$CHOICE(VANILLA,List6c)") == "ZA" );
	REQUIRE( expand_lcl("LOWER", "$CHOICE(VANILLA,List6c)") == "ee" );
	REQUIRE( expand_lcl_as("LOWER", "MASTER", "$CHOICE(VANILLA,List6c)") == "ZKM" );

	insert_macro("CHOCOLATE", "$(VANILLA)-2", TestingMacroSet,  TestMacroSource, def_ctx);
	REQUIRE( lookup("CHOCOLATE") == "$(VANILLA)-2");
	REQUIRE( expand("$CHOICE(CHOCOLATE,List6c)") == "dd" );
	REQUIRE( expand_as("MASTER", "$CHOICE(CHOCOLATE,List6c)") == "YY" );
	REQUIRE( expand_lcl("LOWER", "$CHOICE(CHOCOLATE,List6c)") == "cc" );
	REQUIRE( expand_lcl_as("LOWER", "MASTER", "$CHOICE(CHOCOLATE,List6c)") == "XX" );
}
Exemplo n.º 2
0
void
editor(int descr, dbref player, const char *command)
{
	dbref program;
	int arg[MAX_ARG + 1];
	char buf[BUFFER_LEN];
	const char *word[MAX_ARG + 1];
	int i, j;					/* loop variables */

	program = PLAYER_CURR_PROG(player);

	/* check to see if we are insert mode */
	if (PLAYER_INSERT_MODE(player)) {
		insert(player, command);	/* insert it! */
		return;
	}
	/* parse the commands */
	for (i = 0; i <= MAX_ARG && *command; i++) {
		while (*command && isspace(*command))
			command++;
		j = 0;
		while (*command && !isspace(*command)) {
			buf[j] = *command;
			command++, j++;
		}

		buf[j] = '\0';
		word[i] = alloc_string(buf);
		if ((i == 1) && !string_compare(word[0], "def")) {
			if (word[1] && (word[1][0] == '.' || (word[1][0] >= '0' && word[1][0] <= '9'))) {
				notify(player, "Invalid macro name.");
				return;
			}
			while (*command && isspace(*command))
				command++;
			word[2] = alloc_string(command);
			if (!word[2])
				notify(player, "Invalid definition syntax.");
			else {
				if (insert_macro(word[1], word[2], player, &macrotop)) {
					notify(player, "Entry created.");
				} else {
					notify(player, "That macro already exists!");
				}
			}
			for (; i >= 0; i--) {
				if (word[i])
					free((void *) word[i]);
			}
			return;
		}
		arg[i] = atoi(buf);
		if (arg[i] < 0) {
			notify(player, "Negative arguments not allowed!");
			for (; i >= 0; i--) {
				if (word[i])
					free((void *) word[i]);
			}
			return;
		}
	}
	i--;
	while ((i >= 0) && !word[i])
		i--;
	if (i < 0) {
		return;
	} else {
		switch (word[i][0]) {
		case KILL_COMMAND:
			if (!Wizard(player)) {
				notify(player, "I'm sorry Dave, but I can't let you do that.");
			} else {
				if (kill_macro(word[0], player, &macrotop))
					notify(player, "Macro entry deleted.");
				else
					notify(player, "Macro to delete not found.");
			}
			break;
		case SHOW_COMMAND:
			list_macros(word, i, player, 1);
			break;
		case SHORTSHOW_COMMAND:
			list_macros(word, i, player, 0);
			break;
		case INSERT_COMMAND:
			do_insert(player, program, arg, i);
			notify(player, "Entering insert mode.");
			break;
		case DELETE_COMMAND:
			do_delete(player, program, arg, i);
			break;
		case QUIT_EDIT_COMMAND:
			do_quit(player, program);
			notify(player, "Editor exited.");
			break;
		case COMPILE_COMMAND:
			/* compile code belongs in compile.c, not in the editor */
			do_compile(descr, player, program, 1);
			notify(player, "Compiler done.");
			break;
		case LIST_COMMAND:
			do_list(player, program, arg, i);
			break;
		case EDITOR_HELP_COMMAND:
			spit_file(player, EDITOR_HELP_FILE);
			break;
		case VIEW_COMMAND:
			val_and_head(player, arg, i);
			break;
		case UNASSEMBLE_COMMAND:
			disassemble(player, program);
			break;
		case NUMBER_COMMAND:
			toggle_numbers(player, arg, i);
			break;
		case PUBLICS_COMMAND:
			list_publics(descr, player, arg, i);
			break;
		default:
			notify(player, "Illegal editor command.");
			break;
		}
	}
	for (; i >= 0; i--) {
		if (word[i])
			free((void *) word[i]);
	}
}
Exemplo n.º 3
0
// Populate the testing MACRO_SET with values that we can lookup and expand
// in various ways.
//
static void insert_testing_macros(const char * local, const char * subsys)
{
	static const struct {
		const char * key;
		const char * val;
	} atbl[] = {
		{"FOO", "bar"},
		{"MASTER.foo", "mar"},
		{"MASTER.bar", "hi"},
		{"lower.bar", "'lo"},

		{"lower.pid_snapshot_interval", "12"},
		{"LOWER.VANILLA", "4"},
		{"MASTER.STANDARD", "2"},

		{"RELEASE_DIR", "/condor/test"},
		{"TILDE", "/condor/test"},
		{"LOWER.LOCAL_DIR", "/condor/lower"},
		{"MASTER.SPOOL", "$(LOCAL_DIR)/mspool"},
#ifdef ALLOW_SUBSYS_LOCAL_HEIRARCHY
		{"MASTER.lower.history", "$(SPOOL)/mlhistory"},
		{"lower.master.history", "$(SPOOL)/lmhistory"},
#endif

		// for $F tests
		{"fileBase", "base"},
		{"fileExt", "ex"},
		{"fileDirs", "/dur/der"},
		{"fileSimple", "simple.dat"},
		{"fileLong", "Now is the time for all good men."},
		{"fileCompound", "$(fileDirs)/$(fileBase).$(FileExt)"},
		{"fileAbs", "/one/two/three.for"},
		{"urlAbs", "file:/one/two/three.for"},
		{"fileAbsQuoted", "\"/one/two/three.for\""},
		{"fileRel", "ein/zwei/drei.fir"},
		{"fileRelSpaces", "\"ein/zw ei/dr ei.fir\""},
		{"fileCurRel", "./here"},
		{"fileCurRel2", "./uno/dos.tres"},
#ifdef WIN32
		{"wfileAbs", "c:\\one\\two\\three.for"},
		{"wfileAbsQuoted", "\"c:\\one\\two\\three.for\""},
		{"wfileRel", "ein\\zwei\\drei.fir"},
		{"wfileRelSpaces", "\"ein\\zw ei\\dr ei.fir\""},
		{"wfileCurRel", ".\\here"},
		{"wfileCurRel2", ".\\uno\\dos.tres"},
#endif

		// for $F regressions
		{"Items5", "aa bb cc dd ee"},
		{"Items5Quoted", "\"aa bb cc dd ee\""},
		{"List6c", "aa,bb, cc,dd,ee,ff"},
		{"MASTER.List6c", "JMK,Vvv,XX,YY,ZKM,ZA"},
		{"List6cfq", "$Fq(list6c)"},

		// for $INT and $REAL tests
		{"DoubleVanilla", "$(VANILLA)*2"},
		{"HalfVanilla", "$(VANILLA)/2.0"},
		{"StandardMinusVM", "$(STANDARD)-$(VM)"},
	};

	MACRO_EVAL_CONTEXT ctx = { local, subsys, false, 2 };

	insert_source("Insert", TestingMacroSet, TestMacroSource);

	for (size_t ii = 0; ii < COUNTOF(atbl); ++ii) {
		TestMacroSource.line = ii;
		insert_macro(atbl[ii].key, atbl[ii].val, TestingMacroSet,  TestMacroSource, ctx);
	}

}