Ejemplo n.º 1
0
Archivo: cover.c Proyecto: rbong/jmc
SDL_Surface *load_local (const char *file)
{
    if (file == NULL)
        return NULL;

    char *folder = trim_path (file);

    if (folder == NULL)
        return NULL;

    SDL_Surface *sur = NULL;
    int len = 9;
    char name [] [11] = {   "cover.png", "front.png", "folder.png",
                            "cover.jpg", "front.jpg", "folder.jpg",
                            "cover.gif", "front.gif", "folder.gif" };
    char s [11 + strlen (folder)];
    int i = 0;

    for (i = 0; i < len; i++)
    {
        strcpy (s, folder);
        strcat (s, name [i]);

        if (access (s, F_OK) == 0)
        {
            sur = load_img_sdl (s, -1);
            break;
        }
    }

    free (folder);
    return sur;
}
Ejemplo n.º 2
0
 int debugger_clear_breakpoint(lua_State* L)
{
	if (lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TSTRING)
	{
		dict* linedefined_dictionary = NULL;

		int line = luaL_checkint(L, 1);
		const char* source = luaL_checkstring(L, 2);
		const char* file_name = trim_path(source);
		if (file_name != NULL)
		{
			linedefined_dictionary = dictFetchValue(breakpoint_dictionary, (const void *)line);
			if (linedefined_dictionary != NULL)
			{
				breakpoint_info* bp = dictFetchValue(linedefined_dictionary, file_name);
				if (bp != NULL)
				{
					dictDelete(linedefined_dictionary, file_name);
					luaL_unref(L, LUA_REGISTRYINDEX, bp->conditionFunction);
					free(bp);
					lua_pushinteger(L, 1);
					return 1;
				}
			}
		}

	}
	lua_pushinteger(L, 0);
	return 1;
}
Ejemplo n.º 3
0
fm_s32 fm_cust_config(const fm_s8 *filepath)
{
	fm_s32 ret = 0;
	fm_s8 *filep = NULL;
	fm_s8 file_path[51] = { 0 };

	fm_cust_config_default(&fm_config);
	WCN_DBG(FM_NTC | MAIN, "FM default config\n");
	fm_cust_config_print(&fm_config);

	if (!filepath) {
		filep = FM_CUST_CFG_PATH;
	} else {
		memcpy(file_path, filepath, (strlen(filepath) > 50) ? 50 : strlen(filepath));
		filep = file_path;
		trim_path(&filep);
	}

	ret = fm_cust_config_file(filep, &fm_config);
	WCN_DBG(FM_NTC | MAIN, "FM cust config\n");
	fm_cust_config_print(&fm_config);
	return ret;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    llist_t *paths,*src,*todo;
    set_t *incl;
    map_t *deps;

    if (argc < 2) {
        fprintf(stderr,"FastDep v%s for LAMMPS\n"
                "Usage: %s [-I <path> ...] -- <src1> [<src2> ...]\n",
                version,argv[0]);
        fprintf(stderr,"Supported extensions: %s, %s, %s\n",
                extensions[0], extensions[1], extensions[2]);
        return 1;
    }

    /* hash tables for all known included files and dependencies
     * we guesstimate a little over 2x as many entries as sources. */
    incl = set_init(2*argc);
    deps = map_init(2*argc);

    /* list of include search paths. prefixed by "." and "..". */
    paths = llist_init();
    llist_append(paths,".");
    llist_append(paths,"..");

    while (++argv, --argc > 0) {
        if (strncmp(*argv, "-I", 2) == 0) {
            if ((*argv)[2] != '\0') {
                llist_append(paths,trim_path(*argv+2));
            } else {
                ++argv;
                --argc;
                if (argc > 0) {
                    if (strcmp(*argv,"--") == 0) {
                        break;
                    } else {
                        llist_append(paths,trim_path(*argv));
                    }
                }
            }
        } else if (strcmp(*argv,"--") == 0) {
            break;
        } /* ignore all unrecognized arguments before '--'. */
    }

    src = llist_init();
    while (++argv, --argc > 0) {
        llist_append(src,*argv);
    }

    /* process files to look for includes */
    todo = llist_init();
    find_includes(src->head,todo,paths,incl,deps);
    find_includes(todo->head,todo,paths,incl,deps);
    llist_free(todo);

    fprintf(stdout,"# FastDep v%s for LAMMPS\n",version);
    fputs("# Search path: ",stdout);
    llist_print(paths);
    fprintf(stdout,"# % 5d sources\n# % 5d includes\n# % 5d depfiles\n",
            llist_size(src),set_size(incl),map_size(deps));

    set_free(incl);
    do_depend(src->head,deps);

    llist_free(src);
    llist_free(paths);
    map_free(deps);
    return 0;
}
Ejemplo n.º 5
0
 int debugger_set_breakpoint(lua_State* L)
{
	if (lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TSTRING)
	{
		dict* linedefined_dictionary = NULL;

		int line = luaL_checkint(L, 1);
		const char* source = luaL_checkstring(L, 2);
		const char* file_name = trim_path(source);
		if (file_name == NULL)
		{
			lua_pushinteger(L, 0);
			return 1;
		}

		linedefined_dictionary = dictFetchValue(breakpoint_dictionary, (const void*)line);
		if (linedefined_dictionary == NULL)
		{
			linedefined_dictionary = dictCreate(&dictTypeHeapStringCopyKey, NULL);
			if (linedefined_dictionary == NULL || dictAdd(breakpoint_dictionary, (void*)line, linedefined_dictionary) != DICT_OK)
			{
				lua_pushinteger(L, 0);
				return 1;
			}
		}

		if (dictFetchValue(linedefined_dictionary, file_name) == NULL)
		{
			breakpoint_info* bp = malloc(sizeof(breakpoint_info));
			if (bp == NULL)
			{
				lua_pushinteger(L, 0);
				return 1;
			}

			if (dictAdd(linedefined_dictionary, (void*)file_name,  bp) != DICT_OK)
			{
				free(bp);
				lua_pushinteger(L, 0);
				return 1;
			}

			memset(bp, 0, sizeof(*bp));

			if (lua_type(L, 3) == LUA_TSTRING)
			{
				const char* condition = lua_tostring(L, 3);

				if (luaL_loadstring(L, condition) == 0)
				{
					bp->type |= breakpoint_type_condition;
					bp->conditionFunction = luaL_ref(L, LUA_REGISTRYINDEX);
				}
				else
				{
					free(bp);
					lua_pushinteger(L, 0);
					return 1;
				}

			}

			if (lua_type(L, 4) == LUA_TBOOLEAN)
			{
				if (lua_toboolean(L, 4))
				{
					bp->type |= breakpoint_type_temp;
				}
			}

			bp->line = line;
			strncpy(bp->file_name, file_name, sizeof(bp->file_name) - 1);
		}

		lua_pushinteger(L, 1);
	}
	else
	{
		lua_pushinteger(L, 0);
	}
	return 1;
}
Ejemplo n.º 6
0
 void hook_line(lua_State* L, lua_Debug* ar)
{
	dict* file_dictionary = NULL;

	if (L == NULL || ar == NULL)
	{
		return;
	}

	lua_getinfo(L, "Sn", ar);

	if (ar->currentline <= 0)
	{
		return;
	}

	if (debugger_step_count > 0)
	{
		// 避免总在同一行打转
		if (last_breaked.currentline != ar->currentline || last_breaked.source != ar->source)
		{
			--debugger_step_count;
			if (debugger_step_count <= 0)
			{
				do_break(L, ar);
				return;
			}
		}
	}

	if (debugger_next_count > 0)
	{
		// 避免总在同一行打转
		if (last_breaked.currentline != ar->currentline || last_breaked.source != ar->source)
		{
			lua_Debug caller;
			int frame = debugger_next_start_frame;
			int ok = 0;
			int be_checked = 0;
			int be_called = 0;

			// 检查整个栈判断是否走到当前函数内部
			while ((ok = lua_getstack(L, frame, &caller)) == 1 && lua_getinfo(L, "S", &caller))
			{
				be_checked = 1;
				if (debugger_next_linedefined == caller.linedefined && strcmp(debugger_next_source, caller.source) == 0)
				{
					be_called = 1;
					break;
				}
				++frame;
			}

			// 此时ok == 0,表示自己已经是顶层调用,next应该被取消
			if (be_checked == 0)
			{
				debugger_next_count = 0;
			}
			else
			{
				if (be_called == 0)
				{
					--debugger_next_count;
					debugger_next_linedefined = ar->linedefined;
					strncpy(debugger_next_source, ar->source, sizeof(debugger_next_source) - 1);
				}

				if (debugger_next_count <= 0)
				{
					do_break(L, ar);
					return;
				}
			}
		}

	}

	file_dictionary = dictFetchValue(breakpoint_dictionary, (const void*)ar->currentline);
	if (file_dictionary != NULL)
	{
		int needBreak = 0;
		const char* file_name = trim_path(ar->source);
		breakpoint_info* bp = dictFetchValue(file_dictionary, file_name);
		if (bp == NULL)
		{
			return;
		}

		if (bp->type & breakpoint_type_condition)
		{
			int n = lua_gettop(L);

			lua_rawgeti(L, LUA_REGISTRYINDEX, bp->conditionFunction);
			if (lua_type(L, -1) == LUA_TFUNCTION)
			{
				// 测试条件是否为true
				if (lua_pcall(L, lua_gettop(L) - 1 - n, LUA_MULTRET, 0) == 0)
				{
					int resultAmount = lua_gettop(L) - n;
					if (resultAmount > 0 && lua_type(L, -resultAmount) == LUA_TBOOLEAN)
					{
						if (lua_toboolean(L, -resultAmount))
						{
							needBreak = 1;
						}
					}
				}
			}

			lua_pop(L, lua_gettop(L) - n);
		}
		else
		{
			needBreak = 1;
		}

		// 释放临时断点
		if (bp->type & breakpoint_type_temp)
		{
			dictDelete(file_dictionary, file_name);
			luaL_unref(L, LUA_REGISTRYINDEX, bp->conditionFunction);
			free(bp);
		}

		if (needBreak)
		{
			do_break(L, ar);
		}

	}
}