Index: configfmod.scm ================================================================== --- configfmod.scm +++ configfmod.scm @@ -18,10 +18,12 @@ ;;====================================================================== (declare (unit configfmod)) (declare (uses mtargs)) +(declare (uses commonmod)) +(declare (uses rmtmod)) (declare (uses debugprint)) (declare (uses keysmod)) (module configfmod ( @@ -90,10 +92,11 @@ (srfi 18) directory-utils dot-locking format matchable + mtargs md5 message-digest regex regex-case sparse-vectors @@ -395,11 +398,11 @@ path)) ;; we can be handed a port (res (let ((ht-in (if (not ht) (make-hash-table) ht))) (if (not (configf:lookup ht-in "" "toppath")) - (configf:set-section-var ht-in "" "toppath" path)) + (configf:set-section-var ht-in "" "toppath" (pathname-directory path))) ht-in)) (metapath (if (or (debug:debug-mode 9) keep-filenames) path #f)) (process-wildcards (lambda (res curr-section-name) @@ -1018,11 +1021,12 @@ ;;====================================================================== ;; Config file handling ;;====================================================================== ;; convert to param? -(define configf:std-imports "(import simple-exceptions big-chicken configfmod commonmod rmtmod (prefix mtargs args:))") +(define configf:std-imports "(import scheme big-chicken system-information simple-exceptions big-chicken configfmod commonmod rmtmod chicken.process-context.posix)(import (prefix mtargs args:))(define getenv get-environment-variable)") + (define (configf:process-one matchdat l ht allow-system env-to-use linenum) (let* ((prestr (list-ref matchdat 1)) (cmdtype (list-ref matchdat 2)) ;; eval, system, shell, getenv (cmd (list-ref matchdat 3)) (quotedcmd (conc "\""cmd"\"")) @@ -1033,10 +1037,11 @@ (fullcmd (if (member cmdsym '(scheme scm)) `(eval-needed ,(conc "(lambda (ht)" configf:std-imports + "(set! *toppath* \""(configf:lookup ht "" "toppath")"\")" cmd ")")) (case cmdsym ((system) `(noeval-needed ,(conc (configf:system ht cmd)))) ;; ((shell sh) `(noeval-needed ,(conc (string-translate (shell quotedcmd) "\n" " ")))) ((shell sh) `(noeval-needed ,(conc (string-translate (shell cmd) "\n" " ")))) @@ -1053,26 +1058,26 @@ ((runconfigs-get rget) `(noeval-needed ,(runconfigs-get ht quotedcmd))) ;; (conc "(lambda (ht)(runconfigs-get ht \"" cmd "\"))")) (else `(#f ,(conc "cmd: " cmd " not recognised"))))))) (match fullcmd (('eval-needed newres) - (handle-exceptions - exn - (begin - (debug:print 0 *default-log-port* "WARNING: failed to process config input \"" l "\", fullcmd="fullcmd", exn=" exn) - (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn)) - ;; (print "exn=" (condition->list exn)) - (set! result (conc "#{( " cmdtype ") " cmd "}, full expansion: " fullcmd))) +;;(handle-exceptions +;; exn +;; (begin +;; (debug:print 0 *default-log-port* "WARNING: failed to process config input \"" l "\", eval-needed, newres="newres", exn="(condition->list exn)) +;; (debug:print 0 *default-log-port* " message: " ((condition-property-accessor 'exn 'message) exn)) +;; ;; (print "exn=" (condition->list exn)) +;; (set! result (conc "#{( " cmdtype ") " cmd "}, full expansion: " newres))) (if (or allow-system (not (member cmdtype '("system" "shell" "sh")))) (with-input-from-string newres (lambda () (set! result (if env-to-use ((eval (read) env-to-use) ht) ((eval (read)) ht) )))) - (set! result (conc "#{(" cmdtype ") " cmd "}"))))) + (set! result (conc "#{(" cmdtype ") " cmd "}")))); ) (('noeval-needed newres)(set! result newres)) (else ;; (#f errres) (debug:print 0 *default-log-port* "WARNING: failed to process config input \""l"\", fullcmd="fullcmd"."))) ;; we process as a result (let ((delta (- (current-seconds) start-time))) @@ -1087,11 +1092,11 @@ (let ((result (configf:process-one matchdat l ht allow-system env-to-use linenum))) (loop result)) res)) res))) -(define (configf:process-line-old l ht allow-system env-to-use #!key (linenum #f)) +#;(define (configf:process-line-old l ht allow-system env-to-use #!key (linenum #f)) (let loop ((res l)) (if (string? res) (let ((matchdat (string-search configf:var-expand-regex res))) (if matchdat (let* ((prestr (list-ref matchdat 1)) @@ -1101,12 +1106,11 @@ (result #f) (start-time (current-seconds)) (cmdsym (string->symbol cmdtype)) (fullcmd (conc configf:std-imports - "(import chicken.process-context.posix)" - "(define setenv set-environment-variable)" + ;;"(define setenv set-environment-variable)" (case cmdsym ((scheme scm) (conc "(lambda (ht)" cmd ")")) ((system) (conc "(lambda (ht)(configf:system ht \"" cmd "\"))")) ((shell sh) (conc "(lambda (ht)(string-translate (shell \"" cmd "\") \"\n\" \" \"))")) ((realpath rp)(conc "(lambda (ht)(common:nice-path \"" cmd "\"))"))