GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
gis/token.c
Go to the documentation of this file.
1
17
#include <stdlib.h>
18
#include <grass/gis.h>
19
20
33
char
**
G_tokenize
(
const
char
*buf,
const
char
*delim)
34
{
35
int
i;
36
char
**tokens;
37
char
*p;
38
39
i = 0;
40
while
(!
G_index
(delim, *buf) && (*buf ==
' '
|| *buf ==
'\t'
))
/* needed for G_free () */
41
buf++;
42
43
p =
G_store
(buf);
44
45
tokens = (
char
**)G_malloc(
sizeof
(
char
*));
46
47
while
(1) {
48
while
(!
G_index
(delim, *p) && (*p ==
' '
|| *p ==
'\t'
))
49
p++;
50
if
(*p == 0)
51
break
;
52
tokens[i++] = p;
53
tokens = (
char
**)G_realloc((
char
*)tokens, (i + 1) *
sizeof
(
char
*));
54
55
while
(*p && (
G_index
(delim, *p) ==
NULL
))
56
p++;
57
if
(*p == 0)
58
break
;
59
*p++ = 0;
60
}
61
tokens[i] =
NULL
;
62
63
return
(tokens);
64
}
65
66
76
int
G_number_of_tokens
(
char
**tokens)
77
{
78
int
n;
79
80
for
(n = 0; tokens[n] !=
NULL
; n++) {
81
/* nothing */
82
}
83
84
return
n;
85
}
86
87
98
int
G_free_tokens
(
char
**tokens)
99
{
100
if
(tokens[0] !=
NULL
)
101
G_free
(tokens[0]);
102
G_free
(tokens);
103
104
return
(0);
105
}
lib
gis
token.c
Generated on Sun Mar 16 2014 05:07:48 for GRASS Programmer's Manual by
1.8.1.2