action parse_command_line(const unsigned char * command_line, int * const num_arg, unsigned char ** const string_arg, const int exec_only_options) { int h; action a; const unsigned char *p = command_line; if (num_arg) *num_arg = -1; if (string_arg) *string_arg = NULL; if (!command_line) return NOP_A; if (!*p) return NOP_A; while(isasciispace(*p)) p++; command_line = p; if (!isalpha(*p)) return NOP_A; while(*p && !isasciispace(*p)) p++; h = hash_cmd(command_line, p - command_line); if ((a = hash_table[h]) && !cmdcmp(commands[--a].name, command_line) || (a = short_hash_table[h]) && !cmdcmp(commands[--a].short_name, command_line)) { while(isasciispace(*p)) p++; if (!(*p && (commands[a].flags & NO_ARGS))) { if (!*p || (commands[a].flags & ARG_IS_STRING) || isxdigit(*p) || *p == 'x' || *p =='X') { if ((commands[a].flags & IS_OPTION) || !exec_only_options) { if (*p) { if ((commands[a].flags & ARG_IS_STRING) && string_arg) { int len = strlen(p); if (len > 1 && *p == '"' && p[len - 1] == '"') { p++; len -= 2; } if (len == 0 && !(commands[a].flags & EMPTY_STRING_OK)) return -STRING_IS_EMPTY; if (!(*string_arg = malloc(len + 1))) return -OUT_OF_MEMORY; memcpy(*string_arg, p, len); (*string_arg)[len] = 0; } else if (num_arg) { char *q; *num_arg = strtol(p, &q, 0); if (*q && !isasciispace(*q)) return -NOT_A_NUMBER; } } return a; } D(fprintf(stderr,"parse_command error: Can execute only options.\n");) return -CAN_EXECUTE_ONLY_OPTIONS; } D(fprintf(stderr,"parse_command error: Has numeric argument.\n");) return -HAS_NUMERIC_ARGUMENT; }
void start_prgm(char **env, char **argv) { if (test_access(argv[0])) exit(1); if (!ft_strncmp("./", argv[0], 2)) execve(argv[0] + 2, argv, env); else if ((argv[0] = hash_cmd(argv[0], env))) execve(argv[0], argv, env); command_not_find(argv[0]); exit(1); }
void parse_arguments(char **environ, char *line, int boolean) { char **av; av = ft_strsplit(line, ' '); check_tilde_and_dollar(environ, av, boolean); av[0] = hash_cmd(av[0], environ); map_environ(environ); suspend_terminal(); if (execve(av[0], av, environ) == -1) command_not_find(av[0]); }
//{{{void test_open_off_file(void) void test_open_off_file(void) { struct off_file *o1 = open_off_file("http://s3-us-west-2.amazonaws.com/gqt-data/test/10.1e4.var.bcf.off"); TEST_ASSERT_EQUAL('G', o1->gqt_header->marker[0]); TEST_ASSERT_EQUAL('Q', o1->gqt_header->marker[1]); TEST_ASSERT_EQUAL('T', o1->gqt_header->marker[2]); TEST_ASSERT_EQUAL('o', o1->gqt_header->type); TEST_ASSERT_EQUAL(atoi(MAJOR_VERSION), o1->gqt_header->major); TEST_ASSERT_EQUAL(atoi(MINOR_VERSION), o1->gqt_header->minor); //TEST_ASSERT_EQUAL(atoi(REVISION_VERSION), o1->gqt_header->revision); //TEST_ASSERT_EQUAL(atoi(BUILD_VERSION), o1->gqt_header->build); TEST_ASSERT_EQUAL(0x11223344, o1->gqt_header->magic); TEST_ASSERT_EQUAL(43, o1->gqt_header->num_variants); TEST_ASSERT_EQUAL(10, o1->gqt_header->num_samples); #if 0 TEST_ASSERT_EQUAL(hash_cmd(full_cmd), b1->gqt_header->id_hash); TEST_ASSERT_EQUAL(num_variants, b1->gqt_header->num_variants); TEST_ASSERT_EQUAL(num_samples, b1->gqt_header->num_samples); TEST_ASSERT_EQUAL(header_size,b1->data_start); uint32_t i; for (i = 0; i < 20; i++) TEST_ASSERT_EQUAL(0, b1->gqt_header->more[i]); TEST_ASSERT_EQUAL(u_size, b1->bim_header->u_size); TEST_ASSERT_EQUAL(c_size, b1->bim_header->c_size); TEST_ASSERT_EQUAL(h_size, b1->bim_header->h_size); TEST_ASSERT_EQUAL(1, b1->bim_header->md_line_lens[0]); TEST_ASSERT_EQUAL(2, b1->bim_header->md_line_lens[1]); TEST_ASSERT_EQUAL(3, b1->bim_header->md_line_lens[2]); TEST_ASSERT_EQUAL(4, b1->bim_header->md_line_lens[3]); destroy_bim_file(b1); #endif //remove(file_name); }