#! /usr/local/bin/sizzle -s
!#
;; examples/hello.scm -- ``Hello World!'' for Sizzle.
;;
;; Copyright (C) 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
;;
;; This 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, or (at your option)
;; any later version.
;; 
;; This software 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 package; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.  

; This is the famous Hello-World-program, once written for Guile and
; ported to Sizzle.  It is a little bit enhanced in that it
; understands the command line options `--help' (-h) and `--version'
; (-v), which print a short usage decription or version information,
; respectively.

(use-modules (core getopt-long))

; This is the grammar for the command line synopsis we expect.
(define command-synopsis
  '((version (single-char #\v) (value #f))
    (help    (single-char #\h) (value #f))))

; Display version information and exit.
(define (display-version)
  (display "hello.scm 0.0.1\n"))

; Display the usage help message and exit.
(define (display-help)
  (display "Usage: hello.scm [options...] [filename...]\n")
  (display "  --help, -h           Show this usage information\n")
  (display "  --version, -v        Show version information\n"))

; Interpret options, if --help or --version was given, print out the
; requested information and exit.  Otherwise, print the famous
; message.
(define (main options)
  (let ((help-wanted (option-ref options 'help #f))
	(version-wanted (option-ref options 'version #f)))
    (if (or version-wanted help-wanted)
	(begin
	  (if version-wanted
	      (display-version))
	  (if help-wanted
	      (display-help)))
	(begin
	  (display "Hello, World!") (newline)))))

;
; Call the main program with parsed command line options.
;
(main (getopt-long (command-line) command-synopsis))
