aboutsummaryrefslogtreecommitdiff
path: root/src/macros
diff options
context:
space:
mode:
Diffstat (limited to 'src/macros')
-rw-r--r--src/macros/macros.sc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/macros/macros.sc b/src/macros/macros.sc
index 8ff799b..1ccfeab 100644
--- a/src/macros/macros.sc
+++ b/src/macros/macros.sc
@@ -67,3 +67,19 @@
body ...
(for-i i n
(gsl-rstat-free (array-get var i)))))
+
+(sc-define-syntax (with-file fp filename mode body ...)
+ (with-alloc fp FILE* (begin (fopen filename mode)
+ (unless fp
+ (perror filename)
+ (exit EXIT_FAILURE)))
+ fclose
+ body ...))
+
+(sc-define-syntax* (with-data-file fp filename mode body ...)
+ (let* ((data-file (string-append "data/" filename)))
+ `(with-file fp ,data-file ,mode
+ ,@(if (string=? mode "w")
+ `((fprintf stderr "Writing to %s...\n" ,data-file))
+ '())
+ ,@body)))