rpmlua rpmluaNew() { rpmlua lua = (rpmlua) xcalloc(1, sizeof(*lua)); struct stat st; const luaL_Reg *lib; char *initlua = rpmGenPath(rpmConfigDir(), "init.lua", NULL); static const luaL_Reg extlibs[] = { {"posix", luaopen_posix}, {"rex", luaopen_rex}, {"rpm", luaopen_rpm}, {"os", luaopen_rpm_os}, {NULL, NULL}, }; lua_State *L = lua_open(); luaL_openlibs(L); lua->L = L; for (lib = extlibs; lib->name; lib++) { lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); lua_call(L, 1, 0); lua_settop(L, 0); } #ifndef LUA_GLOBALSINDEX lua_pushglobaltable(L); #endif lua_pushliteral(L, "LUA_PATH"); lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua"); #ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); #else lua_settable(L, -3); #endif lua_pushliteral(L, "print"); lua_pushcfunction(L, rpm_print); #ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); #else lua_settable(L, -3); #endif #ifndef LUA_GLOBALSINDEX lua_pop(L, 1); #endif rpmluaSetData(lua, "lua", lua); if (stat(initlua, &st) != -1) (void)rpmluaRunScriptFile(lua, initlua); free(initlua); return lua; }
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable) { poptContext optCon; int rc; const char *ctx, *execPath; setprogname(argv[0]); /* Retrofit glibc __progname */ /* XXX glibc churn sanity */ if (__progname == NULL) { if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++; else __progname = argv[0]; } #if defined(ENABLE_NLS) (void) setlocale(LC_ALL, "" ); (void) bindtextdomain(PACKAGE, LOCALEDIR); (void) textdomain(PACKAGE); #endif rpmSetVerbosity(RPMLOG_NOTICE); if (optionsTable == NULL) { /* Read rpm configuration (if not already read). */ rpmcliConfigured(); return NULL; } /* XXX hack to get popt working from build tree wrt lt-foo names */ ctx = rstreqn(__progname, "lt-", 3) ? __progname + 3 : __progname; optCon = poptGetContext(ctx, argc, (const char **)argv, optionsTable, 0); { char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL); (void) poptReadConfigFile(optCon, poptfile); free(poptfile); } (void) poptReadDefaultConfig(optCon, 1); if ((execPath = getenv("RPM_POPTEXEC_PATH")) == NULL) execPath = LIBRPMALIAS_EXECPATH; poptSetExecPath(optCon, execPath, 1); /* Process all options, whine if unknown. */ while ((rc = poptGetNextOpt(optCon)) > 0) { fprintf(stderr, _("%s: option table misconfigured (%d)\n"), __progname, rc); exit(EXIT_FAILURE); } if (rc < -1) { fprintf(stderr, "%s: %s: %s\n", __progname, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); exit(EXIT_FAILURE); } /* Read rpm configuration (if not already read). */ rpmcliConfigured(); if (_debug) { rpmIncreaseVerbosity(); rpmIncreaseVerbosity(); } return optCon; }