/** * * (1) opens the word file and adds it to the word file list * (2) reads in the words * (3) puts each word in a Dict_node * (4) links these together by their left pointers at the * front of the list pointed to by dn * (5) returns a pointer to the first of this list */ Dict_node * read_word_file(Dictionary dict, Dict_node * dn, char * filename) { Dict_node * dn_new; Word_file * wf; FILE * fp; const char * s; char file_name_copy[MAX_PATH_NAME+1]; safe_strcpy(file_name_copy, filename+1, sizeof(file_name_copy)); /* get rid of leading '/' */ if ((fp = dictopen(file_name_copy, "r")) == NULL) { prt_error("Error opening word file %s\n", file_name_copy); return NULL; } /*printf(" Reading \"%s\"\n", file_name_copy);*/ /*printf("*"); fflush(stdout);*/ wf = (Word_file *) xalloc(sizeof (Word_file)); safe_strcpy(wf->file, file_name_copy, sizeof(wf->file)); wf->changed = FALSE; wf->next = dict->word_file_header; dict->word_file_header = wf; while ((s = get_a_word(dict, fp)) != NULL) { dn_new = (Dict_node *) xalloc(sizeof(Dict_node)); dn_new->left = dn; dn = dn_new; dn->string = s; dn->file = wf; } fclose(fp); return dn; }
char *replace_by_alias(char *str, t_alias *list) { char *new_str; char *word; int save; int x; x = -1; if ((new_str = copy_str(str)) == NULL) return (NULL); while (new_str[++x]) { if (new_str[x] != ';' && new_str[x] != ' ' && new_str[x] != '\t' && new_str[x] != '|' && new_str[x] != '&') { save = x; if ((word = get_a_word(new_str, &x)) && is_alias(&word, list)) { if ((new_str = replace_word(word, new_str, save, &x)) == NULL) return (NULL); } else if (word) free(word); } } return (new_str); }
/** * * (1) opens the word file and adds it to the word file list * (2) reads in the words * (3) puts each word in a Dict_node * (4) links these together by their left pointers at the * front of the list pointed to by dn * (5) returns a pointer to the first of this list */ Dict_node * read_word_file(Dictionary dict, Dict_node * dn, char * filename) { Word_file * wf; FILE * fp; const char * s; filename += 1; /* get rid of leading '/' */ if ((fp = dictopen(filename, "r")) == NULL) { return NULL; } wf = malloc(sizeof (Word_file)); wf->file = string_set_add(filename, dict->string_set); wf->changed = false; wf->next = dict->word_file_header; dict->word_file_header = wf; while ((s = get_a_word(dict, fp)) != NULL) { if ('\0' == s[0]) /* returned error indication */ { fclose(fp); free_insert_list(dn); return NULL; } Dict_node * dn_new = malloc(sizeof(Dict_node)); dn_new->left = dn; dn = dn_new; dn->string = s; dn->file = wf; } fclose(fp); return dn; }