[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-mcron] [PATCH 13/33] main: Turn 'command-name' into a thunk.
From: |
Mathieu Lirzin |
Subject: |
[Bug-mcron] [PATCH 13/33] main: Turn 'command-name' into a thunk. |
Date: |
Sun, 27 Sep 2015 23:00:24 +0200 |
* scm/mcron/main.scm (command-name): Turn into a thunk.
All callers changed.
---
scm/mcron/main.scm | 39 ++++++++++++++++++---------------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/scm/mcron/main.scm b/scm/mcron/main.scm
index 5987dcf..19631d1 100644
--- a/scm/mcron/main.scm
+++ b/scm/mcron/main.scm
@@ -36,23 +36,21 @@
(mcron core)
(mcron job-specifier)
(mcron vixie-specification)
- (srfi srfi-2))
+ (srfi srfi-2)
+ (srfi srfi-26))
;; Turn debugging on if indicated.
(when config-debug
(debug-enable 'debug)
(debug-enable 'backtrace))
+(define* (command-name #:optional (command (car (command-line))))
+ "Extract the actual command name from COMMAND. This returns the last part
+of COMMAND without any non-alphabetic characters. For example \"in.cron\" and
+\"./mcron\" will return respectively \"cron\" and \"mcron\".
-
-;; To determine the name of the program, scan the first item of the command
line
-;; backwards for the first non-alphabetic character. This allows names like
-;; in.cron to be accepted as an invocation of the cron command.
-
-(define command-name (match:substring (regexp-exec (make-regexp
"[[:alpha:]]*$")
- (car (command-line)))))
-
-
+When COMMAND is not specified this uses the first element of (command-line)."
+ (match:substring (regexp-exec (make-regexp "[[:alpha:]]*$") command)))
;; Code contributed by Sergey Poznyakoff. Print an error message (made up from
;; the parts of rest), and if the error is fatal (present and non-zero) then
@@ -61,7 +59,7 @@
(define (mcron-error exit-code . rest)
(with-output-to-port (current-error-port)
(lambda ()
- (for-each display (append (list command-name ": ") rest))
+ (for-each display (append (list (command-name) ": ") rest))
(newline)))
(when (and exit-code (not (eq? exit-code 0)))
(primitive-exit exit-code)))
@@ -83,14 +81,13 @@
;; We will be doing a lot of testing of the command name, so it makes sense to
;; perform the string comparisons once and for all here.
-(define command-type (cond ((string=? command-name "mcron") 'mcron)
- ((or (string=? command-name "cron")
- (string=? command-name "crond")) 'cron)
- ((string=? command-name "crontab") 'crontab)
- (else
- (mcron-error 12 "The command name is invalid."))))
-
-
+(define command-type
+ (let* ((command (command-name))
+ (command=? (cut string=? command <>)))
+ (cond ((command=? "mcron") 'mcron)
+ ((or (command=? "cron") (command=? "crond")) 'cron)
+ ((command=? "crontab") 'crontab)
+ (else (mcron-error 12 "The command name is invalid.")))))
;; There are a different set of options for the crontab personality compared to
;; all the others, with the --help and --version options common to all the
@@ -124,7 +121,7 @@
(lambda (key func fmt args . rest)
(mcron-error 1 (apply format (append (list #f fmt) args))))))
-(define* (show-version #:optional (command command-name))
+(define* (show-version #:optional (command (command-name)))
"Display version information for COMMAND and quit."
(let* ((name config-package-name)
(short-name (cadr (string-split name #\space)))
@@ -149,7 +146,7 @@ General help using GNU software:
<http://www.gnu.org/gethelp/>\n"
config-package-name
config-package-url))
-(define* (show-help #:optional (command command-name))
+(define* (show-help #:optional (command (command-name)))
"Display informations of usage for COMMAND and quit."
(simple-format #t "Usage: ~a" command)
(display
- [Bug-mcron] [PATCH 26/33] mcron: Make functions 'static'., (continued)
- [Bug-mcron] [PATCH 26/33] mcron: Make functions 'static'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 29/33] environment: Redefine 'modify-environment'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 17/33] main: Add main., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 21/33] main: Remove obsolete debug option., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 22/33] redirect: Use module (ice-9 regex)., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 23/33] mcron: Add forward declarations., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 28/33] main: Remove unused 'regular-file?' procedure., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 24/33] mcron: Use symbolic constants., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 25/33] mcron: Rework comments., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 20/33] build: Enable silent rules by default., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 13/33] main: Turn 'command-name' into a thunk.,
Mathieu Lirzin <=
- [Bug-mcron] [PATCH 19/33] build: Compile and install '.go' files., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 18/33] main: Add (mcron main) module., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 30/33] Define directory-local variables for Emacs., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 31/33] main: Add 'proc-in-directory'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 32/33] main: Remove 'valid-user'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 33/33] core: Use SRFI-9 records for the job data structure., Mathieu Lirzin, 2015/09/27