void process_args(int argc, char** argv) { size_t marker = 0; for(size_t i = 0; i < strlen(argv[0]); i++) { if(argv[0][i] == '/') marker = i + 1; } char str_0[strlen(argv[0]) - marker]; for(size_t i = 0; i < strlen(argv[0]) - marker; i++) { str_0[i] = argv[0][marker + i]; } set_bin_name(str_0); if(argc != 2) { errprintf("%: invalid number of arguments\n"); exit(get_exit_status()); } marker = 0; int count = 0; for(size_t i = 0; i < strlen(argv[1]); i++) { if(argv[1][i] == '.') { marker = i + 1; count++; } } if(count != 1 || strlen(argv[1]) - marker == 0) { errprintf("%: invalid file type\n"); exit(get_exit_status()); } char str_1[strlen(argv[1]) - marker]; for(size_t i = 0; i < strlen(argv[1]) - marker; i++) { str_1[i] = argv[1][marker + i]; } /* NOTE: the length of str_1 seems to be set at 6 no matter what. Will figure it out later. */ }
static void check_cancel_update(void) { update_event_status(); if(get_key(keycode_internal) == IKEY_ESCAPE || get_exit_status()) cancel_update = true; }
int handle_dollar(t_expander *exp) { char *s; s = exp->tmp + 1; if (!*s) return (append(exp)); else if (*s == '?') return (get_exit_status(exp)); else if (*s == '$') return (get_process_pid(exp)); else if (*s == '0') return (get_shell_name(exp)); else return (get_env_variable(exp, s)); }
int cleanup_child(int sig, const char *child_name, pid_t child_pid) { int rv, status, exit_code = 0; char *exit_status; if (child_pid == -1) return 0; /* If we're here because of a signal (arg != 0), pass it on to erld */ if (sig) { LOG_V("passing signal %d to %s", sig, child_name); kill(child_pid, sig); } DEBUG_V("Waiting for %s (pid %d) to exit.", child_name, child_pid); while (((rv = waitpid(child_pid, &status, 0)) == -1) && (errno == EINTR)) /* empty */; CHECK(rv); get_exit_status(status, &exit_status, &exit_code); DEBUG("Wait complete."); LOG_V("%s exited with status %d: %s.", child_name, exit_code, exit_status); syslog(LOG_INFO, "%s exited with status %d: %s.", child_name, exit_code, exit_status); free(exit_status); return exit_code; }
static boolean title_key(context *ctx, int *key) { const struct config_info *conf = get_config(); struct game_context *title = (struct game_context *)ctx; struct world *mzx_world = ctx->world; // NOTE: disabled due to joystick support. See IKEY_RETURN and IKEY_ESCAPE. //int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean reload_curr_file_in_editor = true; boolean confirm_exit = false; switch(*key) { #ifdef CONFIG_HELPSYS case IKEY_h: { // Help system alternate binding. *key = IKEY_F1; break; } #endif case IKEY_s: { // Configure alternate binding. *key = IKEY_F2; break; } case IKEY_F3: case IKEY_l: { if(conf->standalone_mode) return true; load_world_title_selection(title); return true; } case IKEY_F4: { // ALT+F4 - do nothing. if(get_alt_status(keycode_internal)) break; } /* fallthrough */ case IKEY_r: { // Restore saved game if(conf->standalone_mode && !get_counter(mzx_world, "LOAD_MENU", 0)) return true; if(load_savegame_selection(title)) { play_game(ctx, &(title->fade_in)); title->need_reload = true; } return true; } case IKEY_F5: case IKEY_p: { // Play game if(mzx_world->active) { if(mzx_world->only_from_swap) { error("You can only play this game via a swap from another game", ERROR_T_WARNING, ERROR_OPT_OK, 0x3101); return true; } if(load_world_gameplay(title, curr_file)) { play_game(ctx, NULL); title->need_reload = true; } } return true; } case IKEY_F7: case IKEY_u: { if(check_for_updates) { // FIXME this is garbage int current_music_vol = audio_get_music_volume(); int current_pcs_vol = audio_get_pcs_volume(); audio_set_music_volume(0); audio_set_pcs_volume(0); if(mzx_world->active) audio_set_module_volume(0); check_for_updates(ctx, false); audio_set_pcs_volume(current_pcs_vol); audio_set_music_volume(current_music_vol); if(mzx_world->active) audio_set_module_volume(mzx_world->current_board->volume); } return true; } case IKEY_F8: case IKEY_n: { reload_curr_file_in_editor = false; } /* fallthrough */ case IKEY_F9: case IKEY_e: { if(edit_world) { // Editor sfx_clear_queue(); vquick_fadeout(); title->need_reload = true; title->fade_in = true; edit_world(ctx, reload_curr_file_in_editor); } return true; } // Quickload saved game case IKEY_F10: { struct stat file_info; if(conf->standalone_mode && !get_counter(mzx_world, "LOAD_MENU", 0)) return true; if(!stat(curr_sav, &file_info) && load_savegame(title, curr_sav)) { play_game(ctx, &(title->fade_in)); title->need_reload = true; } return true; } case IKEY_RETURN: // Enter { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick actions. //if(key_status != 1) //return true; if(!conf->standalone_mode || get_counter(mzx_world, "ENTER_MENU", 0)) main_menu(ctx); return true; } case IKEY_ESCAPE: { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick actions. //if(key_status != 1) //return true; // ESCAPE_MENU (2.90+) only works on the title screen if the // standalone_mode config option is set if(mzx_world->version < V290 || !conf->standalone_mode || get_counter(mzx_world, "ESCAPE_MENU", 0)) confirm_exit = true; break; } } // Quit if(exit_status || confirm_exit) { // Special behaviour in standalone- only escape exits // ask for confirmation. Exit events instead terminate MegaZeux. if(conf->standalone_mode && !confirm_exit) { core_full_exit(ctx); } else { if(!confirm(mzx_world, "Exit MegaZeux - Are you sure?")) destroy_context(ctx); } return true; } return false; }
static boolean game_key(context *ctx, int *key) { struct game_context *game = (struct game_context *)ctx; struct config_info *conf = get_config(); struct world *mzx_world = ctx->world; struct board *cur_board = mzx_world->current_board; char keylbl[] = "KEY?"; int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean confirm_exit = false; if(*key && !exit_status) { // Get the char for the KEY? labels. If there is no relevant unicode // keypress, we want to use the regular code instead. int key_unicode = get_key(keycode_unicode); int key_char = *key; if(key_unicode > 0 && key_unicode < 256) key_char = key_unicode; if(key_char) { if(key_char < 256) { // Send the KEY? label. // Values over 256 have no meaning here. keylbl[3] = key_char; send_robot_all_def(mzx_world, keylbl); } // In pre-port MZX versions key was a board counter if(mzx_world->version < VERSION_PORT) { char keych = toupper(key_char); // <2.60 it only supported 1-9 and A-Z // This is difficult to version check, so apply it to <2.62 if(mzx_world->version >= V262 || (keych >= 'A' && keych <= 'Z') || (keych >= '1' && keych <= '9')) { cur_board->last_key = keych; } } } switch(*key) { case IKEY_F3: { // Save game if(!mzx_world->dead && player_can_save(mzx_world)) { char save_game[MAX_PATH]; strcpy(save_game, curr_sav); if(!new_file(mzx_world, save_ext, ".sav", save_game, "Save game", 1)) { strcpy(curr_sav, save_game); save_world(mzx_world, curr_sav, true, MZX_VERSION); } } return true; } case IKEY_F4: { // ALT+F4 - do nothing. if(get_alt_status(keycode_internal)) break; // Restore saved game if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { load_savegame_selection(game); } return true; } case IKEY_F5: case IKEY_INSERT: { // Change bomb type if(!mzx_world->dead) player_switch_bomb_type(mzx_world); return true; } // Toggle debug mode case IKEY_F6: { if(edit_world && mzx_world->editing) mzx_world->debug_mode = !(mzx_world->debug_mode); return true; } // Cheat case IKEY_F7: { if(game->allow_cheats || mzx_world->editing) player_cheat_give_all(mzx_world); return true; } // Cheat More case IKEY_F8: { if(game->allow_cheats || mzx_world->editing) player_cheat_zap(mzx_world); return true; } // Quick save case IKEY_F9: { if(!mzx_world->dead) { if(player_can_save(mzx_world)) save_world(mzx_world, curr_sav, true, MZX_VERSION); } return true; } // Quick load saved game case IKEY_F10: { if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { struct stat file_info; if(!stat(curr_sav, &file_info)) load_savegame(game, curr_sav); } return true; } case IKEY_F11: { if(mzx_world->editing) { // Breakpoint editor if(get_alt_status(keycode_internal)) { if(debug_robot_config) debug_robot_config(mzx_world); } // Counter debugger else { if(debug_counters) debug_counters(ctx); } } return true; } case IKEY_RETURN: { send_robot_all_def(mzx_world, "KeyEnter"); // Ignore if this isn't a fresh press if(key_status != 1) return true; if(mzx_world->version < V260 || get_counter(mzx_world, "ENTER_MENU", 0)) game_menu(ctx); return true; } case IKEY_ESCAPE: { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick action. //if(key_status != 1) //return true; // ESCAPE_MENU (2.90+) if(mzx_world->version < V290 || get_counter(mzx_world, "ESCAPE_MENU", 0)) confirm_exit = true; break; } } } // Quit if(exit_status || confirm_exit) { // Special behaviour in standalone- only escape exits // ask for confirmation. Exit events instead terminate MegaZeux. if(conf->standalone_mode && !confirm_exit) { core_full_exit(ctx); } else { if(!confirm(mzx_world, "Quit playing- Are you sure?")) destroy_context(ctx); } return true; } return false; }
int intake(struct world *mzx_world, char *string, int max_len, int x, int y, char color, int exit_type, int filter_type, int *return_x_pos, bool robo_intk, char *macro) { int currx, curr_len, macro_position = -1; int done = 0, place = 0; char cur_char = 0; char temp_char; int use_mask = mzx_world->conf.mask_midchars; int mouse_press; int key; if(macro != NULL) macro_position = 0; // Activate cursor if(insert_on) cursor_underline(); else cursor_solid(); // Put cursor at the end of the string... currx = curr_len = (int)strlen(string); // ...unless return_x_pos says not to. if((return_x_pos) && (*return_x_pos < currx)) currx = *return_x_pos; if(robo_intk && (currx > 75)) move_cursor(77, y); else move_cursor(x + currx, y); if(insert_on) cursor_underline(); else cursor_solid(); do { if(!robo_intk) { if(use_mask) write_string_mask(string, x, y, color, 0); else write_string_ext(string, x, y, color, 0, 0, 16); } else { draw_char('\x11', color, 79, y); if((curr_len < 76) || (currx < 76)) { draw_char('\x10', color, 0, y); if(curr_len < 76) { if(use_mask) write_line_mask(string, x, y, color, 0); else write_line_ext(string, x, y, color, 0, 0, 16); fill_line(76 - curr_len, x + curr_len, y, 32, color); } else { temp_char = string[76]; string[76] = 0; if(use_mask) write_line_mask(string, x, y, color, 0); else write_line_ext(string, x, y, color, 0, 0, 16); string[76] = temp_char; draw_char('\xaf', color, 79, y); } } else { draw_char('\x20', color, 77, y); if(strlen(string + currx - 75) > 78) { temp_char = string[currx + 1]; string[currx + 1] = 0; if(use_mask) { write_line_mask(string + currx - 75, x, y, color, 0); } else { write_line_ext(string + currx - 75, x, y, color, 0, 0, 16); } string[currx + 1] = temp_char; } else { if(use_mask) { write_line_mask(string + currx - 75, x, y, color, 0); } else { write_line_ext(string + currx - 75, x, y, color, 0, 0, 16); } } draw_char('\xae', color, 0, y); if(currx < curr_len) draw_char('\xaf', color, 79, y); } draw_char('\x20', color, 78, y); } if(!robo_intk) { fill_line(max_len + 1 - curr_len, x + curr_len, y, 32, color); } else { write_number(currx + 1, 79, 28, 0, 3, 0, 10); write_number(curr_len + 1, 79, 32, 0, 3, 0, 10); } // Get key if(macro_position != -1) { key = macro[macro_position]; cur_char = key; macro_position++; if(macro[macro_position] == 0) macro_position = -1; if(key == '^') key = IKEY_RETURN; } else { update_screen(); update_event_status_intake(); key = get_key(keycode_internal); place = 0; cur_char = get_key(keycode_unicode); // Exit event mimics escape, so exit_type > 0 only. if(get_exit_status() && exit_type > 0) { key = 0; done = 1; } } mouse_press = get_mouse_press_ext(); if(mouse_press) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); if((mouse_y == y) && (mouse_x >= x) && (mouse_x <= (x + max_len)) && (mouse_press <= MOUSE_BUTTON_RIGHT)) { // Yep, reposition cursor. currx = mouse_x - x; if(currx > curr_len) currx = curr_len; } else { key = -1; done = 1; } } // Handle key cases switch(key) { case IKEY_ESCAPE: { // ESC if(exit_type > 0) { done = 1; } break; } case IKEY_RETURN: { // Enter done = 1; break; } case IKEY_HOME: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // Home currx = 0; } break; } case IKEY_END: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // End currx = curr_len; } break; } case IKEY_LEFT: { if(get_ctrl_status(keycode_internal)) { // Find nearest space to the left if(currx) { char *current_position = string + currx; if(currx) current_position--; if(!isalnum((int)*current_position)) { while(currx && !isalnum((int)*current_position)) { current_position--; currx--; } } do { current_position--; currx--; } while(currx && isalnum((int)*current_position)); if(currx < 0) currx = 0; } } else { // Left if(currx > 0) currx--; } break; } case IKEY_RIGHT: { if(get_ctrl_status(keycode_internal)) { // Find nearest space to the right if(currx < curr_len) { char *current_position = string + currx; char current_char = *current_position; if(!isalnum((int)current_char)) { do { current_position++; currx++; current_char = *current_position; } while(current_char && !isalnum((int)current_char)); } while(current_char && isalnum((int)current_char)) { current_position++; currx++; current_char = *current_position; } } } else { // Right if(currx < curr_len) currx++; } break; } case IKEY_F1: case IKEY_F2: case IKEY_F3: case IKEY_F4: case IKEY_F5: case IKEY_F6: case IKEY_F7: case IKEY_F8: case IKEY_F9: case IKEY_F10: case IKEY_F11: case IKEY_F12: case IKEY_UP: case IKEY_DOWN: case IKEY_TAB: case IKEY_PAGEUP: case IKEY_PAGEDOWN: { done = 1; break; } case IKEY_INSERT: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { // Insert if(insert_on) cursor_solid(); else cursor_underline(); insert_on ^= 1; } break; } case IKEY_BACKSPACE: { // Backspace, at 0 it might exit if(get_alt_status(keycode_internal)) { // Alt-backspace, erase input curr_len = currx = 0; string[0] = 0; } else if(get_ctrl_status(keycode_internal)) { // Find nearest space to the left if(currx) { int old_position = currx; if(!isalnum((int)string[currx])) { while(currx && !isalnum((int)string[currx])) { currx--; } } while(currx && isalnum((int)string[currx])) { currx--; } curr_len -= old_position - currx; memmove(string + currx, string + old_position, strlen(string + old_position) + 1); } } else if(currx == 0) { if(exit_type == 2) { done = 1; } } else { // Move all back 1, decreasing string length memmove(string + currx - 1, string + currx, curr_len - currx + 1); curr_len--; // Cursor back one currx--; } break; } case IKEY_DELETE: { // Delete, at the end might exit if(currx == curr_len) { if(exit_type == 2) done = 1; } else { if(curr_len) { // Move all back 1, decreasing string length memmove(string + currx, string + currx + 1, curr_len - currx); curr_len--; } } break; } case IKEY_c: { if(get_ctrl_status(keycode_internal) && robo_intk) { done = 1; } else if(get_alt_status(keycode_internal) && !filter_type) { // If alt - C is pressed, choose character int new_char = char_selection(last_char); if(new_char >= 32) { cur_char = new_char; last_char = new_char; place = 1; } else { place = 0; } } else { place = 1; } break; } case IKEY_t: { if(get_alt_status(keycode_internal)) { done = 1; } else { place = 1; } break; } case IKEY_l: case IKEY_g: case IKEY_d: case IKEY_f: case IKEY_r: { if(get_ctrl_status(keycode_internal) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_i: { if((get_ctrl_status(keycode_internal) || get_alt_status(keycode_internal)) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_u: case IKEY_o: case IKEY_x: case IKEY_b: case IKEY_s: case IKEY_e: case IKEY_v: case IKEY_p: case IKEY_h: case IKEY_m: { if(get_alt_status(keycode_internal) && robo_intk) { done = 1; } else { place = 1; } break; } case IKEY_LSHIFT: case IKEY_RSHIFT: case 0: { place = 0; break; } default: { // Place the char place = 1; break; } case -1: { break; } } if(place) { if((cur_char != 0) && (cur_char < 32) && (exit_type == 2)) { done = 1; key = cur_char; } else // Keycode.. Filter. if(filter_type & 1) { if((cur_char >= 'a') && (cur_char <= 'z')) cur_char -= 32; } if(filter_type & 2) { if((cur_char >= 'A') && (cur_char <= 'Z')) cur_char += 32; } // Block numbers if((filter_type & 4) && ((cur_char >= '0') && (cur_char <= '9'))) { place = 0; } // Block alpha if((filter_type & 8) && (((cur_char >= 'a') && (cur_char <= 'z')) || ((cur_char >= 'A') && (cur_char <= 'Z')))) { place = 0; } // Block spaces if((filter_type & 16) && (cur_char == ' ')) { place = 0; } // Block high-ASCII if((filter_type & 32) && (cur_char > 126)) { place = 0; } // Block these chars if((filter_type & 64) && ((cur_char == '*') || (cur_char == '[') || (cur_char == ']') || (cur_char == '>') || (cur_char == '<') || (cur_char == ',') || (cur_char == '|') || (cur_char == '?') || (cur_char == '=') || (cur_char == ';') || (cur_char == '\"') || (cur_char =='/'))) { place = 0; } // Block these chars if((filter_type & 128) && ((cur_char == ':') || (cur_char == '\\'))) { place = 0; } // Block these chars if((filter_type & 256) && (((cur_char > ' ') && (cur_char < '0')) || ((cur_char > '9') && (cur_char < 'A')) || ((cur_char > 'Z') && (cur_char < 'a')) || ((cur_char > 'z') && (cur_char < 127)))) { place = 0; } // Now, can it still be placed? if(place && (curr_len != max_len) && (!done) && cur_char) { // Overwrite or insert? if((insert_on) || (currx == curr_len)) { // Insert- Move all ahead 1, increasing string length curr_len++; memmove(string + currx + 1, string + currx, curr_len - currx); } // Add character and move forward one string[currx++] = cur_char; } } // Move cursor if(robo_intk && (currx > 75)) move_cursor(77, y); else move_cursor(x + currx, y); if(insert_on) cursor_underline(); else cursor_solid(); // Loop } while(!done); cursor_off(); if(return_x_pos) *return_x_pos = currx; return key; }
int main(int argc, char** argv) { process_args(argc, argv); return get_exit_status(); }