void assembler_destroy() { struct asm_context_t *ctx; ctx = app.asmcontext; if (!ctx) return; tokens_destroy(&ctx->tokens); symbols_destroy(&ctx->symbols); sections_destroy(&ctx->sections); relocations_destroy(&ctx->relocations); free(ctx); app.asmcontext = NULL; }
int main(int argc, char *argv[]) { init_shell(); static char line[4096]; int line_num = 0; /* Please only print shell prompts when standard input is not a tty */ if (shell_is_interactive) fprintf(stdout, "%d: ", line_num); int bg = 0; while (fgets(line, 4096, stdin)) { /* Split our line into words. */ struct tokens *tokens = tokenize(line); /* Find which built-in function to run. */ int fundex = lookup(tokens_get_token(tokens, 0)); if (fundex >= 0) { cmd_table[fundex].fun(tokens); } else { /* REPLACE this to run commands as programs. */ //Fork in order to account for redirecting //If in background, ignore sigttou signal(SIGTTOU, SIG_IGN); pid_t child_pid = fork(); //check for background processing token if (strcmp("&", tokens_get_token(tokens, tokens_get_length(tokens) - 1)) == 0) { bg = 1; } //Now set the child to have a new pgid if (child_pid == 0) { setpgid(getpid(), getpid()); if (bg == 0) //push it into the foreground { tcsetpgrp(0, getpid()); } run_program(tokens); exit(2); } //If not background, wait for execution and set shell back to foreground if (bg == 0) { int temp; wait(&temp); tcsetpgrp(0, getpid()); } else { processes[num_processes] = child_pid; num_processes += 1; } } bg = 0; if (shell_is_interactive) /* Please only print shell prompts when standard input is not a tty */ fprintf(stdout, "%d: ", ++line_num); /* Clean up memory */ tokens_destroy(tokens); } return 0; }