Author: yamakenz
Date: Fri Aug 17 14:42:16 2007
New Revision: 4853
Modified:
trunk/NEWS
trunk/configure.ac
trunk/scm/uim-sh.scm
trunk/uim/uim-error.c
trunk/uim/uim-sh.c
Log:
* scm/uim-sh.scm
- (uim-sh):
* Change the meaning of rest arguments for uim-sh [file ...] as
[file [arg ...]]
* Support SRFI-22 'main' procedure call
* Return exit status
- (uim-sh-usage): Modify the description about rest arguments
* uim/uim-sh.c
- Exclude stdlib.h for EXIT_FAILURE
- Receive and return exit status from 'uim-sh' procedure
* uim/uim-error.c
- Include sysexits.h
- Define EX_SOFTWARE if not exist
- (uim_throw_error): Replace EXIT_FAILURE with EX_SOFTWARE as
specified in SRFI-22
* configure.ac
- Check sysexits.h
* NEWS
- Update
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Fri Aug 17 14:42:16 2007
@@ -2,8 +2,11 @@
==
* New features
- uim-sh
- - Accept script files after options
+ - Accept script file and arguments for SRFI-22 'main' procedure
+ after uim-sh options
- Add --require-module option (-r for short)
+ - Add --expression option (-e for short)
+ - Add --version option (-V for short)
* Fixed
- uim Scheme library
@@ -17,7 +20,8 @@
- Fix EOF (^d) ignorance on editline feature is enabled
- Fix ignorance of multiple expressions on a line on editline
feature is enabled
- - Fix pseudo -r (require module) option with real require-module
+ - Fix pseudo -r (require module) option for editline feature with
+ real require-module
Overview of changes from 1.4.0-beta to 1.4.0
==
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Aug 17 14:42:16 2007
@@ -258,7 +258,7 @@
AC_CHECK_HEADERS([sys/time.h sys/stat.h sys/un.h getopt.h assert.h signal.h
term.h ncurses/term.h ctype.h pwd.h stdarg.h])
AC_CHECK_HEADERS([pty.h utmp.h util.h libutil.h])
AC_CHECK_HEADERS([curses.h stropts.h])
-AC_CHECK_HEADERS([sys/param.h strings.h netdb.h])
+AC_CHECK_HEADERS([sys/param.h strings.h netdb.h sysexits.h])
# Check for types
AC_TYPE_INT8_T
Modified: trunk/scm/uim-sh.scm
==============================================================================
--- trunk/scm/uim-sh.scm (original)
+++ trunk/scm/uim-sh.scm Fri Aug 17 14:42:16 2007
@@ -57,7 +57,7 @@
(define uim-sh-usage
(lambda ()
- (display "Usage: uim-sh [options] [file ...]
+ (display "Usage: uim-sh [options] [file [arg ...]]
-b
--batch batch mode. suppress shell prompts
-B
@@ -67,12 +67,14 @@
--require-module <name> require module
--editline require editline module for Emacs-like line editing
-e <expr>
- --expression <expr> evaluate <expr> (after loading the file)
+ --expression <expr> evaluate <expr> (after loading the file, and disables
+ 'main' procedure of it)
-V
--version show software version
-h
--help show this help
file absolute path or relative to system scm directory
+ arg ... string argument(s) for 'main' procedure of the file
")))
(define uim-sh-display-version
@@ -129,26 +131,45 @@
;; GaUnit-based unit test for uim.
(define uim-sh
(lambda (args)
- (let ((files (uim-sh-parse-args (cdr args))) ;; drop the command name
- (my-read (if (provided? "editline")
- uim-editline-read
- read)))
- (for-each require files)
+ (let* ((file.args (uim-sh-parse-args (cdr args))) ;; drop the command name
+ (script (safe-car file.args))
+ (my-read (if (provided? "editline")
+ uim-editline-read
+ read))
+ (EX_OK 0)
+ (EX_SOFTWARE 70))
+ (if script
+ (require script))
(cond
- (uim-sh-opt-help (uim-sh-usage))
- (uim-sh-opt-version (uim-sh-display-version))
+ (uim-sh-opt-help
+ (uim-sh-usage)
+ EX_OK)
+
+ (uim-sh-opt-version
+ (uim-sh-display-version)
+ EX_OK)
+
(uim-sh-opt-expression
(let* ((expr (read (open-input-string uim-sh-opt-arg-expression)))
(result (eval expr (interaction-environment))))
(write result)
- (newline)))
+ (newline)
+ EX_OK))
+
+ ((symbol-bound? 'main)
+ (let ((status (main file.args)))
+ (if (integer? status)
+ status
+ EX_SOFTWARE)))
+
(else
(let reloop ()
(and (guard (err (else
(%%inspect-error err)
#t))
(uim-sh-loop my-read))
- (reloop))))))))
+ (reloop)))
+ EX_OK)))))
(define uim-editline-read
(let ((p (open-input-string "")))
Modified: trunk/uim/uim-error.c
==============================================================================
--- trunk/uim/uim-error.c (original)
+++ trunk/uim/uim-error.c Fri Aug 17 14:42:16 2007
@@ -37,11 +37,17 @@
#include <string.h>
#include <stdio.h>
#include <assert.h>
+#if HAVE_SYSEXITS_H
+#include "sysexits.h"
+#endif
#include "uim.h"
#include "uim-internal.h"
+#ifndef EX_SOFTWARE
+#define EX_SOFTWARE 70
+#endif
/* Immediately returns UIM_TRUE if uim is disabled by a fatal error. */
@@ -109,7 +115,7 @@
assert(msg || !msg);
if (!guarded)
- exit(EXIT_FAILURE);
+ exit(EX_SOFTWARE);
err_msg = msg;
LONGJMP(uim_catch_block_env, guarded);
Modified: trunk/uim/uim-sh.c
==============================================================================
--- trunk/uim/uim-sh.c (original)
+++ trunk/uim/uim-sh.c Fri Aug 17 14:42:16 2007
@@ -33,8 +33,6 @@
*/
-#include <stdlib.h>
-
#include "uim.h"
#include "uim-scm.h"
@@ -42,7 +40,8 @@
int
main(int argc, char *argv[])
{
- uim_lisp args;
+ uim_lisp args, exit_status_;
+ int exit_status;
/* TODO: be able to suppress ordinary initialization process */
uim_init();
@@ -50,12 +49,16 @@
uim_scm_require_file("uim-sh.scm");
args = uim_scm_null();
+ exit_status_ = uim_scm_f();
uim_scm_gc_protect(&args);
+ uim_scm_gc_protect(&exit_status_);
+
args = uim_scm_array2list((void **)argv, argc,
(uim_lisp (*)(void *))uim_scm_make_str);
- uim_scm_callf("uim-sh", "o", args);
+ exit_status_ = uim_scm_callf("uim-sh", "o", args);
+ exit_status = uim_scm_c_int(exit_status_);
uim_quit();
- return EXIT_SUCCESS;
+ return exit_status;
}