int console_io(int in, int out) { int buf_len = 1024; int rtcode = 0; char *buf = NULL; buf = calloc(buf_len, sizeof(char)); if (buf == NULL) { perror("console_io:allocate buffer"); rtcode = 1; } else { do { console_prompt(out); rtcode = read(in, buf, buf_len); if (rtcode > 1) { write(out, buf, rtcode); } else if (rtcode < 0) { perror("console_io:read"); rtcode = 2; } } while (rtcode > 0); } free(buf); return(rtcode); }
static void update_console (ExecState *state, GtkWidget *cview) { GtkTextBuffer *buf; GtkTextIter iter; console_record_sample(dataset); if (state == console_state) { real_console_exec(state); if (state->cmd->ci == QUIT) { return; } } buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(cview)); gtk_text_buffer_get_end_iter(buf, &iter); gtk_text_buffer_insert(buf, &iter, "\n", 1); if (!printing_is_redirected(state->prn)) { print_result_to_console(buf, &iter, state); } /* set up prompt for next command and scroll to it */ console_insert_prompt(buf, &iter, console_prompt(state)); console_scroll_to_end(cview, buf, &iter); /* update variable listing in main window if needed */ if (check_dataset_is_changed()) { mark_dataset_as_modified(); populate_varlist(); } /* update sample info if needed */ if (console_sample_changed(dataset)) { set_sample_label(dataset); } #ifdef G_OS_WIN32 gtk_window_present(GTK_WINDOW(gtk_widget_get_toplevel(cview))); gtk_widget_grab_focus(cview); #endif }
void cmd_parse(const char * str) { int name_len; name_len=0; char cmd_name[MAX_LEN_NAME]; int arg_len; arg_len=0; char cmd_arg[MAX_LEN_ARG]; while(*str && *str != ' ') { cmd_name[name_len] = *str; name_len++; str++; } cmd_name[name_len] = '\0'; while(*str && *str == ' ') str++; while(*str && *str != ' ') { cmd_arg[arg_len] = *str; arg_len++; str++; } cmd_arg[arg_len] = '\0'; if (console_streq(cmd_name, led_cmd.name)) { int arg_value; led_cfg_set(1); if(arg_len == 0) led_dat_set(!led_dat_get_state()); else if (arg_len == 1) { arg_value = atoi(cmd_arg); if(arg_value == 1 || arg_value == 0) led_dat_set(arg_value); else { console_print("Bad argument : Not 0 or 1.\r\n"); cmd_print_usage(led_cmd); } } else { console_print("Bad number of arguments\r\n"); cmd_print_usage(led_cmd); } console_prompt(); } else if (console_streq(cmd_name, gpio_cmd.name)) { gpio_output_set(9); gpio_activate(9); console_prompt(); } else { console_print("Unknown command : "); console_print(cmd_name); console_print("\r\n"); console_prompt(); } }
/** * Execute a logic script * @param n Number of the logic resource to execute */ int run_logic (int n) { UINT8 op = 0; UINT8 p[CMD_BSIZE] = { 0 }; UINT8 *code = NULL; int num = 0; /* If logic not loaded, load it */ if (~game.dir_logic[n].flags & RES_LOADED) { _D (_D_WARN "logic %d not loaded!", n); agi_load_resource (rLOGIC, n); } game.lognum = n; cur_logic = &game.logics[game.lognum]; code = cur_logic->data; cur_logic->cIP = cur_logic->sIP; timer_hack = 0; while (ip < game.logics[n].size && !game.quit_prog_now) { #ifdef USE_CONSOLE if (debug.enabled) { if (debug.steps > 0) { if (debug.logic0 || n) { debug_console (n, lCOMMAND_MODE, NULL); debug.steps--; } } else { blit_both (); console_prompt (); do { main_cycle (); } while (!debug.steps && debug.enabled); console_lock (); erase_both (); } } #endif switch (op = *(code + ip++)) { case 0xff: /* if (open/close) */ test_if_code (n); break; case 0xfe: /* goto */ /* +2 covers goto size */ ip += 2 + ((SINT16)lohi_getword (code + ip)); /* timer must keep running even in goto loops, * but Sarien can't do that :( */ if (timer_hack > 20) { poll_timer (); update_timer (); timer_hack = 0; } break; case 0x00: /* return */ return 1; default: num = logic_names_cmd[op].num_args; memmove (p, code + ip, num); memset (p + num, 0, CMD_BSIZE - num); agi_command[op](p); ip += num; } if (game.exit_all_logics) break; } return 0; /* after executing new.room() */ }
int main (int argc, char *argv[]) { int ec; MaxApplZone (); game.clock_enabled = FALSE; game.state = STATE_INIT; init_machine (argc, argv); game.color_fg = 15; game.color_bg = 0; if ((game.sbuf = calloc (_WIDTH, _HEIGHT)) == NULL) { ec = err_NotEnoughMemory; goto bail_out; } #ifdef USE_HIRES if ((game.hires = calloc (_WIDTH * 2, _HEIGHT)) == NULL) { ec = err_NotEnoughMemory; goto bail_out_2; }; opt.hires = 1; #endif if (init_sprites () != err_OK) { ec = err_NotEnoughMemory; goto bail_out_3; } if (init_video () != err_OK) { ec = err_Unk; goto bail_out_4; } console_init (); report ("--- Starting console ---\n\n"); _D ("Init sound"); init_sound (); game.ver = -1; /* Disable conf file warning */ report (" \nSarien " VERSION " is ready.\n"); if (game.state < STATE_LOADED) { console_prompt (); do { main_cycle (); } while (game.state < STATE_RUNNING); if (game.ver < 0) game.ver = 0; /* Enable conf file warning */ } ec = run_game (); deinit_sound (); deinit_video (); bail_out_4: deinit_sprites (); bail_out_3: #ifdef USE_HIRES free (game.hires); #endif bail_out_2: free (game.sbuf); bail_out: if (ec == err_OK || ec == err_DoNothing) { deinit_machine (); exit (ec); } deinit_machine (); return ec; }