1
9
10
11
12
13
14
15
21
22
23
24
25
32
35
36
37
38
43
44
49
50
55
56
61
62
67
68
82
83
84
91
98
105
112
119
126
133
134
135
136
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "jim.h"
#include "jimautoconf.h"
#include "jim-subcmd.h"
6 includes
static int history_cmd_getline(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
char *line = Jim_HistoryGetline(interp, Jim_String(argv[0]));
if (line == NULL) {
if (argc == 2) {
Jim_SetResultInt(interp, -1);
}if (argc == 2) { ... }
return JIM_OK;
}if (line == NULL) { ... }
objPtr = Jim_NewStringObjNoAlloc(interp, line, -1);
if (argc == 2) {
if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) {
Jim_FreeNewObj(interp, objPtr);
return JIM_ERR;
}if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) { ... }
Jim_SetResultInt(interp, Jim_Length(objPtr));
}if (argc == 2) { ... }
else {
Jim_SetResult(interp, objPtr);
}else { ... }
return JIM_OK;
}{ ... }
static int history_cmd_setcompletion(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_HistorySetCompletion(interp, Jim_Length(argv[0]) ? argv[0] : NULL);
return JIM_OK;
}{ ... }
static int history_cmd_load(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_HistoryLoad(Jim_String(argv[0]));
return JIM_OK;
}{ ... }
static int history_cmd_save(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_HistorySave(Jim_String(argv[0]));
return JIM_OK;
}{ ... }
static int history_cmd_add(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_HistoryAdd(Jim_String(argv[0]));
return JIM_OK;
}{ ... }
static int history_cmd_show(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_HistoryShow();
return JIM_OK;
}{ ... }
static int history_cmd_keep(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long len;
if (argc == 1) {
if (Jim_GetLong(interp, argv[0], &len) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetLong(interp, argv[0], &len) != JIM_OK) { ... }
Jim_HistorySetMaxLen(len);
}if (argc == 1) { ... }
else {
Jim_SetResultInt(interp, Jim_HistoryGetMaxLen());
}else { ... }
return JIM_OK;
}{ ... }
static const jim_subcmd_type history_command_table[] = {
{ "add",
"line",
history_cmd_add,
1,
1,
...},
{ "completion",
"command",
history_cmd_setcompletion,
1,
1,
...},
{ "getline",
"prompt ?varname?",
history_cmd_getline,
1,
2,
...},
{ "keep",
"?count?",
history_cmd_keep,
0,
1,
...},
{ "load",
"filename",
history_cmd_load,
1,
1,
...},
{ "save",
"filename",
history_cmd_save,
1,
1,
...},
{ "show",
NULL,
history_cmd_show,
0,
0,
...},
{ NULL }
...};
int Jim_historyInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "history");
Jim_CreateCommand(interp, "history", Jim_SubCmdProc, (void *)history_command_table, NULL);
return JIM_OK;
}{ ... }