Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash -- Guile As SHell
|
2019-01-06 20:47:05 +00:00
|
|
|
;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
|
|
|
|
;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2018-07-17 16:20:06 +01:00
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; This file is part of Gash.
|
2018-07-17 16:20:06 +01:00
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash is free software: you can redistribute it and/or modify
|
2018-07-17 16:20:06 +01:00
|
|
|
;;; it under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;;; (at your option) any later version.
|
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash is distributed in the hope that it will be useful,
|
2018-07-17 16:20:06 +01:00
|
|
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
|
2018-07-17 16:20:06 +01:00
|
|
|
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
(define-module (gash built-ins echo)
|
2019-01-06 20:47:05 +00:00
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (srfi srfi-1)
|
2019-05-17 01:30:54 +01:00
|
|
|
#:use-module (srfi srfi-26))
|
2018-07-17 16:20:06 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; The 'echo' utility.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
2019-01-06 20:47:05 +00:00
|
|
|
(define (escape->control string)
|
|
|
|
(list->string
|
|
|
|
(let loop ((lst (string->list string)))
|
|
|
|
(if (null? lst) '()
|
|
|
|
(let ((char (car lst)))
|
|
|
|
(if (or (not (eq? char #\\))
|
|
|
|
(null? (cdr lst))) (cons char (loop (cdr lst)))
|
|
|
|
(let* ((lst (cdr lst))
|
|
|
|
(char (car lst)))
|
|
|
|
(case char
|
|
|
|
((#\\) (cons #\\ (loop (cdr lst))))
|
|
|
|
((#\a) (cons #\alarm (loop (cdr lst))))
|
|
|
|
((#\b) (cons #\backspace (loop (cdr lst))))
|
|
|
|
((#\c) '())
|
Add support for Guile 2.0.9.
* gash/compat.scm: New file.
* gash/compat/hash-table.scm: New file.
* Makefile.am: Add them.
* .dir-locals.scm: Add indentation for 'if-guile-version-below'.
* guix.scm (guile-2.0.9): New variable.
* gash/built-ins/echo.scm (escape->control): Use '#\esc'.
* gash/environment.scm: Use '(gash compat hash-table)'.
* gash/built-ins/break.scm,
gash/built-ins/cd.scm,
gash/built-ins/command.scm,
gash/built-ins/continue.scm,
gash/built-ins/dot.scm,
gash/built-ins/exec.scm,
gash/built-ins/exit.scm,
gash/built-ins/pwd.scm,
gash/built-ins/return.scm,
gash/built-ins/set.scm,
gash/built-ins/shift.scm,
gash/built-ins/trap.scm,
gash/built-ins/type.scm,
gash/built-ins/umask.scm,
gash/eval.scm,
tests/unit/automake.scm: Use '(gash compat)'.
squash! Add support for Guile 2.0.9.
2019-05-20 00:33:05 +01:00
|
|
|
;; Guile 2.0.9 does not understand '#\escape',
|
|
|
|
;; so we use the older '#\esc'.
|
|
|
|
((#\e) (cons #\esc (loop (cdr lst))))
|
2019-01-06 20:47:05 +00:00
|
|
|
((#\f) (cons #\page (loop (cdr lst))))
|
|
|
|
((#\n) (cons #\newline (loop (cdr lst))))
|
|
|
|
((#\r) (cons #\return (loop (cdr lst))))
|
|
|
|
((#\t) (cons #\tab (loop (cdr lst))))
|
|
|
|
((#\v) (cons #\vtab (loop (cdr lst))))
|
|
|
|
((#\0) (error "echo: TODO: \\0NNN"))
|
|
|
|
((#\x) (error "echo: TODO: \\xNNN"))))))))))
|
|
|
|
|
|
|
|
(define (option? str)
|
|
|
|
(and (> (string-length str) 1)
|
|
|
|
(char=? (string-ref str 0) #\-)
|
|
|
|
(string-every (cut member <> '(#\E #\e #\n)) (substring str 1))))
|
|
|
|
|
2019-05-17 01:30:54 +01:00
|
|
|
(define (main . args)
|
2019-01-06 20:47:05 +00:00
|
|
|
(let* ((options (append-map (compose cdr string->list)
|
|
|
|
(take-while option? args)))
|
|
|
|
(args (drop-while option? args))
|
|
|
|
(newline? (not (member #\n options)))
|
|
|
|
(escapes? (fold (lambda (x acc)
|
|
|
|
(match x
|
|
|
|
(#\e #t)
|
|
|
|
(#\E #f)
|
|
|
|
(_ acc)))
|
|
|
|
#f
|
|
|
|
options))
|
|
|
|
(string (string-join args)))
|
|
|
|
(display (if escapes?
|
|
|
|
(escape->control string)
|
|
|
|
string))
|
|
|
|
(when newline?
|
2018-10-16 23:17:52 +01:00
|
|
|
(newline))
|
|
|
|
0))
|