00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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));
00036 if (*pl==0) break;
00037 if (nwords>=mwords) {*p_overflow=1; break;}
00038 nwords++;
00039 pbegin = pl;
00040 do pl++; while (!isspace(*pl) && *pl!=0);
00041 pend = pl;
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 }