static t_lexer *add_pipe_alone(t_lexer *node, t_parse *tree) { t_inst *last_inst; last_inst = find_last_inst(tree); last_inst->next = init_inst(NULL); last_inst->next->prev = last_inst; return (node->next); }
ss_inst *init_insts(stream_t *stream) { char *buf; char type; long IP, new_IP; new_IP = IP = getpos(stream); ss_inst *head, *ptr; ss_inst *indexes[4]; head = ptr = malloc(sizeof(ss_inst)); while (listench(stream)) { int len = get_parsable_length(stream); buf = calloc(len + 1, sizeof(char)); getstr(stream, len, buf); if (buf[len - 1] == '(' && *buf == '?') { type = '('; indexes[1] = parse_until(stream, ')'); } else if (*buf == '[') { type = '['; indexes[1] = parse_until(stream, ']'); } else if (*buf == '{') { type = '{'; indexes[1] = parse_until(stream, '}'); } else if (*buf == '?') { type = '?'; char iden = buf[len - 1]; if (iden == '(') { indexes[1] = parse_until(stream, ')');/* {expr} */ } else if (strchr(RETN, iden)) { move_stream(stream, 1); new_IP += get_parsable_length(stream); move_stream(stream, -1); } if (listench(stream) == '[') type = 'w'; move_stream(stream, new_IP - IP - 1); // TODO conseq & alt and loop body } else { type = 0; } indexes[0] = init_inst(type, buf); if (type) { for (int i = 1; i < indexes[0]->branch_no; i ++) indexes[0]->indexes[i] = indexes[i]; move_stream(stream, new_IP - IP - 1); } ptr->indexes[0] = indexes[0]; ptr = ptr->indexes[0]; } ss_inst *retn = head->indexes[0]; free_inst(head); return retn; }
static t_lexer *add_pipe_ncmd(t_lexer *node, t_parse *tree) { char **tab; t_inst *last_inst; if (node->next->type == CMD) tab = ft_strsplitspace(node->next->str); else tab = ft_strsplit(node->next->str, '\0'); last_inst = find_last_inst(tree); last_inst->next = init_inst(NULL); last_inst->next->prev = last_inst; last_inst->next->arg = tab; return (node->next->next); }
int parse_options(inst *instance, int argc, char **argv, int rank) { int opt; init_inst(instance); static struct option long_options[] = { {"step", required_argument, 0, 's' }, {"i", required_argument, 0, 'i' }, {"iterations", required_argument, 0, 't' }, {"dt", required_argument, 0, 'd' }, {"grid", required_argument, 0, 'g' }, {"lastdump", required_argument, 0, 'l' }, {"alldump", required_argument, 0, 'a' }, {"sensor", required_argument, 0, 'c' }, {"frequency", required_argument, 0, 'f' }, {0, 0, 0, 0 } }; int long_index = 0; while ((opt = getopt_long_only(argc, argv,"s:i:t:d:g:l:a:S:f:", long_options, &long_index )) != -1) { switch (opt) { case 's' : instance->step = atoi(optarg); break; case 'i' : instance->input_path = optarg; break; case 't' : instance->iteration = atoi(optarg); break; case 'd' : instance->dt = (double) atof(optarg); break; case 'g' : instance->p = atoi(optarg); // printf("%c %c %d\n", argv[optind][0],argv[optind][1], strlen(argv[optind])); if(optind < argc && argv[optind][0] != '-' && (strlen(argv[optind]) < 2 || argv[optind][1] != '-')) { instance->q = atoi(argv[optind]); optind++; } else { fprintf(stderr, "Error: grid need to positive integers\n"); print_usage(); exit(EXIT_FAILURE); } break; case 'l': instance->lastdump = optarg; break; case 'a': instance->alldump = optarg; break; case 'c': instance->sensors = optarg; break; case 'f': instance->frequency = atoi(optarg); break; default: print_usage(); exit(EXIT_FAILURE); } } #ifdef DEBUG if(rank == 0) { fprintf(stderr, "Option Recap:\n" "\tstep: %d\n" "\tinput: %s\n" "\titeration: %d\n" "\tdt: %f\n" "\tgrid: %d %d\n", instance->step, instance->input_path, instance->iteration, instance->dt, instance->p, instance->q); if(instance->lastdump != NULL) { fprintf(stderr, "\tlastdump: %s\n", instance->lastdump); // char *b; // sprintf(b, lastdump, 2); // printf("\t\t%s\n", b); } if(instance->alldump != NULL) fprintf(stderr, "\talldump: %s\n", instance->alldump); if(instance->sensors != NULL) fprintf(stderr, "\tsensor: %s\n", instance->sensors); if(instance->frequency != 1) fprintf(stderr, "\tfrequency: %d\n", instance->frequency); } #endif int err = 0; // Check we have at least the required arguments. if(instance->step < 0 || instance->step > 4) { err = 1; if(rank == 0) fprintf(stderr, "Error: step must be between 0 and 4\n"); } if(instance->iteration <= 0) { err = 1; if(rank == 0) fprintf(stderr, "Error: the number of iterations should be a positive integer\n"); } if(instance->dt == 0) { err = 1; if(rank == 0) fprintf(stderr, "Error: dt should not be 0\n"); } if(instance->p <= 0) { err = 1; if(rank == 0) fprintf(stderr, "Error: the p-coordinate of the grid should be a positive integer\n"); } if(instance->q <= 0) { err = 1; if(rank == 0) fprintf(stderr, "Error: the q-coordinate of the grid should be a positive integer\n"); } if(instance->frequency < 1) { err = 1; if(rank == 0) fprintf(stderr, "Error: the frequency should be a positive integer\n"); } if(err == 1) { if(rank == 0) print_usage(); return 1; } return 0; }