| 7922 | } |
| 7923 | |
| 7924 | char *cbm_adr_render(const cbm_adr_sections_t *sections) { |
| 7925 | if (!sections || sections->count == 0) { |
| 7926 | return heap_strdup(""); |
| 7927 | } |
| 7928 | |
| 7929 | char buf[ST_MAX_DEGREE * ST_GROWTH] = ""; |
| 7930 | int pos = 0; |
| 7931 | bool rendered[ST_MAX_SECTIONS] = {false}; |
| 7932 | |
| 7933 | /* Canonical sections first, in order */ |
| 7934 | for (int c = 0; c < canonical_section_count; c++) { |
| 7935 | for (int i = 0; i < sections->count; i++) { |
| 7936 | if (rendered[i]) { |
| 7937 | continue; |
| 7938 | } |
| 7939 | if (strcmp(sections->keys[i], canonical_sections[c]) == 0) { |
| 7940 | pos = adr_render_section(buf, (int)sizeof(buf), pos, sections->keys[i], |
| 7941 | sections->values[i]); |
| 7942 | rendered[i] = true; |
| 7943 | break; |
| 7944 | } |
| 7945 | } |
| 7946 | } |
| 7947 | |
| 7948 | /* Non-canonical sections alphabetically */ |
| 7949 | int extra[ST_BUF_16]; |
| 7950 | int nextra = 0; |
| 7951 | for (int i = 0; i < sections->count; i++) { |
| 7952 | if (!rendered[i]) { |
| 7953 | extra[nextra++] = i; |
| 7954 | } |
| 7955 | } |
| 7956 | for (int i = SKIP_ONE; i < nextra; i++) { |
| 7957 | int j = i; |
| 7958 | while (j > 0 && strcmp(sections->keys[extra[j]], sections->keys[extra[j - SKIP_ONE]]) < 0) { |
| 7959 | int tmp = extra[j]; |
| 7960 | extra[j] = extra[j - SKIP_ONE]; |
| 7961 | extra[j - SKIP_ONE] = tmp; |
| 7962 | j--; |
| 7963 | } |
| 7964 | } |
| 7965 | for (int i = 0; i < nextra; i++) { |
| 7966 | int idx = extra[i]; |
| 7967 | pos = adr_render_section(buf, (int)sizeof(buf), pos, sections->keys[idx], |
| 7968 | sections->values[idx]); |
| 7969 | } |
| 7970 | |
| 7971 | return heap_strdup(buf); |
| 7972 | } |
| 7973 | |
| 7974 | int cbm_adr_validate_content(const char *content, char *errbuf, int errbuf_size) { |
| 7975 | cbm_adr_sections_t sections = cbm_adr_parse_sections(content); |
no test coverage detected