/* kpse:lookup("plain.tex", {}) */ static int do_lua_kpathsea_lookup(lua_State * L, kpathsea kpse, int idx) { int i; string ret = NULL; string *ret_list = NULL; const_string name = NULL; string user_path = NULL; boolean show_all = false; boolean must_exist = false; kpse_file_format_type user_format = kpse_last_format; int dpi = 600; str_list_type subdir_paths = { 0, NULL }; unsigned saved_debug = kpse->debug; int saved_mktexpk = kpse->format_info[kpse_pk_format].program_enabled_p; int saved_mktexmf = kpse->format_info[kpse_mf_format].program_enabled_p; int saved_mktextex = kpse->format_info[kpse_tex_format].program_enabled_p; int saved_mktextfm = kpse->format_info[kpse_tfm_format].program_enabled_p; name = luaL_checkstring(L, idx); /* todo: fetch parameter values */ if (lua_type(L, idx + 1) == LUA_TTABLE) { lua_pushstring(L, "format"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TSTRING) { int op = luaL_checkoption(L, -1, NULL, filetypenames); user_format = filetypes[op]; } lua_pop(L, 1); lua_pushstring(L, "dpi"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TNUMBER) { dpi = (int) lua_tointeger(L, -1); } lua_pop(L, 1); lua_pushstring(L, "debug"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TNUMBER) { int d = 0; d = (int) lua_tointeger(L, -1); kpse->debug |= d; } lua_pop(L, 1); lua_pushstring(L, "path"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TSTRING) { user_path = xstrdup(lua_tostring(L, -1)); } lua_pop(L, 1); lua_pushstring(L, "all"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { show_all = lua_toboolean(L, -1); } lua_pop(L, 1); lua_pushstring(L, "mktexpk"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { kpathsea_maketex_option(kpse, "pk", lua_toboolean(L, -1)); } lua_pop(L, 1); lua_pushstring(L, "mktextex"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { kpathsea_maketex_option(kpse, "tex", lua_toboolean(L, -1)); } lua_pop(L, 1); lua_pushstring(L, "mktexmf"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { kpathsea_maketex_option(kpse, "mf", lua_toboolean(L, -1)); } lua_pop(L, 1); lua_pushstring(L, "mktextfm"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { kpathsea_maketex_option(kpse, "tfm", lua_toboolean(L, -1)); } lua_pop(L, 1); lua_pushstring(L, "mustexist"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { must_exist = lua_toboolean(L, -1); } lua_pop(L, 1); lua_pushstring(L, "subdir"); lua_gettable(L, idx + 1); if (lua_istable(L, -1)) { lua_pushnil(L); while (lua_next(L, -2) != 0) { /* numeric value */ if (lua_type(L, -1) == LUA_TSTRING) { char *s = xstrdup(lua_tostring(L, -1)); str_list_add(&subdir_paths, s); xfree(s); } lua_pop(L, 1); } } else if (lua_type(L, -1) == LUA_TSTRING) { char *s = xstrdup(lua_tostring(L, -1)); str_list_add(&subdir_paths, s); xfree(s); } lua_pop(L, 1); if (STR_LIST_LENGTH(subdir_paths) > 0) { show_all = 1; } } if (user_path) { /* Translate ; to : if that's our ENV_SEP. See cnf.c. */ if (IS_ENV_SEP(':')) { string loc; for (loc = user_path; *loc; loc++) { if (*loc == ';') *loc = ':'; } } user_path = kpathsea_path_expand(kpse, user_path); if (show_all) { ret_list = kpathsea_all_path_search(kpse, user_path, name); } else { ret = kpathsea_path_search(kpse, user_path, name, must_exist); } free(user_path); } else { /* No user-specified search path, check user format or guess from NAME. */ kpse_file_format_type fmt; if (user_format != kpse_last_format) fmt = user_format; else fmt = find_format(kpse, name, true); switch (fmt) { case kpse_pk_format: case kpse_gf_format: case kpse_any_glyph_format: { kpse_glyph_file_type glyph_ret; string temp = remove_suffix (name); /* Try to extract the resolution from the name. */ unsigned local_dpi = find_dpi(name); if (!local_dpi) local_dpi = (unsigned) dpi; ret = kpathsea_find_glyph(kpse, temp, local_dpi, fmt, &glyph_ret); if (temp != name) free (temp); } break; case kpse_last_format: /* If the suffix isn't recognized, assume it's a tex file. */ fmt = kpse_tex_format; /* fall through */ default: if (show_all) { ret_list = kpathsea_find_file_generic(kpse, name, fmt, must_exist, true); } else { ret = kpathsea_find_file(kpse, name, fmt, must_exist); } } } /* Turn single return into a null-terminated list for uniform treatment. */ if (ret) { ret_list = XTALLOC(2, string); ret_list[0] = ret; ret_list[1] = NULL; } /* Filter by subdirectories, if specified. */ if (STR_LIST_LENGTH(subdir_paths) > 0) { string *new_list = subdir_match(subdir_paths, ret_list); free(ret_list); ret_list = new_list; } kpse->debug = saved_debug; kpse->format_info[kpse_pk_format].program_enabled_p = saved_mktexpk; kpse->format_info[kpse_mf_format].program_enabled_p = saved_mktexmf; kpse->format_info[kpse_tex_format].program_enabled_p = saved_mktextex; kpse->format_info[kpse_tfm_format].program_enabled_p = saved_mktextfm; /* Print output. */ i = 0; if (ret_list) { for (; ret_list[i]; i++) { lua_pushstring(L, ret_list[i]); } free(ret_list); } if (i == 0) { i++; lua_pushnil(L); } return i; }
void kpse_maketex_option (const_string fmtname, boolean value) { kpathsea_maketex_option (kpse_def, fmtname, value); }