Classify one command paragraph; `depth` is the =over nesting. */
| 2383 | |
| 2384 | /* Classify one command paragraph; `depth` is the =over nesting. */ |
| 2385 | static pod_cmd_t pod_classify(const char *src, uint32_t sb, uint32_t eb, int *depth) { |
| 2386 | uint32_t wb = sb + SKIP_ONE; |
| 2387 | while (wb < eb && (isalnum((unsigned char)src[wb]) || src[wb] == '_')) { |
| 2388 | wb++; |
| 2389 | } |
| 2390 | const char *w = src + sb + SKIP_ONE; |
| 2391 | size_t wl = wb - sb - SKIP_ONE; |
| 2392 | pod_cmd_t c = {sb, eb, wb, POD_OTHER, 0}; |
| 2393 | size_t head_len = strlen("head"); |
| 2394 | if (wl == head_len + SKIP_ONE && strncmp(w, "head", head_len) == 0 && |
| 2395 | isdigit((unsigned char)w[head_len])) { |
| 2396 | c.type = POD_HEAD; |
| 2397 | c.level = (uint8_t)(w[head_len] - '0'); |
| 2398 | } else if (pod_word_is(w, wl, "item")) { |
| 2399 | c.type = POD_ITEM; |
| 2400 | c.level = (uint8_t)*depth; |
| 2401 | } else if (pod_word_is(w, wl, "over")) { |
| 2402 | c.type = POD_OVER; |
| 2403 | (*depth)++; |
| 2404 | } else if (pod_word_is(w, wl, "back")) { |
| 2405 | c.type = POD_BACK; |
| 2406 | c.level = (uint8_t)*depth; |
| 2407 | if (*depth > 0) { |
| 2408 | (*depth)--; |
| 2409 | } |
| 2410 | } else if (pod_word_is(w, wl, "cut")) { |
| 2411 | c.type = POD_CUT; |
| 2412 | } |
| 2413 | return c; |
| 2414 | } |
| 2415 | |
| 2416 | /* Command paragraphs of one POD block, in order. */ |
| 2417 | static int pod_commands(CBMArena *a, const char *src, uint32_t pb, uint32_t pe, pod_cmd_t **out) { |
no test coverage detected