6 #include "jimautoconf.h"
7 #include "jim-subcmd.h"
9 static int history_cmd_getline(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
12 char *line
= Jim_HistoryGetline(interp
, Jim_String(argv
[0]));
14 /* On EOF returns -1 if varName was specified; otherwise the empty string. */
17 Jim_SetResultInt(interp
, -1);
22 objPtr
= Jim_NewStringObjNoAlloc(interp
, line
, -1);
24 /* Returns the length of the string if varName was specified */
26 if (Jim_SetVariable(interp
, argv
[1], objPtr
) != JIM_OK
) {
27 Jim_FreeNewObj(interp
, objPtr
);
30 Jim_SetResultInt(interp
, Jim_Length(objPtr
));
33 Jim_SetResult(interp
, objPtr
);
38 static int history_cmd_setcompletion(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
40 Jim_HistorySetCompletion(interp
, Jim_Length(argv
[0]) ? argv
[0] : NULL
);
44 static int history_cmd_load(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
46 Jim_HistoryLoad(Jim_String(argv
[0]));
50 static int history_cmd_save(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
52 Jim_HistorySave(Jim_String(argv
[0]));
56 static int history_cmd_add(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
58 Jim_HistoryAdd(Jim_String(argv
[0]));
62 static int history_cmd_show(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
68 static const jim_subcmd_type history_command_table
[] = {
74 /* Description: Reads one line from the user. Similar to gets. */
78 history_cmd_setcompletion
,
81 /* Description: Sets an autocompletion callback command, or none if "" */
88 /* Description: Loads history from the given file, if possible */
95 /* Description: Saves history to the given file */
102 /* Description: Adds the line to the history ands saves */
109 /* Description: Displays the history */
114 int Jim_historyInit(Jim_Interp
*interp
)
116 if (Jim_PackageProvide(interp
, "history", "1.0", JIM_ERRMSG
))
119 Jim_CreateCommand(interp
, "history", Jim_SubCmdProc
, (void *)history_command_table
, NULL
);