00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <strings.h>
00023 #include "general.h"
00024
00025
00033 void read_wlist_into_array(wlist_filename, verbosity, p_wlist, p_n_wlist)
00034 char *wlist_filename;
00035 char ***p_wlist;
00036 int verbosity, *p_n_wlist;
00037 {
00038 static char rname[]="read_wlist_into_array";
00039 FILE *wlist_fp = rr_iopen(wlist_filename);
00040 char **wlist;
00041 int n_wlist, c, lastc, entry_no;
00042 char wlist_entry[1024], word[256];
00043
00044
00045 lastc = '\0';
00046 n_wlist = 0;
00047 while ((c=getc(wlist_fp)) != EOF) {
00048 if (c == '\n') n_wlist++;
00049 lastc = c;
00050 }
00051 if (lastc != '\n') quit(-1,"%s: no newline at end of %s\n",rname,wlist_filename);
00052 rr_iclose(wlist_fp);
00053 wlist_fp = rr_iopen(wlist_filename);
00054
00055 wlist = (char **) rr_malloc((n_wlist+1)*sizeof(char *));
00056 entry_no = 0;
00057
00058 while (fgets (wlist_entry, sizeof (wlist_entry), wlist_fp)) {
00059 if (strncmp(wlist_entry,"##",2)==0) continue;
00060
00061 sscanf (wlist_entry, "%s ", word);
00062 if (strncmp(wlist_entry,"#",1)==0) {
00063 fprintf(stderr,"\n\n===========================================================\n");
00064 fprintf(stderr,"%s:\nWARNING: line assumed NOT a comment:\n",rname);
00065 fprintf(stderr, ">>> %s <<<\n",wlist_entry);
00066 fprintf(stderr, " '%s' will be included in the vocabulary\n",word);
00067 fprintf(stderr, " (comments must start with '##')\n");
00068 fprintf(stderr,"===========================================================\n\n");
00069 }
00070 wlist[++entry_no] = salloc(word);
00071 }
00072 rr_iclose(wlist_fp);
00073 if (verbosity) fprintf(stderr,"%s: a list of %d words was read from \"%s\".\n",
00074 rname,entry_no,wlist_filename);
00075 *p_wlist = wlist;
00076 *p_n_wlist = entry_no;
00077 }
00078
00079