| 184 | |
| 185 | |
| 186 | static inline int |
| 187 | __cmdline_parse(struct cmdline *cl, const char *buf, bool call_fn) |
| 188 | { |
| 189 | unsigned int inst_num=0; |
| 190 | cmdline_parse_inst_t *inst; |
| 191 | const char *curbuf; |
| 192 | union { |
| 193 | char buf[CMDLINE_PARSE_RESULT_BUFSIZE]; |
| 194 | long double align; /* strong alignment constraint for buf */ |
| 195 | } result, tmp_result; |
| 196 | void (*f)(void *, struct cmdline *, void *) = NULL; |
| 197 | void *data = NULL; |
| 198 | int comment = 0; |
| 199 | int linelen = 0; |
| 200 | int parse_it = 0; |
| 201 | int err = CMDLINE_PARSE_NOMATCH; |
| 202 | int tok; |
| 203 | cmdline_parse_ctx_t *ctx; |
| 204 | char *result_buf = result.buf; |
| 205 | |
| 206 | if (!cl || !buf) |
| 207 | return CMDLINE_PARSE_BAD_ARGS; |
| 208 | |
| 209 | ctx = cl->ctx; |
| 210 | |
| 211 | /* |
| 212 | * - look if the buffer contains at least one line |
| 213 | * - look if line contains only spaces or comments |
| 214 | * - count line length |
| 215 | */ |
| 216 | curbuf = buf; |
| 217 | while (! isendofline(*curbuf)) { |
| 218 | if ( *curbuf == '\0' ) { |
| 219 | debug_printf("Incomplete buf (len=%d)\n", linelen); |
| 220 | return 0; |
| 221 | } |
| 222 | if ( iscomment(*curbuf) ) { |
| 223 | comment = 1; |
| 224 | } |
| 225 | if ( ! isblank2(*curbuf) && ! comment) { |
| 226 | parse_it = 1; |
| 227 | } |
| 228 | curbuf++; |
| 229 | linelen++; |
| 230 | } |
| 231 | |
| 232 | /* skip all endofline chars */ |
| 233 | while (isendofline(buf[linelen])) { |
| 234 | linelen++; |
| 235 | } |
| 236 | |
| 237 | /* empty line */ |
| 238 | if ( parse_it == 0 ) { |
| 239 | debug_printf("Empty line (len=%d)\n", linelen); |
| 240 | return linelen; |
| 241 | } |
| 242 | |
| 243 | debug_printf("Parse line : len=%d, <%.*s>\n", |
no test coverage detected