bug-mit-scheme
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-mit-scheme] [bug #25382] --version, --help command line options


From: Matt Birkholz
Subject: [Bug-mit-scheme] [bug #25382] --version, --help command line options
Date: Mon, 26 Jan 2009 14:35:37 -0700

> From: bryan newbold <address@hidden>
> Date: Thu, 22 Jan 2009 19:57:05 +0000
> 
> [...]
> Could be implemented either in the microcode or scheme?

I tried both: --help and --version support in the machine AND the
band.  I also implemented --quiet and --silent as synonyms for
--batch-mode (suggested by some GNU standard or sump'n).

> For version, something like the usual banner:
> 
> $ mit-scheme --version
> MIT/GNU Scheme running under GNU/Linux
> 
> Copyright 2006 Massachusetts Institute of Technology.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> Image saved on Wednesday September 20, 2006 at 10:31:51 PM
>   Release 7.7.90.+ || Microcode 14.17 || Runtime 15.6 || SF 4.41 || LIAR 4.117
>   Edwin 3.116

I got this for `mit-scheme --version`:

    MIT/GNU Scheme 15.1
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
        1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
        2006, 2007, 2008 Massachusetts Institute of Technology
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Image saved on Monday January 26, 2009 at 12:42:04 PM
      Release 7.7.90.+ || Microcode 15.1 || Runtime 15.7 || SF 4.41
      LIAR/i386 4.118  || Edwin 3.116
    Happy Happy Joy Joy.

That should be completely GNU standard.

For `mit-scheme --quiet --version` I accidentally got this:

    MIT/GNU Scheme 15.1

I'll take that as a feature.

> And --help could show the command line options listed in the man files.

I got the text of `mit-scheme --help` from microcode/option.c, as
close to The Source as possible.  It came out a bit long, but it
includes descriptions of the options supported by the band.  (Search
for "Happy Happy Joy Joy" if you want it to be over.)

    Usage: mit-scheme --OPTION ARG ... --OPTION ARG ...

    This machine accepts the following command-line options.  The options
    may appear in any order, but they must all appear before any options
    for the band.

    --library PATH
      Sets the library search path to PATH.  This is a colon-separated
      list of directories that is searched to find various library files,
      such as bands.  If this option is not given, the value of the
      environment variable MITSCHEME_LIBRARY_PATH is used; it that isn't
      defined, "/usr/local/lib/mit-scheme" is used.

    --band FILENAME
      Specifies the initial band to be loaded.  Searches for FILENAME in
      the working directory and the library directories, returning the
      full pathname of the first readable file of that name.  If this
      option isn't given, the filename is the value of the environment
      variable MITSCHEME_BAND, or if that isn't defined, "runtime.com"; in
      these cases the library directories are searched, but not the
      working directory.

    --fasl FILENAME
      Specifies that a cold load should be performed, using FILENAME as
      the initial file to be loaded.  If this option isn't given, a normal
      load is performed instead.  This option may not be used together
      with the "--band" option.

    --utabmd FILENAME
      Specifies the name of the microcode tables file.  The file is
      searched for in the working directory and the library directories.
      If this option isn't given, the filename is the value of the
      environment variable MITSCHEME_UTABMD_FILE, or if that isn't
      defined, "utabmd.bin"; in these cases the library directories are
      searched, but not the working directory.

    --heap BLOCKS
      Specifies the size of the heap in 1024-word blocks.  Overrides any
      default.  Normally two such heaps are allocated; `bchscheme'
      allocates only one.

    --constant BLOCKS
      Specifies the size of constant space in 1024-word blocks.  Overrides
      any default.

    --stack BLOCKS
      Specifies the size of the stack in 1024-word blocks.  Overrides any
      default.

    --option-summary
      Causes Scheme to write option values to standard error.

    --help
      Causes Scheme to report the available command line options.

    --version
      Causes Scheme to report versions and copyrights, then exit.

    --batch-mode, --quiet, --silent
      Suppresses the startup report of versions and copyrights, and the
      valediction.

    --emacs
      Specifies that Scheme is running as a subprocess of GNU Emacs.
      This option is automatically supplied by GNU Emacs, and should not
      be given under other circumstances.

    --interactive
      If this option isn't specified, and Scheme's standard I/O is not a
      terminal, Scheme will detach itself from its controlling terminal.
      This will prevent it from getting signals sent to the process group
      of that terminal.  If this option is specified, Scheme will not
      detach itself from the controlling terminal.

    --nocore
      Specifies that Scheme should not generate a core dump under any
      circumstances.

    Please report bugs to address@hidden

    Additional options may be supported by the band (and described below).

    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
        1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
        2006, 2007, 2008 Massachusetts Institute of Technology
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Image saved on Monday January 26, 2009 at 1:54:52 PM
      Release 7.7.90.+ || Microcode 15.1 || Runtime 15.7 || SF 4.41
      LIAR/i386 4.118  || Edwin 3.116

    ADDITIONAL OPTIONS supported by this band:

    --no-init-file
      Ignore the .scheme.init file.

    --suspend-file
      Write a world image (unavailable on some operating systems).

    --no-suspend-file
      Do NOT write a world image (available on all operating systems :0).

    --load ARG ...
      Load the argument files.

    --eval ARG ...
      Evaluate the argument expressions.

    --edit
      Causes Edwin to start immediately after Scheme.

    Happy Happy Joy Joy.

> Let me know if you would like a patch?

Howzabout the attached patch, to apply in your src/ with -p0?  It will
have to touch edwin/editor.scm!  It adds a "description" parameter to
three global procedures: argument-command-line-parser,
simple-command-line-parser, set-command-line-parser!.  The only
callers within the system are in runtime/load.scm and
edwin/editor.scm.  But perhaps there are many others out there?

If such a change is more obnoxious than I think, I can leave those
globals be and add new ...-with-help versions.  Does anyone care?

-Matt

Index: edwin/editor.scm
===================================================================
RCS file: /cvsroot/mit-scheme/mit-scheme/v7/src/edwin/editor.scm,v
retrieving revision 1.266
diff -C 2 -r1.266 editor.scm
*** edwin/editor.scm    30 Jan 2008 20:02:00 -0000      1.266
--- edwin/editor.scm    26 Jan 2009 21:29:54 -0000
***************
*** 90,94 ****
  
  (define (edwin . args) (apply edit args))
! (simple-command-line-parser "edit" edit)
  
  (define edwin-editor #f)
--- 90,95 ----
  
  (define (edwin . args) (apply edit args))
! (simple-command-line-parser
!  "edit" "Causes Edwin to start immediately after Scheme." edit)
  
  (define edwin-editor #f)
Index: microcode/boot.c
===================================================================
RCS file: /cvsroot/mit-scheme/mit-scheme/v7/src/microcode/boot.c,v
retrieving revision 9.130
diff -C 2 -r9.130 boot.c
*** microcode/boot.c    30 Jan 2008 20:02:11 -0000      9.130
--- microcode/boot.c    26 Jan 2009 21:29:55 -0000
***************
*** 231,235 ****
    SCHEME_OBJECT expr;
  
!   if (!option_batch_mode)
      {
        outf_console ("MIT/GNU Scheme running under %s\n", OS_Variant);
--- 231,235 ----
    SCHEME_OBJECT expr;
  
!   if (!option_batch_mode && !option_show_version && !option_show_help)
      {
        outf_console ("MIT/GNU Scheme running under %s\n", OS_Variant);
Index: microcode/option.c
===================================================================
RCS file: /cvsroot/mit-scheme/mit-scheme/v7/src/microcode/option.c,v
retrieving revision 1.67
diff -C 2 -r1.67 option.c
*** microcode/option.c  26 Sep 2008 08:30:20 -0000      1.67
--- microcode/option.c  26 Jan 2009 21:29:56 -0000
***************
*** 97,100 ****
--- 97,102 ----
  bool option_disable_core_dump;
  bool option_batch_mode;
+ bool option_show_help;
+ bool option_show_version;
  
  /* String options */
***************
*** 109,181 ****
  unsigned long option_stack_size;
  
! /*
! 
! Scheme accepts the following command-line options.  The options may
! appear in any order, but they must all appear before any other
! arguments on the command line.
! 
! --library PATH
!   Sets the library search path to PATH.  This is a colon-separated
!   list of directories that is searched to find various library files,
!   such as bands.  If this option is not given, the value of the
!   environment variable MITSCHEME_LIBRARY_PATH is used; it that isn't
!   defined, "/usr/local/lib/mit-scheme" is used.
! 
! --band FILENAME
!   Specifies the initial band to be loaded.  Searches for FILENAME in
!   the working directory and the library directories, returning the
!   full pathname of the first readable file of that name.  If this
!   option isn't given, the filename is the value of the environment
!   variable MITSCHEME_BAND, or if that isn't defined, "runtime.com"; in
!   these cases the library directories are searched, but not the
!   working directory.
! 
! --fasl FILENAME
!   Specifies that a cold load should be performed, using FILENAME as
!   the initial file to be loaded.  If this option isn't given, a normal
!   load is performed instead.  This option may not be used together
!   with the "--band" option.
! 
! --utabmd FILENAME
!   Specifies the name of the microcode tables file.  The file is
!   searched for in the working directory and the library directories.
!   If this option isn't given, the filename is the value of the
!   environment variable MITSCHEME_UTABMD_FILE, or if that isn't
!   defined, "utabmd.bin"; in these cases the library directories are
!   searched, but not the working directory.
! 
! --heap BLOCKS
!   Specifies the size of the heap in 1024-word blocks.  Overrides any
!   default.  Normally two such heaps are allocated; `bchscheme'
!   allocates only one.
! 
! --constant BLOCKS
!   Specifies the size of constant space in 1024-word blocks.  Overrides
!   any default.
! 
! --stack BLOCKS
!   Specifies the size of the stack in 1024-word blocks.  Overrides any
!   default.
! 
! --option-summary
!   Causes Scheme to write option information to standard error.
! 
! --emacs
!   Specifies that Scheme is running as a subprocess of GNU Emacs.
!   This option is automatically supplied by GNU Emacs, and should not
!   be given under other circumstances.
! 
! --interactive
!   If this option isn't specified, and Scheme's standard I/O is not a
!   terminal, Scheme will detach itself from its controlling terminal.
!   This will prevent it from getting signals sent to the process group
!   of that terminal.  If this option is specified, Scheme will not
!   detach itself from the controlling terminal.
! 
! --nocore
!   Specifies that Scheme should not generate a core dump under any
!   circumstances.
! 
! */
  
  #ifndef LIBRARY_PATH_VARIABLE
--- 111,200 ----
  unsigned long option_stack_size;
  
! void
! print_help (void)
! {
!   outf_fatal ("Usage: mit-scheme --OPTION ARG ... --OPTION ARG ...\n\
! \n\
! This machine accepts the following command-line options.  The options\n\
! may appear in any order, but they must all appear before any options\n\
! for the band.\n\
! \n\
! --library PATH\n\
!   Sets the library search path to PATH.  This is a colon-separated\n\
!   list of directories that is searched to find various library files,\n\
!   such as bands.  If this option is not given, the value of the\n\
!   environment variable MITSCHEME_LIBRARY_PATH is used; it that isn't\n\
!   defined, \"/usr/local/lib/mit-scheme\" is used.\n\
! \n\
! --band FILENAME\n\
!   Specifies the initial band to be loaded.  Searches for FILENAME in\n\
!   the working directory and the library directories, returning the\n\
!   full pathname of the first readable file of that name.  If this\n\
!   option isn't given, the filename is the value of the environment\n\
!   variable MITSCHEME_BAND, or if that isn't defined, \"runtime.com\"; in\n\
!   these cases the library directories are searched, but not the\n\
!   working directory.\n\
! \n\
! --fasl FILENAME\n\
!   Specifies that a cold load should be performed, using FILENAME as\n\
!   the initial file to be loaded.  If this option isn't given, a normal\n\
!   load is performed instead.  This option may not be used together\n\
!   with the \"--band\" option.\n\
! \n\
! --utabmd FILENAME\n\
!   Specifies the name of the microcode tables file.  The file is\n\
!   searched for in the working directory and the library directories.\n\
!   If this option isn't given, the filename is the value of the\n\
!   environment variable MITSCHEME_UTABMD_FILE, or if that isn't\n\
!   defined, \"utabmd.bin\"; in these cases the library directories are\n\
!   searched, but not the working directory.\n\
! \n\
! --heap BLOCKS\n\
!   Specifies the size of the heap in 1024-word blocks.  Overrides any\n\
!   default.  Normally two such heaps are allocated; `bchscheme'\n\
!   allocates only one.\n\
! \n\
! --constant BLOCKS\n\
!   Specifies the size of constant space in 1024-word blocks.  Overrides\n\
!   any default.\n\
! \n\
! --stack BLOCKS\n\
!   Specifies the size of the stack in 1024-word blocks.  Overrides any\n\
!   default.\n\
! \n\
! --option-summary\n\
!   Causes Scheme to write option values to standard error.\n\
! \n\
! --help\n\
!   Causes Scheme to report the available command line options.\n\
! \n\
! --version\n\
!   Causes Scheme to report versions and copyrights, then exit.\n\
! \n\
! --batch-mode, --quiet, --silent\n\
!   Suppresses the startup report of versions and copyrights, and the\n\
!   valediction.\n\
! \n\
! --emacs\n\
!   Specifies that Scheme is running as a subprocess of GNU Emacs.\n\
!   This option is automatically supplied by GNU Emacs, and should not\n\
!   be given under other circumstances.\n\
! \n\
! --interactive\n\
!   If this option isn't specified, and Scheme's standard I/O is not a\n\
!   terminal, Scheme will detach itself from its controlling terminal.\n\
!   This will prevent it from getting signals sent to the process group\n\
!   of that terminal.  If this option is specified, Scheme will not\n\
!   detach itself from the controlling terminal.\n\
! \n\
! --nocore\n\
!   Specifies that Scheme should not generate a core dump under any\n\
!   circumstances.\n\
! \n\
! Please report bugs to %s.\n\
! \n\
! Additional options may be supported by the band (and described below).\n\
! \n", PACKAGE_BUGREPORT);
! }
  
  #ifndef LIBRARY_PATH_VARIABLE
***************
*** 362,365 ****
--- 381,390 ----
      }
    obstack_free ((&scratch_obstack), descriptors);
+   /* Pass --version and --help through to the band, sort of. */
+   if (strncmp ("--version", scan_argv[-1], 9) == 0)
+     scan_argv--;
+   if (strncmp ("--help", scan_argv[-1], 6) == 0)
+     scan_argv--;
+ 
    option_saved_argc = argc;
    option_saved_argv = argv;
***************
*** 373,376 ****
--- 398,405 ----
    option_argument ("band", true, (&option_raw_band));
    option_argument ("batch-mode", false, (&option_batch_mode));
+   option_argument ("quiet", false, (&option_batch_mode));
+   option_argument ("silent", false, (&option_batch_mode));
+   option_argument ("help", false, (&option_show_help));
+   option_argument ("version", false, (&option_show_version));
    option_argument ("constant", true, (&option_raw_constant));
    option_argument ("emacs", false, (&option_emacs_subprocess));
***************
*** 868,872 ****
--- 897,905 ----
                                 ));
  
