blob: 976eb3a5b5fffb68a493f517147bc630e093410e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
From 4535e00555a3317aa28395a7f7fd02b3d204e6ec Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Mon, 7 Sep 2015 12:32:00 +0200
Subject: [PATCH hurd 09/11] fu_bootshell
---
bootshell/boot.scm | 28 ++++++++++++++++++++++++++++
bootshell/runsystem.scm | 26 +-------------------------
2 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/bootshell/boot.scm b/bootshell/boot.scm
index 75cc75f..8b51459 100644
--- a/bootshell/boot.scm
+++ b/bootshell/boot.scm
@@ -38,6 +38,34 @@
(define (string-prefix-any? lp s)
(any (lambda (p) (string-prefix? p s)) lp))
+;; Locate the first occurrence of needle in haystack.
+(define (string-index haystack needle)
+ (define (index i haystack needle)
+ (if (= (length haystack) 0)
+ #f
+ (if (char=? (car haystack) needle)
+ i
+ (index (+ i 1) (cdr haystack) needle))))
+ (index 0 (string->list haystack) needle))
+
+;; Split haystack at delimiter at most n times.
+(define (string-splitn haystack delimiter n)
+ (define (split acc haystack delimiter n)
+ (if (= (string-length haystack) 0)
+ (reverse acc)
+ (let ((i (string-index haystack delimiter)))
+ (if (not (or (eq? i #f) (= 0 n)))
+ (split (cons (substring haystack 0 i) acc)
+ (substring haystack (+ i 1) (string-length haystack))
+ delimiter (- n 1))
+ (split (cons haystack acc) "" delimiter 0)
+ ))))
+ (split '() haystack delimiter n))
+
+;; Split haystack at delimiter.
+(define (string-split haystack delimiter)
+ (string-splitn haystack delimiter -1))
+
;; The `catch' from init.scm doesn't give the thrown value to the
;; handler. As a crappy workaround, we set! `last-exception' to the
;; last the exception.
diff --git a/bootshell/runsystem.scm b/bootshell/runsystem.scm
index 86b8c16..a2f0ee2 100644
--- a/bootshell/runsystem.scm
+++ b/bootshell/runsystem.scm
@@ -17,31 +17,6 @@
;; You should have received a copy of the GNU General Public License
;; along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
-(define (string-index haystack delimiter)
- (define (index i haystack delimiter)
- (if (= (length haystack) 0)
- #f
- (if (char=? (car haystack) delimiter)
- i
- (index (+ i 1) (cdr haystack) delimiter))))
- (index 0 (string->list haystack) delimiter))
-
-(define (string-splitn haystack delimiter n)
- (define (split acc haystack delimiter n)
- (if (= (string-length haystack) 0)
- (reverse acc)
- (let ((i (string-index haystack delimiter)))
- (if (not (or (eq? i #f) (= 0 n)))
- (split (cons (substring haystack 0 i) acc)
- (substring haystack (+ i 1) (string-length haystack))
- delimiter (- n 1))
- (split (cons haystack acc) "" delimiter 0)
- ))))
- (split '() haystack delimiter n))
-
-(define (string-split haystack delimiter)
- (string-splitn haystack delimiter -1))
-
(define (parse-cmdline c)
(define (parse args kwargs l)
(if (= (length l) 0)
@@ -74,5 +49,6 @@
;(lambda () (boot! init))
(lambda ()
(run '(/sbin/console-run --console=/dev/console -- /bin/bash))
+ (echo "bash started")
(sleep 60))
))))
--
2.1.4
|