int xdotool_main(int argc, char **argv) { /* If argv[1] is a file or "-", read commands from file or stdin, * else use commands from argv. */ struct stat data; int stat_ret; if (argc >= 2) { /* See if the first argument is an existing file */ stat_ret = stat(argv[1], &data); int i = 0; int argv1_is_command= 0; for (i = 0; dispatch[i].name != NULL; i++) { if (!strcasecmp(dispatch[i].name, argv[1])) { argv1_is_command = 1; break; } } if (!argv1_is_command && (strcmp(argv[1], "-") == 0 || stat_ret == 0)) { return script_main(argc, argv); } } return args_main(argc, argv); }
int main(int argc, char** argv) { // global flags for(int iStartArg=1; iStartArg<argc; ++iStartArg) { t_string strArg = STR_TO_WSTR(argv[iStartArg]); tl::trim(strArg); // end of arguments to hermelin if(strArg[0] != T_STR'-') break; if(strArg=="-t" || strArg == "--timing") g_bShowTiming = 1; } const std::array<tl::Log*, 5> arrLogs{{&tl::log_crit, &tl::log_err, &tl::log_warn, &tl::log_info, &tl::log_debug}}; for(tl::Log* pLog : arrLogs) { pLog->SetShowDate(0); pLog->SetShowThread(0); } int iRet = -99; tl::Stopwatch<t_real> watch; try { tl::init_spec_chars(); if(g_bShowTiming) watch.start(); iRet = script_main(argc, argv); if(g_bShowTiming) watch.stop(); } catch(const std::exception& ex) { tl::log_crit(ex.what()); } if(g_bShowTiming && iRet==0) { tl::log_info("================================================================================"); tl::log_info("Script start time: ", watch.GetStartTimeStr()); tl::log_info("Script stop time: ", watch.GetStopTimeStr()); tl::log_info("Script execution time: ", watch.GetDur(), " s"); tl::log_info("================================================================================"); } return iRet; }
static int tcc_compile_and_run(char* filename) { console_printf("Compiling script %s...\n", filename); void* tcc = NULL; TCCState * script_state = NULL; void* script_buf = NULL; tcc = module_load("ML/MODULES/tcc.mo"); if (!tcc) { console_printf("Could not load TCC compiler.\n"); goto err; } script_state = (void*) module_exec(tcc, "tcc_new", 0); if (!script_state) { console_printf("Could not initialize TCC compiler.\n"); goto err; } module_exec(tcc, "tcc_set_options", 2, script_state, "-nostdlib"); module_exec(tcc, "tcc_set_options", 2, script_state, "-Wall"); module_exec(tcc, "tcc_set_options", 2, script_state, "-IML/scripts"); module_exec(tcc, "tcc_set_output_type", 2, script_state, TCC_OUTPUT_MEMORY); int ret_compile = module_exec(tcc, "tcc_add_file", 2, script_state, filename); if (ret_compile < 0) { console_printf("Compilation error.\n"); goto err; } script_load_symbols(tcc, script_state, "ML/modules/5D3_113.sym"); int size = module_exec(tcc, "tcc_relocate", 2, script_state, NULL); if (size <= 0) { console_printf("Linking error.\n"); goto err; } script_buf = (void*) tcc_malloc(size); if (!script_buf) { console_printf("Malloc error.\n"); goto err; } int ret_link = module_exec(tcc, "tcc_relocate", 2, script_state, script_buf); if (ret_link < 0) { console_printf("Relocate error.\n"); goto err; } void (*script_main)() = (void*) module_exec(tcc, "tcc_get_symbol", 2, script_state, "main"); if (!script_main) { console_printf("Your script should have a main function.\n"); goto err; } script_define_param_variables(tcc, script_state); module_exec(tcc, "tcc_delete", 1, script_state); script_state = NULL; module_unload(tcc); tcc = NULL; console_printf("Running script %s...\n", filename); /* http://repo.or.cz/w/tinycc.git/commit/6ed6a36a51065060bd5e9bb516b85ff796e05f30 */ sync_caches(); script_main(); tcc_free(script_buf); script_buf = NULL; return 0; err: if (script_buf) tcc_free(script_buf); if (script_state) module_exec(tcc, "tcc_delete", 1, script_state); if (tcc) module_unload(tcc); return 1; }
int main(int argc, char* argv[]) { script_main(); system("pause"); return 0; }