ref: 600f28654b5823df16698863c2ff390326f284aa
parent: 853cdcee8254f89ebba66b1241081c31e30fe557
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu May 30 13:58:01 EDT 2024
support unused fields (no unused arrays yet)
--- a/fmt.sh
+++ b/fmt.sh
@@ -1,2 +1,2 @@
#!/bin/sh
-raco fmt --width 120 --indent 2 -i *.rkt
+raco fmt --width 100 --indent 2 -i *.rkt
--- a/otf.rkt
+++ b/otf.rkt
@@ -32,14 +32,20 @@
(define (c-type t)
(type-c t))])
-(define-struct field (type name)
+(define-struct field (type name unused)
#:transparent
#:methods gen:code
[(define/generic super-c-type c-type)
(define (gen-h f)
- (list (~a (super-c-type (field-type f)) " " (field-name f) ";")))
+ (list (~a (if (field-unused f) "// unused " "")
+ (super-c-type (field-type f))
+ " "
+ (field-name f)
+ ";")))
(define (gen-c f)
- (list (~a "if(read_" (type-name (field-type f)) "(ctx, &v->" (field-name f) ") < 0){")
+ (list (if (field-unused f)
+ (~a "if(skip(ctx, " (/ (type-bits (field-type f)) 8) ") < 0){")
+ (~a "if(read_" (type-name (field-type f)) "(ctx, &v->" (field-name f) ") < 0){"))
(~a "\twerror(\"%s: %r\", \"" (field-name f) "\");")
(~a "\tgoto err;")
(~a "}")))])
@@ -71,9 +77,12 @@
(flatten (append (list (~a "typedef struct " (cmplx-name c) " " (cmplx-name c) ";")
(~a "struct " (cmplx-name c) " {"))
(indent (flatten (map super-gen-h (cmplx-fields c))))
- (list (~a "};") (~a "int read_" (cmplx-name c) "(Ctx *ctx, " (cmplx-name c) " *v);")))))
+ (list (~a "};")
+ (~a "int read_" (cmplx-name c) "(Ctx *ctx, " (cmplx-name c) " *v);")))))
(define (gen-c c)
- (flatten (append (list (~a "int") (~a "read_" (cmplx-name c) "(Ctx *ctx, " (cmplx-name c) " *v)") (~a "{"))
+ (flatten (append (list (~a "int")
+ (~a "read_" (cmplx-name c) "(Ctx *ctx, " (cmplx-name c) " *v)")
+ (~a "{"))
(indent (flatten (map super-gen-c (cmplx-fields c))))
(list (~a "\treturn 0;")
(~a "err:")
@@ -110,10 +119,15 @@
(define-syntax (mkfield stx)
(syntax-parse stx
- [(_ type:id name:id [count:id]) #'(fieldarr type `name `count)]
+ [(_ {~literal unused} type:id name:id)
+ #'(field type
+ `name
+ #t)]
+ [(_ type:id name:id [count:id]) #'(fieldarr type `name #f `count)]
[(_ type:id name:id)
#'(field type
- `name)]))
+ `name
+ #f)]))
(define-syntax (mkfields stx)
(syntax-parse stx
@@ -152,9 +166,12 @@
{uint16 rangeShift}
{TableRecord tableRecords [numTables]}))
-(mkcmplx EncodingRecord (mkfields {uint16 platformID} {uint16 encodingID} {Offset32 subtableOffset}))
+(mkcmplx EncodingRecord
+ (mkfields {uint16 platformID} {uint16 encodingID} {Offset32 subtableOffset}))
-(mkcmplx TableCmap (mkfields {uint16 version} {uint16 numTables} {EncodingRecord encodingRecords [numTables]}) "cmap")
+(mkcmplx TableCmap
+ (mkfields {uint16 version} {uint16 numTables} {EncodingRecord encodingRecords [numTables]})
+ "cmap")
(mkcmplx TableHead
(mkfields {uint16 majorVersion}
@@ -164,8 +181,8 @@
{uint32 magicNumber}
{uint16 flags}
{uint16 unitsPerEm}
- {LONGDATETIME created}
- {LONGDATETIME modified}
+ {unused LONGDATETIME created}
+ {unused LONGDATETIME modified}
{int16 xMin}
{int16 yMin}
{int16 xMax}