blob: 795d783e67992a161812f4452ca5f939cfd1767c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/* strword.c 2.9.0 92/07/06 - new improved version of strword */
/* - Damian Cugley <pdc@prg.ox.ac.uk> Fri. 1 Mar. 1991
-----------------------------------------------------------------------
This software module copyright (c) 1991 Damian Cugley.
It is provided for free on an "as-is" basis.
See the file COPYING for more information.
-----------------------------------------------------------------------
*/
#include <ctype.h>
#include "strmisc.h"
char *
strword(str, sp)
char *str, /* if non-null, read from this string */
**sp; /* used to store state between calls */
{
char *result,
*p, /* copy word to here */
*q; /* copy word from here */
for (result = (str ? str : *sp); *result && isspace(*result); ++result)
;
p = result;
if (*p == '"')
{ /* word starts with " char */
for (q = p + 1;
*q && !(*q == '"' && *++q != '"');
*p++ = *q++)
;
*sp = q; /* at least 2 past p */
}
else
{
while (*p && !isspace(*p))
p++;
*sp = *p ? p + 1 : p;
}
*p = '\0'; /* chop returned string after end of word */
return *result ? result : (char *)0;
}
|