| 5762 | } |
| 5763 | |
| 5764 | char *cbm_adr_render(const cbm_adr_sections_t *sections) { |
| 5765 | if (!sections || sections->count == 0) { |
| 5766 | return heap_strdup(""); |
| 5767 | } |
| 5768 | |
| 5769 | char buf[ST_MAX_DEGREE * ST_GROWTH] = ""; |
| 5770 | int pos = 0; |
| 5771 | bool rendered[ST_MAX_SECTIONS] = {false}; |
| 5772 | |
| 5773 | /* Canonical sections first, in order */ |
| 5774 | for (int c = 0; c < canonical_section_count; c++) { |
| 5775 | for (int i = 0; i < sections->count; i++) { |
| 5776 | if (rendered[i]) { |
| 5777 | continue; |
| 5778 | } |
| 5779 | if (strcmp(sections->keys[i], canonical_sections[c]) == 0) { |
| 5780 | pos = adr_render_section(buf, (int)sizeof(buf), pos, sections->keys[i], |
| 5781 | sections->values[i]); |
| 5782 | rendered[i] = true; |
| 5783 | break; |
| 5784 | } |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | /* Non-canonical sections alphabetically */ |
| 5789 | int extra[ST_BUF_16]; |
| 5790 | int nextra = 0; |
| 5791 | for (int i = 0; i < sections->count; i++) { |
| 5792 | if (!rendered[i]) { |
| 5793 | extra[nextra++] = i; |
| 5794 | } |
| 5795 | } |
| 5796 | for (int i = SKIP_ONE; i < nextra; i++) { |
| 5797 | int j = i; |
| 5798 | while (j > 0 && strcmp(sections->keys[extra[j]], sections->keys[extra[j - SKIP_ONE]]) < 0) { |
| 5799 | int tmp = extra[j]; |
| 5800 | extra[j] = extra[j - SKIP_ONE]; |
| 5801 | extra[j - SKIP_ONE] = tmp; |
| 5802 | j--; |
| 5803 | } |
| 5804 | } |
| 5805 | for (int i = 0; i < nextra; i++) { |
| 5806 | int idx = extra[i]; |
| 5807 | pos = adr_render_section(buf, (int)sizeof(buf), pos, sections->keys[idx], |
| 5808 | sections->values[idx]); |
| 5809 | } |
| 5810 | |
| 5811 | return heap_strdup(buf); |
| 5812 | } |
| 5813 | |
| 5814 | int cbm_adr_validate_content(const char *content, char *errbuf, int errbuf_size) { |
| 5815 | cbm_adr_sections_t sections = cbm_adr_parse_sections(content); |
no test coverage detected