From d6502d6309c6dcbfe12fe91b864005763c250c57 Mon Sep 17 00:00:00 2001
From: felix <felix@call-with-current-continuation.org>
Date: Fri, 29 Mar 2013 21:14:31 +0100
Subject: [PATCH] added 'ep' procedure to utils unit for explicitly expanding tilde in pathnames
---
NEWS | 1 +
manual/Unit utils | 12 ++++++++++++
types.db | 1 +
utils.import.scm | 1 +
utils.scm | 34 ++++++++++++++++++++++++++++++++++
5 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/NEWS b/NEWS
index a34fbe0..5fecf4a 100644
a
|
b
|
|
15 | 15 | - read-line no longer returns trailing CRs in rare cases on TCP ports (#568) |
16 | 16 | - write and pp now correctly use escape sequences for control characters |
17 | 17 | (thanks to Florian Zumbiehl) |
| 18 | - added "ep" procedure to explicitly expand "~" in pathnames. |
18 | 19 | |
19 | 20 | - Runtime system |
20 | 21 | - Special events in poll() are now handled, avoiding hangs in threaded apps. |
diff --git a/manual/Unit utils b/manual/Unit utils
index 8c1df37..d4dad5c 100644
a
|
b
|
characters that would have a special meaning to the shell are escaped |
47 | 47 | using backslash ({{\}}). |
48 | 48 | |
49 | 49 | |
| 50 | === Tilde-expansion in pathnames |
| 51 | |
| 52 | <procedure>(ep STRING)</procedure> |
| 53 | |
| 54 | If {{STRING}} begins with {{"~/"}} or {{"~USERNAME"}}, return the |
| 55 | argument with the home-path substituted by the users HOME |
| 56 | directory. On Windows, this will be the value of the environment |
| 57 | variables {{USERPROFILE}} or {{HOME}} (or {{"."}} if none of the |
| 58 | variables is set). On Unix systems, the user database is consulted. |
| 59 | If {{STRING}} doesn't begin with a tilde, it is returned unchanged. |
| 60 | |
| 61 | |
50 | 62 | === Dynamic compilation |
51 | 63 | |
52 | 64 | ==== compile-file |
diff --git a/types.db b/types.db
index 3424af0..b4faadb 100644
a
|
b
|
|
2608 | 2608 | (read-all (#(procedure #:enforce) read-all (#!optional (or input-port string)) string)) |
2609 | 2609 | (system* (#(procedure #:clean #:enforce) system* (string #!rest) undefined)) |
2610 | 2610 | (qs (#(procedure #:clean #:enforce) qs (string) string)) |
| 2611 | (ep (#(procedure #:clean #:enforce) ep (string) string)) |
2611 | 2612 | (compile-file (#(procedure #:clean #:enforce) compile-file (string #!rest) (or boolean string))) |
2612 | 2613 | (compile-file-options (#(procedure #:clean #:enforce) compile-file-options (#!optional (list-of string)) (list-of string))) |
2613 | 2614 | (scan-input-lines (#(procedure #:enforce) scan-input-lines (* #!optional input-port) *)) |
diff --git a/utils.import.scm b/utils.import.scm
index 0775546..17be87a 100644
a
|
b
|
|
28 | 28 | 'utils |
29 | 29 | '(read-all |
30 | 30 | system* |
| 31 | ep |
31 | 32 | qs |
32 | 33 | compile-file |
33 | 34 | compile-file-options |
diff --git a/utils.scm b/utils.scm
index 715219d..aa80c3a 100644
a
|
b
|
|
75 | 75 | (string->list str))))))) |
76 | 76 | |
77 | 77 | |
| 78 | ;;; Expand path beginning with "~" |
| 79 | |
| 80 | (define ep |
| 81 | (let ((home |
| 82 | (cond-expand |
| 83 | ((and windows (not cygwin)) |
| 84 | (or (get-environment-variable "USERPROFILE") |
| 85 | (get-environment-variable "HOME") |
| 86 | ".")) |
| 87 | (else |
| 88 | (let ((info (user-information (current-effective-user-id)))) |
| 89 | (list-ref info 5))))) |
| 90 | (slash |
| 91 | (cond-expand |
| 92 | ((and windows (not cygwin)) '(#\\ #\/)) |
| 93 | (else '(#\/))))) |
| 94 | (lambda (path) |
| 95 | (let ((len (string-length path))) |
| 96 | (if (and (fx> len 0) (char=? #\~ (string-ref path 0))) |
| 97 | (let ((rest (substring path 1 len))) |
| 98 | (if (and (fx> len 1) (memq (string-ref path 1) slash)) |
| 99 | (string-append home rest) |
| 100 | (let* ((p (string-index path (lambda (c) (memq c slash)))) |
| 101 | (user (substring path 1 (or p len))) |
| 102 | (info (user-information user))) |
| 103 | (if info |
| 104 | (let ((dir (list-ref info 5))) |
| 105 | (if p |
| 106 | (make-pathname dir (substring path p)) |
| 107 | dir)) |
| 108 | (error "no such user" user))))) |
| 109 | path))))) |
| 110 | |
| 111 | |
78 | 112 | ;;; Compile and load file |
79 | 113 | |
80 | 114 | (define compile-file-options (make-parameter '("-O2" "-d2"))) |