+   if (option_show_help)
+     print_help ();
    if (option_summary)
      describe_options ();
+   if (option_show_version)
+     outf_console ("MIT/GNU Scheme %s\n", PACKAGE_VERSION);
  }
Index: microcode/option.h
===================================================================
RCS file: /cvsroot/mit-scheme/mit-scheme/v7/src/microcode/option.h,v
retrieving revision 1.21
diff -C 2 -r1.21 option.h
*** microcode/option.h  26 Sep 2008 08:30:23 -0000      1.21
--- microcode/option.h  26 Jan 2009 21:29:56 -0000
***************
*** 41,44 ****
--- 41,46 ----
  extern bool option_disable_core_dump;
  extern bool option_batch_mode;
+ extern bool option_show_help;
+ extern bool option_show_version;
  
  /* String options */
Index: runtime/load.scm
===================================================================
RCS file: /cvsroot/mit-scheme/mit-scheme/v7/src/runtime/load.scm,v
retrieving revision 14.103
diff -C 2 -r14.103 load.scm
*** runtime/load.scm    8 Mar 2008 17:43:12 -0000       14.103
--- runtime/load.scm    26 Jan 2009 21:29:57 -0000
***************
*** 510,514 ****
    (let ((entry (assoc (strip-leading-hyphens keyword) 
*command-line-parsers*)))
      (and entry
!        (cdr entry))))
  
  (define (option-keyword? argument)
--- 510,514 ----
    (let ((entry (assoc (strip-leading-hyphens keyword) 
*command-line-parsers*)))
      (and entry
!        (cddr entry))))
  
  (define (option-keyword? argument)
***************
*** 543,547 ****
  ;; delayed actions.
  
! (define (set-command-line-parser! keyword proc)
    (guarantee-string keyword 'SET-COMMAND-LINE-PARSER!)
    (let ((keyword (strip-leading-hyphens keyword)))
--- 543,547 ----
  ;; delayed actions.
  
! (define (set-command-line-parser! keyword description proc)
    (guarantee-string keyword 'SET-COMMAND-LINE-PARSER!)
    (let ((keyword (strip-leading-hyphens keyword)))
***************
*** 550,557 ****
      (let ((place (assoc keyword *command-line-parsers*)))
        (if place
!         (set-cdr! place proc)
          (begin
            (set! *command-line-parsers*
!                 (cons (cons keyword proc)
                        *command-line-parsers*))
            unspecific)))))
--- 550,559 ----
      (let ((place (assoc keyword *command-line-parsers*)))
        (if place
!         (begin
!           (set-car! (cdr place) description)
!           (set-cdr! (cdr place) proc))
          (begin
            (set! *command-line-parsers*
!                 (cons (cons* keyword description proc)
                        *command-line-parsers*))
            unspecific)))))
***************
*** 568,573 ****
             (substring keyword start end))))))
  
