From 9a1757dda88eb6fa090c780768235fb263b3b531 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Mon, 9 Jun 2025 00:27:03 +0300 Subject: [PATCH] fix reading from files not in current dir --- sexc.scm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sexc.scm b/sexc.scm index bb3f0f4..bc35d0e 100644 --- a/sexc.scm +++ b/sexc.scm @@ -1,4 +1,5 @@ (import brev-separate + (chicken pathname) (chicken pretty-print) (chicken process-context) (chicken string) @@ -125,8 +126,20 @@ 'stdin (cadr rest-args)))) +(define (read-from-file file) + (with-input-from-file (pathname-strip-directory file) + (fn (read-forms (list))))) + +(define (set-working-directory file) + (change-directory + (normalize-pathname + (make-absolute-pathname + (current-directory) + (pathname-directory file))))) + (define (main) (let* ((raw-args (command-line-arguments)) + (current-dir (current-directory)) (args (getopt-long raw-args opts-grammar)) (output (get-arg args 'output 'stdout)) @@ -136,9 +149,11 @@ (let* ((raw-forms (if (eq? input 'stdin) (read-forms (list)) - (with-input-from-file input - (lambda () (read-forms (list)))))) + (begin + (set-working-directory input) + (read-from-file input)))) (sex-forms (process-raw-forms raw-forms (list)))) + (change-directory current-dir) (if (get-arg args 'macro-expand #f) (map pp sex-forms) (if (not (eq? output 'stdout))