void read_blif(char* blif_file, int lut_size) { char buffer[BUFSIZE]; int pass, done, doall; blif = my_fopen(blif_file, "r", 0); for (doall = 0; doall <= 1; doall++) { init_parse(doall); /* Three passes to ensure inputs are first blocks, outputs second and * * LUTs and latches third. Just makes the output netlist more readable. */ for (pass = 1; pass <= 3; pass++) { linenum = 0; /* Reset line number. */ done = 0; while ((my_fgets(buffer, BUFSIZE, blif) != NULL) && !done) { get_tok(buffer, pass, doall, &done, lut_size); } rewind(blif); /* Start at beginning of file again */ } } fclose(blif); check_net(lut_size); free_parse(); }
void exec_process(t_shell *sh, t_job *job, int *iofile) { t_parse *parse; parse = init_parse(sh, job->process->cmd); if (check_builtins(parse->argv[0])) { if (iofile[0] != 0) job->process->stdio[0] = iofile[0]; if (iofile[1] != 1) job->process->stdio[1] = iofile[1]; launch_builtin(sh, parse, job); } else if ((job->process->pid = fork()) == 0) { if (iofile[0] != 0) job->process->stdio[0] = iofile[0]; if (iofile[1] != 1) job->process->stdio[1] = iofile[1]; launch_bin(parse, job); } free_parse(&parse); if (iofile[0] != 0) close(iofile[0]); if (iofile[1] != 1) close(iofile[1]); }
void s3_cfg_free_parse(s3_cfg_t *_cfg, s3_cfg_state_t *_parse) { s3_cfg_state_t *root = NULL; assert(_cfg != NULL); assert(_parse != NULL); root = _parse; while (root->back != NULL) root = root->back; free_parse(root); }
void free_parse(s3_cfg_state_t *_parse) { int i; s3_cfg_state_t *scan = NULL; if (_parse->num_expanded > 0) { for (i = s3_arraylist_count(&_parse->expansions) - 1; i >= 0; i--) { scan = (s3_cfg_state_t *)s3_arraylist_get(&_parse->expansions, i); free_parse(scan); } } free_state(_parse); }
void read_blif(char *blif_file, boolean sweep_hanging_nets_and_inputs, t_model *user_models, t_model *library_models) { char buffer[BUFSIZE]; int pass, doall; boolean done; boolean add_truth_table; t_model *inpad_model, *outpad_model, *logic_model, *latch_model; blif = fopen(blif_file, "r"); if(blif == NULL) { printf("Failed to open blif file %s\n", blif_file); exit(1); } load_default_models(library_models, &inpad_model, &outpad_model, &logic_model, &latch_model); /* doall = 0 means do a counting pass, doall = 1 means allocate and load data structures */ for(doall = 0; doall <= 1; doall++) { init_parse(doall); /* Three passes to ensure inputs are first blocks, outputs second and * * LUTs and latches third, subckts last. Just makes the output netlist more readable. */ for(pass = 0; pass <= 4; pass++) { linenum = 0; /* Reset line number. */ done = FALSE; add_truth_table = FALSE; model_lines = 0; while(my_fgets(buffer, BUFSIZE, blif) != NULL) { get_tok(buffer, pass, doall, &done, &add_truth_table, inpad_model, outpad_model, logic_model, latch_model, user_models); } rewind(blif); /* Start at beginning of file again */ } } fclose(blif); check_net(sweep_hanging_nets_and_inputs); free_parse(); }
void read_net (char *net_file, t_subblock_data *subblock_data_ptr) { /* Main routine that parses a netlist file in my (.net) format. */ char buf[BUFSIZE], *ptr; int doall; FILE *fp_net; /* Make two variables below accessible anywhere in the module because I'm * * too lazy to pass them all over the place. */ max_subblocks_per_block = subblock_data_ptr->max_subblocks_per_block; subblock_lut_size = subblock_data_ptr->subblock_lut_size; fp_net = my_fopen (net_file, "r", 0); /* First pass builds the symbol table and counts the number of pins * * on each net. Then I allocate exactly the right amount of storage * * for each net. Finally, the second pass loads the block and net * * arrays. */ for (doall=0;doall<=1;doall++) { /* Pass number. */ init_parse(doall); linenum = 0; /* Reset line number. */ ptr = my_fgets (buf, BUFSIZE, fp_net); while (ptr != NULL) { ptr = get_tok (buf, doall, fp_net); } rewind (fp_net); /* Start at beginning of file again */ } fclose(fp_net); /* Return the three data structures below through subblock_data_ptr. */ subblock_data_ptr->subblock_inf = subblock_inf; subblock_data_ptr->num_subblocks_per_block = num_subblocks_per_block; subblock_data_ptr->chunk_head_ptr = ch_subblock_head_ptr; check_netlist (subblock_data_ptr, num_driver); free_parse(); }
void exec_env(t_shell *sh, char *arg, char **env_cpy) { t_parse *parse; t_job *job; parse = init_parse(sh, arg); job = NULL; if (check_builtins(parse->argv[0])) do_builtins(sh, job, parse); else if ((parse->pid = fork()) == 0) { if (execve(parse->right_path, parse->argv, env_cpy) < 0) { ft_putstr_fd("42sh: command not found: ", 2); ft_putendl_fd(parse->argv[0], 2); exit(127); } } wait(0); free_parse(&parse); }
static int deal_with_int(t_shell *sh, t_job *job, t_parse *parse) { int i; int j; i = 0; j = 1; while (parse->argv[j][i]) { if (parse->argv[j][i] < '0' || parse->argv[j][i] > '9') { ft_putendl_fd("exit: Badly formed number.", 2); return (1); } i++; } i = ft_atoi(parse->argv[1]); free_job(job); free_parse(&parse); reset_term(sh); exit(i); }
int do_exit(t_shell *sh, t_job *job, t_parse *parse) { int i; i = 1; if (!parse->argv[i]) { free_job(job); free_parse(&parse); reset_term(sh); exit(0); } while (parse->argv[i]) i++; if (i > 2) { ft_putendl_fd("exit: Expression Syntax.", 2); return (1); } else if (deal_with_int(sh, job, parse) == 1) return (1); return (0); }
int main (int argc, char **argv) { char * cmdLine; char * username; char ** cmd; char hostname[256]; size_t len = 256; struct sigaction new_action, old_action; /* Inicializa a lista que guarda os processos que rodam em background */ childs = malloc(sizeof(LIST)); ListCreate(childs); /* Inicializa a variável que guarda o ID do processo atual do foreground */ fgChildPid = 0; child_handler_lock = 0; /* Set up the structure to specify the new action. */ new_action.sa_handler = termination_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGINT, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGINT, &new_action, NULL); sigaction (SIGHUP, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGHUP, &new_action, NULL); sigaction (SIGTERM, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGTERM, &new_action, NULL); new_action.sa_handler = child_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGCHLD, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGCHLD, &new_action, NULL); new_action.sa_handler = sigtstop_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGTSTP, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGTSTP, &new_action, NULL); /*inicializa lista que guarda o historico de comandos */ history = malloc(sizeof(struct node)); history->cmd = NULL; history->next = NULL; /* Pega o nome do usuario atual e da máquina */ username = getlogin(); gethostname(hostname, len); asprintf(&userdir, "/home/%s", username); /* Coloca o diretório do usuário como diretório inicial */ chdir(userdir); while (1) { printPrompt(username, hostname); output_r = input_r = 0; rewind(stdin); cmdLine = readline(); if(strcmp(cmdLine, "") != 0) { add_history(cmdLine); cmd = parse(cmdLine); int cmd_id = isBuiltIn(cmd[0]); if(cmd_id >= 0) callBuiltIn(cmd_id, cmd[1]); else { if((childPid = fork()) == 0) { if(output_r) { fd_out = open(output_r_filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR, 0666); dup2(fd_out, 1); } if(input_r) { fd_in = open(input_r_filename, O_RDONLY, 0666); dup2(fd_in, 0); } fgChildPid = childPid; int i = execvp(cmd[0], cmd); if (output_r) close(fd_out); if (input_r) close(fd_in); if(i < 0) { printf("%s: command not found\n", cmd[0]); exit(101); } } else { /*Após criar o processo filho, o pai insere em uma lista ligada o novo processo */ int status; pid_t pidfg; ITEM * p; p = malloc(sizeof(ITEM)); p->pid = childPid; p->isBackground = isBackground; strcpy(p->status, "Running"); strcpy(p->command, cmdLine); ListInsert(childs, p); isBackground = 0; /*E espera ele terminar, caso seja um processo de foreground */ if(!p->isBackground) { child_handler_lock = 1; pidfg = waitpid(childPid, &status, WUNTRACED); child_handler_lock = 0; if ((pidfg >= 0) && (WIFSTOPPED(status) == 0)) ListRemoveByPid(childs, childPid); } } } free_parse(); free(cmdLine); } } }