From 805c04fb9033f0d052e3be01eeeed007f940e810 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sun, 6 Sep 2015 03:05:33 +0200 Subject: main: Improve 'process-user-file' definition. * scm/mcron/main.scm (process-user-file): Rename parameters 'file-path' to 'file-name' and 'assume-guile' to 'guile-syntax?'. Capture 'guile-regexp' and 'vixie-regexp' bindings in the procedure scope. (guile-file-regexp, vixie-file-regexp): Delete variables. --- scm/mcron/main.scm | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'scm/mcron/main.scm') diff --git a/scm/mcron/main.scm b/scm/mcron/main.scm index 58f1efa..727f013 100644 --- a/scm/mcron/main.scm +++ b/scm/mcron/main.scm @@ -188,23 +188,21 @@ received." (mcron-error 0 (apply format (append (list #f fmt) args))) #f))) -(define guile-file-regexp (make-regexp "\\.gui(le)?$")) -(define vixie-file-regexp (make-regexp "\\.vix(ie)?$")) - -(define (process-user-file file-path . assume-guile) - "Process FILE-PATH according its extension. When ASSUME-GUILE is non nil, -usage of guile syntax is forced for FILE-PATH. If a file is not recognized, -it is silently ignored (this deals properly with most editors' backup files, -for instance)." - (cond ((string=? file-path "-") - (if (string=? (option-ref options 'stdin "guile") "vixie") - (read-vixie-port (current-input-port)) - (eval-string (stdin->string)))) - ((or (not (null? assume-guile)) - (regexp-exec guile-file-regexp file-path)) - (load file-path)) - ((regexp-exec vixie-file-regexp file-path) - (read-vixie-file file-path)))) +(define process-user-file + (let ((guile-regexp (make-regexp "\\.gui(le)?$")) + (vixie-regexp (make-regexp "\\.vix(ie)?$"))) + (lambda* (file-name #:optional guile-syntax?) + "Process FILE-NAME according its extension. When GUILE-SYNTAX? is TRUE, +force guile syntax usage. If FILE-NAME format is not recognized, it is +silently ignored." + (cond ((string=? "-" file-name) + (if (string=? (option-ref options 'stdin "guile") "vixie") + (read-vixie-port (current-input-port)) + (eval-string (stdin->string)))) + ((or guile-syntax? (regexp-exec guile-regexp file-name)) + (load file-name)) + ((regexp-exec vixie-regexp file-name) + (read-vixie-file file-name)))))) (define (process-files-in-user-directory) "Process files in $XDG_CONFIG_HOME/cron and/or ~/.cron directories (if -- cgit v1.2.3