;;;;
;;;; secho.stk  -- a simple /bin/echo in Scheme
;;;;
;;;; Copyright © 2009-2020 Erick Gallesio - Polytech'Nice-Sophia <eg@unice.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; 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
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@unice.fr]
;;;;    Creation date:  4-May-2009 10:56 (eg)
;;;;


(define *version* "1.0")

(define (main argv)
  (let ((output-nl #t)
        (out       (current-output-port)))

    (parse-arguments argv
       "Usage: secho [options] [parameter ...]"
       "Available options"
       (("no-newline" :alternate "n" :help "do not output the trailing newline")
         (set! output-nl #f))
       (("error-port" :alternate "2" :help "Use the error port for the outputs")
         (set! out (current-error-port)))
       "Other options"
       (("help" :alternate "h" :help "display this help and exit")
        (arg-usage (current-error-port))
        (exit 1))
       (("version" :alternate "V" :help "output version information and exit")
        (printf "~a version ~a\n" (program-name) *version*)
        (exit 0))
       (else
        (for-each  (lambda (x)
                     (display x out)
                     (display #\space out))
                   other-arguments)
        (when output-nl
          (newline out))))))
