Add a general purpose hashtable pattern matcher
[jimtcl.git] / jim-readline.c
blob9b1f410ad70831555185b2c0813f205923d1821c
1 /*
2 * Jim - Readline bindings for Jim
4 * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and documentation
31 * are those of the authors and should not be interpreted as representing
32 * official policies, either expressed or implied, of the Jim Tcl Project.
35 #include "jim.h"
36 #include "jimautoconf.h"
38 #include <readline/readline.h>
39 #include <readline/history.h>
41 static int JimRlReadlineCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
43 char *line;
45 if (argc != 2) {
46 Jim_WrongNumArgs(interp, 1, argv, "prompt");
47 return JIM_ERR;
49 line = readline(Jim_String(argv[1]));
50 if (!line) {
51 return JIM_EXIT;
53 Jim_SetResult(interp, Jim_NewStringObj(interp, line, -1));
54 return JIM_OK;
57 static int JimRlAddHistoryCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
59 if (argc != 2) {
60 Jim_WrongNumArgs(interp, 1, argv, "string");
61 return JIM_ERR;
63 add_history(Jim_String(argv[1]));
64 return JIM_OK;
67 int Jim_readlineInit(Jim_Interp *interp)
69 if (Jim_PackageProvide(interp, "readline", "1.0", JIM_ERRMSG))
70 return JIM_ERR;
72 Jim_CreateCommand(interp, "readline.readline", JimRlReadlineCommand, NULL, NULL);
73 Jim_CreateCommand(interp, "readline.addhistory", JimRlAddHistoryCommand, NULL, NULL);
74 return JIM_OK;