+(define xml-copyright
+ (take-first (sxpath '(refentry (refsect1 (@ id (equal? "Copyright")))))))
+
+(define (string->gl-type str)
+ (string->symbol
+ (string-join (string-split (string-trim-both str) #\space) "-")))
+
+(define (parse-prototypes sxml)
+ (define all-names
+ (match sxml
+ ((('funcprototype ('funcdef return-type ('function names))
+ . _)
+ ...)
+ names)))
+
+ (define (redundant-variant? s shun-suffix prefer-suffix)
+ (and (string-suffix? shun-suffix s)
+ (member (string-append (substring s 0 (- (string-length s)
+ (string-length shun-suffix)))
+ prefer-suffix)
+ all-names)))
+
+ (define (skip? s)
+ (or
+ ;; Skip double variants if we have a float variant.
+ ;; (http://www.opengl.org/wiki/Common_Mistakes#GL_DOUBLE).
+ (redundant-variant? s "d" "f")
+
+ ;; Skip byte variants if there is a short variant.
+ (redundant-variant? s "b" "s")
+
+ ;; Skip short variants if there is an int variant.
+ (redundant-variant? s "s" "i")
+
+ ;; Skip packed setters like glVertex3fv if e.g. glVertex3f exists.
+ (redundant-variant? s "v" "")
+ (redundant-variant? s "dv" "fv")
+ (redundant-variant? s "bv" "sv")
+ (redundant-variant? s "sv" "iv")))
+
+ (filter-map
+ (lambda (sxml)
+ (match sxml
+ (('funcprototype ('funcdef return-type ('function (? skip?)))
+ . _)
+ #f)
+ (('funcprototype ('funcdef return-type ('function name))
+ ('paramdef ('parameter "void")))
+ `(,(string->symbol name)
+ -> ,(string->gl-type return-type)))
+ (('funcprototype ('funcdef return-type ('function name))
+ ('paramdef ptype ('parameter pname))
+ ...)
+ `(,(string->symbol name)
+ ,@(map (lambda (pname ptype)
+ (list (string->symbol pname)
+ (string->gl-type ptype)))
+ pname ptype)
+ -> ,(string->gl-type return-type)))))
+ sxml))