/* @(#)hcg_parse.c 2.1 93/05/18 */ /******************************************************************************/ /* function : hcg_parse */ /* */ /* subsystem : chgen */ /* */ /* input : s (source line), w (resulting parsed word), idx (see descrip)*/ /* */ /* output : w (next word parsed from s) , idx (see descrip) */ /* */ /* returns : void */ /* */ /* author : Steve Smith / Craig Smith */ /* */ /* created : July, 1991 */ /* */ /* revisions : */ /* */ /* description : This routine will parse the next 'word' out of the specified */ /* input line. A word is defined as ascii text with whitespace */ /* (space or table) on either side. The idx parameter serves */ /* two purposes. On the way in, it represents the starting */ /* position in the source string (s) to begin parsing. Upon */ /* return, idx is set to the start of the next word in the */ /* source string (ie, after the parsed word, AND after any */ /* more whitespace). If there is no word to be parsed (ie, */ /* the source string is exhausted), the resulting word (w) is */ /* safely empty (null-string). This routine does not include */ /* any chgen specific logic or include files, and is very handy */ /* for other projects that require simple but reliable parsing. */ /* */ /******************************************************************************/ #include "chgen_externs.h" void hcg_parse(s,w,idx) char *s; char *w; int *idx; { static char rcsid[] = "$Id: hcg_parse.c,v 1.3.4.1 1999/05/04 17:00:07 jkarner Exp $"; int i; i = 0; while ( (s[*idx] == ' ') || (s[*idx] == '\t') || (s[*idx] == '\n')) /* skip leading whitespace */ (*idx)++; while ( (s[*idx] != ' ') && (s[*idx] != '\t') && (s[*idx] != '\0') && (s[*idx] != '\n')) /* parse word */ { w[i++] = s[*idx]; (*idx)++; } w[i] = '\0'; /* terminate resulting word (which may safely be empty if input exhausted) */ while ( (s[*idx] == ' ') || (s[*idx] == '\t') || (s[*idx] == '\n')) /* skip trailing whitespace, move on to start of next word */ (*idx)++; return; }