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 . */ -(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