Main Page   Compound List   File List   Compound Members   File Members  

rr_libs/rd_wlist_arry.c

Go to the documentation of this file.
00001 /* read_wlist_into_array */
00002 /*=====================================================================
00003                 =======   COPYRIGHT NOTICE   =======
00004 Copyright (C) 1994, Carnegie Mellon University and Ronald Rosenfeld.
00005 All rights reserved.
00006 
00007 This software is made available for research purposes only.  It may be
00008 redistributed freely for this purpose, in full or in part, provided
00009 that this entire copyright notice is included on any copies of this
00010 software and applications and derivations thereof.
00011 
00012 This software is provided on an "as is" basis, without warranty of any
00013 kind, either expressed or implied, as to any matter including, but not
00014 limited to warranty of fitness of purpose, or merchantability, or
00015 results obtained from use of this software.
00016 ======================================================================*/
00017 
00018 /* Edited by Philip Clarkson, March 1997 to prevent compilation warnings */
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      /* warn ARPA sites who may have comments starting with a single '#' */
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 

Generated on Tue Dec 21 13:54:46 2004 by doxygen1.2.18