Rizin
unix-like reverse engineering framework and cli tools
cmd_history.c File Reference
#include <rz_util/rz_path.h>
#include <rz_core.h>
#include <rz_cmd.h>
#include <rz_cons.h>

Go to the source code of this file.

Functions

RZ_IPI RzCmdStatus rz_history_list_or_exec_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_history_clear_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_history_save_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ rz_history_clear_handler()

RZ_IPI RzCmdStatus rz_history_clear_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 32 of file cmd_history.c.

32  {
34  return RZ_CMD_STATUS_OK;
35 }
RZ_API void rz_line_hist_free(void)
Definition: dietline.c:455
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24

References RZ_CMD_STATUS_OK, and rz_line_hist_free().

Referenced by rzshell_cmddescs_init().

◆ rz_history_list_or_exec_handler()

RZ_IPI RzCmdStatus rz_history_list_or_exec_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 10 of file cmd_history.c.

10  {
11  if (argc == 1) {
13  return RZ_CMD_STATUS_OK;
14  }
15 
16  int index = atoi(argv[1]);
17  if (index < 1) {
18  RZ_LOG_ERROR("index must be a positive number.\n");
19  return RZ_CMD_STATUS_ERROR;
20  }
21 
22  const char *cmd = rz_line_hist_get(index);
23  if (!cmd) {
24  RZ_LOG_ERROR("cannot find command with index %d.\n", index);
25  return RZ_CMD_STATUS_ERROR;
26  }
27 
28  int ret = rz_core_cmd0(core, cmd);
29  return !ret ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
30 }
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
RZ_API int rz_line_hist_list(void)
Definition: dietline.c:440
RZ_API const char * rz_line_hist_get(int n)
Definition: dietline.c:424
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58

References argv, cmd, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_cmd0(), rz_line_hist_get(), rz_line_hist_list(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_history_save_handler()

RZ_IPI RzCmdStatus rz_history_save_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 37 of file cmd_history.c.

37  {
38  char *history = rz_path_home_history();
39  rz_line_hist_save(history);
40  free(history);
41  return RZ_CMD_STATUS_OK;
42 }
RZ_API int rz_line_hist_save(RZ_NONNULL const char *path)
Save the history of commands executed until now to file path.
Definition: dietline.c:497
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN char * rz_path_home_history(void)
Return the path for the command history file.
Definition: path.c:212

References free(), RZ_CMD_STATUS_OK, rz_line_hist_save(), and rz_path_home_history().

Referenced by rzshell_cmddescs_init().