BRL-CAD
strtok.c
Go to the documentation of this file.
1 /* This is a public-domain reimplementation of strtok(3).
2  Not derived from licensed software.
3  This code may be used on any computer system for any
4  purpose by anyone.
5 
6  Henry Spencer @ U of Toronto Zoology
7  {allegra, ihnp4, decvax, pyramid}!utzoo!henry
8  Wed Jun 25 19:21:34 EDT 1986
9 */
10 
11 #include "common.h"
12 
13 /* quell warnings */
14 #if defined(HAVE_WUNUSED_CONST_VARIABLE)
15 # if HAVE_GCC_DIAG_PRAGMAS
16 # pragma GCC diagnostic push /* begin ignoring warnings */
17 # pragma GCC diagnostic ignored "-Wunused-const-variable"
18 # elif HAVE_CLANG_DIAG_PRAGMAS
19 # pragma clang diagnostic push /* begin ignoring warnings */
20 # pragma clang diagnostic ignored "-Wunused-const-variable"
21 # endif
22 #endif
23 
24 /* quell empty-compilation unit warnings */
25 static const int unused = 0;
26 
27 #if defined(HAVE_WUNUSED_CONST_VARIABLE)
28 # if HAVE_GCC_DIAG_PRAGMAS
29 # pragma GCC diagnostic pop /* end ignoring warnings */
30 # elif HAVE_CLANG_DIAG_PRAGMAS
31 # pragma clang diagnostic pop /* end ignoring warnings */
32 # endif
33 #endif
34 
35 /*
36  * This public domain version of strtok() made available to systems that
37  * don't have their own.
38  */
39 #ifndef HAVE_STRTOK
40 #include "sysv.h"
41 
42 static char *scanpoint = 0;
43 
44 /**
45  * Get next token from string s (0 on 2nd, 3rd, etc. calls),
46  * where tokens are nonempty strings separated by runs of
47  * chars from delim. Writes NULLs into s to end tokens. delim need not
48  * remain constant from call to call.
49  */
50 char * /* 0 if no token left */
51 strtok(char *s, register const char *delim)
52 {
53  register char *scan;
54  char *tok;
55  register const char *dscan;
56  if (s == (char*)0 && scanpoint == (char*)0)
57  return (char*)0;
58  if (s != (char*)0)
59  scan = s;
60  else
61  scan = scanpoint;
62 
63  /*
64  * Scan leading delimiters.
65  */
66  for (; *scan != '\0'; scan++) {
67  for (dscan = delim; *dscan != '\0'; dscan++)
68  if (*scan == *dscan)
69  break;
70  if (*dscan == '\0')
71  break;
72  }
73  if (*scan == '\0') {
74  scanpoint = (char*)0;
75  return (char*)0;
76  }
77 
78  tok = scan;
79 
80  /*
81  * Scan token.
82  */
83  for (; *scan != '\0'; scan++) {
84  for (dscan = delim; *dscan != '\0';) /* ++ moved down. */
85  if (*scan == *dscan++) {
86  scanpoint = scan+1;
87  *scan = '\0';
88  return tok;
89  }
90  }
91 
92  /*
93  * Reached end of string.
94  */
95  scanpoint = (char*)0;
96  return tok;
97 }
98 
99 #endif
100 
101 /*
102  * Local Variables:
103  * mode: C
104  * tab-width: 8
105  * indent-tabs-mode: t
106  * c-file-style: "stroustrup"
107  * End:
108  * ex: shiftwidth=4 tabstop=8
109  */
if lu s
Definition: nmg_mod.c:3860
Header file for the BRL-CAD common definitions.
char * strtok(char *s, register const char *delim)
Definition: strtok.c:51