| 1 |
;;; |
| 2 |
;;; SRFI-193 - Command line |
| 3 |
;;; |
| 4 |
;;; Public Domain |
| 5 |
;;; |
| 6 |
|
| 7 |
(define-module srfi.193 |
| 8 |
(use file.util) |
| 9 |
(export command-line command-name command-args |
| 10 |
script-file script-directory)) |
| 11 |
(select-module srfi.193) |
| 12 |
|
| 13 |
;; utility |
| 14 |
(define (filename->command-name path) |
| 15 |
(cond-expand |
| 16 |
[gauche.os.windows |
| 17 |
(regexp-replace #/\.(exe|scm)$/ (sys-basename path) "")] |
| 18 |
[else |
| 19 |
(regexp-replace #/\.scm$/ (sys-basename path) "")])) |
| 20 |
|
| 21 |
;;; Fundamental |
| 22 |
|
| 23 |
;; command-line : Built-in |
| 24 |
;; script-file : Built-in |
| 25 |
|
| 26 |
;;; Derived |
| 27 |
|
| 28 |
(define (command-name) |
| 29 |
(let1 arg0 (car (command-line)) |
| 30 |
(and (not (equal? arg0 "")) |
| 31 |
(filename->command-name arg0)))) |
| 32 |
|
| 33 |
(define (command-args) |
| 34 |
(cdr (command-line))) |
| 35 |
|
| 36 |
(define (script-directory) |
| 37 |
(and-let1 sf (script-file) |
| 38 |
(string-append (sys-dirname sf) (string (path-separator))))) |