Permalink
Browse files

Allow exit from .jimrc

Only show error on JIM_ERR from .jimrc
Also fixes to rlprompt.tcl so it can be used from .jimrc

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent 6cd1b1b commit e8bfa491fa726c034a99ff7fc4fc64b990d45e12 @msteveb committed Sep 27, 2010
Showing with 13 additions and 11 deletions.
  1. +11 −6 jimsh.c
  2. +2 −5 rlprompt.tcl
View
17 jimsh.c
@@ -92,29 +92,32 @@ static Jim_Obj *JimGetExePath(Jim_Interp *interp, const char *argv0)
}
#endif /* JIM_ANSIC */
-static void JimLoadJimRc(Jim_Interp *interp)
+static int JimLoadJimRc(Jim_Interp *interp)
{
const char *home;
/* XXX: Move off stack */
char buf[JIM_PATH_LEN + 1];
const char *names[] = { ".jimrc", "jimrc.tcl", NULL };
int i;
FILE *fp;
+ int retcode;
if ((home = getenv("HOME")) == NULL)
- return;
+ return JIM_OK;
for (i = 0; names[i] != NULL; i++) {
if (strlen(home) + strlen(names[i]) + 1 > JIM_PATH_LEN)
continue;
sprintf(buf, "%s/%s", home, names[i]);
if ((fp = fopen(buf, "r")) != NULL) {
fclose(fp);
- if (Jim_EvalFile(interp, buf) != JIM_OK) {
+ retcode = Jim_EvalFile(interp, buf);
+ if (retcode == JIM_ERR) {
Jim_PrintErrorMessage(interp);
}
- return;
+ return retcode;
}
}
+ return JIM_OK;
}
static void JimSetArgv(Jim_Interp *interp, int argc, char *const argv[])
@@ -160,8 +163,10 @@ int main(int argc, char *const argv[])
if (argc == 1) {
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
JimSetArgv(interp, 0, NULL);
- JimLoadJimRc(interp);
- retcode = Jim_InteractivePrompt(interp);
+ retcode = JimLoadJimRc(interp);
+ if (retcode != JIM_EXIT) {
+ retcode = Jim_InteractivePrompt(interp);
+ }
}
else {
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "0");
View
@@ -9,18 +9,15 @@
# rlprompt.shell
# }
# }
+package require readline
proc rlprompt.shell {} {
puts "Readline shell loaded"
puts "Welcome to Jim [info version]!"
set prompt ". "
set buf ""
while 1 {
- try -exit {
- set line [readline.readline $prompt]
- } on exit dummy {
- break
- }
+ set line [readline.readline $prompt]
if {[string length $line] == 0} {
continue

0 comments on commit e8bfa49

Please sign in to comment.