int main(int argc, char *argv[]) { parse_command_line(argc, argv); main_init(); TRACE(TRACE_DEBUG, "%s", "Entering mainloop\n"); /* Enter our mainloop */ event_dispatch(); while(1) { sleep(100); } main_exit(); TRACE(TRACE_DEBUG, "%s", "leaving mainloop, goodbye!\n"); return 0; }
static void android_app_entry(void *data) { char *argv[1]; int argc = 0; int ret = 0; if (rarch_main(argc, argv, data) != 0) goto end; #ifndef HAVE_MAIN do { ret = rarch_main_iterate(); rarch_main_data_iterate(); }while (ret != -1); main_exit(data); #endif end: exit(0); }
static void usage(char *progname) { fprintf(stderr, "Usage: %s [-c <conffilename>] [-h]\n", progname); fprintf(stderr, "\t\t-h\t\tDisplay this information.\n"); main_exit(1); }
int main(int argc, char **argv) { #else int __entry_menu(int argc, char **argv) { InitFunctionPointers(); #endif #if 1 setup_os_exceptions(); #else InstallExceptionHandler(); #endif socket_lib_init(); #if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT) log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT); #endif devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; memoryInitialize(); mount_sd_fat("sd"); VPADInit(); verbosity_enable(); DEBUG_VAR(argc); DEBUG_STR(argv[0]); DEBUG_STR(argv[1]); #if 0 int argc_ = 2; // char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL}; char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL}; rarch_main(argc_, argv_, NULL); #else rarch_main(argc, argv, NULL); #endif // int frames = 0; do { unsigned sleep_ms = 0; int ret = runloop_iterate(&sleep_ms); if (ret == 1 && sleep_ms > 0) retro_sleep(sleep_ms); task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL); if (ret == -1) break; }while(1); // }while(frames++ < 300); main_exit(NULL); unmount_sd_fat("sd"); memoryRelease(); fflush(stdout); fflush(stderr); #if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT) log_deinit(); #endif return 0; }
static void do_iteration(void) { int ret = rarch_main_iterate(); if (ret == -1) { main_exit(NULL); return; } CFRunLoopWakeUp(CFRunLoopGetMain()); /* TODO/FIXME I am almost positive that this is not necessary and is actually a bad thing. 1st. Why it is bad thing. This wakes up the main event loop immediately and the main loop has only one observer, which is this function. In other words, this causes the function to be called immediately. I did an experiment where I saved the time before calling this and then reported the difference between it and the start of do_iteration, and as expected it was about 0. As a result, when we remove this, idle performance (i.e. displaying the RetroArch menu) is 0% CPU as desired. 2nd. Why it is not necessary. The event loop will wake up itself when there is input to the process. This includes touch events, keyboard, bluetooth, etc. Thus, it will be woken up and without any intervention so that we can process that event. Nota bene. Why this analysis might be wrong (and what to do about it). If RA is not idle and is running a core, then I believe it is designed to expect to be called in a busy loop like this because it implements its own frame timer to ensure that the emulation simulation isn't too fast. In that case, this change would only allow emulation to run when there was input, which would make all games turn-based. :) There are two good ways to fix this and still have the desired 0% CPU idle behavior. Approach 1: Change main_entry_decide from returning a boolean (two-values) that are interpreted as CONTINUE and QUIT. Into returning a char-sized enum with three values that are interpreted as QUIT, WAIT, and AGAIN, such that QUIT calls main_exit, WAIT doesn't wake up the loop, and AGAIN does. It would then return AGAIN when a core was active. An ugly way to get the same effect is to look have this code just look at g_extern.is_menu and use the WAIT behavior in that case. Approach 2: Instead of signalling outside of RA whether a core is running, instead externalize the frame time that is inside retroarch. change main_entry_decide to return a value in [-1,MAX_INT] where -1 is interpreted as QUIT, [0,MAX_INT) is interpreted as the amount of time to wait until continuing, and MAX_INT is interpreted as WAIT. This could be more robust because we'd be exposing the scheduling behavior of RA to iOS, which might be good in other platforms as well. Approach 1 is the simplest and essentially just pushes down these requirements to rarch_main_iterate. I have gone with the "ugly way" first because it is the most expedient and safe. Other eyeballs should decide if it isn't necessary. */ }
/** * main_entry: * * Main function of RetroArch. * * If HAVE_MAIN is not defined, will contain main loop and will not * be exited from until we exit the program. Otherwise, will * just do initialization. * * Returns: varies per platform. **/ int rarch_main(int argc, char *argv[], void *data) { void *args = (void*)data; int ret = 0; settings_t *settings = NULL; rarch_ctl(RARCH_CTL_PREINIT, NULL); frontend_driver_init_first(args); rarch_ctl(RARCH_CTL_INIT, NULL); #ifdef HAVE_THREADS async_jobs = async_job_new(); #endif if (frontend_driver_is_inited()) { ret = main_load_content(argc, argv, args, frontend_driver_environment_get_ptr()); if (!ret) return ret; } event_cmd_ctl(EVENT_CMD_HISTORY_INIT, NULL); settings = config_get_ptr(); if (settings->history_list_enable) { char *fullpath = NULL; rarch_system_info_t *system = NULL; runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath); if (content_ctl(CONTENT_CTL_IS_INITED, NULL) || system->no_content) history_playlist_push( g_defaults.history, fullpath, settings->libretro, system ? &system->info : NULL); } ui_companion_driver_init_first(); #ifndef HAVE_MAIN do { unsigned sleep_ms = 0; ret = runloop_iterate(&sleep_ms); if (ret == 1 && sleep_ms > 0) retro_sleep(sleep_ms); runloop_ctl(RUNLOOP_CTL_DATA_ITERATE, NULL); }while(ret != -1); main_exit(args); #endif #ifdef HAVE_THREADS async_job_free(async_jobs); async_jobs = NULL; #endif return 0; }
int main(int argc, char **argv) { #if 1 setup_os_exceptions(); #else InstallExceptionHandler(); #endif ProcUIInit(&SaveCallback); socket_lib_init(); #if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT) log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT); devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; #endif #ifndef IS_SALAMANDER VPADInit(); WPADEnableURCC(true); WPADEnableWiiRemote(true); KPADInit(); #endif verbosity_enable(); printf("starting\n"); fflush(stdout); DEBUG_VAR(ARGV_PTR); if(ARGV_PTR && ((u32)ARGV_PTR < 0x01000000)) { struct { u32 magic; u32 argc; char * argv[3]; }*param = ARGV_PTR; if(param->magic == ARGV_MAGIC) { argc = param->argc; argv = param->argv; } ARGV_PTR = NULL; } DEBUG_VAR(argc); DEBUG_STR(argv[0]); DEBUG_STR(argv[1]); fflush(stdout); #ifdef IS_SALAMANDER int salamander_main(int, char **); salamander_main(argc, argv); #else #if 1 #if 0 int argc_ = 2; // char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL}; char *argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL}; rarch_main(argc_, argv_, NULL); #else rarch_main(argc, argv, NULL); #endif do { unsigned sleep_ms = 0; int ret = runloop_iterate(&sleep_ms); if (ret == 1 && sleep_ms > 0) retro_sleep(sleep_ms); task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL); if (ret == -1) break; } while (1); main_exit(NULL); #endif #endif fflush(stdout); fflush(stderr); ProcUIShutdown(); #if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT) log_deinit(); #endif /* returning non 0 here can prevent loading a different rpx/elf in the HBL environment */ return 0; }
void initiate() { //Prompt Start printf("\n:> "); scanf("%s",&input); //---------------------------------------------------------------------------------------- //EXIT COMMAND if ((stricmp(input,"exit")==0)) //To exit command interpreter { main_exit(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //CLEAR SCREEN COMMAND else if(stricmp(input,"clr")==0) //To clear screen { system("cls"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //TIME COMMANDS else if ((stricmp(input,"time")==0)) //To show time (default format-24hr HH/MM/SS.MS) { sys_time_def(); initiate(); } else if ((stricmp(input,"time-24")==0)) //To show time in 24hrformat (HH:MM) { sys_time_24hr(); initiate(); } else if ((stricmp(input,"time-12")==0)) //To show time in 12hr format (HH:MM AM/PM) { sys_time_12hr(); initiate(); } else if ((stricmp(input,"time-e")==0)) //To show time and provide 'editing' option { system("time"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //DATE COMMANDS else if ((stricmp(input,"date")==0)) //To show date (default format:MM/DD/YYYY) { sys_date_def(); initiate(); } else if ((stricmp(input,"date-e")==0)) //To show date and provide 'editing' option { system("date"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //DAY COMMANDS else if ((stricmp(input,"day")==0)) //To show day/date of month { sys_day(); initiate(); } else if ((stricmp(input,"day-i")==0)) //To show complete day info { sys_day_info(); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- // STRING MANIPULATION COMMANDS else if ((stricmp(input,"strln")==0)) // To return length of string { strln(); initiate(); } //---------------------------------------------------------------------------------------- else { printf("\aCommand not found. \n"); initiate(); } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_FOO_GET_ACTIVE_PLAYLIST_COUNT: if(plist_api) return activeplaylist_get_item_count(&plist_api); return P_ERROR; case WM_FOO_GET_PLAYLIST_ITEM: { char title[512]; wchar_t w_title[512]; if(!ptcomp_api || !plist_api || !pback_api) return P_ERROR; if(wParam == -1 && !is_playing(&pback_api)) return P_ERROR; int tracknumb = (wParam==-1)?(int)get_playing_item_location(&plist_api):wParam; PTITLEFORMAT_OBJECT *t_obj=0; // Must be 0!!! if(!GetWindowText(p_hWnd, title, 512)) return P_ERROR; if(compile(&ptcomp_api, &t_obj, title)) { string_free(); playlist_item_format_title(&plist_api, get_active_playlist(&plist_api), tracknumb, 0, &str, &t_obj, 0, display_level_all); MultiByteToWideChar(CP_UTF8, 0, str.data, -1, w_title, 512); SetWindowTextW(p_hWnd, w_title); service_release((PSERVICE_BASE*)t_obj); return 0; } return P_ERROR; } case WM_FOO_GET_CURRENT_TRACK: if(plist_api) return get_playing_item_location(&plist_api); return P_ERROR; case WM_FOO_ORDER: if(plist_api) {playback_order_set_active(&plist_api, wParam); return 0;} return P_ERROR; case WM_FOO_OPEN: return main_open(&g_api); case WM_FOO_ADD: return main_add_files(&g_api); case WM_FOO_ADDDIR: return main_add_directory(&g_api); case WM_FOO_PLAY: if(pback_api) {start_resume(&pback_api); return 0;} return P_ERROR; case WM_FOO_STOP: if(pback_api) {stop(&pback_api); return 0;} return P_ERROR; case WM_FOO_PLAY_NEXT: if(pback_api) {start(&pback_api, track_command_next); return 0;} return P_ERROR; case WM_FOO_PLAY_PREV: if(pback_api) {start(&pback_api, track_command_prev); return 0;} return P_ERROR; case WM_FOO_PLAY_RANDOM: if(pback_api) {start(&pback_api, track_command_rand); return 0;} return P_ERROR; case WM_FOO_PAUSE: if(pback_api) {pause(&pback_api, true); return 0;} return P_ERROR; case WM_FOO_PLAY_PAUSE: if(pback_api) {play_pause(&pback_api); return 0;} return P_ERROR; case WM_FOO_VOLUME_UP: if(pback_api) {volume_up(&pback_api); return 0;} return P_ERROR; case WM_FOO_VOLUME_DOWN: if(pback_api) {volume_down(&pback_api); return 0;} return P_ERROR; case WM_FOO_GET_VOLUME: if(pback_api) return get_volume(&pback_api); return P_ERROR; case WM_FOO_SET_VOLUME: if(pback_api) {set_volume(&pback_api, wParam); return 0;} return P_ERROR; case WM_FOO_MUTE: if(pback_api) {mute(&pback_api); return 0;} return P_ERROR; case WM_FOO_IS_PLAYING: if(pback_api) return (is_playing(&pback_api) && !is_paused(&pback_api)); return P_ERROR; case WM_FOOL_IS_PAUSED: if(pback_api) return is_paused(&pback_api); return P_ERROR; case WM_FOO_GET_STOP_AFTER_CURRENT: if(pback_api) return get_stop_after_current(&pback_api); return P_ERROR; case WM_FOO_SET_STOP_AFTER_CURRENT: if(pback_api) {set_stop_after_current(&pback_api, wParam); return 0;} return P_ERROR; case WM_FOO_PLAYBACK_CAN_SEEK: if(pback_api) return playback_can_seek(&pback_api); return P_ERROR; case WM_FOO_PLAYBACK_SEEK: if(pback_api) {playback_seek(&pback_api, wParam); return 0;} return P_ERROR; case WM_FOO_PLAYBACK_SEEK_DELTA: if(pback_api) {playback_seek_delta(&pback_api, wParam); return 0;} return P_ERROR; case WM_FOO_GET_POSITION: if(pback_api) return playback_get_position(&pback_api); return P_ERROR; case WM_FOO_GET_LENGTH: if(pback_api) return playback_get_length(&pback_api); return P_ERROR; case WM_FOO_EXIT: return main_exit(&g_api); case WM_FOO_ACTIVATE: return main_activate(&g_api); case WM_FOO_HIDE: return main_hide(&g_api); case WM_FOO_PLAY_TRACK: if(plist_api) {playlist_execute_default_action(&plist_api, get_active_playlist(&plist_api), wParam); return 0;} return P_ERROR; case WM_FOO_REGISTER_CALLBACK: if(wParam & PLAYBACK_START) AddCallback((PFCALLBACK)&callbacks, CSTARTING, (HWND)lParam, 0); if(wParam & PLAYBACK_DYNAMIC_INFO) AddCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO, (HWND)lParam, 0); if(wParam & PLAYBACK_DYNAMIC_INFO_TRACK) AddCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO_TRACK, (HWND)lParam, 0); if(wParam & PLAYBACK_TIME) AddCallback((PFCALLBACK)&callbacks, CTIME, (HWND)lParam, 0); if(wParam & PLAYBACK_VOLUME_CHANGE) AddCallback((PFCALLBACK)&callbacks, CVOLUME_CHANGE, (HWND)lParam, 0); if(wParam & PLAYBACK_STOP) AddCallback((PFCALLBACK)&callbacks, CSTOP, (HWND)lParam, 0); if(wParam & PLAYBACK_SEEK) AddCallback((PFCALLBACK)&callbacks, CSEEK, (HWND)lParam, 0); if(wParam & PLAYBACK_PAUSE) AddCallback((PFCALLBACK)&callbacks, CPAUSE, (HWND)lParam, 0); if(wParam & PLAYBACK_NEW_TRACK) { char caption[512]; if(GetWindowText(p_hWnd, caption, 512)) AddCallback((PFCALLBACK)&callbacks, CNEW_TRACK, (HWND)lParam, caption); } if(wParam & PLAYBACK_EDITED) { char caption[512]; if(GetWindowText(p_hWnd, caption, 512)) AddCallback((PFCALLBACK)&callbacks, CEDITED, (HWND)lParam, caption); } return 0; case WM_FOO_UNREGISTER_CALLBACK: if(wParam & PLAYBACK_START) RemoveCallback((PFCALLBACK)&callbacks, CSTARTING, (HWND)lParam); if(wParam & PLAYBACK_NEW_TRACK) RemoveCallback((PFCALLBACK)&callbacks, CNEW_TRACK, (HWND)lParam); if(wParam & PLAYBACK_STOP) RemoveCallback((PFCALLBACK)&callbacks, CSTOP, (HWND)lParam); if(wParam & PLAYBACK_SEEK) RemoveCallback((PFCALLBACK)&callbacks, CSEEK, (HWND)lParam); if(wParam & PLAYBACK_PAUSE) RemoveCallback((PFCALLBACK)&callbacks, CPAUSE, (HWND)lParam); if(wParam & PLAYBACK_EDITED) RemoveCallback((PFCALLBACK)&callbacks, CEDITED, (HWND)lParam); if(wParam & PLAYBACK_DYNAMIC_INFO) RemoveCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO, (HWND)lParam); if(wParam & PLAYBACK_DYNAMIC_INFO_TRACK) RemoveCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO_TRACK, (HWND)lParam); if(wParam & PLAYBACK_TIME) RemoveCallback((PFCALLBACK)&callbacks, CTIME, (HWND)lParam); if(wParam & PLAYBACK_VOLUME_CHANGE) RemoveCallback((PFCALLBACK)&callbacks, CVOLUME_CHANGE, (HWND)lParam); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } }
static void on_kill(int signum) { fprintf(LOG_OUT, "Exiting, got signal %d\n", signum); main_exit(); exit(1); }
gint wizard_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) { main_exit(0); return FALSE; }
/** 用户程序执行入口。 */ void main(int argc,char * argv[]) { int len = 0; int testint; double testdouble; char * teststr = 0; //char * xor_key_str = "xorkey_334566_hello_world"; char * rc4_key_str = "rc4key_334566_hello_world"; int rc4_key_len = strlen(rc4_key_str); ZL_EXP_INT builtinID,sdlID; ZL_EXP_VOID * VM; if(argc < 2) { printf("usage: %s <filename> ... (用法错误,应该是程序名加文件名加选项参数的形式,文件名通常是以.zlc结尾,也可以是.zl结尾)\n",argv[0]); #ifdef ZL_EXP_OS_IN_WINDOWS system("pause"); #endif exit(-1); } printf("compiling(编译中)...\n"); debuglog = fopen("main_debuglogs.txt","w+"); VM = zenglApi_Open(); zenglApi_SetFlags(VM,(ZENGL_EXPORT_VM_MAIN_ARG_FLAGS)(ZL_EXP_CP_AF_IN_DEBUG_MODE | ZL_EXP_CP_AF_OUTPUT_DEBUG_INFO)); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_COMPILE_INFO,main_userdef_info); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_RUN_INFO,main_userdef_run_info); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_RUN_PRINT,main_userdef_run_print); //zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_MODULE_INIT,main_userdef_module_init); //也可以在此处设置模块初始化句柄 if((builtinID = zenglApi_SetModInitHandle(VM,"builtin",main_builtin_module_init)) == -1) main_exit(VM,"设置use模块句柄失败:%s",zenglApi_GetErrorString(VM)); if((sdlID = zenglApi_SetModInitHandle(VM,"sdl",main_sdl_module_init)) == -1) main_exit(VM,"设置use模块句柄失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetModFunHandle(VM,builtinID,"bltTest",main_builtin_printf) == -1) main_exit(VM,"设置模块函数失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetExtraData(VM,"name","my name is zengl") == -1) main_exit(VM,"设置额外数据失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetExtraData(VM,"val","my val is zengl too") == -1) main_exit(VM,"设置额外数据失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_Run(VM,argv[1]) == -1) //编译执行zengl脚本 main_exit(VM,"错误:编译<%s>失败:%s\n",argv[1],zenglApi_GetErrorString(VM)); if((teststr = zenglApi_GetValueAsString(VM,"glmytest")) == ZL_EXP_NULL) main_exit(VM,"获取变量glmytest失败:%s\n",zenglApi_GetErrorString(VM)); if(zenglApi_GetValueAsInt(VM,"i",&testint) == -1) main_exit(VM,"获取变量i失败:%s\n",zenglApi_GetErrorString(VM)); if(zenglApi_GetValueAsDouble(VM,"floatnum",&testdouble) == -1) main_exit(VM,"获取变量floatnum失败:%s\n",zenglApi_GetErrorString(VM)); printf("the value of glmytest in test.zl is %s , i is %d , floatnum is %.16g\n",teststr,testint,testdouble); zenglApi_Reset(VM); builtinID = zenglApi_SetModInitHandle(VM,"builtin",main_builtin_module_init); //zenglApi_SetModFunHandle(VM,0,"printf",main_builtin_printf); if(zenglApi_Run(VM,"test2.zl") == -1) //编译执行zengl脚本 main_exit(VM,"错误:编译<test2.zl>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_Reset(VM); zenglApi_Push(VM,ZL_EXP_FAT_INT,0,1415,0); zenglApi_Push(VM,ZL_EXP_FAT_STR,"test second arg",0,0); //zenglApi_SetSourceXorKey(VM,xor_key_str); zenglApi_SetSourceRC4Key(VM,rc4_key_str,rc4_key_len); if(zenglApi_Call(VM,"encrypt_script/test.zl","OutIn","clsTest") == -1) //编译执行zengl脚本里的类函数 main_exit(VM,"错误:编译<test fun call>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_Close(VM); fclose(debuglog); printf("compile finished(编译结束)\n"); /*下面是脚本普通异或加密和还原的测试*/ /*main_output_xor_source("test.zl","encrypt_script/test.zl",xor_key_str); main_output_xor_source("encrypt_script/test.zl","encrypt_script/test_src.zl",xor_key_str); main_output_xor_source("test2.zl","encrypt_script/test2.zl",xor_key_str); main_output_xor_source("encrypt_script/test2.zl","encrypt_script/test2_src.zl",xor_key_str); main_output_xor_source("test3.zl","encrypt_script/test3.zl",xor_key_str); main_output_xor_source("encrypt_script/test3.zl","encrypt_script/test3_src.zl",xor_key_str);*/ /*下面是脚本RC4加密和还原的测试*/ main_output_rc4_source("test.zl","encrypt_script/test.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test.zl","encrypt_script/test_src.zl",rc4_key_str); main_output_rc4_source("test2.zl","encrypt_script/test2.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test2.zl","encrypt_script/test2_src.zl",rc4_key_str); main_output_rc4_source("test3.zl","encrypt_script/test3.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test3.zl","encrypt_script/test3_src.zl",rc4_key_str); #ifdef ZL_EXP_OS_IN_WINDOWS system("pause"); #endif }
void initiate() { //Prompt Start printf("\n:> "); fgets(input,sizeof(input),stdin); //---------------------------------------------------------------------------------------- //EXIT COMMAND if((stricmp(input,"exit\n")==0)) //To exit command interpreter { main_exit(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //CLEAR SCREEN COMMAND else if(stricmp(input,"clr\n")==0) //To clear screen { system("cls"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //TIME COMMANDS else if((stricmp(input,"time\n")==0)) //To show time (default format-24hr HH/MM/SS.MS) { sys_time_def(); initiate(); } else if((stricmp(input,"time-24\n")==0)) //To show time in 24hrformat (HH:MM) { sys_time_24hr(); initiate(); } else if((stricmp(input,"time-12\n")==0)) //To show time in 12hr format (HH:MM AM/PM) { sys_time_12hr(); initiate(); } else if((stricmp(input,"time-e\n")==0)) //To show time and provide 'editing' option { system("time"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //DATE COMMANDS else if((stricmp(input,"date\n")==0)) //To show date (default format:MM/DD/YYYY) { sys_date_def(); initiate(); } else if((stricmp(input,"date-e\n")==0)) //To show date and provide 'editing' option { system("date"); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //DAY COMMANDS else if((stricmp(input,"day\n")==0)) //To show day/date of month { sys_day(); initiate(); } else if((stricmp(input,"day-i\n")==0)) //To show complete day info { sys_day_info(); initiate(); } //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- // STRING MANIPULATION COMMANDS else if((stricmp(input,"strln\n")==0)) // Returns length of String { strln(); initiate(); } else if((stricmp(input,"strwht\n")==0)) // Returns no. of whitespaces in the String { strwht(); initiate(); } else if((stricmp(input,"strslice\n")==0)) // Returns a SubString from the given String using mentioned indices { strslice(); initiate(); } else if((stricmp(input,"strcap\n")==0)) // Capitalises the entered String { strcap(); initiate(); } else if((stricmp(input,"strtolow\n")==0)) // Converts uppercase String to lowercase { strtolow(); initiate(); } //---------------------------------------------------------------------------------------- else { printf("\aCommand not found.\n"); initiate(); } }
int main(int argc, char *argv[]) { FILE *fp; #if USING_DMALLOC dmalloc_debug(1); #endif /* start the clock (which is used by the Logit fnc) */ (void) refetch_ticker(); GetArgs(argc, argv); if (conf_file_read(confname)) { Logit("Failed to read config file \"%s\"", confname); strcpy(confname, "./nngs.cnf"); conf_file_write(confname); Logit("Created \"%s\"", confname); } Logit("Starting %s (%s %s) From: %s" , conffile.version_string, conffile.compile_date, conffile.compile_time, confname); if (daemonise()) { Logit("Failed to daemonise, giving up"); main_exit(1); } conf_file_write("written.cnf"); signal(SIGTERM, TerminateServer); signal(SIGINT, TerminateServer); #if 0 signal(SIGPIPE, SIG_IGN); #else signal(SIGPIPE, BrokenPipe); #endif signal(SIGCHLD, reapchild); mink_init(); startuptime = time(NULL); srand(startuptime); read_ban_ip_list(); if (!all_the_internets() ) { fprintf(stderr, "Network initialize failed on ports %s.\n" , conffile.server_ports); main_exit(1); } player_high = 0; game_high = 0; bytes_sent = 0; bytes_received = 0; #ifdef SGI /*mallopt(100, 1);*/ /* Turn on malloc(3X) debugging (Irix only) */ #endif command_init(); EmoteInit(conffile.emotes_file); help_init(); /*Logit("commands_init()");*/ commands_init(); /*Logit("channel_init()");*/ channel_init(); /*Logit("player_array_init()");*/ player_array_init(); player_init(); ladder_init(NUM_LADDERS); Ladder9 = ladder_new(LADDERSIZE); Ladder19 = ladder_new(LADDERSIZE); completed_games = 0; num_logins = num_logouts = new_players = 0; num_9 = 0; fp = xyfopen(FILENAME_LADDER9, "r"); if (fp) { num_9 = ladder_load(fp, Ladder9); Logit("%d players loaded from file %s", num_9, filename() ); fclose(fp); } num_19 = 0; fp = xyfopen(FILENAME_LADDER19, "r"); if (fp) { num_19 = ladder_load(fp, Ladder19); Logit("%d players loaded from file %s", num_19, filename() ); fclose(fp); } /* mink_init();*/ if (conffile.admin_name) create_admin_account(conffile.admin_name ); Logit("Server up and running."); main_event_loop(); Logit("Closing down."); net_closeAll(); main_exit(0); return 0; }
/** 用户程序执行入口。 */ int main(int argc,char * argv[]) { int len = 0; long testint; //int * testint_ptr; //double testdouble; char * teststr = 0; //char * xor_key_str = "xorkey_334566_hello_world"; char * rc4_key_str = "rc4key_334566_hello_world"; int rc4_key_len = strlen(rc4_key_str); char * run_str = "//this is a test for zenglApi_RunStr \n" "inc 'test2.zl';\n" "a = 135; \n" "b=2;\n" "print 'a-b is '+(a-b); \n" "bltLoadScript('test3.zl'); \n"; //行尾设置\n换行符这样查找语法错误时,方便定位行号信息 int run_str_len = strlen(run_str); ZL_EXP_INT builtinID,sdlID; ZL_EXP_VOID * VM; if(argc < 2) { printf("usage: %s <filename> ... (用法错误,应该是:程序名 + zengl脚本文件名的形式,在后面加-d参数可以开启调试)\n",argv[0]); #ifdef ZL_EXP_OS_IN_WINDOWS system("pause"); #endif exit(-1); } printf("compiling(编译中)...\n"); debuglog = fopen("main_debuglogs.txt","w+"); VM = zenglApi_Open(); zenglApi_SetFlags(VM,(ZENGL_EXPORT_VM_MAIN_ARG_FLAGS)(ZL_EXP_CP_AF_IN_DEBUG_MODE | ZL_EXP_CP_AF_OUTPUT_DEBUG_INFO)); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_COMPILE_INFO,main_userdef_info); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_RUN_INFO,main_userdef_run_info); zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_RUN_PRINT,main_userdef_run_print); //zenglApi_SetHandle(VM,ZL_EXP_VFLAG_HANDLE_MODULE_INIT,main_userdef_module_init); //也可以在此处设置模块初始化句柄 if((builtinID = zenglApi_SetModInitHandle(VM,"builtin",main_builtin_module_init)) == -1) main_exit(VM,"设置use模块句柄失败:%s",zenglApi_GetErrorString(VM)); if((sdlID = zenglApi_SetModInitHandle(VM,"sdl",main_sdl_module_init)) == -1) main_exit(VM,"设置use模块句柄失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetModFunHandle(VM,builtinID,"bltTest",main_builtin_printf) == -1) main_exit(VM,"设置模块函数失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetExtraData(VM,"name","my name is zengl") == -1) main_exit(VM,"设置额外数据失败:%s",zenglApi_GetErrorString(VM)); if(zenglApi_SetExtraData(VM,"val","my val is zengl too") == -1) main_exit(VM,"设置额外数据失败:%s",zenglApi_GetErrorString(VM)); //zenglApi_SetSourceRC4Key(VM,rc4_key_str,rc4_key_len); if(argc >= 3 && strcmp(argv[2],"-d") == 0) zenglApi_DebugSetBreakHandle(VM,main_debug_break,main_debug_conditionError,ZL_EXP_TRUE,ZL_EXP_FALSE); //设置调试API if(zenglApi_Run(VM,argv[1]) == -1) //编译执行zengl脚本 main_exit(VM,"错误:编译<%s>失败:%s\n",argv[1],zenglApi_GetErrorString(VM)); if(zenglApi_GetValueAsInt(VM,"i",&testint) != -1) printf("after run , the i is %ld\n",testint); zenglApi_Reset(VM); zenglApi_SetFlags(VM,(ZENGL_EXPORT_VM_MAIN_ARG_FLAGS)(ZL_EXP_CP_AF_IN_DEBUG_MODE)); zenglApi_SetModInitHandle(VM,"builtin",main_builtin_module_init); printf("\n[next test zenglApi_RunStr]: \n"); //zenglApi_DebugSetBreakHandle(VM,main_debug_break,main_debug_conditionError,ZL_EXP_TRUE,ZL_EXP_FALSE); if(zenglApi_RunStr(VM,run_str,run_str_len,"runstr") == -1) //编译执行字符串脚本 main_exit(VM,"错误:编译runstr失败:%s\n",zenglApi_GetErrorString(VM)); printf("\n[next test zenglApi_Call and zenglApi_ReUse]: \n"); zenglApi_Reset(VM); zenglApi_Push(VM,ZL_EXP_FAT_INT,0,1415,0); zenglApi_Push(VM,ZL_EXP_FAT_INT,0,3,0); if(zenglApi_Call(VM,"test2.zl","test","clsTest") == -1) //编译执行zengl脚本里的类函数 main_exit(VM,"错误:编译<test fun call>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_ReUse(VM,0); //不清理虚拟内存的ReUse zenglApi_Push(VM,ZL_EXP_FAT_INT,0,14,0); zenglApi_Push(VM,ZL_EXP_FAT_FLOAT,0,0,3.14); if(zenglApi_Call(VM,"test2.zl","test","clsTest") == -1) //编译执行zengl脚本里的类函数 main_exit(VM,"错误:编译<test fun call>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_ReUse(VM,1); //清理虚拟内存的ReUse if(zenglApi_Call(VM,"test2.zl","test","clsTest") == -1) //编译执行zengl脚本里的类函数 main_exit(VM,"错误:编译<test fun call>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_ReUse(VM,1); //清理虚拟内存的ReUse zenglApi_SetModInitHandle(VM,"builtin",main_builtin_module_init); if(zenglApi_Run(VM,"test2.zl") == -1) //编译执行zengl脚本 main_exit(VM,"错误:编译<test2.zl>失败:%s\n",zenglApi_GetErrorString(VM)); zenglApi_Close(VM); fclose(debuglog); printf("compile finished(编译结束)\n"); /*下面是脚本普通异或加密和还原的测试*/ /*main_output_xor_source("test.zl","encrypt_script/test.zl",xor_key_str); main_output_xor_source("encrypt_script/test.zl","encrypt_script/test_src.zl",xor_key_str); main_output_xor_source("test2.zl","encrypt_script/test2.zl",xor_key_str); main_output_xor_source("encrypt_script/test2.zl","encrypt_script/test2_src.zl",xor_key_str); main_output_xor_source("test3.zl","encrypt_script/test3.zl",xor_key_str); main_output_xor_source("encrypt_script/test3.zl","encrypt_script/test3_src.zl",xor_key_str);*/ /*下面是脚本RC4加密和还原的测试*/ /*main_output_rc4_source("test.zl","encrypt_script/test.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test.zl","encrypt_script/test_src.zl",rc4_key_str); main_output_rc4_source("test2.zl","encrypt_script/test2.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test2.zl","encrypt_script/test2_src.zl",rc4_key_str); main_output_rc4_source("test3.zl","encrypt_script/test3.zl",rc4_key_str); main_output_rc4_source("encrypt_script/test3.zl","encrypt_script/test3_src.zl",rc4_key_str);*/ #ifdef ZL_EXP_OS_IN_WINDOWS system("pause"); #endif return 0; }
/** * main_entry: * * Main function of RetroArch. * * If HAVE_MAIN is not defined, will contain main loop and will not * be exited from until we exit the program. Otherwise, will * just do initialization. * * Returns: varies per platform. **/ int rarch_main(int argc, char *argv[], void *data) { void *args = (void*)data; int ret = 0; settings_t *settings = NULL; driver_t *driver = NULL; rarch_main_alloc(); driver = driver_get_ptr(); if (driver) driver->frontend_ctx = (frontend_ctx_driver_t*)frontend_ctx_init_first(); if (!driver || !driver->frontend_ctx) RARCH_WARN("Frontend context could not be initialized.\n"); if (driver->frontend_ctx && driver->frontend_ctx->init) driver->frontend_ctx->init(args); rarch_main_new(); if (driver->frontend_ctx) { if (!(ret = (main_load_content(argc, argv, args, driver->frontend_ctx->environment_get, driver->frontend_ctx->process_args)))) return ret; } event_command(EVENT_CMD_HISTORY_INIT); settings = config_get_ptr(); if (settings->history_list_enable) { global_t *global = global_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr(); if (global->content_is_init || system->no_content) history_playlist_push( g_defaults.history, global->fullpath, settings->libretro, system ? &system->info : NULL); } if (driver) driver->ui_companion = (ui_companion_driver_t*)ui_companion_init_first(); if (driver->ui_companion && driver->ui_companion->toggle) { if (settings->ui.companion_start_on_boot) driver->ui_companion->toggle(driver->ui_companion_data); } #ifndef HAVE_MAIN do{ ret = rarch_main_iterate(); rarch_main_data_iterate(); }while(ret != -1); main_exit(args); #endif return 0; }
/** * @brief * SIGTERM signal handler. * * @param[in] signo * Always SIGTERM (ignored) */ static void sigterm (int signo UNUSED) { main_exit(); }