int main(void) { char *line; t_map map; bzero(&map, sizeof(map)); if (!(map.cells = ht_create(2048)) || !(map.list = new_vector(sizeof(char *))) || !extract_nb_ants(&map) || map.ants_nb > 1000000) exit(write(1, "Error\n", 6)); line = NULL; while (get_next_line(0, &line) == 1) { write(1, line, ft_strlen(line)); write(1, "\n", 1); if (!analyze_line(line, &map)) break ; free(line); } write(1, "\n", 1); if (map.start && map.end) solve_master(&map); else write(1, "Error\n", 6); return (1); }
// // process_config_file // // There is no error checking on the handling of string or the reading // of the file. // static void process_config_file(ifstream &the_file, bool personalized) { for (;;) { string line; getline(the_file, line); if (!the_file && line.size() == 0) return; analyze_line(line, personalized); } }
int read_line(char *line, char *ts) { char *i_char; int j = 0; char *info[LINE_COLUMNS]; /* info[0] = strstrtok(line, DELIMETER_FOUR); for(j = 1; ; j++) { i_char = strstrtok(NULL, DELIMETER_FOUR); if(i_char == NULL) break; info[j] = i_char; } */ for(j = 0; ; j++) { i_char = strstr(line, DELIMETER_FOUR); if(i_char == NULL) { info[j++] = line; info[j] = NULL; //printf("hahaha %d is %s\n", j - 1, info[j - 1]); break; } *(line + strlen(line) - strlen(i_char)) = '\0'; info[j] = line; line = i_char + strlen(DELIMETER_FOUR); } /* for(j = 0; j < LINE_COLUMNS; j++) { if(info[j] == NULL) break; if(strcmp(info[j], "\n") == 0) break; printf("%d is %s\n", j, info[j]); } return; */ if(strcmp(info[j - 1], "\n") == 0 && (j == LINE_COLUMNS - 5 || j == LINE_COLUMNS - 2 || j == LINE_COLUMNS)) { strcpy(ts, info[0]); return analyze_line(info); } else { fprintf(stderr, " Invalid line!\n"); return -1; } }