lock.test: Improve check for aio.lock support
[jimtcl.git] / jim-readline.c
blob39051b03960beed7a0c53ce86106ada7a29590a8
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>
37 #include <readline/readline.h>
38 #include <readline/history.h>
40 static int JimRlReadlineCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
42 char *line;
44 if (argc != 2) {
45 Jim_WrongNumArgs(interp, 1, argv, "prompt");
46 return JIM_ERR;
48 line = readline(Jim_String(argv[1]));
49 if (!line) {
50 return JIM_EXIT;
52 Jim_SetResult(interp, Jim_NewStringObj(interp, line, -1));
53 return JIM_OK;
56 static int JimRlAddHistoryCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
58 if (argc != 2) {
59 Jim_WrongNumArgs(interp, 1, argv, "string");
60 return JIM_ERR;
62 add_history(Jim_String(argv[1]));
63 return JIM_OK;
66 int Jim_readlineInit(Jim_Interp *interp)
68 if (Jim_PackageProvide(interp, "readline", "1.0", JIM_ERRMSG))
69 return JIM_ERR;
71 Jim_CreateCommand(interp, "readline.readline", JimRlReadlineCommand, NULL, NULL);
72 Jim_CreateCommand(interp, "readline.addhistory", JimRlAddHistoryCommand, NULL, NULL);
73 return JIM_OK;