void create_index(char *filepath) { PWord_t PValue; // Judy array element. Word_t Bytes; // size of JudySL array. char buffer[MAXLINE]; // string to insert FILE *fp; fp = fopen(filepath, "r"); if (fp == NULL) { perror ("db open failure"); return; } while(fgets(buffer, sizeof(buffer), fp) != NULL) { remove_eol(buffer); JSLI(PValue, PJArray, buffer); // store string into array if (PValue == PJERR) // if out of memory? { // so do something printf("Malloc failed -- get more ram\n"); exit(1); } ++(*PValue); // count instances of string } fclose(fp); }
int get_next_query_descripton(char query_description[]) { fgets(query_description, 100, fquery); remove_eol(query_description); if(!feof(fquery)) return 1; return 0; }
int get_next_base_description(char base_description[]) { fgets(base_description, 100, fdatabase); remove_eol(base_description); if(!feof(fdatabase)) return 1; return 0; }
void get_next_query_string(char *str) { char line[100]; int i = 0; long prev_pos = ftell(fquery); fgets(line, 100, fquery); remove_eol(line); str[0] = 0; i = 0; do { strcat(str + i, line); prev_pos = ftell(fquery); if (fgets(line, 100, fquery) == NULL) break; remove_eol(line); i += 80; } while (line[0] != '>'); fseek(fquery, prev_pos, SEEK_SET); }
void get_next_base_string(char *base) { char line[100]; int i = 0; long prev_pos = ftell(fdatabase); base[0] = 0; i = 0; fgets(line, 100, fdatabase); remove_eol(line); do { strcat(base + i, line); prev_pos = ftell(fdatabase); if (fgets(line, 100, fdatabase) == NULL) break; remove_eol(line); i += 80; } while (line[0] != '>'); fseek(fdatabase, prev_pos, SEEK_SET); }
int main(int argc, void **argv) { char buffer[MAXLINE]; Word_t Bytes; FILE *fp = NULL; int result =0; int count = 0; int i,j; int start_len; if(argc < 2) { printf("provide file to search\n"); return; } char *file = argv[1]; // populate map and new sorted list create_index(file); fp = fopen(file, "r"); if (fp == NULL) { perror("no sorted list exist"); goto process_done; } // loop through the list from the longest word while(fgets(buffer, sizeof(buffer), fp) !=NULL) { remove_eol(buffer); start_len = strlen(buffer); while(1) { if (start_len < MIN_WORD_LEN*MIN_WORD_LEN) break; if (string_prime_div(buffer, start_len - 1)) { printf("%d.%s\n", count, buffer); count++; break; } else { start_len--; } } } printf("total %d of words found that composed of other word in the list\n", count); JSLFA(Bytes, PJArray); fclose(fp); process_done: return 0; }