chiark / gitweb /
Stop trying to indent XML output
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 16 Jan 2025 13:50:00 +0000 (13:50 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 19 Jan 2025 00:49:30 +0000 (00:49 +0000)
The indentation wasn't always correct, and made the C code ugly.  I've
now found "xmllint --format", which does a better job, so I think it's
quite reasonable to stop trying to do it myself.

bedstead.c

index da5e8a4d554f82e0cc17b240abd663dba7fd0df8..b88db87678cc4917fb29fd00d47086f88b55f92d 100644 (file)
@@ -3222,10 +3222,10 @@ main(int argc, char **argv)
        printf("<ttFont sfntVersion='OTTO'>\n");
 /* Convenient macros for TTX values. */
 #define TTXF(key, format, ...) \
-    printf("  <" key " value='" format "'/>\n", __VA_ARGS__)
+    printf("<" key " value='" format "'/>\n", __VA_ARGS__)
 #define TTXI(key, i) TTXF(key, "%ld", (long)(i))
 #define TTXS(key, s) TTXF(key, "%s", (s))
-       printf(" <head>\n");
+       printf("<head>\n");
        TTXS("tableVersion", "1.0");
        TTXS("fontRevision", VERSION);
        TTXI("checkSumAdjustment", 0);
@@ -3252,9 +3252,9 @@ main(int argc, char **argv)
        TTXI("fontDirectionHint", 0); /* Fully bi-di. */
        TTXI("indexToLocFormat", 0);
        TTXI("glyphDataFormat", 0);
-       printf(" </head>\n");
+       printf("</head>\n");
 
-       printf(" <hhea>\n");
+       printf("<hhea>\n");
        TTXS("tableVersion", "0x00010000");
        TTXI("ascent", ASCENT * YPIX);
        TTXI("descent", -DESCENT * YPIX);
@@ -3269,14 +3269,14 @@ main(int argc, char **argv)
        TTXI("reserved2", 0); TTXI("reserved3", 0);
        TTXI("metricDataFormat", 0);
        TTXI("numberOfHMetrics", 0); /* Will be calculated by TTX. */
-       printf(" </hhea>\n");
+       printf("</hhea>\n");
 
-       printf(" <maxp>\n");
+       printf("<maxp>\n");
        TTXS("tableVersion", "0x5000");
        TTXI("numGlyphs", nglyphs);
-       printf(" </maxp>\n");
+       printf("</maxp>\n");
 
-       printf(" <OS_2>\n");
+       printf("<OS_2>\n");
        TTXI("version", 4);
        TTXI("xAvgCharWidth", XSIZE * XPIX);
        TTXI("usWeightClass", weight->ttfweight);
@@ -3372,16 +3372,16 @@ main(int argc, char **argv)
        TTXI("usDefaultChar", 0);
        TTXI("usBreakChar", 32);
        TTXI("usMaxContext", 1); /* No pair subs. */
-       printf(" </OS_2>\n");
+       printf("</OS_2>\n");
 
-       printf(" <name>\n");
+       printf("<name>\n");
        /* Encode each name in Mac Roman and Windows UTF-16. */
 #define NAMEF(id, f, ...) \
-       printf("  <namerecord nameID='%d' " \
-              " platformID='1' platEncID='0' langID='0x0' unicode='True'>" \
+       printf("<namerecord nameID='%d' " \
+              "platformID='1' platEncID='0' langID='0x0' unicode='True'>" \
               f "</namerecord>\n" \
-              "  <namerecord nameID='%d' " \
-              " platformID='3' platEncID='1' langID='0x409'>" \
+              "<namerecord nameID='%d' " \
+              "platformID='3' platEncID='1' langID='0x409'>" \
               f "</namerecord>\n", \
               (int)(id), __VA_ARGS__, (int)(id), __VA_ARGS__)
 #define NAME(id, s) NAMEF(id, "%s", s)
@@ -3414,9 +3414,9 @@ main(int argc, char **argv)
        for (i = 0; i < ngsub_features; i++)
                if (gsub_features[i].name != NULL)
                        NAME(NAMEBASE_GSUB + i, gsub_features[i].name);
-       printf(" </name>\n");
+       printf("</name>\n");
 
-       printf(" <post>\n");
+       printf("<post>\n");
        TTXS("formatType", "3.0");
        TTXS("italicAngle", "0.0");
        TTXI("underlinePosition", -YPIX);
@@ -3424,31 +3424,31 @@ main(int argc, char **argv)
        TTXI("isFixedPitch", 1);
        TTXI("minMemType42", 0); TTXI("maxMemType42", 0);
        TTXI("minMemType1", 0); TTXI("maxMemType1", 0);
-       printf(" </post>\n");
+       printf("</post>\n");
 
        for (i = 0; i < nglyphs; i++)
                glyphs_by_name[i] = glyphs + i;
        qsort(glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
              &compare_glyphs_by_name);
 
-       printf(" <GlyphOrder>\n");
+       printf("<GlyphOrder>\n");
        for (i = 0; i < nglyphs; i++)
-               printf("  <GlyphID name='%s'/>\n", glyphs[i].name);
-       printf(" </GlyphOrder>\n");
+               printf("<GlyphID name='%s'/>\n", glyphs[i].name);
+       printf("</GlyphOrder>\n");
 
-       printf(" <cmap><tableVersion version='0'/>\n");
+       printf("<cmap><tableVersion version='0'/>\n");
        docmap(0, 3, 4);   /* Unicode 2.0+, BMP only */
        docmap(0, 4, 12);  /* Unicode 2.0+, full repertoire */
        docmap(3, 1, 4);   /* Windows Unicode, BMP only */
        docmap(3, 10, 12); /* Windows Unicode, full repertoire */
-       printf(" </cmap>\n");
+       printf("</cmap>\n");
 
        dogpos(); /* Must be before 'CFF ' because it uses glyph bitmaps. */
        dogsub();
 
-       printf(" <CFF>\n");
+       printf("<CFF>\n");
        TTXI("major", 1); TTXI("minor", 0);
-       printf("  <CFFFont name='%s'>\n",
+       printf("<CFFFont name='%s'>\n",
               fullname_to_fontname(get_fullname()));
        TTXS("version", VERSION);
        TTXS("Notice", "Dedicated to the public domain");
@@ -3462,7 +3462,7 @@ main(int argc, char **argv)
             1.0/(YSIZE * YPIX), 1.0/(YSIZE * YPIX));
        TTXF("FontBBox", "0 %d %d %d", (int)(-DESCENT * YPIX),
             (int)(XSIZE * XPIX), (int)(ASCENT * YPIX));
-       printf("   <Private>\n");
+       printf("<Private>\n");
        TTXF("BlueValues", "0 0 %4g %4g %4g %4g %4g %4g",
             (double)(YPIX * XHEIGHT),    (double)(YPIX * XHEIGHT),
             (double)(YPIX * ALEFHEIGHT), (double)(YPIX * ALEFHEIGHT),
@@ -3479,37 +3479,37 @@ main(int argc, char **argv)
        /*      printf("StrokedFont: 1\n"); */
        /*      printf("StrokeWidth: 50\n"); */
        /* } */
-       printf("    <Subrs>\n");
+       printf("<Subrs>\n");
        nsubrs = 0;
        for (i = 0; i < nglyphs; i++) {
                struct glyph *g = &glyphs[i];
                if (g->flags & IS_ALIAS) {
                        g = realglyph(g);
                        if (g->flags & IS_SUBR) continue;
-                       printf("     <CharString> <!-- %s -->", g->name);
+                       printf("<CharString> <!-- %s -->", g->name);
                        doglyph(g);
                        g->flags = IS_SUBR;
                        g->subr_idx = nsubrs++;
                        printf("</CharString>\n");
                }
        }
-       printf("    </Subrs>\n");
-       printf("   </Private>\n");
-       printf("   <CharStrings>\n");
+       printf("</Subrs>\n");
+       printf("</Private>\n");
+       printf("<CharStrings>\n");
        for (i = 0; i < nglyphs; i++) {
-               printf("    <CharString name='%s'>", glyphs[i].name);
+               printf("<CharString name='%s'>", glyphs[i].name);
                doglyph(&glyphs[i]);
                printf("</CharString>\n");
        }
-       printf("   </CharStrings>\n");
-       printf("  </CFFFont>\n");
-       printf(" </CFF>\n");
-       printf(" <hmtx>\n");
+       printf("</CharStrings>\n");
+       printf("</CFFFont>\n");
+       printf("</CFF>\n");
+       printf("<hmtx>\n");
        for (i = 0; i < nglyphs; i++)
-               printf("  <mtx name='%s' width='%d' lsb='%d'/>\n",
+               printf("<mtx name='%s' width='%d' lsb='%d'/>\n",
                       glyphs[i].name, (int)(XSIZE * XPIX),
                       (int)realglyph(&glyphs[i])->left_sidebearing);
-       printf(" </hmtx>\n");
+       printf("</hmtx>\n");
        printf("</ttFont>\n");
        return EXIT_SUCCESS;
 }
@@ -3653,13 +3653,13 @@ dopanose(void)
         * DuckRat = XRat = 5/7
         */
        panose[9] = 7; /* Ducking/Large */
-       printf("  <panose>\n"
-              "   <bFamilyType value='%d'/><bSerifStyle value='%d'/>\n"
-              "   <bWeight value='%d'/><bProportion value='%d'/>\n"
-              "   <bContrast value='%d'/><bStrokeVariation value='%d'/>\n"
-              "   <bArmStyle value='%d'/><bLetterForm value='%d'/>\n"
-              "   <bMidline value='%d'/><bXHeight value='%d'/>\n"
-              "  </panose>\n",
+       printf("<panose>\n"
+              "<bFamilyType value='%d'/><bSerifStyle value='%d'/>\n"
+              "<bWeight value='%d'/><bProportion value='%d'/>\n"
+              "<bContrast value='%d'/><bStrokeVariation value='%d'/>\n"
+              "<bArmStyle value='%d'/><bLetterForm value='%d'/>\n"
+              "<bMidline value='%d'/><bXHeight value='%d'/>\n"
+              "</panose>\n",
               panose[0], panose[1], panose[2], panose[3], panose[4],
               panose[5], panose[6], panose[7], panose[8], panose[9]);
 }
@@ -3670,7 +3670,7 @@ docmap(int pid, int eid, int format)
        int i;
        long limit = 0x10000;
 
-       printf("  <cmap_format_%d platformID='%d' platEncID='%d' language='0'",
+       printf("<cmap_format_%d platformID='%d' platEncID='%d' language='0'",
               format, pid, eid);
        if (format == 12) {
                limit = 0x110000;
@@ -3681,9 +3681,9 @@ docmap(int pid, int eid, int format)
        for (i = 0; i < nglyphs; i++)
                if (glyphs[i].unicode >= 0 &&
                    glyphs[i].unicode < limit)
-                       printf("    <map code='0x%lx' name='%s'/>\n",
+                       printf("<map code='0x%lx' name='%s'/>\n",
                               (long)glyphs[i].unicode, glyphs[i].name);
-       printf("  </cmap_format_%d>\n", format);
+       printf("</cmap_format_%d>\n", format);
 }
 
 static void
@@ -3691,60 +3691,58 @@ dogsub(void)
 {
        int i, j;
 
-       printf(" <GSUB>\n");
+       printf("<GSUB>\n");
        TTXS("Version", "0x00010000");
-       printf("  <ScriptList>\n");
+       printf("<ScriptList>\n");
        for (i = 0; i < ngsub_scripts; i++) {
-               printf("   <ScriptRecord>\n");
+               printf("<ScriptRecord>\n");
                TTXS("ScriptTag", gsub_scripts[i].tag);
-               printf("    <Script><DefaultLangSys>\n");
+               printf("<Script><DefaultLangSys>\n");
                TTXI("ReqFeatureIndex", 0xffff); /* No required feature. */
                for (j = 0; j < ngsub_features; j++)
                        if (gsub_features[j].scripts & gsub_scripts[i].flag)
                                TTXI("FeatureIndex", j);
-               printf("    </DefaultLangSys></Script>\n");
-               printf("   </ScriptRecord>\n");
+               printf("</DefaultLangSys></Script>\n");
+               printf("</ScriptRecord>\n");
        }
-       printf("  </ScriptList>\n");
-       printf("  <FeatureList>\n");
+       printf("</ScriptList>\n");
+       printf("<FeatureList>\n");
        for (i = 0; i < ngsub_features; i++) {
-               printf("    <FeatureRecord>\n");
+               printf("<FeatureRecord>\n");
                TTXS("FeatureTag", gsub_features[i].tag);
-               printf("     <Feature>\n");
+               printf("<Feature>\n");
                if (gsub_features[i].name != NULL) {
                        if (gsub_features[i].tag[0] == 's') {
-                               printf("      <FeatureParamsStylisticSet>\n");
+                               printf("<FeatureParamsStylisticSet>\n");
                                TTXI("Version", 0);
                                TTXI("UINameID", NAMEBASE_GSUB + i);
-                               printf("      </FeatureParamsStylisticSet>\n");
+                               printf("</FeatureParamsStylisticSet>\n");
                        } else {
-                               printf("      "
-                                      "<FeatureParamsCharacterVariants>\n");
+                               printf("<FeatureParamsCharacterVariants>\n");
                                TTXI("Format", 0);
                                TTXI("FeatUILabelNameID", NAMEBASE_GSUB + i);
                                TTXI("FeatUITooltipTextNameID", 0);
                                TTXI("SampleTextNameID", 0);
                                TTXI("NumNamedParameters", 0);
                                TTXI("FirstParamUILabelNameID", 0);
-                               printf("      "
-                                      "</FeatureParamsCharacterVariants>\n");
+                               printf("</FeatureParamsCharacterVariants>\n");
                        }
                }
                /* We only have one GSUB lookup per feature, thankfully. */
                TTXI("LookupListIndex", i);
-               printf("     </Feature>\n");
-               printf("    </FeatureRecord>\n");
+               printf("</Feature>\n");
+               printf("</FeatureRecord>\n");
        }
-       printf("  </FeatureList>\n");
-       printf("  <LookupList>\n");
+       printf("</FeatureList>\n");
+       printf("<LookupList>\n");
        for (i = 0; i < ngsub_features; i++) {
-               printf("    <Lookup> <!-- '%s' -->\n", gsub_features[i].tag);
+               printf("<Lookup> <!-- '%s' -->\n", gsub_features[i].tag);
                if (gsub_features[i].suffix != NULL) {
                        /* Single lookup for all glyphs with a suffix. */
                        TTXI("LookupFlag", 0);
-                       printf("     <SingleSubst>\n");
+                       printf("<SingleSubst>\n");
                        dosinglesubs(gsub_features[i].suffix);
-                       printf("     </SingleSubst>\n");
+                       printf("</SingleSubst>\n");
                } else if (gsub_features[i].xml != NULL) {
                        /* Raw XML for a substitution. */
                        TTXI("LookupFlag", 0);
@@ -3752,15 +3750,15 @@ dogsub(void)
                } else {
                        /* All possible alternative glyphs. */
                        TTXI("LookupFlag", 0);
-                       printf("     <AlternateSubst>\n");
+                       printf("<AlternateSubst>\n");
                        doaltsubs(gsub_features[i].noverrides,
                                  gsub_features[i].overrides);
-                       printf("     </AlternateSubst>\n");
+                       printf("</AlternateSubst>\n");
                }
-               printf("    </Lookup>\n");
+               printf("</Lookup>\n");
        }
-       printf("  </LookupList>\n");
-       printf(" </GSUB>\n");
+       printf("</LookupList>\n");
+       printf("</GSUB>\n");
 
 }
 
@@ -3783,7 +3781,7 @@ doaltsubs(int noverrides, const struct alt_sub_override overrides[noverrides])
                        bool overridden = next_override < noverrides &&
                                strcmp(glyphs_by_name[i-1]->name,
                                       overrides[next_override].base) == 0;
-                       printf("      %s<AlternateSet glyph='%s'>",
+                       printf("%s<AlternateSet glyph='%s'>",
                               overridden ? "<!-- " : "",
                               glyphs_by_name[i-1]->name);
                        for (; i < nglyphs && HASDOT(i); i++)
@@ -3795,9 +3793,9 @@ doaltsubs(int noverrides, const struct alt_sub_override overrides[noverrides])
                }
        }
 
-       printf("      <!-- overrides -->\n");
+       printf("<!-- overrides -->\n");
        for (i = 0; i < noverrides; i++) {
-               printf("      <AlternateSet glyph='%s'>", overrides[i].base);
+               printf("<AlternateSet glyph='%s'>", overrides[i].base);
                for (j = 0; j < MAX_ALT_SUB_OVERRIDE &&
                             overrides[i].alt[j] != NULL; j++)
                        printf("<Alternate glyph='%s'/>",
@@ -3816,7 +3814,7 @@ dosinglesubs(char const *suffix)
        for (i = 0; i < nglyphs; i++)
                if ((dot = strchr(glyphs[i].name, '.')) != NULL &&
                    strcmp(dot, suffix) == 0)
-                       printf("      <Substitution in='%.*s' out='%s'/>\n",
+                       printf("<Substitution in='%.*s' out='%s'/>\n",
                               (int)(dot - glyphs[i].name),
                               glyphs[i].name, glyphs[i].name);
 }
@@ -3837,34 +3835,34 @@ dogpos(void)
        int dx, dh, i;
 
        /* We only support one 'GPOS' lookup, 'palt'. */
-       printf(" <GPOS>\n");
+       printf("<GPOS>\n");
        TTXS("Version", "0x00010000");
-       printf("  <ScriptList>\n");
-       printf("   <ScriptRecord>\n");
+       printf("<ScriptList>\n");
+       printf("<ScriptRecord>\n");
        TTXS("ScriptTag", "DFLT");
-       printf("    <Script><DefaultLangSys>\n");
+       printf("<Script><DefaultLangSys>\n");
        TTXI("ReqFeatureIndex", 0xffff); /* No required feature. */
        TTXI("FeatureIndex", 0);
-       printf("    </DefaultLangSys></Script>\n");
-       printf("   </ScriptRecord>\n");
-       printf("   <ScriptRecord>\n");
+       printf("</DefaultLangSys></Script>\n");
+       printf("</ScriptRecord>\n");
+       printf("<ScriptRecord>\n");
        TTXS("ScriptTag", "latn");
-       printf("    <Script><DefaultLangSys>\n");
+       printf("<Script><DefaultLangSys>\n");
        TTXI("ReqFeatureIndex", 0xffff); /* No required feature. */
        TTXI("FeatureIndex", 0);
-       printf("    </DefaultLangSys></Script>\n");
-       printf("   </ScriptRecord>\n");
-       printf("  </ScriptList>\n");
-       printf("  <FeatureList>\n");
-       printf("   <FeatureRecord>\n");
+       printf("</DefaultLangSys></Script>\n");
+       printf("</ScriptRecord>\n");
+       printf("</ScriptList>\n");
+       printf("<FeatureList>\n");
+       printf("<FeatureRecord>\n");
        TTXS("FeatureTag", "palt");
-       printf("    <Feature>\n");
+       printf("<Feature>\n");
        TTXI("LookupListIndex", 0);
-       printf("    </Feature>\n");
-       printf("   </FeatureRecord>\n");
-       printf("  </FeatureList>\n");
-       printf("  <LookupList>\n");
-       printf("   <Lookup>\n");
+       printf("</Feature>\n");
+       printf("</FeatureRecord>\n");
+       printf("</FeatureList>\n");
+       printf("<LookupList>\n");
+       printf("<Lookup>\n");
        TTXI("LookupFlag", 0);
        /*
         * We have only a few dx/dh combinations, so it makes sense to
@@ -3873,9 +3871,9 @@ dogpos(void)
         */
        for (dx = 0; dx < XSIZE - 1; dx++)
                for (dh = (dx == 0 ? 1 : dx); dh < XSIZE - 1; dh++) {
-                       printf("       <SinglePos Format='1'>\n");
+                       printf("<SinglePos Format='1'>\n");
                        printf("<!-- dx = %d; dh = %d -->\n", dx, dh);
-                       printf("        <Coverage>\n");
+                       printf("<Coverage>\n");
                        for (i = 0; i < nglyphs; i++) {
                                struct glyph *g = realglyph(&glyphs[i]);
                                if (g->flags & (MOS6|MOS4)) continue;
@@ -3887,17 +3885,16 @@ dogpos(void)
                                    (fp == 0 && dx == 0 && dh == 3))
                                        TTXS("Glyph", glyphs[i].name);
                        }
-                       printf("        </Coverage>\n");
+                       printf("</Coverage>\n");
                        TTXI("ValueFormat", 5);
-                       printf("        <Value XPlacement='%i' "
-                              "XAdvance='%i'/>\n",
+                       printf("<Value XPlacement='%i' XAdvance='%i'/>\n",
                               (int)(-dx * XPIX), (int)(-dh * XPIX));
-                       printf("       </SinglePos>\n");
+                       printf("</SinglePos>\n");
                }
                        
-       printf("   </Lookup>\n");
-       printf("  </LookupList>\n");
-       printf(" </GPOS>\n");
+       printf("</Lookup>\n");
+       printf("</LookupList>\n");
+       printf("</GPOS>\n");
 }
 
 /* Emit a charstring for a glyph. */