00001 #include <stdlib.h>
00002 #include <grass/gis.h>
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 char **G_tokenize ( char *buf, char *delim)
00021 {
00022 int i;
00023 char **tokens;
00024
00025 i = 0;
00026 while (*buf == ' ' || *buf == '\t')
00027 buf++;
00028
00029 buf = G_store (buf);
00030
00031 tokens = (char **) G_malloc (sizeof (char *));
00032
00033 while (1)
00034 {
00035 while (*buf == ' ' || *buf == '\t')
00036 buf++;
00037 if (*buf == 0)
00038 break;
00039 tokens[i++] = buf;
00040 tokens = (char **) G_realloc ((char *) tokens, (i+1) * sizeof (char *));
00041
00042 while (*buf && (G_index(delim,*buf) == NULL))
00043 buf++;
00044 if (*buf == 0)
00045 break;
00046 *buf++ = 0;
00047 }
00048 tokens[i] = NULL;
00049
00050 return (tokens);
00051 }
00052
00053 int G_number_of_tokens(char **tokens)
00054 {
00055 int n;
00056
00057 for (n = 0; tokens[n] != NULL ; n++)
00058 {
00059
00060 }
00061 return n;
00062 }
00063
00064 int G_free_tokens (char **tokens)
00065 {
00066 if (tokens[0] != NULL)
00067 G_free (tokens[0]);
00068 G_free (tokens);
00069 return (0);
00070 }