Go to the documentation of this file.00001
00017 #include <stdlib.h>
00018 #include <grass/gis.h>
00019
00020
00033 char **G_tokenize(const char *buf, const char *delim)
00034 {
00035 int i;
00036 char **tokens;
00037 char *p;
00038
00039 i = 0;
00040 while (!G_index(delim, *buf) && (*buf == ' ' || *buf == '\t'))
00041 buf++;
00042
00043 p = G_store(buf);
00044
00045 tokens = (char **)G_malloc(sizeof(char *));
00046
00047 while (1) {
00048 while (!G_index(delim, *p) && (*p == ' ' || *p == '\t'))
00049 p++;
00050 if (*p == 0)
00051 break;
00052 tokens[i++] = p;
00053 tokens = (char **)G_realloc((char *)tokens, (i + 1) * sizeof(char *));
00054
00055 while (*p && (G_index(delim, *p) == NULL))
00056 p++;
00057 if (*p == 0)
00058 break;
00059 *p++ = 0;
00060 }
00061 tokens[i] = NULL;
00062
00063 return (tokens);
00064 }
00065
00066
00076 int G_number_of_tokens(char **tokens)
00077 {
00078 int n;
00079
00080 for (n = 0; tokens[n] != NULL; n++) {
00081
00082 }
00083
00084 return n;
00085 }
00086
00087
00098 int G_free_tokens(char **tokens)
00099 {
00100 if (tokens[0] != NULL)
00101 G_free(tokens[0]);
00102 G_free(tokens);
00103
00104 return (0);
00105 }