diff options
author | antirez <antirez> | 2005-04-05 11:51:17 +0000 |
---|---|---|
committer | antirez <antirez> | 2005-04-05 11:51:17 +0000 |
commit | 0b5ec7f323c8eb15c7b2055616c7b7af1e5afd3d (patch) | |
tree | 9353a8d64b2a6c1c9b560d0feae191435de66c68 /jimsh.c | |
parent | a96abb6e891079e1e2dadcebee354fc72ed7d9bf (diff) | |
download | jimtcl-0b5ec7f323c8eb15c7b2055616c7b7af1e5afd3d.zip jimtcl-0b5ec7f323c8eb15c7b2055616c7b7af1e5afd3d.tar.gz jimtcl-0b5ec7f323c8eb15c7b2055616c7b7af1e5afd3d.tar.bz2 |
.jimrc support (or jimrc.tcl). Minimal readline extension, just enough
to allow to the pure-Jim rlprompt extension to provide a readline-aware
interactive shell with history.
Diffstat (limited to 'jimsh.c')
-rw-r--r-- | jimsh.c | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -1,7 +1,7 @@ /* Jimsh - An interactive shell for Jim * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> * - * $Id: jimsh.c,v 1.3 2005/03/08 17:06:08 antirez Exp $ + * $Id: jimsh.c,v 1.4 2005/04/05 11:51:18 antirez Exp $ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,33 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #define JIM_EMBEDDED #include "jim.h" +void JimLoadJimRc(Jim_Interp *interp) +{ + const char *home; + char buf [JIM_PATH_LEN+1]; + const char *names[] = {".jimrc", "jimrc.tcl", NULL}; + int i; + FILE *fp; + + if ((home = getenv("HOME")) == NULL) return; + 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) { + Jim_PrintErrorMessage(interp); + } + return; + } + } +} + int main(int argc, char *const argv[]) { int retcode, n; @@ -47,13 +70,15 @@ int main(int argc, char *const argv[]) Jim_SetVariableStr(interp, "argv", listObj); if (argc == 1) { + Jim_SetVariableStrWithStr(interp, "jim_interactive", "1"); + JimLoadJimRc(interp); retcode = Jim_InteractivePrompt(interp); } else { + Jim_SetVariableStrWithStr(interp, "jim_interactive", "0"); if ((retcode = Jim_EvalFile(interp, argv[1])) == JIM_ERR) { Jim_PrintErrorMessage(interp); } } - Jim_FreeInterp(interp); return retcode; } |