00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include <stdio.h>
00046
00047 #include "parse.h"
00048
00050 #if 0
00051 #define dprintf(x) do { printf x; fflush(stdout); } while (0);
00052 #else
00053 #define dprintf(x)
00054 #endif
00055
00056
00057
00058
00059 char *
00060 parse_getarg(parse_t *state)
00061 {
00062 char *c;
00063 char *old_current;
00064
00069
00070
00071
00072 if (state->current == NULL) {
00073 dprintf(("parse_getarg() returning NULL (1)\n"));
00074 return (NULL);
00075 }
00076
00077 c = state->current;
00078
00079
00080
00081
00082 while (*c == state->delim)
00083 c++;
00084
00085
00086
00087
00088 if (*c == '\0') {
00089 state->current = NULL;
00090 dprintf(("parse_getarg() returning NULL (2)\n"));
00091 return (NULL);
00092 }
00093
00094
00095
00096
00097
00098 old_current = c;
00099 state->current = c;
00100 while (*c != state->delim && *c != '\0')
00101 c++;
00102
00103
00104
00105
00106
00107
00108 if (*c == state->delim) {
00109 *c++ = '\0';
00110 state->current = c;
00111 dprintf(("parse_getarg() returning %s\n", old_current));
00112 return (old_current);
00113 }
00114
00115
00116
00117
00118
00119
00120 state->current = NULL;
00121 dprintf(("parse_getarg() returning %s\n", old_current));
00122 return (old_current);
00123 }
00124
00125 char *
00126 parse_getallargs(parse_t *state)
00127 {
00128 char *c;
00129 char *e;
00130
00131
00132
00133
00134 if (state->current == NULL) {
00135 dprintf(("parse_getallargs() returning NULL (1)\n"));
00136 return (NULL);
00137 }
00138
00139 c = state->current;
00140 state->current = NULL;
00141
00142
00143
00144
00145 while (*c == state->delim)
00146 c++;
00147
00148 if (1)
00149 {
00150
00151
00152
00153
00154
00155 if (*c == ':')
00156 c++;
00157
00158
00159
00160
00161 while (*c == state->delim)
00162 c++;
00163 }
00164
00165
00166
00167
00168
00169 if (*c == '\0') {
00170 dprintf(("parse_getallargs() returning NULL (2)\n"));
00171 return (NULL);
00172 }
00173
00174
00175
00176
00177 e = c + strlen(c) - 1;
00178 while ((e != c) && (*e == state->delim))
00179 e--;
00180
00181
00182
00183
00184
00185 if ((e == c) && (*e == state->delim)) {
00186 dprintf(("parse_getallargs() returning NULL (3)\n"));
00187 return (NULL);
00188 }
00189
00190
00191
00192
00193 e++;
00194 *e = '\0';
00195
00196 dprintf(("parse_getallargs() returning %s\n", c));
00197 return (c);
00198 }
00199
00200 int
00201 parse_init(parse_t *state, char *pointer)
00202 {
00203 if (pointer && !*pointer)
00204 pointer = NULL;
00205
00206 state->current = pointer;
00207 state->base = pointer;
00208 state->delim = ' ';
00209
00210 return (0);
00211 }
00212
00213 void
00214 parse_cleanup(parse_t *state)
00215 {
00216 state->base = NULL;
00217 state->current = NULL;
00218 state->delim = ' ';
00219 }