| 160 | } |
| 161 | |
| 162 | static bool ad_lines(ad_doc_t *d, const char *src, int len) { |
| 163 | int count = 1; |
| 164 | for (int i = 0; i < len; i++) { |
| 165 | count += src[i] == '\n'; |
| 166 | } |
| 167 | d->L = (ad_line_t *)cbm_arena_alloc(d->scratch, (size_t)count * sizeof(*d->L)); |
| 168 | d->in_block = (unsigned char *)cbm_arena_alloc(d->scratch, (size_t)count); |
| 169 | if (!d->L || !d->in_block) { |
| 170 | return false; |
| 171 | } |
| 172 | memset(d->in_block, 0, (size_t)count); |
| 173 | int pos = 0; |
| 174 | for (int i = 0; i < count; i++) { |
| 175 | const char *nl = memchr(src + pos, '\n', (size_t)(len - pos)); |
| 176 | int end = nl ? (int)(nl - src) : len; |
| 177 | d->L[i] = (ad_line_t){src + pos, end - pos}; |
| 178 | pos = end + 1; |
| 179 | } |
| 180 | d->n = count; |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | /* Delimited blocks, then the headings outside them. */ |
| 185 | static void ad_structure(ad_doc_t *d) { |
no test coverage detected