Main Page   Compound List   File List   Compound Members   File Members  

rr_libs/parse_line.c

Go to the documentation of this file.
00001 /* parse_line(): given a text line, return pointers to word begin/end positions. */
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 #include <ctype.h>
00019 
00024 void parse_line(
00025         char *line, int mwords, int canonize,
00026         char **pword_begin, char **pword_end, int *p_nwords, int *p_overflow)
00027 {
00028   char *pl, *psq, *ptmp, *pbegin, *pend;
00029   int  nwords=0;
00030 
00031   *p_overflow = 0;
00032   pl = line-1;
00033   psq = line;
00034   do {
00035      do pl++; while (isspace(*pl));           /* find beginning of next word */
00036      if (*pl==0) break;                       /* no more words */
00037      if (nwords>=mwords) {*p_overflow=1; break;} /* no room for next word */
00038      nwords++;
00039      pbegin = pl;
00040      do pl++; while (!isspace(*pl) && *pl!=0); /* find end of current word */
00041      pend = pl;   /* (word ends in whitespace or e.o.line) */
00042 
00043      if (canonize) {
00044         *pword_begin++ = psq;
00045         if (psq!=pbegin) for (ptmp=pbegin; ptmp<pend;) *psq++ = *ptmp++;
00046         else psq = pend;
00047         *pword_end++ = psq;
00048         *psq++ = ' ';
00049      }
00050      else {
00051         *pword_begin++ = pbegin;
00052         *pword_end++ = pend;
00053      }
00054   } while (*pl!=0);
00055 
00056   if (canonize) **(pword_end-1) = '\0';
00057   *p_nwords = nwords;
00058 }

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