shithub: fnt

Download patch

ref: 49510dd517a058166d1c60a4e9731061ff89d6b2
parent: e46528a5028c4d2080d075002037444769e93218
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jun 11 22:35:24 EDT 2024

generate tag -> parser map for tagged tables

--- a/otf.rkt
+++ b/otf.rkt
@@ -341,17 +341,60 @@
                    {int16 glyphDataFormat unused (= 0)})
          "head")
 
+(define (cmplx-tagged? c)
+  (non-empty-string? (cmplx-tag c)))
+
 (printf (format gen-h))
+(printf (~a "\nenum{NumParseTagged = " (count (λ (c) (cmplx-tagged? c)) cmplxs) "};\n"))
 (printf #<<EOF
+
+typedef struct ParseTagged ParseTagged;
+
+struct ParseTagged {
+	u32int tag;
+	int (*parse)(Ctx *ctx, void *dest);
+};
+
+extern ParseTagged parsetagged[NumParseTagged];
+EOF
+        )
+(printf #<<EOF
+
 extern int identΔ;
 
 #pragma varargck type "T" s64int
 #pragma varargck type "t" u32int
 #pragma varargck type "V" u32int
+
+void otfinit(void);
 EOF
         )
 
 (printf (format (λ (c) (gen-c c #f #f))))
+
+(define (ft t i)
+  (~a "'" (string-ref t i) "'<<" (* 8 (- 3 i))))
+
+(printf "ParseTagged parsetagged[NumParseTagged] = {\n")
+(for ([s (in-list (filter-map (λ (c)
+                                (match (cmplx-tag c)
+                                  ["" #f]
+                                  [tag
+                                   (~a "\t{"
+                                       (ft tag 0)
+                                       "|"
+                                       (ft tag 1)
+                                       "|"
+                                       (ft tag 2)
+                                       "|"
+                                       (ft tag 3)
+                                       ", (void*)read_"
+                                       (cmplx-name c)
+                                       "},\n")]))
+                              cmplxs))])
+  (printf s))
+(printf "};\n")
+
 (printf #<<EOF
 
 int identΔ = 2;
@@ -379,7 +422,8 @@
 }
 
 void
-otfinit(void){
+otfinit(void)
+{
 	tmfmtinstall();
 	fmtinstall('V', Vfmt);
 	fmtinstall('T', Tfmt);