int main(int argc, char** argv) { for (int n=1; n<argc; ++n) { const char* file=argv[n]; lua_State *L = lua_open(); luaopen_io(L); // provides io.* luaopen_base(L); luaopen_table(L); luaopen_math(L); // luaopen_loadlib(L); // luaopen_loadlib(L); std::cerr << "-- Loading file:" << file << std::endl; int s = luaL_loadfile(L, file); if (s==0) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); std::cerr << std::endl; } return 0; }
void Lua::done(int exitstatus){ #ifdef linux fflush(stdin); fflush(stdout); fflush(stderr); dup2(fileno(lua_std_in),STDIN_FILENO); //this stuff recovers stdin/stdout/stderr after the instrumentated process closed them dup2(fileno(lua_std_out),STDOUT_FILENO); dup2(fileno(lua_std_err),STDERR_FILENO); #else freopen ("closing_log_stdout.txt","w",stdout); freopen ("closing_log_stderr.txt","w",stderr); fprintf(stderr,"error output:\n"); printf("std output:\n"); #endif luaopen_debug(L); //lua_pushcfunction(L, errorHandler); lua_getglobal(L, "debug"); //addes debug backtrace as formater for errors lua_getfield(L, -1, "traceback"); lua_getglobal(L, "at_exit"); lua_pushnumber(L, exitstatus); report_errors(lua_pcall(L, 1, 0, -3)); // last -3 = debug.backtrace is used as error function fclose(stdout); fclose(stderr); }
static my_bool ssl_should_retry(Vio *vio, int ret, enum enum_vio_io_event *event) { int ssl_error; SSL *ssl= vio->ssl_arg; my_bool should_retry= TRUE; /* Retrieve the result for the SSL I/O operation. */ ssl_error= SSL_get_error(ssl, ret); /* Retrieve the result for the SSL I/O operation. */ switch (ssl_error) { case SSL_ERROR_WANT_READ: *event= VIO_IO_EVENT_READ; break; case SSL_ERROR_WANT_WRITE: *event= VIO_IO_EVENT_WRITE; break; default: #ifndef DBUG_OFF report_errors(ssl); #endif should_retry= FALSE; ssl_set_sys_error(ssl_error); break; } return should_retry; }
void rldelf_init(void) { init_add_ons(); // create the debug area { size_t size = TO_PAGE_SIZE(sizeof(runtime_loader_debug_area)); runtime_loader_debug_area *area; area_id areaID = _kern_create_area(RUNTIME_LOADER_DEBUG_AREA_NAME, (void **)&area, B_RANDOMIZED_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (areaID < B_OK) { FATAL("Failed to create debug area.\n"); _kern_loading_app_failed(areaID); } area->loaded_images = &get_loaded_images(); } // initialize error message if needed if (report_errors()) { void *buffer = malloc(1024); if (buffer == NULL) return; gErrorMessage.SetTo(buffer, 1024, 'Rler'); } }
static void test01(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); printf("version: %s\n", qpdf_get_pdf_version(qpdf)); printf("linearized: %d\n", qpdf_is_linearized(qpdf)); printf("encrypted: %d\n", qpdf_is_encrypted(qpdf)); if (qpdf_is_encrypted(qpdf)) { printf("user password: %s\n", qpdf_get_user_password(qpdf)); printf("extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf)); printf("extract for any purpose: %d\n", qpdf_allow_extract_all(qpdf)); printf("print low resolution: %d\n", qpdf_allow_print_low_res(qpdf)); printf("print high resolution: %d\n", qpdf_allow_print_high_res(qpdf)); printf("modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf)); printf("modify forms: %d\n", qpdf_allow_modify_form(qpdf)); printf("modify annotations: %d\n", qpdf_allow_modify_annotation(qpdf)); printf("modify other: %d\n", qpdf_allow_modify_other(qpdf)); printf("modify anything: %d\n", qpdf_allow_modify_all(qpdf)); } report_errors(); }
void Lua::setup(std::string filename){ #ifdef linux lua_std_in = fdopen(dup(STDIN_FILENO), "r"); lua_std_out = fdopen(dup(STDOUT_FILENO), "a"); lua_std_err = fdopen(dup(STDERR_FILENO), "a"); fprintf(lua_std_err,"-- Loading Lua libs\n"); #else printf("-- Loading Lua libs\n"); #endif luaL_openlibs(L); open_all(); if(lua_cpcall(L,init_callback_table,0) != 0) { lua_error(L); } lua_register(L, "add_ins_callback", add_ins_call); #ifdef linux fprintf(lua_std_err,"-- Loading file: %s \n",filename.c_str()); #else printf("-- Loading file: %s \n",filename.c_str()); #endif lua_getglobal(L, "debug"); //addes debug backtrace as formater for errors lua_getfield(L, -1, "traceback"); int s = luaL_loadfile(L, filename.c_str()); if ( s==0 ) { s = lua_pcall(L, 0, LUA_MULTRET, -2); // LAST 0 is the traceback } report_errors(s); std::cerr << std::endl; }
void on_status_command_finished (AnjutaCommand *command, guint return_code, gpointer user_data) { report_errors (command, return_code); svn_status_command_destroy (SVN_STATUS_COMMAND (command)); }
void main(int argc, char *argv[]) { /* Initialise some variables */ symboltable = NULL; current_line = 1; lineptr = linebuf; /* Process any command line arguments */ do_commandline(argc, argv); /* Display the welcome screen */ do_start(); /* Open any requested file */ if (filename != NULL) { file = fopen(filename, "r"); if (!file) { fprintf(stderr,"jsparse: Could not open file requested file \"%s\"\n", filename); exit(1); } /* yyin is the file handle for yacc */ yyin = file; } /* Build in predefined symbols */ do_predefined(); /* Start parsing */ do { yyparse(); } while (!feof(yyin)); current_line--; /* Report any unreported errors if we received at least one line of code */ if (current_line > 0) { report_errors(); } /* Display summary statistics */ printf("\n%d line", current_line); if (current_line != 1) printf("s"); printf(" processed. %d Error", numerrors); if (numerrors != 1) printf("s"); printf(", "); /* if (warnings_flag || !(warnings_flag || errors_flag)) {*/ if (warnings_flag) { printf("%d Warning", numwarnings); if (numwarnings != 1) printf("s"); printf(".\n\n"); } else { printf("Warnings disabled.\n\n"); } }
static void test10(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_set_attempt_recovery(qpdf, QPDF_FALSE); qpdf_read(qpdf, infile, password); report_errors(); }
void LuaPhysicsSetup::initPhysics() { m_guiHelper->setUpAxis(upaxis); const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; int numPrefixes = sizeof(prefix)/sizeof(const char*); char relativeFileName[1024]; FILE* f=0; int result = 0; for (int i=0;!f && i<numPrefixes;i++) { sprintf(relativeFileName,"%s%s",prefix[i],sLuaFileName); f = fopen(relativeFileName,"rb"); } if (f) { fclose(f); lua_State *L = luaL_newstate(); luaopen_io(L); // provides io.* luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); //luaopen_package(L); luaL_openlibs(L); // make my_function() available to Lua programs lua_register(L, "createDefaultDynamicsWorld", gCreateDefaultDynamicsWorld); lua_register(L, "deleteDynamicsWorld", gDeleteDynamicsWorld); lua_register(L, "createCubeShape", gCreateCubeShape); lua_register(L, "createSphereShape", gCreateSphereShape); lua_register(L, "loadMultiBodyFromUrdf",gLoadMultiBodyFromUrdf); lua_register(L, "createRigidBody", gCreateRigidBody); lua_register(L, "setBodyPosition", gSetBodyPosition); lua_register(L, "setBodyOrientation", gSetBodyOrientation); int s = luaL_loadfile(L, relativeFileName); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); } else { b3Error("Cannot find Lua file%s\n",sLuaFileName); } }
void TestScreen::draw(SpriteBatch *_sb) { _localSb = _sb; if(!doneInit) finalInitLua(); onLoopFunction(); report_errors(L, s); //_sb->sbDrawFont("f CPP", 0, 0, clr.strongGreen, float(3), true); }
bool cPlugin_NewLua::CallFunction( int a_NumArgs, int a_NumResults, const char * a_FunctionName) { ASSERT(lua_isfunction(m_LuaState, -a_NumArgs - 1)); int s = lua_pcall(m_LuaState, a_NumArgs, a_NumResults, 0); if (report_errors(m_LuaState, s)) { LOGWARN("Error in plugin %s calling function %s()", GetName().c_str(), a_FunctionName); return false; } return true; }
static void test09(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_stream_data_mode(qpdf, qpdf_s_uncompress); qpdf_write(qpdf); report_errors(); }
static void test07(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_qdf_mode(qpdf, QPDF_TRUE); qpdf_write(qpdf); report_errors(); }
static void test03(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_content_normalization(qpdf, QPDF_TRUE); qpdf_write(qpdf); report_errors(); }
static void test11(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_r2_encryption_parameters( qpdf, "user1", "owner1", QPDF_FALSE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE); qpdf_write(qpdf); report_errors(); }
static void test13(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); printf("user password: %s\n", qpdf_get_user_password(qpdf)); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_preserve_encryption(qpdf, QPDF_FALSE); qpdf_write(qpdf); report_errors(); }
static void test02(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) { qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_write(qpdf); } report_errors(); }
int vio_ssl_write(Vio *vio, const gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf, size)); r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r < 0) report_errors((SSL*) vio->ssl_arg); #endif DBUG_PRINT("exit", ("%d", r)); DBUG_RETURN(r); }
THRCOMP ThLua(_anchor proc_anchor) { int value; port_ent port_tab[1]; value = dfsdfpt(proc_anchor, 1, port_tab, "PROG"); char pgmname [100]; void * ptr; long size; char *type; value = dfsrecv(proc_anchor, &ptr, &port_tab[0], 0, &size, &type); memcpy(pgmname,ptr,size); pgmname[size] = '\0'; value = dfsdrop(proc_anchor, &ptr); lua_State *L = lua_open(); luaL_openlibs (L); lua_pushstring(L, "lua_dfsanchor"); /* push key */ lua_pushlightuserdata(L, (void *)&proc_anchor); /* push address */ lua_settable(L, LUA_REGISTRYINDEX); lua_register(L, "dfsrecv", thl_recv); lua_register(L, "dfsdrop", thl_drop); lua_register(L, "dfscrep", thl_crep); lua_register(L, "dfssend", thl_send); lua_register(L, "dfselct", thl_elct); lua_register(L, "dfsclos", thl_clos); lua_register(L, "dfsderef", thl_deref); lua_register(L, "myprint", myprint); int s = luaL_loadfile(L, pgmname); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); return(0); }
bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output) { ASSERT(!a_Split.empty()); CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]); if (cmd == m_ConsoleCommands.end()) { LOGWARNING("Console command handler is registered in cPluginManager but not in cPlugin, wtf? Console command \"%s\", plugin \"%s\".", a_Split[0].c_str(), GetName().c_str() ); return false; } cCSLock Lock(m_CriticalSection); // Push the function to be called: lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, cmd->second); // same as lua_getref() // Push the split: lua_createtable(m_LuaState, a_Split.size(), 0); int newTable = lua_gettop(m_LuaState); int index = 1; std::vector<std::string>::const_iterator iter = a_Split.begin(), end = a_Split.end(); while(iter != end) { tolua_pushstring(m_LuaState, (*iter).c_str()); lua_rawseti(m_LuaState, newTable, index); ++iter; ++index; } // Call function: int s = lua_pcall(m_LuaState, 1, 2, 0); if (report_errors(m_LuaState, s)) { LOGERROR("Lua error. Stack size: %i", lua_gettop(m_LuaState)); return false; } // Handle return values: if (lua_isstring(m_LuaState, -1)) { AString str = tolua_tocppstring(m_LuaState, -1, ""); a_Output.Out(str); } bool RetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0); lua_pop(m_LuaState, 2); // Pop return values return RetVal; }
static void test06(char const* infile, char const* password, char const* outfile, char const* outfile2) { char* buf = NULL; unsigned long size = 0; read_file_into_memory(infile, &buf, &size); qpdf_read_memory(qpdf, infile, buf, size, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_object_stream_mode(qpdf, qpdf_o_generate); qpdf_write(qpdf); report_errors(); }
static void on_commit_command_finished (AnjutaCommand *command, guint return_code, Subversion *plugin) { AnjutaStatus *status; status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, NULL); anjuta_status (status, _("Subversion: Commit complete."), 5); report_errors (command, return_code); svn_commit_command_destroy (SVN_COMMIT_COMMAND (command)); }
static void test15(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_static_aes_IV(qpdf, QPDF_TRUE); qpdf_set_r4_encryption_parameters( qpdf, "user2", "owner2", QPDF_TRUE, QPDF_TRUE, qpdf_r3p_low, qpdf_r3m_all, QPDF_TRUE, QPDF_TRUE); qpdf_write(qpdf); report_errors(); }
size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) { size_t r; DBUG_ENTER("vio_ssl_read"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); r= SSL_read((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); #endif DBUG_PRINT("exit", ("%u", (uint) r)); DBUG_RETURN(r); }
int main(int argc, char** argv) { for (int n=1; n<argc; ++n) { Lua_State L; open_libs(L); int s = luaL_loadfile(L, argv[n]); if (s==0) s = execute_program(L); report_errors(L, s); // lua_close(L) automatically called here } return 0; }
static void test14(char const* infile, char const* password, char const* outfile, char const* outfile2) { qpdf_read(qpdf, infile, password); qpdf_init_write(qpdf, outfile); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_minimum_pdf_version(qpdf, "1.6"); qpdf_write(qpdf); qpdf_init_write(qpdf, outfile2); qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_force_pdf_version(qpdf, "1.4"); qpdf_write(qpdf); report_errors(); }
void nscapi::settings_proxy::set_string(std::string path, std::string key, std::string value) { Plugin::SettingsRequestMessage request; nscapi::protobuf::functions::create_simple_header(request.mutable_header()); Plugin::SettingsRequestMessage::Request *payload = request.add_payload(); payload->set_plugin_id(plugin_id_); Plugin::SettingsRequestMessage::Request::Update *item = payload->mutable_update(); item->mutable_node()->set_key(key); item->mutable_node()->set_path(path); item->mutable_value()->set_string_data(value); std::string response_string; core_->settings_query(request.SerializeAsString(), response_string); Plugin::SettingsResponseMessage response; response.ParseFromString(response_string); report_errors(response, core_, "update " + path + "." + key); }
void cPlugin_NewLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum) { ASSERT(a_FnRef != LUA_REFNIL); cCSLock Lock(m_CriticalSection); lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // Push the function to be called tolua_pushusertype(m_LuaState, &a_Window, "cWindow"); tolua_pushnumber (m_LuaState, a_SlotNum); // Call function: int s = lua_pcall(m_LuaState, 2, 0, 0); if (report_errors(m_LuaState, s)) { LOGERROR("LUA error in %s. Stack size: %i", __FUNCTION__, lua_gettop(m_LuaState)); } }
bool SCRIPT_ExecuteInitial() { int s; /* Execute Main Script */ s = luaL_loadfile(L, "main.lua"); /* No errors ? Execute it */ if (s == 0) { s = lua_pcall(L, 0, LUA_MULTRET, 0); } /* Report any errors at this stage */ report_errors(L, s); return (s != 0) ? false : true; }