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(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_load(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
40 Jim_HistoryLoad(Jim_String(argv
[0]));
44 static int history_cmd_save(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
46 Jim_HistorySave(Jim_String(argv
[0]));
50 static int history_cmd_add(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
52 Jim_HistoryAdd(Jim_String(argv
[0]));
56 static int history_cmd_show(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
62 static const jim_subcmd_type history_command_table
[] = {
68 /* Description: Reads one line from the user. Similar to gets. */
75 /* Description: Loads history from the given file, if possible */
82 /* Description: Saves history to the given file */
89 /* Description: Adds the line to the history ands saves */
96 /* Description: Displays the history */
101 static int JimHistorySubCmdProc(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
103 return Jim_CallSubCmd(interp
, Jim_ParseSubCmd(interp
, history_command_table
, argc
, argv
), argc
, argv
);
106 static void JimHistoryDelProc(Jim_Interp
*interp
, void *privData
)
111 int Jim_historyInit(Jim_Interp
*interp
)
114 if (Jim_PackageProvide(interp
, "history", "1.0", JIM_ERRMSG
))
117 history
= Jim_Alloc(sizeof(*history
));
120 Jim_CreateCommand(interp
, "history", JimHistorySubCmdProc
, history
, JimHistoryDelProc
);