예제 #1
0
const char* platform_mask_getname(MaskHandle data)
{
	strcpy(buffer, path_getdir(data->mask));
	if (strlen(buffer) > 0)
		strcat(buffer, "/");
	strcat(buffer, data->entry->d_name);
	return buffer;
}
예제 #2
0
MaskHandle platform_mask_open(const char* mask)
{
	const char* path = path_getdir(mask);
	if (strlen(path) == 0)
		path = ".";
		
	MaskHandle data = ALLOCT(struct PlatformMaskData);
	data->handle = opendir(path);
	data->mask = (char*)malloc(strlen(mask) + 1);
	strcpy(data->mask, mask);
	return data;
}
예제 #3
0
int io_openfile(const char* path)
{
	/* Make sure that all parts of the path exist */
	io_mkdir(path_getdir(path));

	/* Now I can open the file */
	file = fopen(path, "w");
	if (file == NULL)
	{
		printf("** Unable to open file '%s' for writing\n", path);
		return 0;
	}
	else
	{
		return 1;
	}
}
예제 #4
0
static int dopackage(lua_State* L)
{
	const char* oldScript;
	char oldcwd[8192];
	char filename[8192];
	int result;

	/* Clear the current global so included script can create a new one */
	lua_pushnil(L);
	lua_setglobal(L, "package");

	/* Remember the current state of things so I can restore after script runs */
	oldScript = currentScript;
	strcpy(oldcwd, io_getcwd());

	/* Try to locate the script file */
	strcpy(filename, lua_tostring(L, 1));
	if (!io_fileexists(filename))
	{
		strcpy(filename, path_join("", lua_tostring(L, 1), "lua"));
	}
	if (!io_fileexists(filename))
	{
		strcpy(filename, path_join(lua_tostring(L, 1), "premake.lua", ""));
	}

	if (!io_fileexists(filename))
	{
		lua_pushstring(L, "Unable to open package '");
		lua_pushvalue(L, 1);
		lua_pushstring(L, "'");
		lua_concat(L, 3);
		lua_error(L);
	}

	currentScript = filename;
	io_chdir(path_getdir(filename));

	result = lua_dofile(L, path_getname(filename));
	
	/* Restore the previous state */
	currentScript = oldScript;
	io_chdir(oldcwd);
	
	return 0;
}
예제 #5
0
static const char* filterLinksForPaths(const char* name)
{
	int i = prj_find_package(name);
	if (i >= 0)
	{
		const char* lang = prj_get_language_for(i);
		if (matches(lang, "c++") || matches(lang, "c"))
		{
			const char* target = prj_get_target_for(i);
			const char* dir = path_getdir(target);
			if (!prj_has_libpath(dir))
			{
				return dir;
			}
		}
	}
	return NULL;
}
예제 #6
0
int main(int argc, char** argv)
{
	/* If no args are specified... */
	if (argc == 1)
	{
		puts(HELP_MSG);
		return 1;
	}

	/* Set defaults */
	os_detect();
	g_filename = DEFAULT;
	g_cc       = NULL;
	g_dotnet   = NULL;
	g_verbose  = 0;

	/* Process any options that will effect script processing */
	arg_set(argc, argv);
	if (!preprocess())
		return 1;

	/* chdir() to the directory containing the project script, so that
	 * relative paths may be used in the script */
	io_chdir(path_getdir(g_filename));

	/* Now run the script */
	g_hasScript = script_run(g_filename);
	if (g_hasScript < 0)
	{
		puts("** Script failed to run, ending.");
		return 1;
	}

	/* Process any options that depend on the script output */
	arg_reset();
	if (!postprocess())
		return 1;

	/* All done */
	if (g_hasScript)
		script_close();
	prj_close();
	return 0;
}
예제 #7
0
static int matchfiles(lua_State* L)
{
	int numArgs, i;
	const char* pkgPath;

	/* Get the current package path */
	lua_getglobal(L, "package");
	lua_pushstring(L, "path");
	lua_gettable(L, -2);
	pkgPath = lua_tostring(L, -1);
	lua_pop(L, 2);

	/* If path is same as current, I can ignore it */
	if (matches(path_getdir(currentScript), pkgPath))
		pkgPath = "";

	/* Create a table to hold the results */
	lua_newtable(L);

	/* Read and scan for each mask in turn */
	numArgs = lua_gettop(L) - 1;
	for (i = 1; i <= numArgs; ++i)
	{
		const char* mask = luaL_checkstring(L, i);
		const char* maskWithPath = path_combine(pkgPath, mask);
		io_mask_open(maskWithPath);
		while(io_mask_getnext())
		{
			if (io_mask_isfile())
			{
				const char* name = io_mask_getname();
				if (strlen(pkgPath) > 0)
					name += strlen(pkgPath) + 1;
				lua_pushstring(L, name);
				lua_rawseti(L, -2, luaL_getn(L, -2) + 1);
			}
		}
		io_mask_close();
	}

	return 1;
}
예제 #8
0
static void buildNewProject()
{
	lua_newtable(L);

	lua_pushstring(L, "name");
	lua_pushstring(L, "MyProject");
	lua_settable(L, -3);

	lua_pushstring(L, "path");
	lua_pushstring(L, path_getdir(currentScript));
	lua_settable(L, -3);

	/* Hook "index" metamethod so I can tell when the config list changes */
	lua_newtable(L);
	lua_pushstring(L, "__newindex");
	lua_pushcfunction(L, setconfigs);
	lua_settable(L, -3);
	lua_setmetatable(L, -2);

	/* Set default values */
	lua_pushstring(L, "script");
	lua_pushstring(L, path_getname(currentScript));
	lua_settable(L, -3);

	lua_pushstring(L, "bindir");
	lua_pushstring(L, ".");
	lua_settable(L, -3);

	lua_pushstring(L, "libdir");
	lua_pushstring(L, ".");
	lua_settable(L, -3);

	lua_pushstring(L, "configs");
	lua_newtable(L);
	lua_pushstring(L, "Debug");
	lua_rawseti(L, -2, 1);
	lua_pushstring(L, "Release");
	lua_rawseti(L, -2, 2);
	lua_settable(L, -3);

	lua_setglobal(L, "project");
}
예제 #9
0
char* util_getexedir(char* outpath)
{
    GetModuleFileName(NULL, outpath, DH_PATH_MAX);
    path_getdir(outpath, outpath);
    return path_norm(outpath, outpath);
}
예제 #10
0
void vs_list_files(const char* path, int stage)
{
	int i;
	const char* pchHeader = prj_get_pch_header();
	const char* pchSource = prj_get_pch_source();
	const char* trimPrefix = prj_get_trimprefix();

	const char* ptr = path;
	while (strncmp(ptr, "../", 3) == 0)
		ptr += 3;

	ptr = strchr(ptr, '/');
	while (ptr != NULL) 
		ptr = strchr(ptr + 1, '/');

	ptr = strrchr(path, '/');
	ptr = (ptr == NULL) ? (char*)path : ptr + 1;

	switch (stage)
	{
	case WST_OPENGROUP:
		if (strlen(path) > 0 && !matches(ptr, "..") && (!trimPrefix || strncmp(path, trimPrefix, strlen(trimPrefix)) == 0))
		{
			tag_open("Filter");
			tag_attr("Name=\"%s\"", ptr);
			tag_attr("Filter=\"\"");
		}
		break;

	case WST_CLOSEGROUP:
		if (strlen(path) > 0 && !matches(ptr, "..") && (!trimPrefix || strncmp(path, trimPrefix, strlen(trimPrefix)) == 0))
			tag_close("Filter", 1);
		break;

	case WST_SOURCEFILE:
		tag_open("File");
		tag_attr_open("RelativePath");
		if (path[0] != '.')
			io_print(".\\");
		io_print(path_translate(path, "windows"));
		tag_attr_close();

		/* Add FileConfiguration section if this is a special PCH file, or
		   if it's a custom-built .asm */
		if (matches(path_getname(path), pchSource) || endsWith(path, ".asm")
			|| (prj_is_kind("cxxtestgen") && endsWith(path, ".h")))
		{
			for (i = 0; i < prj_get_numconfigs(); ++i)
			{
				prj_select_config(i);

				tag_open("FileConfiguration");
				tag_attr("Name=\"%s|Win32\"", prj_get_cfgname());

				if (endsWith(path, ".asm"))
				{
					tag_open("Tool");
					tag_attr("Name=\"VCCustomBuildTool\"");
					tag_attr("Description=\"Assembling $(InputPath)\"");

					{
					// note: copy into our strings because path_* use static buffers.
					char nasm_path[512];	// PATH_MAX isn't defined
					char input_dir[512];
					strcpy(nasm_path, path_translate(prj_get_nasmpath(), "windows"));
					// note: NASM chokes on -i"path" and says "no input file".
					// we therefore use the *relative* input directory, not VC's $(InputDir) -
					// this is more likely not to contain a space in directory name.
					strcpy(input_dir, path_translate(path_getdir(path) , "windows"));
					// required - NASM just concatenates include path and filename.
					strcat(input_dir, "\\");
					tag_attr("CommandLine=\"%s -i %s -f win32 &quot;$(InputPath)&quot; -o &quot;$(IntDir)\\$(InputName).obj&quot;\"",
						nasm_path, input_dir);
					}
					tag_attr("Outputs=\"$(IntDir)\\$(InputName).obj\"");
					tag_close("Tool", 0);
				}
				else if (prj_is_kind("cxxtestgen") && endsWith(path, ".h"))
				{
					char *targetname = strdup(path_swapextension(path, ".h", ".cpp"));
					char *testoptions = strdup(prj_get_cxxtest_options());
					
					// use relative file path instead of $(InputPath) to bypass cxxtestgen command line argument parsing weirdness
					const char *sourcename = path;

					tag_open("Tool");
					tag_attr("Name=\"VCCustomBuildTool\"");
					tag_attr("Description=\"Generating %s\"", targetname);
					tag_attr("CommandLine=\"%s%s --part %s -o &quot;%s&quot; &quot;%s&quot;\"",
						endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"",
						path_translate(prj_get_cxxtestpath(), "windows"),
						testoptions,
						targetname,
						sourcename
					);
					tag_attr("Outputs=\"%s\"", targetname);
					tag_close("Tool", 0);

					free(targetname);
					free(testoptions);
				}
				else /* (.asm doesn't need PCH) */
				{
					tag_open("Tool");
					tag_attr("Name=\"VCCLCompilerTool\"");
					tag_attr("UsePrecompiledHeader=\"1\"");
					tag_close("Tool", 0);
				}
				tag_close("FileConfiguration", 1);
			}
		}

		tag_close("File", 1);

		break;
	}
}
예제 #11
0
파일: engine.c 프로젝트: septag/darkhammer
result_t eng_init(const struct init_params* params)
{
    result_t r = RET_OK;

    ASSERT(g_eng == NULL);
    g_eng = (struct engine*)ALLOC(sizeof(struct engine), 0);
    if (g_eng == 0)
        return err_printn(__FILE__, __LINE__, RET_OUTOFMEMORY);
    memset(g_eng, 0x00, sizeof(struct engine));

    eng_zero();

    memcpy(&g_eng->params, params, sizeof(struct init_params));

    hw_getinfo(&g_eng->hwinfo, HWINFO_ALL);

    /* console (before anything else) */
    if (BIT_CHECK(params->flags, ENG_FLAG_CONSOLE))	{
		r |= con_init(params->console_lines_max);
		if (IS_FAIL(r))
			return RET_FAIL;
		log_outputfunc(TRUE, con_log, NULL);
    }

    /* show build options */
#if !defined(FULL_VERSION)
#error "must define FULL_VERSION macro"
#endif

    time_t raw_tm;
    time(&raw_tm);

    log_printf(LOG_TEXT, "init darkhammer engine v%s build[%s, %s, %s, %s], time: %s", 
        FULL_VERSION,
#if defined(_DEBUG_)
    		"debug"
#else
    		"release"
#endif
    		,
#if defined(_PROFILE_)
    		"profile"
#else
    		"no-profile"
#endif
    		,
#if defined(_X86_)
    		"x86"
#elif defined(_X64_)
    		"x64"
#endif
    		,
#if defined(_ENABLEASSERT_)
    		"assert"
#else
    		"no-assert"
#endif
            , asctime(localtime(&raw_tm)));

    /* hardware info */
    hw_printinfo(&g_eng->hwinfo, HWINFO_ALL);

    size_t tmp_sz = params->dev.buffsize_tmp;
    size_t data_sz = data_sz = params->dev.buffsize_data;
    tmp_sz = tmp_sz != 0 ? ((size_t)tmp_sz*1024) : FRAME_STACK_SIZE;
    data_sz = data_sz != 0 ? ((size_t)data_sz*1024) : DATA_SIZE;

    /* allocators */
    /* dynamic allocator for data in dev (editor) mode, stack allocator in game (normal) mode */
    if (BIT_CHECK(params->flags, ENG_FLAG_OPTIMIZEMEMORY))   {
        /* lsr (load-stay-resident) allocator for essential engine data */
        r |= mem_stack_create(mem_heap(), &g_eng->lsr_stack, LSR_SIZE, MID_DATA);
        mem_stack_bindalloc(&g_eng->lsr_stack, &g_eng->lsr_alloc);

        r |= mem_freelist_create(mem_heap(), &g_eng->data_freelist, data_sz, MID_DATA);
        mem_freelist_bindalloc(&g_eng->data_freelist, &g_eng->data_alloc);
    }   else    {
        mem_heap_bindalloc(&g_eng->data_alloc);
        mem_heap_bindalloc(&g_eng->lsr_alloc);

        g_eng->data_alloc.alloc_fn = eng_allocfn_data;
        g_eng->data_alloc.alignedalloc_fn = eng_alignedallocfn_data;
        g_eng->lsr_alloc.alloc_fn = eng_allocfn_lsr;
        g_eng->lsr_alloc.alignedalloc_fn = eng_alignedallocfn_lsr;

        r = RET_OK;
    }

    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: out of memory for allocators");
        return RET_FAIL;
    }

    /* timer manager and frame timer */
    g_eng->timer = timer_createinstance(TRUE);

    /* add engine's own data path to file-mgr */
    if (params->data_path != NULL)   {
        char data_path_ext[DH_PATH_MAX];
        path_getfileext(data_path_ext, params->data_path);
        if (str_isequal_nocase(data_path_ext, "pak"))    {
            if (IS_FAIL(pak_open(&g_eng->data_pak, mem_heap(), params->data_path, 0)))    {
                err_print(__FILE__, __LINE__, "engine init: could not open data pak");
                return RET_FAIL;
            }
        }   else   {
            if (!util_pathisdir(params->data_path)) {
                err_print(__FILE__, __LINE__, "engine init: data path is not valid");
                return RET_FAIL;
            }
            fio_addvdir(params->data_path, FALSE);
        }
        /* assume that share directory is same as data dir */
        path_getdir(g_eng->share_dir, params->data_path);
    }   else    {
        char data_path[DH_PATH_MAX];
        char share_dir[DH_PATH_MAX];
#ifndef SHARE_DIR
        char exe_dir[DH_PATH_MAX];
        path_join(share_dir, util_getexedir(exe_dir), "..", NULL);
        path_norm(share_dir, share_dir);
#else
        path_norm(share_dir, SHARE_DIR);
#endif
        path_join(data_path, share_dir, "data", NULL);
        if (!util_pathisdir(data_path)) {
            err_print(__FILE__, __LINE__, "engine init: data path is not valid");
            return RET_FAIL;
        }

        fio_addvdir(data_path, FALSE);  /* set default (config.h configured on build) data dir */
        strcpy(g_eng->share_dir, share_dir);
    }

    uint rs_flags = 0;
    /* activate hot loading in DEV mode */
    rs_flags |= BIT_CHECK(params->flags, ENG_FLAG_DEV) ? RS_FLAG_HOTLOADING : 0;
    if (!BIT_CHECK(params->flags, ENG_FLAG_DISABLEBGLOAD))  {
        rs_flags |= RS_FLAG_PREPARE_BGLOAD;
    }

    /* task manager */
    uint thread_cnt = maxui(g_eng->hwinfo.cpu_core_cnt - 1, 1);
    r = tsk_initmgr(thread_cnt, 0, tmp_sz, 0);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init task-mgr");
        return RET_FAIL;
    }
    struct allocator* tmp_alloc = tsk_get_tmpalloc(0);
    A_SAVE(tmp_alloc);

    /* resource manager (with only 1 thread for multi-thread loading) */
    r = rs_initmgr(rs_flags, 1);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init res-mgr");
        return RET_FAIL;
    }
    rs_set_dataalloc(&g_eng->lsr_alloc);

    /* graphics renderer */
    r = gfx_init(&params->gfx);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init gfx");
        return RET_FAIL;
    }

    /* debug HUD */
    r = hud_init(BIT_CHECK(params->flags, ENG_FLAG_CONSOLE));
    if (IS_FAIL(r))	{
        err_print(__FILE__, __LINE__, "engine init failed: could not init debug-hud");
        return RET_FAIL;
    }

    /* Physics */
    if (!BIT_CHECK(params->flags, ENG_FLAG_DISABLEPHX)) {
        r = phx_init(params);
        if (IS_FAIL(r)) {
            err_print(__FILE__, __LINE__, "engine init failed: could not init physics");
            return RET_FAIL;
        }
    }

    /* component manager */
    r = cmp_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init cmp-mgr");
        return RET_FAIL;
    }
    cmp_set_globalalloc(&g_eng->data_alloc, tsk_get_tmpalloc(0));

    /* world manager */
    r = wld_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init world-mgr");
        return RET_FAIL;
    }

    /* scene manager */
    r = scn_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init scene-mgr");
        return RET_FAIL;
    }

    /* init lua */
    r = sct_init(&params->sct, BIT_CHECK(params->flags, ENG_FLAG_DEV) ? TRUE : FALSE);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init script engine");
        return RET_FAIL;
    }

    /* web-server */
