Exemplo n.º 1
0
static int preprocess()
{
	const char* flag = arg_getflag();
	while (flag != NULL)
	{
		if (matches(flag, "--file"))
		{
			g_filename = arg_getflagarg();
			if (g_filename == NULL)
			{
				puts("** Usage: --file filename");
				puts(HELP_MSG);
				return 1;
			}
		}
		else if (matches(flag, "--os"))
		{
			const char* os = arg_getflagarg();
			if (os == NULL || !os_set(os))
			{
				puts("** Usage: --os osname");
				puts(HELP_MSG);
				return 1;
			}
		}
		else if (matches(flag, "--version"))
		{
			printf("premake (Premake Build Script Generator) %s\n", VERSION);
		}

		flag = arg_getflag();
	}

	return 1;
}
Exemplo n.º 2
0
static void buildOptionsTable()
{
	const char* flag;
	const char* arg;

	lua_newtable(L);

	arg_reset();
	flag = arg_getflag();
	while (flag != NULL)
	{
		if (strncmp(flag, "--", 2) == 0)
			flag += 2;

		lua_pushstring(L, flag);

		/* If the flag has an argument, push that too */
		arg = arg_getflagarg();
		if (arg != NULL)
			lua_pushstring(L, arg);
		else
			lua_pushboolean(L, 1);

		lua_settable(L, -3);
		flag = arg_getflag();
	}

	lua_setglobal(L, "options");
}
Exemplo n.º 3
0
int script_docommand(const char* cmd)
{
	char buffer[512];
	const char* arg;

	/* Trim off the leading '--' */
	if (strncmp(cmd, "--", 2) == 0)
		cmd += 2;

	/* Look for a handler */
	strcpy(buffer, "do");
	strcat(buffer, cmd);
	lua_getglobal(L, buffer);
	if (!lua_isfunction(L, -1))
	{
		/* Fall back to the default handler */
		lua_getglobal(L, "docommand");
		if (!lua_isfunction(L, -1))
		{
			lua_pop(L, 1);
			return 0;
		}
	}

	/* Push the command and arguments onto the stack */
	lua_pushstring(L, cmd);
	arg = arg_getflagarg();
	if (arg != NULL)
		lua_pushstring(L, arg);
	else
		lua_pushnil(L);

	lua_call(L, 2, 0);
	return 1;
}
Exemplo n.º 4
0
static int postprocess()
{
	int noScriptWarning = 0;

	const char* flag = arg_getflag();
	while (flag != NULL)
	{
		if (g_hasScript && !script_export())
			return 0;

		if (matches(flag, "--help"))
		{
			showUsage();
		}
		else if (matches(flag, "--version"))
		{
			/* ignore quietly */
		}
		else if (matches(flag, "--file"))
		{
			arg_getflagarg();
		}
		else
		{
			if (!g_hasScript)
			{
				if (!noScriptWarning)
				{
					puts("** No Premake script found!");
					noScriptWarning = 1;
				}
			}
			else
			{
				script_docommand(flag);
			}
		}

		flag = arg_getflag();
	}

	return 1;
}