int main(int argc, char *argv[]) { int count, i, tmp, j; int builtin_f; int hist_expand_status; cmd **cmds; char *hist_tmp; sh_init(); using_history(); while (buf = readline(getprompt())) { if (buf[0] == '!') { // history expand hist_expand_status = history_expand(buf, &hist_tmp); if (hist_expand_status == 1) { buf = realloc(buf, (strlen(hist_tmp)+1) * sizeof(char)); strcpy(buf, hist_tmp); } else { fprintf(stderr, "shell: %s: event not found\n", buf); free(buf); continue; } } if (*buf) add_history(buf); cmds = malloc(INIT_SIZE * sizeof(cmd *)); cmds_init(cmds, INIT_SIZE); tmp = strlen(buf); buf = realloc(buf, (tmp + 2) * sizeof(char)); buf[tmp] = '\n'; buf[tmp+1] = '\0'; count = parse(buf, cmds, INIT_SIZE); buf[tmp] = '\0'; //print(cmds, count); if (count != -1) for (i = 0; i < count; ++i) { builtin_f = 0; for (j = 0; j < BUILTIN_N; ++j) if (strcmp(cmds[i]->argv[0], builtin_list[j]) == 0) { (*builtins[j])(cmds[i]); builtin_f = 1; break; } if (!builtin_f) exec_cmd(cmds[i]); } jobctl_print_msgs(); for (i = 0; i < count; ++i) cmd_dealloc(cmds[i]); free(buf); } return 0; }
void cmd_pic_con(){ // Attempts to set the console picture. WAD_PIC *temp_pic; int error=1; // Read up the proposed picture. temp_pic=wad_loadpic(INTERNAL_WAD,player_pic_con); if(temp_pic!=NULL){ if(temp_pic->w==320&&temp_pic->h==200){ conpic=wad_loadpic(INTERNAL_WAD,player_pic_con); error=0; } wad_killpic(temp_pic); } if(error==1){ con_printf("invalid background (titlepic reset)"); strcpy(player_pic_con,"titlepic"); conpic=wad_loadpic(INTERNAL_WAD,"titlepic"); cmds_init(); // To mirror the change in pic_con. } }
void init_stdin() { cmds_init(); fcntl(0, F_SETFL, O_NONBLOCK); event_set(&stdinEvent, 0, EV_READ, handle_stdin, &stdinEvent); event_add(&stdinEvent, NULL); }
void cons_init(void) { curExecEnv = -1; ev_register(EV_USER_INT,cons_sigIntrpt); cmds_init(); }