#if defined(_PROFILE_)
    r = prf_initmgr();
    if (IS_FAIL(r))	{
    	log_print(LOG_WARNING, "profiler manager init failed: service will not be available");
    	prf_releasemgr();
    }
#endif

    /* lod-scheme */
    r = lod_initmgr();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: could not init lod-scheme");
        return RET_FAIL;
    }

    /* init basic resources */
    r = rs_init_resources();
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "engine init failed: coult not init res-mgr resources");
        return RET_FAIL;
    }

    /* switch back to normal data allocator */
    rs_set_dataalloc(&g_eng->data_alloc);

    /* enable background-loading if res-mgr is prepared for (see above rs_initmgr) */
    if (gfx_check_feature(GFX_FEATURE_THREADED_CREATES))
        rs_add_flags(RS_FLAG_BGLOADING);
    log_print(LOG_TEXT, "init ok: ready.");

    /* init world vars */
    eng_world_regvars();

    /* engine specific console commnads */
    con_register_cmd("showfps", eng_console_showfps, NULL, "showfps [1*/0]");
    con_register_cmd("showft", eng_console_showft, NULL, "showft [1*/0]");
    con_register_cmd("showgraph", eng_console_showgraph, NULL, "showgraph [ft][fps][drawcalls]");
    con_register_cmd("lockfps", eng_console_lockfps, NULL, "lockfps [fps]");

    /* execute console commands - should be the final stage if initialization */
    if (BIT_CHECK(params->flags, ENG_FLAG_CONSOLE))	{
		for (uint i = 0; i < params->console_cmds_cnt; i++)	{
			con_exec(params->console_cmds + i*128);
		}
    }

    A_LOAD(tmp_alloc);
    return RET_OK;
}
예제 #12
0
static int newpackage(lua_State* L)
{
	int count, i;

	lua_newtable(L);

	/* Add this package to the master list in the registry */
	lua_getregistry(L);
	lua_pushstring(L, "packages");
	lua_gettable(L, -2);
	count = luaL_getn(L, -1);

	lua_pushvalue(L, -3);
	lua_rawseti(L, -2, count + 1);

	lua_pop(L, 2);

	/* Set default values */
	if (count == 0)
	{
		lua_getglobal(L, "project");
		lua_pushstring(L, "name");
		lua_pushstring(L, "name");
		lua_gettable(L, -3);
		lua_settable(L, -4);
		lua_pop(L, 1);
	}
	else
	{
		lua_pushstring(L, "name");
		lua_pushstring(L, "Package");
		lua_pushnumber(L, count);
		lua_concat(L, 2);
		lua_settable(L, -3);
	}

	lua_pushstring(L, "script");
	lua_pushstring(L, currentScript);
	lua_settable(L, -3);

	lua_pushstring(L, "path");
	lua_pushstring(L, path_getdir(currentScript));
	lua_settable(L, -3);

	lua_pushstring(L, "language");
	lua_pushstring(L, "c++");
	lua_settable(L, -3);

	lua_pushstring(L, "kind");
	lua_pushstring(L, "exe");
	lua_settable(L, -3);

	lua_pushstring(L, "objdir");
	lua_pushstring(L, "obj");
	lua_settable(L, -3);

	buildNewConfig(NULL);

	/* Build list of configurations matching what is in the project, and
	 * which can be indexed by name or number */
	lua_pushstring(L, "config");
	lua_newtable(L);

	lua_getglobal(L, "project");
	lua_pushstring(L, "configs");
	lua_gettable(L, -2);
	count = luaL_getn(L, -1);
	
	for (i = 1; i <= count; ++i)
	{
		lua_rawgeti(L, -1, i);

		lua_newtable(L);

		buildNewConfig(lua_tostring(L, -2));
	
		lua_pushvalue(L, -1);
		lua_rawseti(L, -6, i);
		lua_settable(L, -5);
	}

	lua_pop(L, 2);

	/* Hook the index metamethod so I can dynamically add file configs */
	lua_newtable(L);
	lua_pushstring(L, "__index");
	lua_pushcfunction(L, newfileconfig);
	lua_settable(L, -3);
	lua_setmetatable(L, -2);

	/* Set the 'package' global to point to it */
	lua_pushvalue(L, -1);
	lua_setglobal(L, "package");

	lua_settable(L, -3);

	return 1;
}