| 429 | /* tok822_scan_limit - tokenize string */ |
| 430 | |
| 431 | TOK822 *tok822_scan_limit(const char *str, TOK822 **tailp, int tok_count_limit) |
| 432 | { |
| 433 | TOK822 *head = 0; |
| 434 | TOK822 *tail = 0; |
| 435 | TOK822 *tp; |
| 436 | int ch; |
| 437 | int tok_count = 0; |
| 438 | |
| 439 | /* |
| 440 | * XXX 2822 new feature: Section 4.1 allows "." to appear in a phrase (to |
| 441 | * allow for forms such as: Johnny B. Goode <johhny@domain.org>. I cannot |
| 442 | * handle that at the tokenizer level - it is not context sensitive. And |
| 443 | * to fix this at the parser level requires radical changes to preserve |
| 444 | * white space as part of the token stream. Thanks a lot, people. |
| 445 | */ |
| 446 | while ((ch = *(const unsigned char *) str++) != 0) { |
| 447 | if (IS_SPACE_TAB_CR_LF(ch)) |
| 448 | continue; |
| 449 | if (ch == '(') { |
| 450 | tp = tok822_alloc(TOK822_COMMENT, (char *) 0); |
| 451 | str = tok822_comment(tp, str); |
| 452 | } else if (ch == '[') { |
| 453 | tp = tok822_alloc(TOK822_DOMLIT, (char *) 0); |
| 454 | COLLECT_SKIP_LAST(tp, str, ch, ch != ']'); |
| 455 | } else if (ch == '"') { |
| 456 | tp = tok822_alloc(TOK822_QSTRING, (char *) 0); |
| 457 | COLLECT_SKIP_LAST(tp, str, ch, ch != '"'); |
| 458 | } else if (ch != '\\' && strchr(tok822_opchar, ch)) { |
| 459 | tp = tok822_alloc(ch, (char *) 0); |
| 460 | } else { |
| 461 | tp = tok822_alloc(TOK822_ATOM, (char *) 0); |
| 462 | str -= 1; /* \ may be first */ |
| 463 | COLLECT(tp, str, ch, !IS_SPACE_TAB_CR_LF(ch) && !strchr(tok822_opchar, ch)); |
| 464 | tok822_quote_atom(tp); |
| 465 | } |
| 466 | if (head == 0) { |
| 467 | head = tail = tp; |
| 468 | while (tail->next) |
| 469 | tail = tail->next; |
| 470 | } else { |
| 471 | tail = tok822_append(tail, tp); |
| 472 | } |
| 473 | if (tok_count_limit > 0 && ++tok_count >= tok_count_limit) |
| 474 | break; |
| 475 | } |
| 476 | if (tailp) |
| 477 | *tailp = tail; |
| 478 | return (head); |
| 479 | } |
| 480 | |
| 481 | /* tok822_parse_limit - translate external string to token tree */ |
| 482 |
no test coverage detected
searching dependent graphs…