! (define (simple-command-line-parser keyword thunk)
    (set-command-line-parser! keyword
      (lambda (command-line)
        (values (cdr command-line) thunk))))
--- 570,578 ----
             (substring keyword start end))))))
  
! (define (simple-command-line-parser keyword description thunk)
!   (guarantee-string description 'SIMPLE-COMMAND-LINE-PARSER)
    (set-command-line-parser! keyword
+                           (if (string-null? description) ""
+                               (string-append "--"keyword"\n  "description))
      (lambda (command-line)
        (values (cdr command-line) thunk))))
***************
*** 576,581 ****
  (define simple-option-parser simple-command-line-parser)
  
! (define (argument-command-line-parser keyword multiple? procedure)
!   (set-command-line-parser! keyword
      (if multiple?
        (lambda (command-line)
--- 581,588 ----
  (define simple-option-parser simple-command-line-parser)
  
! (define (argument-command-line-parser keyword multiple? description procedure)
!   (set-command-line-parser!
!    keyword (string-append "--"keyword
!                         (if multiple? " ARG ...\n  " " ARG\n  ")description)
      (if multiple?
        (lambda (command-line)
***************
*** 606,612 ****
--- 613,634 ----
          (end '() accum)))))
  
+ (define (show-command-line-options)
+   (write-string "
+ 
+ ADDITIONAL OPTIONS supported by this band:\n")
+   (do ((parsers (reverse *command-line-parsers*) (cdr parsers)))
+       ((null? parsers))
+     (let ((description (cadar parsers)))
+       (if (not (string-null? description))
+         (begin
+           (newline)
+           (write-string description)
+           (newline)))))
+   (%exit 0))
+ 
  (define (initialize-command-line-parsers)
    (set! *command-line-parsers* '())
    (simple-command-line-parser "no-init-file"
+        "Ignore the .scheme.init file."
      (lambda ()
        (set! *load-init-file?* #f)
***************
*** 614,630 ****
    (set! generate-suspend-file? #f)
    (simple-command-line-parser "suspend-file"
      (lambda ()
        (set! generate-suspend-file? #t)
        unspecific))
    (simple-command-line-parser "no-suspend-file"
      (lambda ()
        (set! generate-suspend-file? #f)
        unspecific))
!   (argument-command-line-parser "load" #t
      (lambda (arg)
        (run-in-nearest-repl
         (lambda (repl)
         (load arg (repl/environment repl))))))
!   (argument-command-line-parser "eval" #t
      (lambda (arg)
        (run-in-nearest-repl
--- 636,654 ----
    (set! generate-suspend-file? #f)
    (simple-command-line-parser "suspend-file"
+         "Write a world image (unavailable on some operating systems)."
      (lambda ()
        (set! generate-suspend-file? #t)
        unspecific))
    (simple-command-line-parser "no-suspend-file"
+        "Do NOT write a world image (available on all operating systems :0)."
      (lambda ()
        (set! generate-suspend-file? #f)
        unspecific))
!   (argument-command-line-parser "load" #t "Load the argument files."
      (lambda (arg)
        (run-in-nearest-repl
         (lambda (repl)
         (load arg (repl/environment repl))))))
!   (argument-command-line-parser "eval" #t "Evaluate the argument expressions."
      (lambda (arg)
        (run-in-nearest-repl
***************
*** 634,636 ****
                                  environment)
                            environment
!                           repl)))))))
\ No newline at end of file
--- 658,666 ----
                                  environment)
                            environment
!                           repl))))))
!   (simple-command-line-parser "help" ""
!     (lambda ()
!       (show-command-line-options)))
!   (simple-command-line-parser "version" ""
!     (lambda ()
!       (%exit 0))))
\ No newline at end of file

reply via email to

[Prev in Thread] Current Thread [Next in Thread]