OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
s_parse.c
Go to the documentation of this file.
1 #include <string.h>
2 #include "fmt_check.h"
3 
4 char *s_parse(char* str, int enc)
5 /*******************************************************************
6 
7  s_parse
8 
9  purpose: along the lines of strtok, s_parse parses a string
10  using the space as a delimiter as well as an enclosing
11  character like " or ' to return substrings
12 
13  Returns type: char * the pointer to the next substring or NULL
14  if string is exhausted
15 
16  Parameters: (in calling order)
17  Type Name I/O Description
18  ---- ---- --- -----------
19  char* str I input string on first call
20  NULL for subsequent calls
21  int enc I enclosing character such as
22  ' or "
23 
24  Modification history:
25  Programmer Date Description of change
26  ---------- ---- ---------------------
27  W. Robinson 10-Mar-1995 Original development
28 
29  *******************************************************************/ {
30  static char *ptr;
31  char *s_ptr;
32  int start, ienc;
33 
34  /* get the location of this string locally */
35  if (str != NULL)
36  ptr = str;
37  /* 1 - get to a character which is non blank or enclosing */
38  start = 0;
39  ienc = 0;
40  do {
41  if (*ptr == 0)
42  return NULL;
43  else if (*ptr == enc) {
44  ienc = 1;
45  s_ptr = ptr + 1;
46  start = (*(ptr + 1) == 0) ? 0 : 1;
47  } else if (*ptr != ' ') {
48  start = 1;
49  s_ptr = ptr;
50  }
51  ptr++;
52  } while (start == 0);
53 
54  /* find the next blank or, if a quote the ending quote */
55 
56  start = 0;
57  do {
58  if (*ptr == 0)
59  return s_ptr;
60  else if (ienc == 1 && *ptr == enc) {
61  *ptr++ = 0;
62  return s_ptr;
63  } else if (ienc == 0 && *ptr == ' ') {
64  *ptr++ = 0;
65  return s_ptr;
66  } else
67  ptr++;
68  } while (start == 0);
69 
70  return NULL;
71 
72 }
73 
74 
75 
76 
77 
78 
79 
80 
#define NULL
Definition: decode_rs.h:63
char * s_parse(char *str, int enc)
Definition: s_parse.c:4
const char * str
Definition: l1c_msi.cpp:35