mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
adding define-c-strerror
This commit is contained in:
parent
17102697e9
commit
bce1e6a4d2
1 changed files with 22 additions and 0 deletions
|
@ -567,6 +567,28 @@
|
|||
(for-each (lambda (x) (set! *consts* (cons (list type x) *consts*)))
|
||||
(cddr expr))))))
|
||||
|
||||
;; custom strerror which reports constants as their names
|
||||
(define-syntax define-c-strerror
|
||||
(er-macro-transformer
|
||||
(lambda (expr rename compare)
|
||||
(let ((name (cadr expr))
|
||||
(errnos (cddr expr)))
|
||||
`(,(rename 'c-declare)
|
||||
,(string-concatenate
|
||||
`("\nchar* " ,(x->string name) "(const int err) {
|
||||
static char buf[64];
|
||||
switch (err) {
|
||||
"
|
||||
,@(map (lambda (errno)
|
||||
(let ((e (x->string errno)))
|
||||
(string-append " case " e ": return \"" e "\";\n")))
|
||||
errnos)
|
||||
|
||||
" }
|
||||
sprintf(buf, \"unknown error: %d\", err);
|
||||
return buf;
|
||||
}")))))))
|
||||
|
||||
(define-syntax c-typedef
|
||||
(er-macro-transformer
|
||||
(lambda (expr rename compare)
|
||||
|
|
Loading…
Add table
Reference in a new issue