diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/macros/macros.sc | 16 |
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))) |