t_instr *ft_first_line(char *str) { t_instr *ptr; int i; char *str2; int a; ptr = NULL; a = ft_strlen_mod(str); if (check_v(str, a) == 1) { str2 = (char *)malloc(sizeof(*str2) * 1000); ptr = (t_instr *)malloc(sizeof(t_instr) * 1000); i = 0; str2 = cut_str(str, a - 5); ptr->height = ft_atoi(str2); ptr->length = a; ptr->empty = str[a - 4]; ptr->obst = str[a - 3]; ptr->full = str[a - 2]; } return (ptr); }
// Check the integrity of tablefile bool tablecheck(FILE *table) { // Check IP vals if(!check_ip(table)) { // IP vals are invalid fprintf(stderr, "ERROR: tablecheck failed for IP (Initial Permutation) values.\n"); return false; } // Check E vals if(!check_e(table)) { // E vals are invalid fprintf(stderr, "ERROR: tablecheck failed for E (Expansion) values.\n"); return false; } // Check P vals if(!check_p(table)) { // P vals are invalid fprintf(stderr, "ERROR: tablecheck failed for P (Permutation) values.\n"); return false; } // Check S# vals char header[3]; for(int i=1; i<=8; i++) { sprintf(header, "S%d=", i); if(!check_s(table, header)) { // S# vals are invalid fprintf(stderr, "ERROR: tablecheck failed for S%d (Substitution) values.\n", i); return false; } } // Check V vals if(!check_v(table)) { // V vals are invalid fprintf(stderr, "ERROR: tablecheck failed for V (Circular Rotation) values.\n"); return false; } // Check PC1 vals if(!check_pc1(table)) { // PC1 vals are invalid fprintf(stderr, "ERROR: tablecheck failed for PC1 (Permutated Choice 1) values.\n"); return false; } // Check PC2 vals if(!check_pc2(table)) { // PC2 vals are invalid fprintf(stderr, "ERROR: tablecheck failed for PC2 (Permutated Choice 2) values.\n"); return false; } return true; // PSEUDO-CODE // - Use read_line_vals method to search through file until finds a line starting with header // - Read each item in the line into an array of ints, using comma delimiters to separate // - Run whatever test is needed on the array to ensure that all the values are valid // - Usually something like counting the instances of each number to ensure correct permutation // - Repeat for all headers }