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

Go to the source code of this file.

Classes

struct  argv_modes_t
 

Macros

#define MAX_CHILDREN_SHOW   7
 
#define MIN_SUMMARY_WIDTH   6
 
#define MAX_RIGHT_ALIGHNMENT   20
 
#define NCMDS   (sizeof(cmd->cmds) / sizeof(*cmd->cmds))
 
#define CASE_TYPE(x, y)
 
#define CASE_CDTYPE(x, y)
 

Functions

RZ_IPI int rz_output_mode_to_char (RzOutputMode mode)
 
RZ_IPI const char * rz_output_mode_to_summary (RzOutputMode mode)
 
 RZ_LIB_VERSION (rz_cmd)
 
static void fill_details (RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
 
static int cd_sort (const void *a, const void *b)
 
static bool cmd_desc_set_parent (RzCmd *cmd, RzCmdDesc *cd, RzCmdDesc *parent)
 
static void cmd_desc_unset_parent (RzCmdDesc *cd)
 
static void cmd_desc_remove_from_ht_cmds (RzCmd *cmd, RzCmdDesc *cd)
 
static void cmd_desc_free (RzCmdDesc *cd)
 
static RzCmdDesccreate_cmd_desc (RzCmd *cmd, RzCmdDesc *parent, RzCmdDescType type, const char *name, const RzCmdDescHelp *help, bool ht_insert)
 
RZ_API void rz_cmd_alias_init (RzCmd *cmd)
 
RZ_API RzCmdrz_cmd_new (bool has_cons)
 
RZ_API RzCmdrz_cmd_free (RzCmd *cmd)
 
RZ_API RzCmdDescrz_cmd_get_root (RzCmd *cmd)
 Get the root command descriptor. More...
 
RZ_API void rz_cmd_batch_start (RzCmd *cmd)
 Mark the start of the batched changes to RzCmd. More...
 
static void sort_groups (RzCmdDesc *group)
 
RZ_API void rz_cmd_batch_end (RzCmd *cmd)
 Mark the end of the batched changes to RzCmd. More...
 
static RzOutputMode suffix2mode (const char *suffix)
 
static bool has_cd_submodes (const RzCmdDesc *cd)
 
static bool is_valid_argv_modes (RzCmdDesc *cd, char last_letter)
 
RZ_API RzCmdDescrz_cmd_desc_get_exec (RzCmdDesc *cd)
 
static RzCmdDesccmd_get_desc_best (RzCmd *cmd, const char *cmd_identifier, bool best_match)
 
RZ_API RzCmdDescrz_cmd_get_desc_best (RzCmd *cmd, const char *cmd_identifier)
 Retrieve the command descriptor that best matches the name cmd_identifier. More...
 
RZ_API RzCmdDescrz_cmd_get_desc (RzCmd *cmd, const char *cmd_identifier)
 Retrieve the command descriptor for the command named cmd_identifier. More...
 
RZ_API bool rz_cmd_desc_set_default_mode (RzCmdDesc *cd, RzOutputMode mode)
 Set the default mode of the command descriptor, if the type allows it. More...
 
RZ_API char ** rz_cmd_alias_keys (RzCmd *cmd, int *sz)
 
RZ_API void rz_cmd_alias_free (RzCmd *cmd)
 
RZ_API bool rz_cmd_alias_del (RzCmd *cmd, const char *k)
 
RZ_API int rz_cmd_alias_set (RzCmd *cmd, const char *k, const char *v, int remote)
 
RZ_API char * rz_cmd_alias_get (RzCmd *cmd, const char *k, int remote)
 
RZ_API int rz_cmd_set_data (RzCmd *cmd, void *data)
 
RZ_API int rz_cmd_add (RzCmd *c, const char *cmd, RzCmdCb cb)
 
RZ_API int rz_cmd_del (RzCmd *cmd, const char *command)
 
RZ_API int rz_cmd_call (RzCmd *cmd, const char *input)
 
static RzCmdStatus int2cmdstatus (int v)
 
static void get_minmax_argc (RzCmdDesc *cd, int *min_argc, int *max_argc)
 
static RzOutputMode get_cd_default_mode (RzCmdDesc *cd)
 
static bool has_cd_default_mode (RzCmdDesc *cd)
 
static RzOutputMode cd_suffix2mode (RzCmdDesc *cd, const char *cmdid)
 
static void args_preprocessing (RzCmdDesc *cd, RzCmdParsedArgs *args)
 
static RzCmdStatus argv_call_cb (RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
 
static RzCmdStatus call_cd (RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
 
RZ_API RzCmdStatus rz_cmd_call_parsed_args (RzCmd *cmd, RzCmdParsedArgs *args)
 
static size_t strlen0 (const char *s)
 
static size_t strbuf_append_calc (RzStrBuf *sb, const char *s)
 
static void fill_modes_children_chars (RzStrBuf *sb, const RzCmdDesc *cd)
 
static size_t fill_children_chars (RzStrBuf *sb, const RzCmdDesc *cd)
 
static bool show_children_shortcut (const RzCmdDesc *cd)
 
static void fill_colored_args (RzCmd *cmd, RzStrBuf *sb, const char *line, bool use_color, const char *reset_color)
 
static void fill_wrapped_comment (RzCmd *cmd, RzStrBuf *sb, const char *comment, size_t columns, bool use_color)
 
static void close_optionals (size_t *n_optionals, RzStrBuf *sb, size_t *len)
 
static size_t fill_args (RzStrBuf *sb, const RzCmdDesc *cd)
 
static void fill_usage_strbuf (RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
 
static size_t calc_padding_len (const RzCmdDesc *cd, const char *name, bool show_children)
 
static void update_minmax_len (RzCmdDesc *cd, size_t *max_len, size_t *min_len, bool show_children)
 
static void do_print_child_help (RzCmd *cmd, RzStrBuf *sb, const RzCmdDesc *cd, const char *name, const char *summary, bool show_children, size_t max_len, bool use_color)
 
static void print_child_help (RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, size_t max_len, bool use_color)
 
static char * group_get_help (RzCmd *cmd, RzCmdDesc *cd, bool use_color)
 
static void fill_argv_modes_help_strbuf (RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
 
static const RzCmdDescDetailget_cd_details (RzCmdDesc *cd)
 
static RzCmdDescDetailget_cd_details_cb (RzCmd *cmd, RzCmdDesc *cd)
 
static void fill_details_do (RzCmd *cmd, const RzCmdDescDetail *detail_it, RzStrBuf *sb, bool use_color)
 
static void fill_details_static (RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
 
static void fill_details_cb (RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
 
static char * argv_get_help (RzCmd *cmd, RzCmdDesc *cd, size_t detail, bool use_color)
 
static char * fake_get_help (RzCmd *cmd, RzCmdDesc *cd, bool use_color)
 
static char * oldinput_get_help (RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *a)
 
static char * get_help (RzCmd *cmd, RzCmdDesc *cd, const char *cmdid, RzCmdParsedArgs *args, bool use_color, size_t detail)
 
static void fill_args_json (const RzCmd *cmd, const RzCmdDesc *cd, PJ *j)
 
RZ_API bool rz_cmd_get_help_json (RzCmd *cmd, const RzCmdDesc *cd, PJ *j)
 Generates a JSON output of the given help message description. More...
 
RZ_API bool rz_cmd_get_help_strbuf (RzCmd *cmd, const RzCmdDesc *cd, bool use_color, RzStrBuf *sb)
 Generates a text output of the given help message description (summary format) More...
 
RZ_API char * rz_cmd_get_help (RzCmd *cmd, RzCmdParsedArgs *args, bool use_color)
 
RZ_API RzCmdMacroItemrz_cmd_macro_item_new (void)
 
RZ_API void rz_cmd_macro_item_free (RzCmdMacroItem *item)
 
RZ_API void rz_cmd_macro_init (RzCmdMacro *mac)
 
RZ_API void rz_cmd_macro_fini (RzCmdMacro *mac)
 
RZ_API int rz_cmd_macro_add (RzCmdMacro *mac, const char *oname)
 
RZ_API int rz_cmd_macro_rm (RzCmdMacro *mac, const char *_name)
 
RZ_API void rz_cmd_macro_list (RzCmdMacro *mac)
 
RZ_API void rz_cmd_macro_meta (RzCmdMacro *mac)
 
RZ_API int rz_cmd_macro_cmd_args (RzCmdMacro *mac, const char *ptr, const char *args, int nargs)
 
RZ_API char * rz_cmd_macro_label_process (RzCmdMacro *mac, RzCmdMacroLabel *labels, int *labels_n, char *ptr)
 
static int macro_call (RzCmdMacro *mac, const char *name, bool multiple)
 
RZ_API int rz_cmd_macro_call (RzCmdMacro *mac, const char *name)
 
RZ_API int rz_cmd_macro_call_multiple (RzCmdMacro *mac, const char *name)
 
RZ_API int rz_cmd_macro_break (RzCmdMacro *mac, const char *value)
 
RZ_API RzCmdParsedArgsrz_cmd_parsed_args_new (const char *cmd, int n_args, char **args)
 
RZ_API RzCmdParsedArgsrz_cmd_parsed_args_newcmd (const char *cmd)
 
RZ_API RzCmdParsedArgsrz_cmd_parsed_args_newargs (int n_args, char **args)
 
RZ_API void rz_cmd_parsed_args_free (RzCmdParsedArgs *a)
 
static void free_array (char **arr, int n)
 
RZ_API bool rz_cmd_parsed_args_setargs (RzCmdParsedArgs *a, int n_args, char **args)
 
RZ_API bool rz_cmd_parsed_args_addarg (RzCmdParsedArgs *a, const char *arg)
 
RZ_API bool rz_cmd_parsed_args_setcmd (RzCmdParsedArgs *a, const char *cmd)
 
static void parsed_args_iterateargs (RzCmdParsedArgs *a, RzStrBuf *sb)
 
RZ_API char * rz_cmd_parsed_args_argstr (RzCmdParsedArgs *a)
 
RZ_API char * rz_cmd_parsed_args_execstr (RzCmdParsedArgs *a)
 
RZ_API const char * rz_cmd_parsed_args_cmd (RzCmdParsedArgs *a)
 
static RzCmdDescargv_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, bool ht_insert)
 
RZ_API RzCmdDescrz_cmd_desc_argv_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help)
 
static RzCmdDescargv_modes_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help, bool ht_insert)
 
static RzCmdDescargv_state_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help, bool ht_insert)
 
RZ_API RzCmdDescrz_cmd_desc_argv_modes_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help)
 Create a new command descriptor for a command that supports multiple output modes (e.g. rizin commands, json, csv, etc.). More...
 
RZ_API RzCmdDescrz_cmd_desc_argv_state_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help)
 Create a new command descriptor for a command that supports multiple output modes (e.g. rizin commands, json, csv, etc.), where the state of the output is handled by RzCmd itself. More...
 
RZ_API RzCmdDescrz_cmd_desc_inner_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help)
 
RZ_API RzCmdDescrz_cmd_desc_group_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
 Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well. More...
 
RZ_API RzCmdDescrz_cmd_desc_group_modes_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
 Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well. The sub-command supports multiple output modes (e.g. rizin commands, json, csv, etc.). More...
 
RZ_API RzCmdDescrz_cmd_desc_group_state_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
 Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well. The sub-command supports multiple output modes (e.g. rizin commands, json, csv, etc.), where the state of the output is handled by RzCmd itself. More...
 
RZ_API RzCmdDescrz_cmd_desc_oldinput_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdCb cb, const RzCmdDescHelp *help)
 
RZ_API RzCmdDescrz_cmd_desc_fake_new (RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help)
 
RZ_API RzCmdDescrz_cmd_desc_parent (RzCmdDesc *cd)
 
RZ_API bool rz_cmd_desc_has_handler (const RzCmdDesc *cd)
 
RZ_API bool rz_cmd_desc_remove (RzCmd *cmd, RzCmdDesc *cd)
 
RZ_API const RzCmdDescArgrz_cmd_desc_get_arg (RzCmd *cmd, const RzCmdDesc *cd, size_t i)
 Get a reference to the i-th argument of a command descriptor. More...
 
static RzCmdDescHelpmode_cmd_desc_help (RzCmdDescHelp *dst, const RzCmdDescHelp *src, const char *suffix)
 
static void cmd_foreach_cmdname_modes (RzCmd *cmd, RzCmdDesc *cd, int modes, RzCmdForeachNameCb cb, void *user)
 
static void cmd_foreach_cmdname (RzCmd *cmd, RzCmdDesc *cd, RzCmdForeachNameCb cb, void *user)
 
RZ_API void rz_cmd_foreach_cmdname (RzCmd *cmd, RzCmdDesc *begin, RzCmdForeachNameCb cb, void *user)
 Execute a callback function on each possible command the user can execute. More...
 
static char * escape_special_chars (const char *s, const char *special_chars)
 
static char * unescape_special_chars (const char *s, const char *special_chars)
 
RZ_API char * rz_cmd_escape_arg (const char *arg, RzCmdEscape esc)
 
RZ_API char * rz_cmd_unescape_arg (const char *arg, RzCmdEscape esc)
 
RZ_API void rz_cmd_state_output_array_start (RzCmdStateOutput *state)
 Mark the start of an array of elements in the output. More...
 
RZ_API void rz_cmd_state_output_array_end (RzCmdStateOutput *state)
 Mark the end of an array of elements in the output. More...
 
RZ_API void rz_cmd_state_output_set_columnsf (RzCmdStateOutput *state, const char *fmt,...)
 Specify the columns of the command output. More...
 
RZ_API void rz_cmd_state_output_fini (RZ_NONNULL RzCmdStateOutput *state)
 Clear the inner fields of RzCmdStateOutput structure, but do not free it. More...
 
RZ_API void rz_cmd_state_output_free (RZ_NONNULL RzCmdStateOutput *state)
 Free the RzCmdStateOutput structure and its inner fields appropriately. More...
 
RZ_API bool rz_cmd_state_output_init (RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
 Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode. More...
 
RZ_API void rz_cmd_state_output_print (RZ_NONNULL RzCmdStateOutput *state)
 Print the output accumulated in state to RzCons, if necessary. More...
 
RZ_API void rz_cmd_desc_details_free (RzCmdDescDetail *details)
 Free an array of RzCmdDescDetail sections. More...
 

Variables

static const char * SPECIAL_CHARS_REGULAR = "@;~$#|`\"'()<>"
 
static const char * SPECIAL_CHARS_REGULAR_SINGLE = "@;~$#|`\"'()<> "
 
static const char * SPECIAL_CHARS_PF = "@;~$#|`\"'<>"
 
static const char * SPECIAL_CHARS_DOUBLE_QUOTED = "\"$()`"
 
static const char * SPECIAL_CHARS_SINGLE_QUOTED = "'"
 
static const RzCmdDescHelp not_defined_help
 
static const RzCmdDescHelp root_help
 
static const struct argv_modes_t argv_modes []
 
static int value = 0
 

Macro Definition Documentation

◆ CASE_CDTYPE

#define CASE_CDTYPE (   x,
 
)
Value:
case (x): \
type = (y); \
break
int x
Definition: mipsasm.c:20

◆ CASE_TYPE

#define CASE_TYPE (   x,
 
)
Value:
case (x): \
argtype = (y); \
break

◆ MAX_CHILDREN_SHOW

#define MAX_CHILDREN_SHOW   7

Number of sub-commands to show as options when displaying the help of a command. When a command has more options than MAX_CHILDREN_SHOW, ? is shown instead.

Example with MAX_CHILDREN_SHOW=3: w -> wa -> wb -> wc

When doing ?, you would see: w[abc]

If there is also: -> wd you would see: w[?]

Definition at line 30 of file cmd_api.c.

◆ MAX_RIGHT_ALIGHNMENT

#define MAX_RIGHT_ALIGHNMENT   20

Definition at line 33 of file cmd_api.c.

◆ MIN_SUMMARY_WIDTH

#define MIN_SUMMARY_WIDTH   6

Definition at line 32 of file cmd_api.c.

◆ NCMDS

#define NCMDS   (sizeof(cmd->cmds) / sizeof(*cmd->cmds))

Definition at line 95 of file cmd_api.c.

Function Documentation

◆ args_preprocessing()

static void args_preprocessing ( RzCmdDesc cd,
RzCmdParsedArgs args 
)
static

Performs a preprocessing step on the user arguments.

This is used to group together some arguments that are returned by the parser as multiple arguments but we want to let the command handler see them as a single one to make life easier for users.

It can also provide default arguments as specified by the command descriptor.

For example: cmdid pd 10 would be considered as having 2 arguments, "pd" and "10". However, if <cmdid> was defined to have as argument RZ_CMD_ARG_FLAG_LAST, we want to group "pd" and "10" in one single argument "pd 10" and pass that to <cmdid> handler.

Definition at line 667 of file cmd_api.c.

667  {
668  const RzCmdDescArg *arg;
669  size_t i, j;
670  for (arg = cd->help->args, i = 1; arg && arg->name && i < args->argc - 1; arg++, i++) {
671  char *tmp;
672  if (arg->flags & RZ_CMD_ARG_FLAG_LAST) {
673  if (arg->type == RZ_CMD_ARG_TYPE_CMD) {
674  for (j = i; j < args->argc; j++) {
675  char *s = rz_cmd_escape_arg(args->argv[j], RZ_CMD_ESCAPE_ONE_ARG);
676  if (strcmp(s, args->argv[j])) {
677  free(args->argv[j]);
678  args->argv[j] = s;
679  } else {
680  free(s);
681  }
682  }
683  }
684 
685  tmp = rz_str_array_join((const char **)&args->argv[i], args->argc - i, " ");
686  if (!tmp) {
687  return;
688  }
689  for (j = i; j < args->argc; j++) {
690  free(args->argv[j]);
691  }
692  args->argv[i] = tmp;
693  args->argc = i + 1;
694  return;
695  }
696  }
697  for (; arg && arg->name; arg++, i++) {
698  if (arg->default_value && i >= args->argc) {
699  rz_cmd_parsed_args_addarg(args, arg->default_value);
700  }
701  }
702 }
lzma_index ** i
Definition: index.h:629
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
static csh cd
Definition: asm_mips_cs.c:10
RZ_API char * rz_cmd_escape_arg(const char *arg, RzCmdEscape esc)
Definition: cmd_api.c:2516
RZ_API bool rz_cmd_parsed_args_addarg(RzCmdParsedArgs *a, const char *arg)
Definition: cmd_api.c:2081
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int args
Definition: mipsasm.c:18
static RzSocket * s
Definition: rtr.c:28
@ RZ_CMD_ESCAPE_ONE_ARG
The string should be escaped so that it appears as one single argument.
Definition: rz_cmd.h:79
#define RZ_CMD_ARG_FLAG_LAST
Definition: rz_cmd.h:67
@ RZ_CMD_ARG_TYPE_CMD
Argument is an rizin command.
Definition: rz_cmd.h:46
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861
const char * name
Definition: sparc-opc.c:1838

References arg(), args, cd, free(), i, arg::name, RZ_CMD_ARG_FLAG_LAST, RZ_CMD_ARG_TYPE_CMD, rz_cmd_escape_arg(), RZ_CMD_ESCAPE_ONE_ARG, rz_cmd_parsed_args_addarg(), rz_str_array_join(), s, and autogen_x86imm::tmp.

Referenced by argv_call_cb().

◆ argv_call_cb()

static RzCmdStatus argv_call_cb ( RzCmd cmd,
RzCmdDesc cd,
RzCmdParsedArgs args 
)
static

Definition at line 704 of file cmd_api.c.

704  {
705  if (!rz_cmd_desc_has_handler(cd)) {
707  }
708 
710 
711  int i;
712  const char *s;
713  rz_cmd_parsed_args_foreach_arg(args, i, s) {
714  RZ_LOG_DEBUG("processed parsed_arg %d: '%s'\n", i, s);
715  }
716 
718  switch (cd->type) {
720  if (args->argc < cd->d.argv_data.min_argc || args->argc > cd->d.argv_data.max_argc) {
722  }
723  return cd->d.argv_data.cb(cmd->data, args->argc, (const char **)args->argv);
726  if (!mode) {
728  }
729  if (args->argc < cd->d.argv_modes_data.min_argc || args->argc > cd->d.argv_modes_data.max_argc) {
731  }
732  return cd->d.argv_modes_data.cb(cmd->data, args->argc, (const char **)args->argv, mode);
735  if (!mode) {
737  }
738  if (args->argc < cd->d.argv_state_data.min_argc || args->argc > cd->d.argv_state_data.max_argc) {
740  }
743  return RZ_CMD_STATUS_INVALID;
744  }
745  RzCmdStatus res = cd->d.argv_state_data.cb(cmd->data, args->argc, (const char **)args->argv, &state);
746  if (args->extra && state.mode == RZ_OUTPUT_MODE_TABLE) {
747  bool res = rz_table_query(state.d.t, args->extra);
748  if (!res) {
750  return RZ_CMD_STATUS_INVALID;
751  }
752  }
753  if (res == RZ_CMD_STATUS_OK) {
755  }
757  return res;
758  default:
759  return RZ_CMD_STATUS_INVALID;
760  }
761 }
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
Definition: cmd_api.c:2634
RZ_API const char * rz_cmd_parsed_args_cmd(RzCmdParsedArgs *a)
Definition: cmd_api.c:2135
RZ_API bool rz_cmd_desc_has_handler(const RzCmdDesc *cd)
Definition: cmd_api.c:2336
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
Definition: cmd_api.c:2603
static void args_preprocessing(RzCmdDesc *cd, RzCmdParsedArgs *args)
Definition: cmd_api.c:667
static RzOutputMode cd_suffix2mode(RzCmdDesc *cd, const char *cmdid)
Definition: cmd_api.c:640
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
Definition: cmd_api.c:2668
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
const char int mode
Definition: ioapi.h:137
@ RZ_CMD_DESC_TYPE_ARGV_STATE
Definition: rz_cmd.h:403
@ RZ_CMD_DESC_TYPE_ARGV
Definition: rz_cmd.h:361
@ RZ_CMD_DESC_TYPE_ARGV_MODES
Definition: rz_cmd.h:391
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
@ RZ_CMD_STATUS_INVALID
command could not be executed (e.g. shell level error, bad expression, etc.)
Definition: rz_cmd.h:27
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
RZ_API bool rz_table_query(RzTable *t, const char *q)
Definition: table.c:1050
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
Represent the output state of a command handler.
Definition: rz_cmd.h:91
Definition: dis.h:43

References args, args_preprocessing(), cd, cd_suffix2mode(), cmd, i, rz_cmd_desc_has_handler(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, rz_cmd_parsed_args_cmd(), rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), RZ_CMD_STATUS_INVALID, RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, RZ_LOG_DEBUG, RZ_OUTPUT_MODE_TABLE, rz_table_query(), and s.

Referenced by call_cd().

◆ argv_get_help()

static char* argv_get_help ( RzCmd cmd,
RzCmdDesc cd,
size_t  detail,
bool  use_color 
)
static

Definition at line 1266 of file cmd_api.c.

1266  {
1268  const char *pal_reset = "";
1269  if (cmd->has_cons && use_color) {
1270  RzCons *cons = rz_cons_singleton();
1271  pal_reset = cons->context->pal.reset;
1272  }
1273 
1274  fill_usage_strbuf(cmd, sb, cd, use_color);
1275 
1276  if (cd->type == RZ_CMD_DESC_TYPE_ARGV_MODES || cd->type == RZ_CMD_DESC_TYPE_ARGV_STATE) {
1277  fill_argv_modes_help_strbuf(cmd, sb, cd, use_color);
1278  }
1279 
1280  switch (detail) {
1281  case 1:
1282  case 2:
1283  if (cd->help->description) {
1284  rz_strbuf_append(sb, "\n");
1285  fill_colored_args(cmd, sb, cd->help->description, use_color, pal_reset);
1286  rz_strbuf_append(sb, "\n");
1287  }
1288  fill_details(cmd, cd, sb, use_color);
1289  break;
1290  default:
1291  rz_strbuf_free(sb);
1292  return NULL;
1293  }
1294  return rz_strbuf_drain(sb);
1295 }
static SblHeader sb
Definition: bin_mbn.c:26
static void fill_argv_modes_help_strbuf(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
Definition: cmd_api.c:1148
static void fill_details(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
Definition: cmd_api.c:1261
static void fill_usage_strbuf(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
Definition: cmd_api.c:997
static void fill_colored_args(RzCmd *cmd, RzStrBuf *sb, const char *line, bool use_color, const char *reset_color)
Definition: cmd_api.c:882
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502

References cd, cmd, rz_cons_t::context, fill_argv_modes_help_strbuf(), fill_colored_args(), fill_details(), fill_usage_strbuf(), NULL, rz_cons_context_t::pal, rz_cons_printable_palette_t::reset, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, rz_cons_singleton(), rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), and sb.

Referenced by fake_get_help(), and get_help().

◆ argv_modes_new()

static RzCmdDesc* argv_modes_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvModesCb  cb,
const RzCmdDescHelp help,
bool  ht_insert 
)
static

Definition at line 2158 of file cmd_api.c.

2158  {
2159  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_ARGV_MODES, name, help, ht_insert);
2160  if (!res) {
2161  return NULL;
2162  }
2163 
2164  res->d.argv_modes_data.cb = cb;
2165  res->d.argv_modes_data.modes = modes;
2166  res->d.argv_modes_data.default_mode = RZ_OUTPUT_MODE_STANDARD;
2167  get_minmax_argc(res, &res->d.argv_modes_data.min_argc, &res->d.argv_modes_data.max_argc);
2168  return res;
2169 }
static RzCmdDesc * create_cmd_desc(RzCmd *cmd, RzCmdDesc *parent, RzCmdDescType type, const char *name, const RzCmdDescHelp *help, bool ht_insert)
Definition: cmd_api.c:161
static void get_minmax_argc(RzCmdDesc *cd, int *min_argc, int *max_argc)
Definition: cmd_api.c:592
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
Definition: z80asm.h:102
union rz_cmd_desc_t::@262 d
struct rz_cmd_desc_t::@262::@266 argv_modes_data
static const char * cb[]
Definition: z80_tab.h:176

References rz_cmd_desc_t::argv_modes_data, cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, get_minmax_argc(), cmd_descs_generate::help, NULL, RZ_CMD_DESC_TYPE_ARGV_MODES, and RZ_OUTPUT_MODE_STANDARD.

Referenced by rz_cmd_desc_argv_modes_new(), and rz_cmd_desc_group_modes_new().

◆ argv_new()

static RzCmdDesc* argv_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
RzCmdArgvCb  cb,
const RzCmdDescHelp help,
bool  ht_insert 
)
static

Definition at line 2142 of file cmd_api.c.

2142  {
2143  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_ARGV, name, help, ht_insert);
2144  if (!res) {
2145  return NULL;
2146  }
2147 
2148  res->d.argv_data.cb = cb;
2149  get_minmax_argc(res, &res->d.argv_data.min_argc, &res->d.argv_data.max_argc);
2150  return res;
2151 }
struct rz_cmd_desc_t::@262::@264 argv_data

References rz_cmd_desc_t::argv_data, cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, get_minmax_argc(), cmd_descs_generate::help, NULL, and RZ_CMD_DESC_TYPE_ARGV.

Referenced by rz_cmd_desc_argv_new(), and rz_cmd_desc_group_new().

◆ argv_state_new()

static RzCmdDesc* argv_state_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvStateCb  cb,
const RzCmdDescHelp help,
bool  ht_insert 
)
static

Definition at line 2171 of file cmd_api.c.

2171  {
2172  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_ARGV_STATE, name, help, ht_insert);
2173  if (!res) {
2174  return NULL;
2175  }
2176 
2177  res->d.argv_state_data.cb = cb;
2178  res->d.argv_state_data.modes = modes;
2179  res->d.argv_state_data.default_mode = RZ_OUTPUT_MODE_STANDARD;
2180  get_minmax_argc(res, &res->d.argv_state_data.min_argc, &res->d.argv_state_data.max_argc);
2181  return res;
2182 }
struct rz_cmd_desc_t::@262::@267 argv_state_data

References rz_cmd_desc_t::argv_state_data, cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, get_minmax_argc(), cmd_descs_generate::help, NULL, RZ_CMD_DESC_TYPE_ARGV_STATE, and RZ_OUTPUT_MODE_STANDARD.

Referenced by rz_cmd_desc_argv_state_new(), and rz_cmd_desc_group_state_new().

◆ calc_padding_len()

static size_t calc_padding_len ( const RzCmdDesc cd,
const char *  name,
bool  show_children 
)
static

Definition at line 1051 of file cmd_api.c.

1051  {
1052  size_t name_len = strlen(name);
1053  size_t args_len = 0;
1054  size_t children_length = 0;
1055  if (show_children && show_children_shortcut(cd)) {
1056  RzStrBuf sb;
1057  rz_strbuf_init(&sb);
1059  children_length += rz_strbuf_length(&sb);
1060  rz_strbuf_fini(&sb);
1061  }
1062  if (cd->help->args_str) {
1063  args_len = strlen0(cd->help->args_str);
1064  } else {
1065  RzStrBuf sb;
1066  rz_strbuf_init(&sb);
1067  fill_args(&sb, cd);
1068  args_len = rz_strbuf_length(&sb);
1069  rz_strbuf_fini(&sb);
1070  }
1071  return name_len + args_len + children_length;
1072 }
static bool show_children_shortcut(const RzCmdDesc *cd)
Definition: cmd_api.c:877
static size_t strlen0(const char *s)
Definition: cmd_api.c:803
static size_t fill_children_chars(RzStrBuf *sb, const RzCmdDesc *cd)
Definition: cmd_api.c:823
static size_t fill_args(RzStrBuf *sb, const RzCmdDesc *cd)
Definition: cmd_api.c:946
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28

References cd, fill_args(), fill_children_chars(), rz_strbuf_fini(), rz_strbuf_init(), rz_strbuf_length(), sb, show_children_shortcut(), and strlen0().

Referenced by do_print_child_help(), and update_minmax_len().

◆ call_cd()

static RzCmdStatus call_cd ( RzCmd cmd,
RzCmdDesc cd,
RzCmdParsedArgs args 
)
static

Definition at line 763 of file cmd_api.c.

763  {
764  char *exec_string;
766 
767  int i;
768  const char *s;
769  rz_cmd_parsed_args_foreach_arg(args, i, s) {
770  RZ_LOG_DEBUG("parsed_arg %d: '%s'\n", i, s);
771  }
772 
773  switch (cd->type) {
775  if (!cd->d.group_data.exec_cd) {
777  }
778  return call_cd(cmd, cd->d.group_data.exec_cd, args);
782  return argv_call_cb(cmd, cd, args);
784  exec_string = rz_cmd_parsed_args_execstr(args);
785  res = int2cmdstatus(cd->d.oldinput_data.cb(cmd->data, exec_string + strlen(cd->name)));
786  RZ_FREE(exec_string);
787  return res;
788  default:
789  RZ_LOG_ERROR("RzCmdDesc type not handled\n");
790  return RZ_CMD_STATUS_INVALID;
791  }
792 }
RZ_API char * rz_cmd_parsed_args_execstr(RzCmdParsedArgs *a)
Definition: cmd_api.c:2122
static RzCmdStatus call_cd(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
Definition: cmd_api.c:763
static RzCmdStatus int2cmdstatus(int v)
Definition: cmd_api.c:582
static RzCmdStatus argv_call_cb(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
Definition: cmd_api.c:704
@ RZ_CMD_DESC_TYPE_GROUP
Definition: rz_cmd.h:368
@ RZ_CMD_DESC_TYPE_OLDINPUT
Definition: rz_cmd.h:355
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_FREE(x)
Definition: rz_types.h:369

References args, argv_call_cb(), cd, cmd, i, int2cmdstatus(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_OLDINPUT, rz_cmd_parsed_args_execstr(), RZ_CMD_STATUS_INVALID, RZ_CMD_STATUS_NONEXISTINGCMD, RZ_FREE, RZ_LOG_DEBUG, RZ_LOG_ERROR, and s.

Referenced by rz_cmd_call_parsed_args().

◆ cd_sort()

static int cd_sort ( const void *  a,
const void *  b 
)
static

Definition at line 100 of file cmd_api.c.

100  {
101  RzCmdDesc *ca = (RzCmdDesc *)a;
102  RzCmdDesc *cb = (RzCmdDesc *)b;
103  return rz_str_casecmp(ca->name, cb->name);
104 }
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
Definition: str.c:121
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
char * name
Definition: rz_cmd.h:425

References a, b, cb, rz_cmd_desc_t::name, and rz_str_casecmp().

Referenced by cmd_desc_set_parent(), and sort_groups().

◆ cd_suffix2mode()

static RzOutputMode cd_suffix2mode ( RzCmdDesc cd,
const char *  cmdid 
)
static

Definition at line 640 of file cmd_api.c.

640  {
641  if (!has_cd_submodes(cd)) {
642  return 0;
643  }
644  RzOutputMode mode = suffix2mode(cmdid + strlen(cd->name));
647  }
648  return mode;
649 }
static bool has_cd_submodes(const RzCmdDesc *cd)
Definition: cmd_api.c:279
static bool has_cd_default_mode(RzCmdDesc *cd)
Definition: cmd_api.c:636
static RzOutputMode get_cd_default_mode(RzCmdDesc *cd)
Definition: cmd_api.c:625
static RzOutputMode suffix2mode(const char *suffix)
Definition: cmd_api.c:269

References cd, get_cd_default_mode(), has_cd_default_mode(), has_cd_submodes(), RZ_OUTPUT_MODE_STANDARD, and suffix2mode().

Referenced by argv_call_cb().

◆ close_optionals()

static void close_optionals ( size_t n_optionals,
RzStrBuf sb,
size_t len 
)
static

Definition at line 939 of file cmd_api.c.

939  {
940  for (; *n_optionals > 0; (*n_optionals)--) {
941  rz_strbuf_append(sb, "]");
942  (*len)++;
943  }
944 }

References rz_strbuf_append(), and sb.

Referenced by fill_args().

◆ cmd_desc_free()

static void cmd_desc_free ( RzCmdDesc cd)
static

Definition at line 151 of file cmd_api.c.

151  {
152  if (!cd) {
153  return;
154  }
155 
156  rz_pvector_clear(&cd->children);
157  free(cd->name);
158  free(cd);
159 }
RZ_API void rz_pvector_clear(RzPVector *vec)
Definition: vector.c:326

References cd, free(), and rz_pvector_clear().

Referenced by create_cmd_desc(), rz_cmd_desc_remove(), and rz_cmd_free().

◆ cmd_desc_remove_from_ht_cmds()

static void cmd_desc_remove_from_ht_cmds ( RzCmd cmd,
RzCmdDesc cd 
)
static

Definition at line 141 of file cmd_api.c.

141  {
142  void **it_cd;
143  bool res = ht_pp_delete(cmd->ht_cmds, cd->name);
144  rz_return_if_fail(res);
145  rz_cmd_desc_children_foreach(cd, it_cd) {
146  RzCmdDesc *child_cd = *it_cd;
148  }
149 }
static void cmd_desc_remove_from_ht_cmds(RzCmd *cmd, RzCmdDesc *cd)
Definition: cmd_api.c:141
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References cd, cmd, and rz_return_if_fail.

Referenced by rz_cmd_desc_remove().

◆ cmd_desc_set_parent()

static bool cmd_desc_set_parent ( RzCmd cmd,
RzCmdDesc cd,
RzCmdDesc parent 
)
static

Definition at line 106 of file cmd_api.c.

106  {
107  rz_return_val_if_fail(cd && !cd->parent, false);
108  if (parent) {
109  switch (parent->type) {
113  break;
119  return false;
120  }
121  }
122  if (parent) {
123  cd->parent = parent;
124  rz_pvector_push(&parent->children, cd);
125  if (!cmd->batch && parent->help->sort_subcommands) {
126  rz_pvector_sort(&parent->children, cd_sort);
127  }
128  parent->n_children++;
129  }
130  return true;
131 }
static int cd_sort(const void *a, const void *b)
Definition: cmd_api.c:100
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_CMD_DESC_TYPE_FAKE
Definition: rz_cmd.h:384
@ RZ_CMD_DESC_TYPE_INNER
Definition: rz_cmd.h:376
RZ_API void rz_pvector_sort(RzPVector *vec, RzPVectorComparator cmp)
Definition: vector.c:408
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
bool sort_subcommands
Definition: rz_cmd.h:327
const RzCmdDescHelp * help
Definition: rz_cmd.h:444
RzCmdDescType type
Definition: rz_cmd.h:418
RzPVector children
Definition: rz_cmd.h:440
int n_children
Definition: rz_cmd.h:436

References cd, cd_sort(), rz_cmd_desc_t::children, cmd, rz_cmd_desc_t::help, rz_cmd_desc_t::n_children, RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, RZ_CMD_DESC_TYPE_OLDINPUT, rz_pvector_push(), rz_pvector_sort(), rz_return_val_if_fail, rz_warn_if_reached, rz_cmd_desc_help_t::sort_subcommands, and rz_cmd_desc_t::type.

Referenced by create_cmd_desc().

◆ cmd_desc_unset_parent()

static void cmd_desc_unset_parent ( RzCmdDesc cd)
static

Definition at line 133 of file cmd_api.c.

133  {
134  rz_return_if_fail(cd && cd->parent);
135  RzCmdDesc *parent = cd->parent;
137  parent->n_children--;
138  cd->parent = NULL;
139 }
RZ_API void rz_pvector_remove_data(RzPVector *vec, void *x)
Definition: vector.c:362

References cd, rz_cmd_desc_t::children, rz_cmd_desc_t::n_children, NULL, rz_pvector_remove_data(), and rz_return_if_fail.

Referenced by rz_cmd_desc_remove().

◆ cmd_foreach_cmdname()

static void cmd_foreach_cmdname ( RzCmd cmd,
RzCmdDesc cd,
RzCmdForeachNameCb  cb,
void *  user 
)
static

Definition at line 2427 of file cmd_api.c.

2427  {
2428  if (!cd) {
2429  return;
2430  }
2431 
2432  void **it_cd;
2433 
2434  switch (cd->type) {
2435  case RZ_CMD_DESC_TYPE_ARGV:
2436  if (rz_cmd_desc_has_handler(cd)) {
2437  cb(cmd, cd, user);
2438  }
2439  break;
2441  cmd_foreach_cmdname_modes(cmd, cd, cd->d.argv_state_data.modes, cb, user);
2442  break;
2444  cmd_foreach_cmdname_modes(cmd, cd, cd->d.argv_modes_data.modes, cb, user);
2445  break;
2446  case RZ_CMD_DESC_TYPE_FAKE:
2447  break;
2449  if (rz_cmd_desc_has_handler(cd)) {
2450  cb(cmd, cd, user);
2451  }
2452  // fallthrough
2455  rz_cmd_desc_children_foreach(cd, it_cd) {
2456  RzCmdDesc *child = *it_cd;
2457  cmd_foreach_cmdname(cmd, child, cb, user);
2458  }
2459  break;
2460  }
2461 }
static void cmd_foreach_cmdname(RzCmd *cmd, RzCmdDesc *cd, RzCmdForeachNameCb cb, void *user)
Definition: cmd_api.c:2427
static void cmd_foreach_cmdname_modes(RzCmd *cmd, RzCmdDesc *cd, int modes, RzCmdForeachNameCb cb, void *user)
Definition: cmd_api.c:2406

References cb, cd, cmd, cmd_foreach_cmdname_modes(), rz_cmd_desc_has_handler(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, and RZ_CMD_DESC_TYPE_OLDINPUT.

Referenced by rz_cmd_foreach_cmdname().

◆ cmd_foreach_cmdname_modes()

static void cmd_foreach_cmdname_modes ( RzCmd cmd,
RzCmdDesc cd,
int  modes,
RzCmdForeachNameCb  cb,
void *  user 
)
static

Definition at line 2406 of file cmd_api.c.

2406  {
2407  size_t i;
2408  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
2409  if (modes & argv_modes[i].mode) {
2410  RzCmdDescHelp mode_help;
2411  const RzCmdDescHelp *copy = cd->help;
2412  cd->help = mode_cmd_desc_help(&mode_help, copy, argv_modes[i].summary_suffix);
2413 
2414  char *name = cd->name;
2415  cd->name = rz_str_newf("%s%s", name, argv_modes[i].suffix);
2416 
2417  cb(cmd, cd, user);
2418 
2419  free(cd->name);
2420  free((char *)mode_help.summary);
2421  cd->name = name;
2422  cd->help = copy;
2423  }
2424  }
2425 }
static RzCmdDescHelp * mode_cmd_desc_help(RzCmdDescHelp *dst, const RzCmdDescHelp *src, const char *suffix)
Definition: cmd_api.c:2395
static const struct argv_modes_t argv_modes[]
unsigned char suffix[65536]
Definition: gun.c:164
const char * name
Definition: op.c:541
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
const char * summary
Definition: rz_cmd.h:289

References argv_modes, cb, cd, cmd, free(), i, mode_cmd_desc_help(), name, RZ_ARRAY_SIZE, rz_str_newf(), suffix, and rz_cmd_desc_help_t::summary.

Referenced by cmd_foreach_cmdname().

◆ cmd_get_desc_best()

static RzCmdDesc* cmd_get_desc_best ( RzCmd cmd,
const char *  cmd_identifier,
bool  best_match 
)
static

Definition at line 303 of file cmd_api.c.

303  {
304  rz_return_val_if_fail(cmd && cmd_identifier, NULL);
305  char *cmdid = strdup(cmd_identifier);
306  char *end_cmdid = cmdid + strlen(cmdid);
307  RzCmdDesc *res = NULL;
308  bool is_exact_match = true;
309  char last_letter = '\0', o_last_letter = end_cmdid > cmdid ? *(end_cmdid - 1) : '\0';
310  // match longer commands first
311  while (*cmdid) {
312  RzCmdDesc *cd = ht_pp_find(cmd->ht_cmds, cmdid, NULL);
313  if (cd) {
314  switch (cd->type) {
320  if (!best_match && (!is_exact_match && !is_valid_argv_modes(rz_cmd_desc_get_exec(cd), last_letter))) {
321  break;
322  }
323  res = cd;
324  goto out;
326  res = cd;
327  goto out;
329  break;
330  }
331  }
332  // only the last letter is considered, then we zero last_letter
333  last_letter = o_last_letter;
334  o_last_letter = '\0';
335 
336  is_exact_match = false;
337  *(--end_cmdid) = '\0';
338  }
339 out:
340  free(cmdid);
341  return res;
342 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static bool is_valid_argv_modes(RzCmdDesc *cd, char last_letter)
Definition: cmd_api.c:283
RZ_API RzCmdDesc * rz_cmd_desc_get_exec(RzCmdDesc *cd)
Definition: cmd_api.c:291
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")

References cd, cmd, free(), is_valid_argv_modes(), NULL, out, rz_cmd_desc_get_exec(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, RZ_CMD_DESC_TYPE_OLDINPUT, rz_return_val_if_fail, and strdup().

Referenced by rz_cmd_get_desc(), and rz_cmd_get_desc_best().

◆ create_cmd_desc()

static RzCmdDesc* create_cmd_desc ( RzCmd cmd,
RzCmdDesc parent,
RzCmdDescType  type,
const char *  name,
const RzCmdDescHelp help,
bool  ht_insert 
)
static

Definition at line 161 of file cmd_api.c.

161  {
162  RzCmdDesc *res = RZ_NEW0(RzCmdDesc);
163  if (!res) {
164  return NULL;
165  }
166  res->type = type;
167  res->name = strdup(name);
168  if (!res->name) {
169  goto err;
170  }
171  res->n_children = 0;
172  res->help = help ? help : &not_defined_help;
174  if (ht_insert && !ht_pp_insert(cmd->ht_cmds, name, res)) {
175  goto err;
176  }
177  cmd_desc_set_parent(cmd, res, parent);
178  return res;
179 err:
180  cmd_desc_free(res);
181  return NULL;
182 }
static bool err
Definition: armass.c:435
static void cmd_desc_free(RzCmdDesc *cd)
Definition: cmd_api.c:151
static const RzCmdDescHelp not_defined_help
Definition: cmd_api.c:45
static bool cmd_desc_set_parent(RzCmd *cmd, RzCmdDesc *cd, RzCmdDesc *parent)
Definition: cmd_api.c:106
int type
Definition: mipsasm.c:17
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43

References rz_cmd_desc_t::children, cmd, cmd_desc_free(), cmd_desc_set_parent(), err, cmd_descs_generate::help, rz_cmd_desc_t::help, rz_cmd_desc_t::n_children, rz_cmd_desc_t::name, not_defined_help, NULL, RZ_NEW0, rz_pvector_init(), strdup(), type, and rz_cmd_desc_t::type.

Referenced by argv_modes_new(), argv_new(), argv_state_new(), rz_cmd_desc_fake_new(), rz_cmd_desc_group_modes_new(), rz_cmd_desc_group_new(), rz_cmd_desc_group_state_new(), rz_cmd_desc_inner_new(), rz_cmd_desc_oldinput_new(), and rz_cmd_new().

◆ do_print_child_help()

static void do_print_child_help ( RzCmd cmd,
RzStrBuf sb,
const RzCmdDesc cd,
const char *  name,
const char *  summary,
bool  show_children,
size_t  max_len,
bool  use_color 
)
static

Definition at line 1080 of file cmd_api.c.

1080  {
1081  size_t str_len = calc_padding_len(cd, name, show_children);
1082  int padding = str_len < max_len ? max_len - str_len : 0;
1083  const char *pal_args_color = "",
1084  *pal_opt_color = "",
1085  *pal_help_color = "",
1086  *pal_input_color = "",
1087  *pal_reset = "";
1088 
1089  if (cmd->has_cons && use_color) {
1090  RzCons *cons = rz_cons_singleton();
1091  pal_args_color = cons->context->pal.args;
1092  pal_opt_color = cons->context->pal.reset;
1093  pal_help_color = cons->context->pal.help;
1094  pal_input_color = cons->context->pal.input;
1095  pal_reset = cons->context->pal.reset;
1096  }
1097 
1098  size_t columns = 0;
1099  columns += strbuf_append_calc(sb, "| ");
1100  rz_strbuf_append(sb, pal_input_color);
1101  columns += strbuf_append_calc(sb, name);
1102  if (show_children && show_children_shortcut(cd)) {
1103  rz_strbuf_append(sb, pal_opt_color);
1104  columns += fill_children_chars(sb, cd);
1105  }
1106  rz_strbuf_append(sb, pal_args_color);
1107  if (cd->help->args_str) {
1108  columns += strbuf_append_calc(sb, cd->help->args_str);
1109  } else {
1110  columns += fill_args(sb, cd);
1111  }
1112  rz_strbuf_appendf(sb, " %*s", padding, "");
1113  columns += padding + 1;
1114  rz_strbuf_append(sb, pal_help_color);
1115 
1116  fill_wrapped_comment(cmd, sb, summary, columns, use_color);
1117  rz_strbuf_appendf(sb, "%s\n", pal_reset);
1118 }
static size_t strbuf_append_calc(RzStrBuf *sb, const char *s)
Definition: cmd_api.c:807
static void fill_wrapped_comment(RzCmd *cmd, RzStrBuf *sb, const char *comment, size_t columns, bool use_color)
Definition: cmd_api.c:906
static size_t calc_padding_len(const RzCmdDesc *cd, const char *name, bool show_children)
Definition: cmd_api.c:1051
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
int summary
Definition: zipcmp.c:234

References rz_cons_printable_palette_t::args, calc_padding_len(), cd, cmd, rz_cons_t::context, fill_args(), fill_children_chars(), fill_wrapped_comment(), rz_cons_printable_palette_t::help, rz_cons_printable_palette_t::input, rz_cons_context_t::pal, rz_cons_printable_palette_t::reset, rz_cons_singleton(), rz_strbuf_append(), rz_strbuf_appendf(), sb, show_children_shortcut(), strbuf_append_calc(), and summary.

Referenced by fill_argv_modes_help_strbuf(), print_child_help(), and rz_cmd_get_help_strbuf().

◆ escape_special_chars()

static char* escape_special_chars ( const char *  s,
const char *  special_chars 
)
static

Definition at line 2479 of file cmd_api.c.

2479  {
2480  size_t s_len = strlen(s);
2481  char *d = RZ_NEWS(char, s_len * 2 + 1);
2482  int i, j = 0;
2483  for (i = 0; i < s_len; i++) {
2484  if (strchr(special_chars, s[i])) {
2485  d[j++] = '\\';
2486  }
2487  d[j++] = s[i];
2488  }
2489  d[j++] = '\0';
2490  return d;
2491 }
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define d(i)
Definition: sha256.c:44

References d, i, RZ_NEWS, and s.

Referenced by rz_cmd_escape_arg().

◆ fake_get_help()

static char* fake_get_help ( RzCmd cmd,
RzCmdDesc cd,
bool  use_color 
)
static

Definition at line 1297 of file cmd_api.c.

1297  {
1298  // abuse detail=2 of the argv help as they show essentially the same info
1299  return argv_get_help(cmd, cd, 2, use_color);
1300 }
static char * argv_get_help(RzCmd *cmd, RzCmdDesc *cd, size_t detail, bool use_color)
Definition: cmd_api.c:1266

References argv_get_help(), cd, and cmd.

Referenced by get_help().

◆ fill_args()

static size_t fill_args ( RzStrBuf sb,
const RzCmdDesc cd 
)
static

Definition at line 946 of file cmd_api.c.

946  {
947  const RzCmdDescArg *arg;
948  size_t n_optionals = 0;
949  size_t len = 0;
950  bool has_array = false;
951  for (arg = cd->help->args; arg && arg->name; arg++) {
952  if (arg->type == RZ_CMD_ARG_TYPE_FAKE) {
953  if (!arg->optional) {
954  // Assume arg is a closing bracket
955  close_optionals(&n_optionals, sb, &len);
956  }
958  len += strlen(arg->name);
959  continue;
960  }
961 
962  if (has_array) {
964  break;
965  }
966  if (!arg->no_space) {
967  rz_strbuf_append(sb, " ");
968  len++;
969  }
970  if (arg->optional) {
971  rz_strbuf_append(sb, "[");
972  len++;
973  n_optionals++;
974  }
975  if (arg->flags & RZ_CMD_ARG_FLAG_ARRAY) {
976  has_array = true;
977  rz_strbuf_appendf(sb, "<%s1>", arg->name);
978  len += strlen(arg->name) + 3;
979  rz_strbuf_appendf(sb, " <%s2> ...", arg->name);
980  len += strlen(arg->name) + 8;
981  } else if (arg->flags & RZ_CMD_ARG_FLAG_OPTION) {
982  rz_strbuf_appendf(sb, "-%s", arg->name);
983  len += strlen(arg->name) + 1;
984  } else {
985  rz_strbuf_appendf(sb, "<%s>", arg->name);
986  len += strlen(arg->name) + 2;
987  if (arg->default_value) {
988  rz_strbuf_appendf(sb, "=%s", arg->default_value);
989  len += strlen(arg->default_value) + 1;
990  }
991  }
992  }
993  close_optionals(&n_optionals, sb, &len);
994  return len;
995 }
size_t len
Definition: 6502dis.c:15
static void close_optionals(size_t *n_optionals, RzStrBuf *sb, size_t *len)
Definition: cmd_api.c:939
#define RZ_CMD_ARG_FLAG_ARRAY
Definition: rz_cmd.h:72
@ RZ_CMD_ARG_TYPE_FAKE
This is not considered a real argument, just used to show something in the help. Name of arg is shown...
Definition: rz_cmd.h:37
#define RZ_CMD_ARG_FLAG_OPTION
Definition: rz_cmd.h:76

References arg(), cd, close_optionals(), len, arg::name, RZ_CMD_ARG_FLAG_ARRAY, RZ_CMD_ARG_FLAG_OPTION, RZ_CMD_ARG_TYPE_FAKE, rz_strbuf_append(), rz_strbuf_appendf(), rz_warn_if_reached, and sb.

Referenced by calc_padding_len(), do_print_child_help(), fill_usage_strbuf(), and rz_cmd_get_help_json().

◆ fill_args_json()

static void fill_args_json ( const RzCmd cmd,
const RzCmdDesc cd,
PJ j 
)
static

Definition at line 1353 of file cmd_api.c.

1353  {
1354  const RzCmdDescArg *arg;
1355  bool has_array = false;
1356  pj_ka(j, "args");
1357  const char *argtype = NULL;
1358  for (arg = cd->help->args; arg && arg->name; arg++) {
1359  if (has_array) {
1361  break;
1362  }
1363  pj_o(j);
1364 #define CASE_TYPE(x, y) \
1365  case (x): \
1366  argtype = (y); \
1367  break
1368  switch (arg->type) {
1370  CASE_TYPE(RZ_CMD_ARG_TYPE_NUM, "number");
1371  CASE_TYPE(RZ_CMD_ARG_TYPE_RZNUM, "expression");
1372  CASE_TYPE(RZ_CMD_ARG_TYPE_STRING, "string");
1373  CASE_TYPE(RZ_CMD_ARG_TYPE_ENV, "environment_variable");
1375  CASE_TYPE(RZ_CMD_ARG_TYPE_FCN, "function");
1376  CASE_TYPE(RZ_CMD_ARG_TYPE_FILE, "filename");
1377  CASE_TYPE(RZ_CMD_ARG_TYPE_OPTION, "option");
1378  CASE_TYPE(RZ_CMD_ARG_TYPE_CMD, "command");
1379  CASE_TYPE(RZ_CMD_ARG_TYPE_MACRO, "macro");
1380  CASE_TYPE(RZ_CMD_ARG_TYPE_EVAL_KEY, "evaluable");
1381  CASE_TYPE(RZ_CMD_ARG_TYPE_EVAL_FULL, "evaluable_full");
1382 #undef CASE_TYPE
1383  default:
1384  argtype = "unknown";
1385  break;
1386  }
1387  pj_ks(j, "type", argtype);
1388  pj_ks(j, "name", arg->name);
1389  if (arg->type == RZ_CMD_ARG_TYPE_FAKE) {
1390  pj_end(j);
1391  continue;
1392  }
1393  if (arg->no_space) {
1394  pj_kb(j, "nospace", true);
1395  }
1396  if (!arg->optional) {
1397  pj_kb(j, "required", true);
1398  }
1399  if (arg->flags & RZ_CMD_ARG_FLAG_LAST) {
1400  pj_kb(j, "is_last", true);
1401  }
1402  if (arg->flags & RZ_CMD_ARG_FLAG_ARRAY) {
1403  pj_kb(j, "is_array", true);
1404  }
1405  if (arg->flags & RZ_CMD_ARG_FLAG_OPTION) {
1406  pj_kb(j, "is_option", true);
1407  }
1408  if (arg->default_value) {
1409  pj_ks(j, "default", arg->default_value);
1410  }
1411  if (arg->type == RZ_CMD_ARG_TYPE_CHOICES) {
1412  pj_ka(j, "choices");
1413  char **ochoice = arg->choices_cb ? arg->choices_cb(cmd->data) : (char **)arg->choices;
1414  for (char **choice = ochoice; *choice; choice++) {
1415  pj_s(j, *choice);
1416  }
1417  pj_end(j);
1418  if (arg->choices_cb) {
1419  for (char **choice = ochoice; *choice; choice++) {
1420  free(*choice);
1421  }
1422  free(ochoice);
1423  }
1424  }
1425  pj_end(j);
1426  }
1427  pj_end(j);
1428 }
#define CASE_TYPE(x, y)
@ RZ_CMD_ARG_TYPE_FCN
Argument can be the name of an existing function.
Definition: rz_cmd.h:43
@ RZ_CMD_ARG_TYPE_MACRO
Argument is the name of a pre-defined macro.
Definition: rz_cmd.h:47
@ RZ_CMD_ARG_TYPE_STRING
Argument that can be an arbitrary string.
Definition: rz_cmd.h:40
@ RZ_CMD_ARG_TYPE_EVAL_KEY
Argument is the name of a evaluable variable (e.g. et command)
Definition: rz_cmd.h:48
@ RZ_CMD_ARG_TYPE_EVAL_FULL
Argument is the name+(optional)value of a evaluable variable (e.g. e command)
Definition: rz_cmd.h:49
@ RZ_CMD_ARG_TYPE_OPTION
Argument is an option, prefixed with -. It is present or not. No argument.
Definition: rz_cmd.h:45
@ RZ_CMD_ARG_TYPE_CHOICES
Argument can be one of the provided choices.
Definition: rz_cmd.h:42
@ RZ_CMD_ARG_TYPE_NUM
Argument is a number.
Definition: rz_cmd.h:38
@ RZ_CMD_ARG_TYPE_RZNUM
Argument that can be interpreted by RzNum (numbers, flags, operations, etc.)
Definition: rz_cmd.h:39
@ RZ_CMD_ARG_TYPE_FILE
Argument is a filename.
Definition: rz_cmd.h:44
@ RZ_CMD_ARG_TYPE_ENV
Argument can be the name of an existing rizin variable.
Definition: rz_cmd.h:41
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170

References arg(), CASE_TYPE, cd, cmd, free(), arg::name, NULL, pj_end(), pj_ka(), pj_kb(), pj_ks(), pj_o(), pj_s(), RZ_CMD_ARG_FLAG_ARRAY, RZ_CMD_ARG_FLAG_LAST, RZ_CMD_ARG_FLAG_OPTION, RZ_CMD_ARG_TYPE_CHOICES, RZ_CMD_ARG_TYPE_CMD, RZ_CMD_ARG_TYPE_ENV, RZ_CMD_ARG_TYPE_EVAL_FULL, RZ_CMD_ARG_TYPE_EVAL_KEY, RZ_CMD_ARG_TYPE_FAKE, RZ_CMD_ARG_TYPE_FCN, RZ_CMD_ARG_TYPE_FILE, RZ_CMD_ARG_TYPE_MACRO, RZ_CMD_ARG_TYPE_NUM, RZ_CMD_ARG_TYPE_OPTION, RZ_CMD_ARG_TYPE_RZNUM, RZ_CMD_ARG_TYPE_STRING, and rz_warn_if_reached.

Referenced by rz_cmd_get_help_json().

◆ fill_argv_modes_help_strbuf()

static void fill_argv_modes_help_strbuf ( RzCmd cmd,
RzStrBuf sb,
RzCmdDesc cd,
bool  use_color 
)
static

Definition at line 1148 of file cmd_api.c.

1148  {
1149  size_t max_len = 0, min_len = SIZE_MAX;
1150  update_minmax_len(cd, &max_len, &min_len, true);
1151  max_len++; // consider the suffix letter
1152  if (max_len - min_len > MAX_RIGHT_ALIGHNMENT) {
1153  max_len = min_len + MAX_RIGHT_ALIGHNMENT;
1154  }
1155 
1156  size_t i;
1157  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
1158  if (cd->d.argv_modes_data.modes & argv_modes[i].mode) {
1159  char *name = rz_str_newf("%s%s", cd->name, argv_modes[i].suffix);
1160  char *summary = rz_str_newf("%s%s", cd->help->summary, argv_modes[i].summary_suffix);
1161  do_print_child_help(cmd, sb, cd, name, summary, false, max_len, use_color);
1162  free(name);
1163  free(summary);
1164  }
1165  }
1166 }
static void update_minmax_len(RzCmdDesc *cd, size_t *max_len, size_t *min_len, bool show_children)
Definition: cmd_api.c:1074
static void do_print_child_help(RzCmd *cmd, RzStrBuf *sb, const RzCmdDesc *cd, const char *name, const char *summary, bool show_children, size_t max_len, bool use_color)
Definition: cmd_api.c:1080
#define MAX_RIGHT_ALIGHNMENT
Definition: cmd_api.c:33
#define SIZE_MAX
RzOutputMode mode
Definition: cmd_api.c:60
const char * summary_suffix
Definition: cmd_api.c:59
const char * suffix
Definition: cmd_api.c:58

References argv_modes, cd, cmd, do_print_child_help(), free(), i, MAX_RIGHT_ALIGHNMENT, argv_modes_t::mode, RZ_ARRAY_SIZE, rz_str_newf(), sb, SIZE_MAX, argv_modes_t::suffix, summary, argv_modes_t::summary_suffix, and update_minmax_len().

Referenced by argv_get_help().

◆ fill_children_chars()

static size_t fill_children_chars ( RzStrBuf sb,
const RzCmdDesc cd 
)
static

Definition at line 823 of file cmd_api.c.

823  {
824  if (cd->help->options) {
825  return strbuf_append_calc(sb, cd->help->options);
826  }
827 
828  RzStrBuf csb;
829  rz_strbuf_init(&csb);
830 
831  void **it;
832  bool has_other_commands = false;
833  const RzCmdDesc *exec_cd = rz_cmd_desc_get_exec((RzCmdDesc *)cd);
834  if (exec_cd) {
835  switch (exec_cd->type) {
838  fill_modes_children_chars(&csb, exec_cd);
839  break;
840  default:
841  break;
842  }
843  }
844  rz_cmd_desc_children_foreach(cd, it) {
845  RzCmdDesc *child = *(RzCmdDesc **)it;
846  if (rz_str_startswith(child->name, cd->name) && strlen(child->name) == strlen(cd->name) + 1) {
847  rz_strbuf_appendf(&csb, "%c", child->name[strlen(cd->name)]);
848  } else if (strcmp(child->name, cd->name)) {
849  has_other_commands = true;
850  }
851  }
852 
853  if (rz_strbuf_is_empty(&csb) || rz_strbuf_length(&csb) >= MAX_CHILDREN_SHOW) {
854  rz_strbuf_fini(&csb);
855  rz_strbuf_set(&csb, "?");
856  has_other_commands = false;
857  }
858 
859  if (has_other_commands) {
860  rz_strbuf_append(&csb, "?");
861  }
862 
863  if (!cd->n_children || rz_cmd_desc_has_handler(cd)) {
864  rz_strbuf_prepend(&csb, "[");
865  rz_strbuf_append(&csb, "]");
866  } else {
867  rz_strbuf_prepend(&csb, "<");
868  rz_strbuf_append(&csb, ">");
869  }
870  size_t res = rz_strbuf_length(&csb);
871  char *s = rz_strbuf_drain_nofree(&csb);
873  free(s);
874  return res;
875 }
#define MAX_CHILDREN_SHOW
Definition: cmd_api.c:30
static void fill_modes_children_chars(RzStrBuf *sb, const RzCmdDesc *cd)
Definition: cmd_api.c:812
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
Definition: strbuf.c:349
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API bool rz_strbuf_prepend(RzStrBuf *sb, const char *s)
Definition: strbuf.c:201
RZ_API bool rz_strbuf_is_empty(RzStrBuf *sb)
Definition: strbuf.c:24

References cd, fill_modes_children_chars(), free(), MAX_CHILDREN_SHOW, rz_cmd_desc_t::name, rz_cmd_desc_get_exec(), rz_cmd_desc_has_handler(), RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, rz_str_startswith(), rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_drain_nofree(), rz_strbuf_fini(), rz_strbuf_init(), rz_strbuf_is_empty(), rz_strbuf_length(), rz_strbuf_prepend(), rz_strbuf_set(), s, sb, strbuf_append_calc(), and rz_cmd_desc_t::type.

Referenced by calc_padding_len(), do_print_child_help(), and fill_usage_strbuf().

◆ fill_colored_args()

static void fill_colored_args ( RzCmd cmd,
RzStrBuf sb,
const char *  line,
bool  use_color,
const char *  reset_color 
)
static

Definition at line 882 of file cmd_api.c.

882  {
883  const char *pal_args_color = "";
884  if (cmd->has_cons && use_color) {
885  RzCons *cons = rz_cons_singleton();
886  pal_args_color = cons->context->pal.args;
887  }
888 
889  while (line) {
890  const char *close_arg = NULL;
891  const char *open_arg = strchr(line, '<');
892  if (!open_arg) {
893  break;
894  }
895  close_arg = strchr(open_arg, '>');
896  if (!close_arg) {
897  break;
898  }
899  rz_strbuf_appendf(sb, "%.*s%s", (int)(open_arg - line), line, pal_args_color);
900  rz_strbuf_appendf(sb, "%.*s%s", (int)(close_arg - open_arg + 1), open_arg, reset_color);
901  line = close_arg + 1;
902  }
904 }
line
Definition: setup.py:34

References rz_cons_printable_palette_t::args, cmd, rz_cons_t::context, setup::line, NULL, rz_cons_context_t::pal, rz_cons_singleton(), rz_strbuf_append(), rz_strbuf_appendf(), and sb.

Referenced by argv_get_help(), and fill_wrapped_comment().

◆ fill_details()

static void fill_details ( RzCmd cmd,
RzCmdDesc cd,
RzStrBuf sb,
bool  use_color 
)
static

Definition at line 1261 of file cmd_api.c.

1261  {
1262  fill_details_static(cmd, cd, sb, use_color);
1263  fill_details_cb(cmd, cd, sb, use_color);
1264 }
static void fill_details_cb(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
Definition: cmd_api.c:1252
static void fill_details_static(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
Definition: cmd_api.c:1244

References cd, cmd, fill_details_cb(), fill_details_static(), and sb.

Referenced by argv_get_help(), and group_get_help().

◆ fill_details_cb()

static void fill_details_cb ( RzCmd cmd,
RzCmdDesc cd,
RzStrBuf sb,
bool  use_color 
)
static

Definition at line 1252 of file cmd_api.c.

1252  {
1253  RzCmdDescDetail *detail_it = get_cd_details_cb(cmd, cd);
1254  if (!detail_it) {
1255  return;
1256  }
1257  fill_details_do(cmd, detail_it, sb, use_color);
1258  rz_cmd_desc_details_free(detail_it);
1259 }
RZ_API void rz_cmd_desc_details_free(RzCmdDescDetail *details)
Free an array of RzCmdDescDetail sections.
Definition: cmd_api.c:2698
static void fill_details_do(RzCmd *cmd, const RzCmdDescDetail *detail_it, RzStrBuf *sb, bool use_color)
Definition: cmd_api.c:1189
static RzCmdDescDetail * get_cd_details_cb(RzCmd *cmd, RzCmdDesc *cd)
Definition: cmd_api.c:1178

References cd, cmd, fill_details_do(), get_cd_details_cb(), rz_cmd_desc_details_free(), and sb.

Referenced by fill_details().

◆ fill_details_do()

static void fill_details_do ( RzCmd cmd,
const RzCmdDescDetail detail_it,
RzStrBuf sb,
bool  use_color 
)
static

Definition at line 1189 of file cmd_api.c.

1189  {
1190  const char *pal_help_color = "",
1191  *pal_input_color = "",
1192  *pal_label_color = "",
1193  *pal_args_color = "",
1194  *pal_reset = "";
1195  if (cmd->has_cons && use_color) {
1196  RzCons *cons = rz_cons_singleton();
1197  pal_help_color = cons->context->pal.help;
1198  pal_input_color = cons->context->pal.input;
1199  pal_label_color = cons->context->pal.label;
1200  pal_args_color = cons->context->pal.args;
1201  pal_reset = cons->context->pal.reset;
1202  }
1203 
1204  while (detail_it->name) {
1205  if (!RZ_STR_ISEMPTY(detail_it->name)) {
1206  rz_strbuf_appendf(sb, "\n%s%s:%s\n", pal_label_color, detail_it->name, pal_reset);
1207  }
1208  const RzCmdDescDetailEntry *entry_it = detail_it->entries;
1209  size_t max_len = 0, min_len = SIZE_MAX;
1210  while (entry_it && entry_it->text) {
1211  size_t len = strlen(entry_it->text) + strlen0(entry_it->arg_str);
1212  if (max_len < len) {
1213  max_len = len;
1214  }
1215  if (min_len > len) {
1216  min_len = len;
1217  }
1218  entry_it++;
1219  }
1220  if (max_len - min_len > MAX_RIGHT_ALIGHNMENT) {
1221  max_len = min_len + MAX_RIGHT_ALIGHNMENT;
1222  }
1223 
1224  entry_it = detail_it->entries;
1225  while (entry_it && entry_it->text) {
1226  size_t len = strlen(entry_it->text) + strlen0(entry_it->arg_str);
1227  int padding = len < max_len ? max_len - len : 0;
1228  const char *arg_str = entry_it->arg_str ? entry_it->arg_str : "";
1229  rz_strbuf_appendf(sb, "| %s%s%s%s %*s%s",
1230  pal_input_color, entry_it->text,
1231  pal_args_color, arg_str,
1232  padding, "",
1233  pal_help_color);
1234  size_t columns = strlen("| ") + strlen(entry_it->text) +
1235  strlen(" ") + strlen(arg_str) + padding;
1236  fill_wrapped_comment(cmd, sb, entry_it->comment, columns, use_color);
1237  rz_strbuf_appendf(sb, "%s\n", pal_reset);
1238  entry_it++;
1239  }
1240  detail_it++;
1241  }
1242 }
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
A detailed entry that can be used to show additional info about a command entry.
Definition: rz_cmd.h:172
const char * comment
Definition: rz_cmd.h:180
const char * text
Definition: rz_cmd.h:176
const char * arg_str
Definition: rz_cmd.h:187
const char * name
Definition: rz_cmd.h:197
const RzCmdDescDetailEntry * entries
Definition: rz_cmd.h:201

References rz_cmd_desc_detail_entry_t::arg_str, rz_cons_printable_palette_t::args, cmd, rz_cmd_desc_detail_entry_t::comment, rz_cons_t::context, rz_cmd_desc_detail_t::entries, fill_wrapped_comment(), rz_cons_printable_palette_t::help, rz_cons_printable_palette_t::input, rz_cons_printable_palette_t::label, len, MAX_RIGHT_ALIGHNMENT, rz_cmd_desc_detail_t::name, rz_cons_context_t::pal, rz_cons_printable_palette_t::reset, rz_cons_singleton(), RZ_STR_ISEMPTY, rz_strbuf_appendf(), sb, SIZE_MAX, strlen0(), and rz_cmd_desc_detail_entry_t::text.

Referenced by fill_details_cb(), and fill_details_static().

◆ fill_details_static()

static void fill_details_static ( RzCmd cmd,
RzCmdDesc cd,
RzStrBuf sb,
bool  use_color 
)
static

Definition at line 1244 of file cmd_api.c.

1244  {
1245  const RzCmdDescDetail *detail_it = get_cd_details(cd);
1246  if (!detail_it) {
1247  return;
1248  }
1249  fill_details_do(cmd, detail_it, sb, use_color);
1250 }
static const RzCmdDescDetail * get_cd_details(RzCmdDesc *cd)
Definition: cmd_api.c:1168

References cd, cmd, fill_details_do(), get_cd_details(), and sb.

Referenced by fill_details().

◆ fill_modes_children_chars()

static void fill_modes_children_chars ( RzStrBuf sb,
const RzCmdDesc cd 
)
static

Definition at line 812 of file cmd_api.c.

812  {
813  // RZ_CMD_DESC_TYPE_ARGV_MODES does not have actual children for
814  // the output modes, so we consider it separately
815  size_t i;
816  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
817  if (cd->d.argv_modes_data.modes & argv_modes[i].mode) {
819  }
820  }
821 }

References argv_modes, cd, i, argv_modes_t::mode, RZ_ARRAY_SIZE, rz_strbuf_append(), sb, and suffix.

Referenced by fill_children_chars().

◆ fill_usage_strbuf()

static void fill_usage_strbuf ( RzCmd cmd,
RzStrBuf sb,
RzCmdDesc cd,
bool  use_color 
)
static

Definition at line 997 of file cmd_api.c.

997  {
998  const char *pal_label_color = "",
999  *pal_args_color = "",
1000  *pal_input_color = "",
1001  *pal_help_color = "",
1002  *pal_reset = "";
1003 
1004  if (cmd->has_cons && use_color) {
1005  RzCons *cons = rz_cons_singleton();
1006  pal_label_color = cons->context->pal.label;
1007  pal_args_color = cons->context->pal.args;
1008  pal_input_color = cons->context->pal.input;
1009  pal_help_color = cons->context->pal.help;
1010  pal_reset = cons->context->pal.reset;
1011  }
1012 
1013  size_t columns = 0;
1014  rz_strbuf_append(sb, pal_label_color);
1015  columns += strbuf_append_calc(sb, "Usage: ");
1016  rz_strbuf_append(sb, pal_reset);
1017  if (cd->help->usage) {
1018  columns += strbuf_append_calc(sb, cd->help->usage);
1019  rz_strbuf_append(sb, pal_reset);
1020  } else {
1021  rz_strbuf_append(sb, pal_input_color);
1022  columns += strbuf_append_calc(sb, cd->name);
1023  if (show_children_shortcut(cd)) {
1024  rz_strbuf_append(sb, pal_reset);
1025  columns += fill_children_chars(sb, cd);
1026  }
1027  rz_strbuf_append(sb, pal_args_color);
1028  if (cd->help->args_str) {
1029  columns += strbuf_append_calc(sb, cd->help->args_str);
1030  } else {
1031  columns += fill_args(sb, cd);
1032  }
1033  rz_strbuf_append(sb, pal_reset);
1034  }
1035  if (cd->help->summary) {
1036  RzStrBuf *summary_sb = rz_strbuf_new(cd->help->summary);
1037  if (summary_sb) {
1038  columns += strbuf_append_calc(sb, " ");
1039  rz_strbuf_append(sb, pal_help_color);
1040  if (has_cd_default_mode(cd)) {
1042  }
1043  fill_wrapped_comment(cmd, sb, rz_strbuf_get(summary_sb), columns, use_color);
1044  rz_strbuf_append(sb, pal_reset);
1045  rz_strbuf_free(summary_sb);
1046  }
1047  }
1048  rz_strbuf_append(sb, "\n");
1049 }
RZ_IPI const char * rz_output_mode_to_summary(RzOutputMode mode)
Definition: cmd_api.c:83
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321

References rz_cons_printable_palette_t::args, cd, cmd, rz_cons_t::context, fill_args(), fill_children_chars(), fill_wrapped_comment(), get_cd_default_mode(), has_cd_default_mode(), rz_cons_printable_palette_t::help, rz_cons_printable_palette_t::input, rz_cons_printable_palette_t::label, rz_cons_context_t::pal, rz_cons_printable_palette_t::reset, rz_cons_singleton(), rz_output_mode_to_summary(), rz_strbuf_append(), rz_strbuf_appendf(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_new(), sb, show_children_shortcut(), and strbuf_append_calc().

Referenced by argv_get_help(), and group_get_help().

◆ fill_wrapped_comment()

static void fill_wrapped_comment ( RzCmd cmd,
RzStrBuf sb,
const char *  comment,
size_t  columns,
bool  use_color 
)
static

Definition at line 906 of file cmd_api.c.

906  {
907  int rows, cols;
908  bool is_interactive = false;
909  const char *help_color = "";
910  if (cmd->has_cons) {
911  RzCons *cons = rz_cons_singleton();
912  cols = rz_cons_get_size(&rows);
913  is_interactive = rz_cons_is_interactive();
914  help_color = use_color ? cons->context->pal.help : "";
915  }
916  if (is_interactive && cols > 0 && cols - columns > MIN_SUMMARY_WIDTH && !RZ_STR_ISEMPTY(comment)) {
917  char *text = strdup(comment);
918  RzList *wrapped_text = rz_str_wrap(text, cols - columns - 2);
919  RzListIter *it;
920  const char *line;
921  bool first = true;
922  rz_list_foreach (wrapped_text, it, line) {
923  if (!first) {
924  rz_strbuf_appendf(sb, "\n%*s", (int)(columns + 2), "");
925  } else {
926  rz_strbuf_append(sb, "# ");
927  first = false;
928  }
929 
930  fill_colored_args(cmd, sb, line, use_color, help_color);
931  }
932  rz_list_free(wrapped_text);
933  free(text);
934  } else if (!RZ_STR_ISEMPTY(comment)) {
935  rz_strbuf_appendf(sb, "# %s", comment);
936  }
937 }
#define MIN_SUMMARY_WIDTH
Definition: cmd_api.c:32
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API RzList * rz_str_wrap(char *str, size_t width)
Definition: str.c:3996

References cmd, rz_cons_t::context, fill_colored_args(), free(), rz_cons_printable_palette_t::help, setup::line, MIN_SUMMARY_WIDTH, rz_cons_context_t::pal, rz_cons_get_size(), rz_cons_is_interactive(), rz_cons_singleton(), rz_list_free(), RZ_STR_ISEMPTY, rz_str_wrap(), rz_strbuf_append(), rz_strbuf_appendf(), sb, strdup(), and create_tags_rz::text.

Referenced by do_print_child_help(), fill_details_do(), and fill_usage_strbuf().

◆ free_array()

static void free_array ( char **  arr,
int  n 
)
static

Definition at line 2049 of file cmd_api.c.

2049  {
2050  int i;
2051  for (i = 0; i < n; i++) {
2052  free(arr[i]);
2053  }
2054  free(arr);
2055 }
int n
Definition: mipsasm.c:19

References syscall_preprocessing::arr, free(), i, and n.

Referenced by rz_cmd_parsed_args_setargs().

◆ get_cd_default_mode()

static RzOutputMode get_cd_default_mode ( RzCmdDesc cd)
static

Definition at line 625 of file cmd_api.c.

625  {
626  switch (cd->type) {
628  return cd->d.argv_modes_data.default_mode;
630  return cd->d.argv_state_data.default_mode;
631  default:
633  }
634 }

References cd, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, and RZ_OUTPUT_MODE_STANDARD.

Referenced by cd_suffix2mode(), fill_usage_strbuf(), and has_cd_default_mode().

◆ get_cd_details()

static const RzCmdDescDetail* get_cd_details ( RzCmdDesc cd)
static

Definition at line 1168 of file cmd_api.c.

1168  {
1169  do {
1170  if (cd->help->details) {
1171  return cd->help->details;
1172  }
1173  cd = cd->parent;
1174  } while (cd);
1175  return NULL;
1176 }

References cd, and NULL.

Referenced by fill_details_static().

◆ get_cd_details_cb()

static RzCmdDescDetail* get_cd_details_cb ( RzCmd cmd,
RzCmdDesc cd 
)
static

Definition at line 1178 of file cmd_api.c.

1178  {
1179  do {
1180  if (cd->help->details || cd->help->details_cb) {
1181  const char *argv[] = { cd->name, NULL };
1182  return cd->help->details_cb ? cd->help->details_cb(cmd->data, 1, argv) : NULL;
1183  }
1184  cd = cd->parent;
1185  } while (cd);
1186  return NULL;
1187 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40

References argv, cd, cmd, and NULL.

Referenced by fill_details_cb().

◆ get_help()

static char* get_help ( RzCmd cmd,
RzCmdDesc cd,
const char *  cmdid,
RzCmdParsedArgs args,
bool  use_color,
size_t  detail 
)
static

Definition at line 1324 of file cmd_api.c.

1324  {
1325  switch (cd->type) {
1327  if (cd->d.group_data.exec_cd && (detail > 1 || (detail == 1 && strcmp(cmdid, cd->name)))) {
1328  return get_help(cmd, cd->d.group_data.exec_cd, cmdid, args, use_color, detail);
1329  }
1330  if (detail == 1) {
1331  // show the group help only when doing <cmd>?
1332  return group_get_help(cmd, cd, use_color);
1333  }
1334  return argv_get_help(cmd, cd, detail, use_color);
1335  case RZ_CMD_DESC_TYPE_ARGV:
1338  return argv_get_help(cmd, cd, detail, use_color);
1339  case RZ_CMD_DESC_TYPE_FAKE:
1340  if (detail != 1) {
1341  return NULL;
1342  }
1343  return fake_get_help(cmd, cd, use_color);
1345  return oldinput_get_help(cmd, cd, args);
1348  return NULL;
1349  }
1350  return NULL;
1351 }
static char * fake_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color)
Definition: cmd_api.c:1297
static char * group_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color)
Definition: cmd_api.c:1124
static char * get_help(RzCmd *cmd, RzCmdDesc *cd, const char *cmdid, RzCmdParsedArgs *args, bool use_color, size_t detail)
Definition: cmd_api.c:1324
static char * oldinput_get_help(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *a)
Definition: cmd_api.c:1302

References args, argv_get_help(), cd, cmd, fake_get_help(), group_get_help(), NULL, oldinput_get_help(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, RZ_CMD_DESC_TYPE_OLDINPUT, and rz_warn_if_reached.

Referenced by rz_cmd_get_help().

◆ get_minmax_argc()

static void get_minmax_argc ( RzCmdDesc cd,
int min_argc,
int max_argc 
)
static

Definition at line 592 of file cmd_api.c.

592  {
593  *min_argc = 1;
594  *max_argc = 1;
595  const RzCmdDescArg *arg = cd->help->args;
596  while (arg && arg->name && !arg->optional) {
597  if (arg->type == RZ_CMD_ARG_TYPE_FAKE) {
598  arg++;
599  continue;
600  }
601  (*min_argc)++;
602  (*max_argc)++;
603  if (arg->flags & RZ_CMD_ARG_FLAG_LAST) {
604  return;
605  } else if (arg->flags & RZ_CMD_ARG_FLAG_ARRAY) {
606  *max_argc = INT_MAX;
607  return;
608  }
609  arg++;
610  }
611  while (arg && arg->name) {
612  if (arg->type == RZ_CMD_ARG_TYPE_FAKE) {
613  arg++;
614  continue;
615  }
616  (*max_argc)++;
617  if (arg->flags & RZ_CMD_ARG_FLAG_ARRAY) {
618  *max_argc = INT_MAX;
619  return;
620  }
621  arg++;
622  }
623 }
#define INT_MAX
Definition: cp-demangle.c:131

References cd, INT_MAX, arg::name, RZ_CMD_ARG_FLAG_ARRAY, RZ_CMD_ARG_FLAG_LAST, and RZ_CMD_ARG_TYPE_FAKE.

Referenced by argv_modes_new(), argv_new(), and argv_state_new().

◆ group_get_help()

static char* group_get_help ( RzCmd cmd,
RzCmdDesc cd,
bool  use_color 
)
static

Definition at line 1124 of file cmd_api.c.

1124  {
1126  fill_usage_strbuf(cmd, sb, cd, use_color);
1127 
1128  void **it_cd;
1129  size_t max_len = 0, min_len = SIZE_MAX;
1130 
1131  rz_cmd_desc_children_foreach(cd, it_cd) {
1132  RzCmdDesc *child = *(RzCmdDesc **)it_cd;
1133  update_minmax_len(child, &max_len, &min_len, true);
1134  }
1135  if (max_len - min_len > MAX_RIGHT_ALIGHNMENT) {
1136  max_len = min_len + MAX_RIGHT_ALIGHNMENT;
1137  }
1138 
1139  rz_cmd_desc_children_foreach(cd, it_cd) {
1140  RzCmdDesc *child = *(RzCmdDesc **)it_cd;
1141  print_child_help(cmd, sb, child, max_len, use_color);
1142  }
1143 
1144  fill_details(cmd, cd, sb, use_color);
1145  return rz_strbuf_drain(sb);
1146 }
static void print_child_help(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, size_t max_len, bool use_color)
Definition: cmd_api.c:1120

References cd, cmd, fill_details(), fill_usage_strbuf(), MAX_RIGHT_ALIGHNMENT, NULL, print_child_help(), rz_strbuf_drain(), rz_strbuf_new(), sb, SIZE_MAX, and update_minmax_len().

Referenced by get_help().

◆ has_cd_default_mode()

static bool has_cd_default_mode ( RzCmdDesc cd)
static

Definition at line 636 of file cmd_api.c.

636  {
638 }

References cd, get_cd_default_mode(), and RZ_OUTPUT_MODE_STANDARD.

Referenced by cd_suffix2mode(), and fill_usage_strbuf().

◆ has_cd_submodes()

static bool has_cd_submodes ( const RzCmdDesc cd)
static

Definition at line 279 of file cmd_api.c.

279  {
280  return cd->type == RZ_CMD_DESC_TYPE_ARGV_MODES || cd->type == RZ_CMD_DESC_TYPE_ARGV_STATE;
281 }

References cd, RZ_CMD_DESC_TYPE_ARGV_MODES, and RZ_CMD_DESC_TYPE_ARGV_STATE.

Referenced by cd_suffix2mode(), is_valid_argv_modes(), and show_children_shortcut().

◆ int2cmdstatus()

static RzCmdStatus int2cmdstatus ( int  v)
static

Definition at line 582 of file cmd_api.c.

582  {
583  if (v == -2) {
584  return RZ_CMD_STATUS_EXIT;
585  } else if (v < 0) {
586  return RZ_CMD_STATUS_ERROR;
587  } else {
588  return RZ_CMD_STATUS_OK;
589  }
590 }
const char * v
Definition: dsignal.c:12
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
@ RZ_CMD_STATUS_EXIT
command handler asks to exit the prompt loop
Definition: rz_cmd.h:29

References RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_EXIT, RZ_CMD_STATUS_OK, and v.

Referenced by call_cd().

◆ is_valid_argv_modes()

static bool is_valid_argv_modes ( RzCmdDesc cd,
char  last_letter 
)
static

Definition at line 283 of file cmd_api.c.

283  {
284  if (!cd || !has_cd_submodes(cd) || last_letter == '\0') {
285  return false;
286  }
287  char suffix[] = { last_letter, '\0' };
288  return cd->d.argv_modes_data.modes & suffix2mode(suffix);
289 }

References cd, has_cd_submodes(), suffix, and suffix2mode().

Referenced by cmd_get_desc_best().

◆ macro_call()

static int macro_call ( RzCmdMacro mac,
const char *  name,
bool  multiple 
)
static

Definition at line 1853 of file cmd_api.c.

1853  {
1854  char *args;
1855  int nargs = 0;
1856  char *str, *ptr, *ptr2;
1857  RzListIter *iter;
1858  static int macro_level = 0;
1859  RzCmdMacroItem *m;
1860  /* labels */
1861  int labels_n = 0;
1862  struct rz_cmd_macro_label_t labels[MACRO_LABELS];
1863 
1864  str = strdup(name);
1865  if (!str) {
1866  perror("strdup");
1867  return false;
1868  }
1869  ptr = strchr(str, ')');
1870  if (!ptr) {
1871  RZ_LOG_ERROR("Missing end ')' parenthesis.\n");
1872  free(str);
1873  return false;
1874  } else {
1875  *ptr = '\0';
1876  }
1877 
1878  args = strchr(str, ' ');
1879  if (args) {
1880  *args = '\0';
1881  args++;
1883  }
1884 
1885  macro_level++;
1886  if (macro_level > MACRO_LIMIT) {
1887  RZ_LOG_ERROR("Maximum macro recursivity reached.\n");
1888  macro_level--;
1889  free(str);
1890  return 0;
1891  }
1892  ptr = strchr(str, ';');
1893  if (ptr) {
1894  *ptr = 0;
1895  }
1896 
1898  rz_list_foreach (mac->macros, iter, m) {
1899  if (!strcmp(str, m->name)) {
1900  char *ptr = m->code;
1901  char *end = strchr(ptr, '\n');
1902  char *init_ptr = ptr;
1903  char *init_end = end;
1904  if ((m->nargs == 0 && nargs != m->nargs) ||
1905  (m->nargs != 0 &&
1906  ((multiple && (nargs % m->nargs != 0 || nargs == 0)) ||
1907  (!multiple && nargs != m->nargs)))) {
1908  if (!multiple || m->nargs == 0 || nargs == 0) {
1909  RZ_LOG_ERROR("Macro '%s' expects %d args, not %d\n", m->name, m->nargs, nargs);
1910  } else {
1911  RZ_LOG_ERROR("Macro '%s' expects %d args and %d is not a multiple of %d\n",
1912  m->name, m->nargs, nargs, m->nargs);
1913  }
1914  macro_level--;
1915  free(str);
1917  return false;
1918  }
1919  mac->brk = 0;
1920  int args_processed = 0;
1921  do {
1922  if (end) {
1923  *end = '\0';
1924  }
1925  if (rz_cons_is_breaked()) {
1926  RZ_LOG_ERROR("Interrupted at (%s)\n", ptr);
1927  if (end) {
1928  *end = '\n';
1929  }
1930  free(str);
1932  return false;
1933  }
1934  rz_cons_flush();
1935  /* Label handling */
1936  ptr2 = rz_cmd_macro_label_process(mac, &(labels[0]), &labels_n, ptr);
1937  if (!ptr2) {
1938  RZ_LOG_ERROR("Oops. invalid label name\n");
1939  break;
1940  } else if (ptr != ptr2) {
1941  ptr = ptr2;
1942  if (end) {
1943  *end = '\n';
1944  }
1945  end = strchr(ptr, '\n');
1946  continue;
1947  }
1948  /* Command execution */
1949  if (*ptr) {
1950  mac->num->value = value;
1951  int r = rz_cmd_macro_cmd_args(mac, ptr, args, nargs);
1952  // TODO: handle quit? r == 0??
1953  // quit, exits the macro. like a break
1954  value = mac->num->value;
1955  if (r < 0) {
1956  free(str);
1958  return r;
1959  }
1960  }
1961  if (end) {
1962  *end = '\n';
1963  ptr = end + 1;
1964  /* Fetch next command */
1965  end = strchr(ptr, '\n');
1966  } else {
1967  args_processed += m->nargs;
1968  if (!multiple || args_processed >= nargs) {
1969  macro_level--;
1970  free(str);
1971  goto out_clean;
1972  }
1973  args = (char *)rz_str_word_get0(args, m->nargs);
1974  ptr = init_ptr;
1975  end = init_end;
1976  }
1977  } while (!mac->brk);
1978  if (mac->brk) {
1979  macro_level--;
1980  free(str);
1981  goto out_clean;
1982  }
1983  }
1984  }
1985  RZ_LOG_ERROR("No macro named '%s'\n", str);
1986  macro_level--;
1987  free(str);
1988 out_clean:
1990  return true;
1991 }
RZ_API int rz_cmd_macro_cmd_args(RzCmdMacro *mac, const char *ptr, const char *args, int nargs)
Definition: cmd_api.c:1729
RZ_API char * rz_cmd_macro_label_process(RzCmdMacro *mac, RzCmdMacroLabel *labels, int *labels_n, char *ptr)
Definition: cmd_api.c:1780
static int value
Definition: cmd_api.c:93
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
#define r
Definition: crypto_rc6.c:12
#define MACRO_LIMIT
Definition: rz_cmd.h:16
#define MACRO_LABELS
Definition: rz_cmd.h:17
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
RzNum * num
Definition: rz_cmd.h:145
RzList * macros
Definition: rz_cmd.h:148
ut64 value
Definition: rz_num.h:63

References args, rz_cmd_macro_t::brk, test_evm::end, free(), regress::m, MACRO_LABELS, MACRO_LIMIT, rz_cmd_macro_t::macros, cmd_descs_generate::nargs, NULL, rz_cmd_macro_t::num, rz_cmd_macro_label_t::ptr, r, rz_cmd_macro_cmd_args(), rz_cmd_macro_label_process(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_flush(), rz_cons_is_breaked(), RZ_LOG_ERROR, rz_str_word_get0(), rz_str_word_set0(), cmd_descs_generate::str, strdup(), value, and rz_num_t::value.

Referenced by rz_cmd_macro_call(), and rz_cmd_macro_call_multiple().

◆ mode_cmd_desc_help()

static RzCmdDescHelp* mode_cmd_desc_help ( RzCmdDescHelp dst,
const RzCmdDescHelp src,
const char *  suffix 
)
static

Definition at line 2395 of file cmd_api.c.

2395  {
2396  dst->summary = rz_str_newf("%s%s", src->summary, suffix);
2397  dst->description = src->description;
2398  dst->args_str = src->args_str;
2399  dst->usage = src->usage;
2400  dst->options = src->options;
2401  dst->details = src->details;
2402  dst->args = src->args;
2403  return dst;
2404 }
lzma_index * src
Definition: index.h:567
char * dst
Definition: lz4.h:724

References dst, rz_str_newf(), src, and suffix.

Referenced by cmd_foreach_cmdname_modes().

◆ oldinput_get_help()

static char* oldinput_get_help ( RzCmd cmd,
RzCmdDesc cd,
RzCmdParsedArgs a 
)
static

Definition at line 1302 of file cmd_api.c.

1302  {
1303  if (!cmd->has_cons) {
1304  return NULL;
1305  }
1306 
1307  char *res = NULL;
1308  rz_cons_push();
1309  // rz_cons_push disables flushing, which is going to be a problem if a help menu is
1310  // displayed.
1311  rz_cons_set_flush(true);
1313  if (status == RZ_CMD_STATUS_OK) {
1314  rz_cons_filter();
1315  res = rz_cons_get_buffer_dup();
1316  }
1317  if (!res) {
1318  res = strdup("");
1319  }
1320  rz_cons_pop();
1321  return res;
1322 }
RZ_API RzCmdStatus rz_cmd_call_parsed_args(RzCmd *cmd, RzCmdParsedArgs *args)
Definition: cmd_api.c:794
RZ_API void rz_cons_filter(void)
Definition: cons.c:836
RZ_API RZ_OWN char * rz_cons_get_buffer_dup(void)
Return a newly allocated buffer containing what's currently in RzCons buffer.
Definition: cons.c:827
RZ_API void rz_cons_set_flush(bool flush)
Set whether RzCons should flush content to screen or not.
Definition: cons.c:2006
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145

References a, cmd, NULL, rz_cmd_call_parsed_args(), RZ_CMD_STATUS_OK, rz_cons_filter(), rz_cons_get_buffer_dup(), rz_cons_pop(), rz_cons_push(), rz_cons_set_flush(), status, and strdup().

Referenced by get_help().

◆ parsed_args_iterateargs()

static void parsed_args_iterateargs ( RzCmdParsedArgs a,
RzStrBuf sb 
)
static

Definition at line 2105 of file cmd_api.c.

2105  {
2106  int i;
2107  for (i = 1; i < a->argc; i++) {
2108  if (i > 1) {
2109  rz_strbuf_append(sb, " ");
2110  }
2111  rz_strbuf_append(sb, a->argv[i]);
2112  }
2113 }

References a, i, rz_strbuf_append(), and sb.

Referenced by rz_cmd_parsed_args_argstr(), and rz_cmd_parsed_args_execstr().

◆ print_child_help()

static void print_child_help ( RzCmd cmd,
RzStrBuf sb,
RzCmdDesc cd,
size_t  max_len,
bool  use_color 
)
static

Definition at line 1120 of file cmd_api.c.

1120  {
1121  do_print_child_help(cmd, sb, cd, cd->name, cd->help->summary ? cd->help->summary : "", true, max_len, use_color);
1122 }

References cd, cmd, do_print_child_help(), and sb.

Referenced by group_get_help().

◆ rz_cmd_add()

RZ_API int rz_cmd_add ( RzCmd c,
const char *  cmd,
RzCmdCb  cb 
)

Definition at line 528 of file cmd_api.c.

528  {
529  int idx = (ut8)cmd[0];
530  RzCmdItem *item = c->cmds[idx];
531  if (!item) {
532  item = RZ_NEW0(RzCmdItem);
533  c->cmds[idx] = item;
534  }
535  strncpy(item->cmd, cmd, sizeof(item->cmd) - 1);
536  item->callback = cb;
537  return true;
538 }
#define ut8
Definition: dcpu16.h:8
int idx
Definition: setup.py:197
#define c(i)
Definition: sha256.c:43
RzCmdCb callback
Definition: rz_cmd.h:153
char cmd[64]
Definition: rz_cmd.h:152

References c, rz_cmd_item_t::callback, cb, rz_cmd_item_t::cmd, cmd, setup::idx, RZ_NEW0, and ut8.

Referenced by rz_core_cmd_init().

◆ rz_cmd_alias_del()

RZ_API bool rz_cmd_alias_del ( RzCmd cmd,
const char *  k 
)

Definition at line 431 of file cmd_api.c.

431  {
432  int i; // find
433  for (i = 0; i < cmd->aliases.count; i++) {
434  if (!k || !strcmp(k, cmd->aliases.keys[i])) {
435  RZ_FREE(cmd->aliases.values[i]);
436  cmd->aliases.count--;
437  if (cmd->aliases.count > 0) {
438  if (i > 0) {
439  free(cmd->aliases.keys[i]);
440  cmd->aliases.keys[i] = cmd->aliases.keys[0];
441  free(cmd->aliases.values[i]);
442  cmd->aliases.values[i] = cmd->aliases.values[0];
443  }
444  memmove(cmd->aliases.values,
445  cmd->aliases.values + 1,
446  cmd->aliases.count * sizeof(void *));
447  memmove(cmd->aliases.keys,
448  cmd->aliases.keys + 1,
449  cmd->aliases.count * sizeof(void *));
450  }
451  return true;
452  }
453  }
454  return false;
455 }
const char * k
Definition: dsignal.c:11

References cmd, free(), i, k, and RZ_FREE.

Referenced by rz_cmd_alias().

◆ rz_cmd_alias_free()

RZ_API void rz_cmd_alias_free ( RzCmd cmd)

Definition at line 419 of file cmd_api.c.

419  {
420  int i; // find
421  for (i = 0; i < cmd->aliases.count; i++) {
422  free(cmd->aliases.keys[i]);
423  free(cmd->aliases.values[i]);
424  }
425  cmd->aliases.count = 0;
426  RZ_FREE(cmd->aliases.keys);
427  RZ_FREE(cmd->aliases.values);
428  free(cmd->aliases.remote);
429 }

References cmd, free(), i, and RZ_FREE.

Referenced by rz_cmd_free().

◆ rz_cmd_alias_get()

RZ_API char* rz_cmd_alias_get ( RzCmd cmd,
const char *  k,
int  remote 
)

Definition at line 501 of file cmd_api.c.

501  {
502  int matches, i;
503  if (!cmd || !k) {
504  return NULL;
505  }
506  for (i = 0; i < cmd->aliases.count; i++) {
507  matches = 0;
508  if (remote) {
509  if (cmd->aliases.remote[i]) {
510  matches = !strncmp(k, cmd->aliases.keys[i],
511  strlen(cmd->aliases.keys[i]));
512  }
513  } else {
514  matches = !strcmp(k, cmd->aliases.keys[i]);
515  }
516  if (matches) {
517  return cmd->aliases.values[i];
518  }
519  }
520  return NULL;
521 }

References cmd, i, k, and NULL.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), getFileData(), rz_cmd_alias(), rz_cmd_call(), rz_cmd_shell_cat_handler(), and rz_core_cmd_subst_i().

◆ rz_cmd_alias_init()

RZ_API void rz_cmd_alias_init ( RzCmd cmd)

Definition at line 184 of file cmd_api.c.

184  {
185  cmd->aliases.count = 0;
186  cmd->aliases.keys = NULL;
187  cmd->aliases.values = NULL;
188 }

References cmd, and NULL.

Referenced by rz_cmd_new().

◆ rz_cmd_alias_keys()

RZ_API char** rz_cmd_alias_keys ( RzCmd cmd,
int sz 
)

Definition at line 412 of file cmd_api.c.

412  {
413  if (sz) {
414  *sz = cmd->aliases.count;
415  }
416  return cmd->aliases.keys;
417 }

References cmd.

Referenced by autocomplete_minus(), and rz_cmd_alias().

◆ rz_cmd_alias_set()

RZ_API int rz_cmd_alias_set ( RzCmd cmd,
const char *  k,
const char *  v,
int  remote 
)

Definition at line 458 of file cmd_api.c.

458  {
459  void *tofree = NULL;
460  if (!strncmp(v, "base64:", 7)) {
461  ut8 *s = rz_base64_decode_dyn(v + 7, -1);
462  if (s) {
463  tofree = s;
464  v = (const char *)s;
465  }
466  }
467  int i;
468  for (i = 0; i < cmd->aliases.count; i++) {
469  int matches = !strcmp(k, cmd->aliases.keys[i]);
470  if (matches) {
471  free(cmd->aliases.values[i]);
472  cmd->aliases.values[i] = strdup(v);
473  free(tofree);
474  return 1;
475  }
476  }
477 
478  i = cmd->aliases.count++;
479  char **K = (char **)realloc(cmd->aliases.keys,
480  sizeof(char *) * cmd->aliases.count);
481  if (K) {
482  cmd->aliases.keys = K;
483  int *R = (int *)realloc(cmd->aliases.remote,
484  sizeof(int) * cmd->aliases.count);
485  if (R) {
486  cmd->aliases.remote = R;
487  char **V = (char **)realloc(cmd->aliases.values,
488  sizeof(char *) * cmd->aliases.count);
489  if (V) {
490  cmd->aliases.values = V;
491  cmd->aliases.keys[i] = strdup(k);
492  cmd->aliases.values[i] = strdup(v);
493  cmd->aliases.remote[i] = remote;
494  }
495  }
496  }
497  free(tofree);
498  return 0;
499 }
#define R(x, b, m)
Definition: arc.h:168
uint8_t ut8
Definition: lh5801.h:11
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65
#define V(handle, symbol)

References cmd, free(), i, k, NULL, R, realloc(), rz_base64_decode_dyn(), s, strdup(), v, and V.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_cmd_alias(), and rz_core_cmd_subst_i().

◆ rz_cmd_batch_end()

RZ_API void rz_cmd_batch_end ( RzCmd cmd)

Mark the end of the batched changes to RzCmd.

All groups are sorted, if necessary. Call rz_cmd_batch_start before using this function.

Definition at line 264 of file cmd_api.c.

264  {
265  cmd->batch = false;
267 }
static void sort_groups(RzCmdDesc *group)
Definition: cmd_api.c:244
RZ_API RzCmdDesc * rz_cmd_get_root(RzCmd *cmd)
Get the root command descriptor.
Definition: cmd_api.c:230

References cmd, rz_cmd_get_root(), and sort_groups().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_batch_start()

RZ_API void rz_cmd_batch_start ( RzCmd cmd)

Mark the start of the batched changes to RzCmd.

Commands added after this call won't be sorted until rz_cmd_batch_end is called.

Definition at line 240 of file cmd_api.c.

240  {
241  cmd->batch = true;
242 }

References cmd.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_call()

RZ_API int rz_cmd_call ( RzCmd cmd,
const char *  input 
)

Definition at line 546 of file cmd_api.c.

546  {
547  struct rz_cmd_item_t *c;
548  int ret = -1;
550  if (!*input) {
551  if (cmd->nullcallback) {
552  ret = cmd->nullcallback(cmd->data);
553  }
554  } else {
555  char *nstr = NULL;
556  const char *ji = rz_cmd_alias_get(cmd, input, 1);
557  if (ji) {
558  if (*ji == '$') {
559  rz_cons_strcat(ji + 1);
560  return true;
561  } else {
562  nstr = rz_str_newf("R! %s", input);
563  input = nstr;
564  }
565  }
566  if (!*input) {
567  free(nstr);
568  return -1;
569  }
570  c = cmd->cmds[((ut8)input[0]) & 0xff];
571  if (c && c->callback) {
572  const char *inp = (*input) ? input + 1 : "";
573  ret = c->callback(cmd->data, inp);
574  } else {
575  ret = -1;
576  }
577  free(nstr);
578  }
579  return ret;
580 }
RZ_API char * rz_cmd_alias_get(RzCmd *cmd, const char *k, int remote)
Definition: cmd_api.c:501
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References c, cmd, free(), input(), NULL, rz_cmd_alias_get(), rz_cons_strcat(), rz_return_val_if_fail, rz_str_newf(), and ut8.

Referenced by rz_core_cmd_subst_i().

◆ rz_cmd_call_parsed_args()

RZ_API RzCmdStatus rz_cmd_call_parsed_args ( RzCmd cmd,
RzCmdParsedArgs args 
)

Definition at line 794 of file cmd_api.c.

794  {
796  if (!cd) {
798  }
799 
800  return call_cd(cmd, cd, args);
801 }
RZ_API RzCmdDesc * rz_cmd_get_desc(RzCmd *cmd, const char *cmd_identifier)
Retrieve the command descriptor for the command named cmd_identifier.
Definition: cmd_api.c:372

References args, call_cd(), cd, cmd, rz_cmd_get_desc(), rz_cmd_parsed_args_cmd(), and RZ_CMD_STATUS_NONEXISTINGCMD.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), and oldinput_get_help().

◆ rz_cmd_del()

RZ_API int rz_cmd_del ( RzCmd cmd,
const char *  command 
)

Definition at line 540 of file cmd_api.c.

540  {
541  int idx = (ut8)command[0];
542  RZ_FREE(cmd->cmds[idx]);
543  return 0;
544 }
const char * command
Definition: main.c:7

References cmd, command, setup::idx, RZ_FREE, and ut8.

◆ rz_cmd_desc_argv_modes_new()

RZ_API RzCmdDesc* rz_cmd_desc_argv_modes_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvModesCb  cb,
const RzCmdDescHelp help 
)

Create a new command descriptor for a command that supports multiple output modes (e.g. rizin commands, json, csv, etc.).

Parameters
cmdreference to the RzCmd
parentParent command descriptor of the command being added
nameBase name of the command. New commands will be created with the proper suffix based on the supported modes
modesModes supported by the handler (see RzOutputMode). They can be put in OR to support multiple modes
cbCallback that actually executes the command
helpHelp structure used to describe the command when using ? and ??

Definition at line 2195 of file cmd_api.c.

2195  {
2196  rz_return_val_if_fail(cmd && parent && name && help && help->args && modes, NULL);
2197  return argv_modes_new(cmd, parent, name, modes, cb, help, true);
2198 }
static RzCmdDesc * argv_modes_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help, bool ht_insert)
Definition: cmd_api.c:2158

References argv_modes_new(), cb, cmd, cmd_descs_generate::help, NULL, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_argv_new()

RZ_API RzCmdDesc* rz_cmd_desc_argv_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
RzCmdArgvCb  cb,
const RzCmdDescHelp help 
)

Definition at line 2153 of file cmd_api.c.

2153  {
2154  rz_return_val_if_fail(cmd && parent && name && help && help->args, NULL);
2155  return argv_new(cmd, parent, name, cb, help, true);
2156 }
static RzCmdDesc * argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, bool ht_insert)
Definition: cmd_api.c:2142

References argv_new(), cb, cmd, cmd_descs_generate::help, NULL, and rz_return_val_if_fail.

Referenced by rz_cmd_example_init(), and rzshell_cmddescs_init().

◆ rz_cmd_desc_argv_state_new()

RZ_API RzCmdDesc* rz_cmd_desc_argv_state_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvStateCb  cb,
const RzCmdDescHelp help 
)

Create a new command descriptor for a command that supports multiple output modes (e.g. rizin commands, json, csv, etc.), where the state of the output is handled by RzCmd itself.

Parameters
cmdreference to the RzCmd
parentParent command descriptor of the command being added
nameBase name of the command. New commands will be created with the proper suffix based on the supported modes
modesModes supported by the handler (see RzOutputMode). They can be put in OR to support multiple modes
cbCallback that actually executes the command
helpHelp structure used to describe the command when using ? and ??

Definition at line 2212 of file cmd_api.c.

2212  {
2213  rz_return_val_if_fail(cmd && parent && name && help && help->args && modes, NULL);
2214  return argv_state_new(cmd, parent, name, modes, cb, help, true);
2215 }
static RzCmdDesc * argv_state_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help, bool ht_insert)
Definition: cmd_api.c:2171

References argv_state_new(), cb, cmd, cmd_descs_generate::help, NULL, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_details_free()

RZ_API void rz_cmd_desc_details_free ( RzCmdDescDetail details)

Free an array of RzCmdDescDetail sections.

Usually command handlers do not need to free the details sections because they are const, but due to details_cb those sections could be dynamically generated. In that case all the data within the details should be dynamically allocated memory, even the one marked as const, as they are going to be freed anyway.

Parameters
entriesPointer to the array of RzCmdDescDetails

Definition at line 2698 of file cmd_api.c.

2698  {
2699  RzCmdDescDetail *detail_it = details;
2700  while (detail_it->name) {
2701  free((char *)detail_it->name);
2702  RzCmdDescDetailEntry *oentry, *entry;
2703  oentry = entry = (RzCmdDescDetailEntry *)detail_it->entries;
2704  while (entry && entry->text) {
2705  free((char *)entry->text);
2706  free((char *)entry->comment);
2707  free((char *)entry->arg_str);
2708  entry++;
2709  }
2710  free(oentry);
2711  detail_it++;
2712  }
2713  free(details);
2714 }
while(len< limit &&buf1[len]==buf2[len])++len
Definition: zipcmp.c:77
const char * comment
Definition: zipcmp.c:84

References entry::comment, rz_cmd_desc_detail_t::entries, free(), rz_cmd_desc_detail_t::name, and while().

Referenced by fill_details_cb(), and rz_hash_bang_details_cb().

◆ rz_cmd_desc_fake_new()

RZ_API RzCmdDesc* rz_cmd_desc_fake_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
const RzCmdDescHelp help 
)

Definition at line 2326 of file cmd_api.c.

2326  {
2327  rz_return_val_if_fail(cmd && parent && name && help, NULL);
2328  return create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_FAKE, name, help, true);
2329 }

References cmd, create_cmd_desc(), cmd_descs_generate::help, NULL, RZ_CMD_DESC_TYPE_FAKE, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_get_arg()

RZ_API const RzCmdDescArg* rz_cmd_desc_get_arg ( RzCmd cmd,
const RzCmdDesc cd,
size_t  i 
)

Get a reference to the i-th argument of a command descriptor.

Get a reference to the i-th argument of a command. This function is useful to know which RzCmdDescArg an argument actually belongs to. In particular, it deals with arguments with special flags like RZ_CMD_ARG_FLAG_LAST or RZ_CMD_ARG_FLAG_ARRAY, where even if there is just one RzCmdDescArg, everything is considered as part of the same RzCmdDescArg.

Definition at line 2375 of file cmd_api.c.

2375  {
2376  const RzCmdDescArg *arg = cd->help->args;
2377  size_t j = 0;
2378  while (arg && arg->name) {
2379  if (arg->type == RZ_CMD_ARG_TYPE_FAKE) {
2380  arg++;
2381  continue;
2382  }
2383  if (i == j) {
2384  return arg;
2385  }
2386  if ((arg->flags & RZ_CMD_ARG_FLAG_LAST) || (arg->flags & RZ_CMD_ARG_FLAG_ARRAY)) {
2387  return arg;
2388  }
2389  arg++;
2390  j++;
2391  }
2392  return NULL;
2393 }

References arg(), cd, i, arg::name, NULL, RZ_CMD_ARG_FLAG_ARRAY, RZ_CMD_ARG_FLAG_LAST, and RZ_CMD_ARG_TYPE_FAKE.

Referenced by autocmplt_cmd_arg(), and fill_autocmplt_data_cmdarg().

◆ rz_cmd_desc_get_exec()

RZ_API RzCmdDesc* rz_cmd_desc_get_exec ( RzCmdDesc cd)

Definition at line 291 of file cmd_api.c.

291  {
292  if (!cd) {
293  return NULL;
294  }
295  switch (cd->type) {
297  return cd->d.group_data.exec_cd;
298  default:
299  return cd;
300  }
301 }

References cd, NULL, and RZ_CMD_DESC_TYPE_GROUP.

Referenced by cmd_get_desc_best(), fill_children_chars(), get_cd_from_cmdid(), and rz_cmd_desc_set_default_mode().

◆ rz_cmd_desc_group_modes_new()

RZ_API RzCmdDesc* rz_cmd_desc_group_modes_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvModesCb  cb,
const RzCmdDescHelp help,
const RzCmdDescHelp group_help 
)

Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well. The sub-command supports multiple output modes (e.g. rizin commands, json, csv, etc.).

Parameters
cmdreference to the RzCmd
parentParent command descriptor of the command being added
nameBase name of the group/sub-command. New commands will be created with the proper suffix based on the supported modes
modesModes supported by the handler (see RzOutputMode). They can be put in OR to support multiple modes
cbCallback that actually executes the command
helpHelp structure used to describe the command when using ? and ??
group_helpHelp structure used to describe the group

Definition at line 2268 of file cmd_api.c.

2268  {
2269  rz_return_val_if_fail(cmd && parent && name && group_help && modes && cb && help && help->args, NULL);
2270  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_GROUP, name, group_help, true);
2271  if (!res) {
2272  return NULL;
2273  }
2274 
2275  RzCmdDesc *exec_cd = argv_modes_new(cmd, res, name, modes, cb, help, false);
2276  if (!exec_cd) {
2277  rz_cmd_desc_remove(cmd, res);
2278  return NULL;
2279  }
2280 
2281  res->d.group_data.exec_cd = exec_cd;
2282  return res;
2283 }
RZ_API bool rz_cmd_desc_remove(RzCmd *cmd, RzCmdDesc *cd)
Definition: cmd_api.c:2356
struct rz_cmd_desc_t::@262::@265 group_data

References argv_modes_new(), cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, rz_cmd_desc_t::group_data, cmd_descs_generate::help, NULL, rz_cmd_desc_remove(), RZ_CMD_DESC_TYPE_GROUP, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_group_new()

RZ_API RzCmdDesc* rz_cmd_desc_group_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
RzCmdArgvCb  cb,
const RzCmdDescHelp help,
const RzCmdDescHelp group_help 
)

Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well.

Parameters
cmdreference to the RzCmd
parentParent command descriptor of the command being added
nameBase name of the group/sub-command.
cbCallback that actually executes the command
helpHelp structure used to describe the command when using ? and ??
group_helpHelp structure used to describe the group

Definition at line 2233 of file cmd_api.c.

2233  {
2234  rz_return_val_if_fail(cmd && parent && name && group_help, NULL);
2235  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_GROUP, name, group_help, true);
2236  if (!res) {
2237  return NULL;
2238  }
2239 
2240  RzCmdDesc *exec_cd = NULL;
2241  if (cb && help) {
2243  exec_cd = argv_new(cmd, res, name, cb, help, false);
2244  if (!exec_cd) {
2245  rz_cmd_desc_remove(cmd, res);
2246  return NULL;
2247  }
2248  }
2249 
2250  res->d.group_data.exec_cd = exec_cd;
2251  return res;
2252 }

References argv_new(), cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, rz_cmd_desc_t::group_data, cmd_descs_generate::help, NULL, rz_cmd_desc_remove(), RZ_CMD_DESC_TYPE_GROUP, and rz_return_val_if_fail.

Referenced by rz_cmd_dex_init_handler(), rz_cmd_java_init_handler(), and rzshell_cmddescs_init().

◆ rz_cmd_desc_group_state_new()

RZ_API RzCmdDesc* rz_cmd_desc_group_state_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
int  modes,
RzCmdArgvStateCb  cb,
const RzCmdDescHelp help,
const RzCmdDescHelp group_help 
)

Create a new command descriptor for a name that is used both as a group but that has a sub-command with the same name as well. The sub-command supports multiple output modes (e.g. rizin commands, json, csv, etc.), where the state of the output is handled by RzCmd itself.

Parameters
cmdreference to the RzCmd
parentParent command descriptor of the command being added
nameBase name of the group/sub-command. New commands will be created with the proper suffix based on the supported modes
modesModes supported by the handler (see RzOutputMode). They can be put in OR to support multiple modes
cbCallback that actually executes the command
helpHelp structure used to describe the command when using ? and ??
group_helpHelp structure used to describe the group

Definition at line 2299 of file cmd_api.c.

2299  {
2300  rz_return_val_if_fail(cmd && parent && name && group_help && modes && cb && help && help->args, NULL);
2301  RzCmdDesc *res = create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_GROUP, name, group_help, true);
2302  if (!res) {
2303  return NULL;
2304  }
2305 
2306  RzCmdDesc *exec_cd = argv_state_new(cmd, res, name, modes, cb, help, false);
2307  if (!exec_cd) {
2308  rz_cmd_desc_remove(cmd, res);
2309  return NULL;
2310  }
2311 
2312  res->d.group_data.exec_cd = exec_cd;
2313  return res;
2314 }

References argv_state_new(), cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, rz_cmd_desc_t::group_data, cmd_descs_generate::help, NULL, rz_cmd_desc_remove(), RZ_CMD_DESC_TYPE_GROUP, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_has_handler()

RZ_API bool rz_cmd_desc_has_handler ( const RzCmdDesc cd)

Definition at line 2336 of file cmd_api.c.

2336  {
2337  rz_return_val_if_fail(cd, false);
2338  switch (cd->type) {
2339  case RZ_CMD_DESC_TYPE_ARGV:
2340  return cd->d.argv_data.cb;
2342  return cd->d.argv_modes_data.cb;
2344  return cd->d.argv_state_data.cb;
2346  return cd->d.oldinput_data.cb;
2347  case RZ_CMD_DESC_TYPE_FAKE:
2349  return false;
2351  return cd->d.group_data.exec_cd && rz_cmd_desc_has_handler(cd->d.group_data.exec_cd);
2352  }
2353  return false;
2354 }

References cd, RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, RZ_CMD_DESC_TYPE_OLDINPUT, and rz_return_val_if_fail.

Referenced by argv_call_cb(), cmd_foreach_cmdname(), and fill_children_chars().

◆ rz_cmd_desc_inner_new()

RZ_API RzCmdDesc* rz_cmd_desc_inner_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
const RzCmdDescHelp help 
)

Definition at line 2217 of file cmd_api.c.

2217  {
2218  rz_return_val_if_fail(cmd && parent && name && help, NULL);
2219  return create_cmd_desc(cmd, parent, RZ_CMD_DESC_TYPE_INNER, name, help, false);
2220 }

References cmd, create_cmd_desc(), cmd_descs_generate::help, NULL, RZ_CMD_DESC_TYPE_INNER, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_oldinput_new()

RZ_API RzCmdDesc* rz_cmd_desc_oldinput_new ( RzCmd cmd,
RzCmdDesc parent,
const char *  name,
RzCmdCb  cb,
const RzCmdDescHelp help 
)

Definition at line 2316 of file cmd_api.c.

2316  {
2317  rz_return_val_if_fail(cmd && parent && name && cb, NULL);
2319  if (!res) {
2320  return NULL;
2321  }
2322  res->d.oldinput_data.cb = cb;
2323  return res;
2324 }
struct rz_cmd_desc_t::@262::@263 oldinput_data

References cb, cmd, create_cmd_desc(), rz_cmd_desc_t::d, cmd_descs_generate::help, NULL, rz_cmd_desc_t::oldinput_data, RZ_CMD_DESC_TYPE_OLDINPUT, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_desc_parent()

RZ_API RzCmdDesc* rz_cmd_desc_parent ( RzCmdDesc cd)

Definition at line 2331 of file cmd_api.c.

2331  {
2333  return cd->parent;
2334 }

References cd, NULL, and rz_return_val_if_fail.

◆ rz_cmd_desc_remove()

RZ_API bool rz_cmd_desc_remove ( RzCmd cmd,
RzCmdDesc cd 
)

Definition at line 2356 of file cmd_api.c.

2356  {
2357  rz_return_val_if_fail(cmd && cd, false);
2358  if (cd->parent) {
2360  }
2362  cmd_desc_free(cd);
2363  return true;
2364 }
static void cmd_desc_unset_parent(RzCmdDesc *cd)
Definition: cmd_api.c:133

References cd, cmd, cmd_desc_free(), cmd_desc_remove_from_ht_cmds(), cmd_desc_unset_parent(), and rz_return_val_if_fail.

Referenced by rz_cmd_desc_group_modes_new(), rz_cmd_desc_group_new(), and rz_cmd_desc_group_state_new().

◆ rz_cmd_desc_set_default_mode()

RZ_API bool rz_cmd_desc_set_default_mode ( RzCmdDesc cd,
RzOutputMode  mode 
)

Set the default mode of the command descriptor, if the type allows it.

Command descriptors that support multiple output modes can also have a default one. This function can be used to set it.

Returns
True if the default output mode was changed, false otherwise.

Definition at line 384 of file cmd_api.c.

384  {
385  rz_return_val_if_fail(cd, false);
386 
387  switch (cd->type) {
389  if (cd->d.argv_modes_data.modes & RZ_OUTPUT_MODE_STANDARD) {
390  return false;
391  }
392  cd->d.argv_modes_data.default_mode = mode;
393  return true;
395  if (cd->d.argv_state_data.modes & RZ_OUTPUT_MODE_STANDARD) {
396  return false;
397  }
398  cd->d.argv_state_data.default_mode = mode;
399  return true;
400  case RZ_CMD_DESC_TYPE_GROUP: {
401  RzCmdDesc *exec_cd = rz_cmd_desc_get_exec(cd);
402  if (exec_cd) {
403  return rz_cmd_desc_set_default_mode(exec_cd, mode);
404  }
405  return false;
406  }
407  default:
408  return false;
409  }
410 }
RZ_API bool rz_cmd_desc_set_default_mode(RzCmdDesc *cd, RzOutputMode mode)
Set the default mode of the command descriptor, if the type allows it.
Definition: cmd_api.c:384

References cd, rz_cmd_desc_get_exec(), RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_GROUP, RZ_OUTPUT_MODE_STANDARD, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_escape_arg()

RZ_API char* rz_cmd_escape_arg ( const char *  arg,
RzCmdEscape  esc 
)

Returns an heap-allocated string with special characters considered by the rizin grammar as special characters escaped. Use this when you need to escape a string that should appear as argument of a command.

Definition at line 2516 of file cmd_api.c.

2516  {
2517  switch (esc) {
2518  case RZ_CMD_ESCAPE_ONE_ARG:
2526  case RZ_CMD_ESCAPE_PF_ARG:
2528  }
2530 }
static const char * SPECIAL_CHARS_SINGLE_QUOTED
Definition: cmd_api.c:43
static char * escape_special_chars(const char *s, const char *special_chars)
Definition: cmd_api.c:2479
static const char * SPECIAL_CHARS_DOUBLE_QUOTED
Definition: cmd_api.c:42
static const char * SPECIAL_CHARS_REGULAR_SINGLE
Definition: cmd_api.c:40
static const char * SPECIAL_CHARS_REGULAR
Definition: cmd_api.c:39
static const char * SPECIAL_CHARS_PF
Definition: cmd_api.c:41
#define rz_return_val_if_reached(val)
Definition: rz_assert.h:122
@ RZ_CMD_ESCAPE_MULTI_ARG
The string should be escaped so that it appears as one or multiple arguments.
Definition: rz_cmd.h:80
@ RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in '....'.
Definition: rz_cmd.h:83
@ RZ_CMD_ESCAPE_PF_ARG
The string should be escaped so that it appears as one or multiple pf arguments.
Definition: rz_cmd.h:81
@ RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in "....".
Definition: rz_cmd.h:82

References escape_special_chars(), RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG, RZ_CMD_ESCAPE_MULTI_ARG, RZ_CMD_ESCAPE_ONE_ARG, RZ_CMD_ESCAPE_PF_ARG, RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG, rz_return_val_if_reached, SPECIAL_CHARS_DOUBLE_QUOTED, SPECIAL_CHARS_PF, SPECIAL_CHARS_REGULAR, SPECIAL_CHARS_REGULAR_SINGLE, SPECIAL_CHARS_SINGLE_QUOTED, and strdup().

Referenced by args_preprocessing(), config_print_node(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), handle_cmd_substitution_arg(), and rz_reopen_debug_handler().

◆ rz_cmd_foreach_cmdname()

RZ_API void rz_cmd_foreach_cmdname ( RzCmd cmd,
RzCmdDesc begin,
RzCmdForeachNameCb  cb,
void *  user 
)

Execute a callback function on each possible command the user can execute.

Only command names that can actually execute something are iterated. Help commands (e.g. ?, h?, etc.) are ignored.

Parameters
cmdReference to RzCmd
beginReference to RzCmdDesc from where to begin the for loop; if NULL the root will be used.
cbCallback function that is called for each command name.
userAdditional user data that is passed to the callback cb.

Definition at line 2474 of file cmd_api.c.

2474  {
2475  RzCmdDesc *cd = begin ? begin : rz_cmd_get_root(cmd);
2476  cmd_foreach_cmdname(cmd, cd, cb, user);
2477 }

References cb, cd, cmd, cmd_foreach_cmdname(), and rz_cmd_get_root().

Referenced by autocmplt_cmdidentifier(), and rz_cmd_help_search_handler().

◆ rz_cmd_free()

RZ_API RzCmd* rz_cmd_free ( RzCmd cmd)

Definition at line 208 of file cmd_api.c.

208  {
209  int i;
210  if (!cmd) {
211  return NULL;
212  }
213  ht_up_free(cmd->ts_symbols_ht);
215  rz_cmd_macro_fini(&cmd->macro);
216  ht_pp_free(cmd->ht_cmds);
217  for (i = 0; i < NCMDS; i++) {
218  if (cmd->cmds[i]) {
219  RZ_FREE(cmd->cmds[i]);
220  }
221  }
222  cmd_desc_free(cmd->root_cmd_desc);
223  free(cmd);
224  return NULL;
225 }
RZ_API void rz_cmd_alias_free(RzCmd *cmd)
Definition: cmd_api.c:419
RZ_API void rz_cmd_macro_fini(RzCmdMacro *mac)
Definition: cmd_api.c:1551
#define NCMDS
Definition: cmd_api.c:95

References cmd, cmd_desc_free(), free(), i, NCMDS, NULL, rz_cmd_alias_free(), rz_cmd_macro_fini(), and RZ_FREE.

Referenced by rz_core_fini().

◆ rz_cmd_get_desc()

RZ_API RzCmdDesc* rz_cmd_get_desc ( RzCmd cmd,
const char *  cmd_identifier 
)

Retrieve the command descriptor for the command named cmd_identifier.

Check if there is a command with exactly the name cmd_identifier.

If there isn't, it removes one letter at a time to be compatible with radare2 behaviour until all commands are converted to rzshell. This best-matching works only to find OLDINPUT command references.

Parameters
cmdReference to RzCmd instance
cmd_identifierName of the command to search
Returns
RzCmdDesc reference or NULL if not found

Definition at line 372 of file cmd_api.c.

372  {
373  return cmd_get_desc_best(cmd, cmd_identifier, false);
374 }
static RzCmdDesc * cmd_get_desc_best(RzCmd *cmd, const char *cmd_identifier, bool best_match)
Definition: cmd_api.c:303

References cmd, and cmd_get_desc_best().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), get_cd_from_cmdid(), rz_cmd_call_parsed_args(), rz_cmd_get_help(), and rz_cmd_help_search_handler().

◆ rz_cmd_get_desc_best()

RZ_API RzCmdDesc* rz_cmd_get_desc_best ( RzCmd cmd,
const char *  cmd_identifier 
)

Retrieve the command descriptor that best matches the name cmd_identifier.

Check if there is a command with exactly the name cmd_identifier. If there isn't, it tries to find the best matching one (right now by by removing one letter at a time, but this matching algorithm may be improved later).

Parameters
cmdReference to RzCmd instance
cmd_identifierName of the command to search
Returns
RzCmdDesc reference or NULL if not found

Definition at line 355 of file cmd_api.c.

355  {
356  return cmd_get_desc_best(cmd, cmd_identifier, true);
357 }

References cmd, and cmd_get_desc_best().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL().

◆ rz_cmd_get_help()

RZ_API char* rz_cmd_get_help ( RzCmd cmd,
RzCmdParsedArgs args,
bool  use_color 
)

Definition at line 1494 of file cmd_api.c.

1494  {
1495  char *cmdid = strdup(rz_cmd_parsed_args_cmd(args));
1496  if (!cmdid) {
1497  return NULL;
1498  }
1499  char *cmdid_p = cmdid + strlen(cmdid) - 1;
1500  size_t detail = 0;
1501  while (cmdid_p >= cmdid && *cmdid_p == '?' && detail < 2) {
1502  *cmdid_p = '\0';
1503  cmdid_p--;
1504  detail++;
1505  }
1506 
1507  char *res = NULL;
1508  if (detail == 0) {
1509  // there should be at least one `?`
1510  goto err;
1511  }
1512 
1513  RzCmdDesc *cd = cmdid_p >= cmdid ? rz_cmd_get_desc(cmd, cmdid) : rz_cmd_get_root(cmd);
1514  if (!cd || !cd->help) {
1515  goto err;
1516  }
1517 
1518  res = get_help(cmd, cd, cmdid, args, use_color, detail);
1519 err:
1520  free(cmdid);
1521  return res;
1522 }

References args, cd, cmd, err, free(), get_help(), NULL, rz_cmd_get_desc(), rz_cmd_get_root(), rz_cmd_parsed_args_cmd(), and strdup().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), and get_help_wrong_cmd().

◆ rz_cmd_get_help_json()

RZ_API bool rz_cmd_get_help_json ( RzCmd cmd,
const RzCmdDesc cd,
PJ j 
)

Generates a JSON output of the given help message description.

Parameters
cmdreference to RzCmd
cdreference to RzCmdDesc
jreference to PJ
Returns
returns false if an invalid argument was given, otherwise true.

Definition at line 1439 of file cmd_api.c.

1439  {
1440  rz_return_val_if_fail(cmd && cd && j, false);
1441  pj_ko(j, cd->name);
1442  pj_ks(j, "cmd", cd->name);
1443  const char *type;
1444  switch (cd->type) {
1445 #define CASE_CDTYPE(x, y) \
1446  case (x): \
1447  type = (y); \
1448  break
1456 #undef CASE_CDTYPE
1457  default:
1458  type = "unknown";
1459  break;
1460  }
1461  pj_ks(j, "type", type);
1462  if (cd->help->args_str) {
1463  pj_ks(j, "args_str", cd->help->args_str);
1464  } else {
1466  fill_args(sb, cd);
1467  char *args = rz_strbuf_drain(sb);
1468  pj_ks(j, "args_str", args);
1469  free(args);
1470  }
1471  fill_args_json(cmd, cd, j);
1472  pj_ks(j, "description", cd->help->description ? cd->help->description : "");
1473  pj_ks(j, "summary", cd->help->summary ? cd->help->summary : "");
1474  pj_end(j);
1475  return true;
1476 }
static void fill_args_json(const RzCmd *cmd, const RzCmdDesc *cd, PJ *j)
Definition: cmd_api.c:1353
#define CASE_CDTYPE(x, y)
RZ_API PJ * pj_ko(PJ *j, const char *k)
Definition: pj.c:156

References args, CASE_CDTYPE, cd, cmd, fill_args(), fill_args_json(), free(), NULL, pj_end(), pj_ko(), pj_ks(), RZ_CMD_DESC_TYPE_ARGV, RZ_CMD_DESC_TYPE_ARGV_MODES, RZ_CMD_DESC_TYPE_ARGV_STATE, RZ_CMD_DESC_TYPE_FAKE, RZ_CMD_DESC_TYPE_GROUP, RZ_CMD_DESC_TYPE_INNER, RZ_CMD_DESC_TYPE_OLDINPUT, rz_return_val_if_fail, rz_strbuf_drain(), rz_strbuf_new(), sb, and type.

Referenced by help_search_cmd_desc_entry().

◆ rz_cmd_get_help_strbuf()

RZ_API bool rz_cmd_get_help_strbuf ( RzCmd cmd,
const RzCmdDesc cd,
bool  use_color,
RzStrBuf sb 
)

Generates a text output of the given help message description (summary format)

Parameters
cmdreference to RzCmd
cdreference to RzCmdDesc
use_coloroutput strings with color codes.
sbreference to RzStrBuf
Returns
returns false if an invalid argument was given, otherwise true.

Definition at line 1488 of file cmd_api.c.

1488  {
1489  rz_return_val_if_fail(cmd && cd && sb, false);
1490  do_print_child_help(cmd, sb, cd, cd->name, cd->help->summary, false, MAX_RIGHT_ALIGHNMENT, use_color);
1491  return true;
1492 }

References cd, cmd, do_print_child_help(), MAX_RIGHT_ALIGHNMENT, rz_return_val_if_fail, and sb.

Referenced by help_search_cmd_desc_entry().

◆ rz_cmd_get_root()

RZ_API RzCmdDesc* rz_cmd_get_root ( RzCmd cmd)

Get the root command descriptor.

Definition at line 230 of file cmd_api.c.

230  {
231  return cmd->root_cmd_desc;
232 }

References cmd.

Referenced by rz_cmd_batch_end(), rz_cmd_dex_init_handler(), rz_cmd_example_init(), rz_cmd_foreach_cmdname(), rz_cmd_get_help(), rz_cmd_java_init_handler(), and rzshell_cmddescs_init().

◆ rz_cmd_macro_add()

RZ_API int rz_cmd_macro_add ( RzCmdMacro mac,
const char *  oname 
)

Definition at line 1558 of file cmd_api.c.

1558  {
1559  struct rz_cmd_macro_item_t *macro;
1560  char *name, *args = NULL;
1561  // char buf[RZ_CMD_MAXLEN];
1562  RzCmdMacroItem *m;
1563  int macro_update;
1564  RzListIter *iter;
1565  char *pbody;
1566  // char *bufp;
1567  char *ptr;
1568  int lidx;
1569 
1570  if (!*oname) {
1571  rz_cmd_macro_list(mac);
1572  return 0;
1573  }
1574 
1575  name = strdup(oname);
1576  if (!name) {
1577  perror("strdup");
1578  return 0;
1579  }
1580 
1581  pbody = strchr(name, ';');
1582  if (!pbody) {
1583  eprintf("Invalid macro body\n");
1584  free(name);
1585  return false;
1586  }
1587  *pbody = '\0';
1588  pbody++;
1589 
1590  if (*name && name[1] && name[strlen(name) - 1] == ')') {
1591  eprintf("rz_cmd_macro_add: missing macro body?\n");
1592  free(name);
1593  return -1;
1594  }
1595 
1596  macro = NULL;
1597  ptr = strchr(name, ' ');
1598  if (ptr) {
1599  *ptr = '\0';
1600  args = ptr + 1;
1601  }
1602  macro_update = 0;
1603  rz_list_foreach (mac->macros, iter, m) {
1604  if (!strcmp(name, m->name)) {
1605  macro = m;
1606  free(macro->name);
1607  free(macro->code);
1608  free(macro->args);
1609  macro_update = 1;
1610  break;
1611  }
1612  }
1613  if (ptr) {
1614  *ptr = ' ';
1615  }
1616  if (!macro) {
1618  if (!macro) {
1619  free(name);
1620  return 0;
1621  }
1622  }
1623 
1624  macro->name = strdup(name);
1625  macro->codelen = (pbody[0]) ? strlen(pbody) + 2 : 4096;
1626  macro->code = (char *)malloc(macro->codelen);
1627  *macro->code = '\0';
1628  macro->nargs = 0;
1629  if (!args) {
1630  args = "";
1631  }
1632  macro->args = strdup(args);
1633  ptr = strchr(macro->name, ' ');
1634  if (ptr != NULL) {
1635  *ptr = '\0';
1636  macro->nargs = rz_str_word_set0(ptr + 1);
1637  }
1638 
1639  for (lidx = 0; pbody[lidx]; lidx++) {
1640  if (pbody[lidx] == ';') {
1641  pbody[lidx] = '\n';
1642  } else if (pbody[lidx] == ')' && pbody[lidx - 1] == '\n') {
1643  pbody[lidx] = '\0';
1644  }
1645  }
1646  strncpy(macro->code, pbody, macro->codelen);
1647  macro->code[macro->codelen - 1] = 0;
1648  if (macro_update == 0) {
1649  rz_list_append(mac->macros, macro);
1650  }
1651  free(name);
1652  return 0;
1653 }
RZ_API RzCmdMacroItem * rz_cmd_macro_item_new(void)
Definition: cmd_api.c:1526
RZ_API void rz_cmd_macro_list(RzCmdMacro *mac)
Definition: cmd_api.c:1680
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
void * malloc(size_t size)
Definition: malloc.c:123
#define eprintf(x, y...)
Definition: rlcc.c:7
Definition: z80asm.h:130
char * name
Definition: z80asm.h:132
char ** args
Definition: z80asm.h:134

References args, macro::args, eprintf, free(), regress::m, rz_cmd_macro_t::macros, malloc(), name, macro::name, NULL, rz_cmd_macro_item_new(), rz_cmd_macro_list(), rz_list_append(), rz_str_word_set0(), and strdup().

Referenced by rz_cmd_macro().

◆ rz_cmd_macro_break()

RZ_API int rz_cmd_macro_break ( RzCmdMacro mac,
const char *  value 
)

Definition at line 2001 of file cmd_api.c.

2001  {
2002  mac->brk = 1;
2003  mac->brk_value = NULL;
2004  mac->_brk_value = (ut64)rz_num_math(mac->num, value);
2005  if (value && *value) {
2006  mac->brk_value = &mac->_brk_value;
2007  }
2008  return 0;
2009 }
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
ut64 _brk_value
Definition: rz_cmd.h:139
ut64 * brk_value
Definition: rz_cmd.h:138
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_cmd_macro_t::_brk_value, rz_cmd_macro_t::brk, rz_cmd_macro_t::brk_value, NULL, rz_cmd_macro_t::num, rz_num_math(), ut64(), and value.

Referenced by rz_cmd_macro().

◆ rz_cmd_macro_call()

RZ_API int rz_cmd_macro_call ( RzCmdMacro mac,
const char *  name 
)

Definition at line 1993 of file cmd_api.c.

1993  {
1994  return macro_call(mac, name, false);
1995 }
static int macro_call(RzCmdMacro *mac, const char *name, bool multiple)
Definition: cmd_api.c:1853

References macro_call().

Referenced by rz_cmd_macro(), rz_core_cmd_foreach(), and rz_interpret_macro_handler().

◆ rz_cmd_macro_call_multiple()

RZ_API int rz_cmd_macro_call_multiple ( RzCmdMacro mac,
const char *  name 
)

Definition at line 1997 of file cmd_api.c.

1997  {
1998  return macro_call(mac, name, true);
1999 }

References macro_call().

Referenced by rz_interpret_macro_multiple_handler().

◆ rz_cmd_macro_cmd_args()

RZ_API int rz_cmd_macro_cmd_args ( RzCmdMacro mac,
const char *  ptr,
const char *  args,
int  nargs 
)

Definition at line 1729 of file cmd_api.c.

1729  {
1730  int i, j;
1731  char *pcmd, cmd[RZ_CMD_MAXLEN];
1732  const char *arg = args;
1733 
1734  for (*cmd = i = j = 0; j < RZ_CMD_MAXLEN && ptr[j]; i++, j++) {
1735  if (ptr[j] == '$') {
1736  if (ptr[j + 1] >= '0' && ptr[j + 1] <= '9') {
1737  int wordlen;
1738  int w = ptr[j + 1] - '0';
1739  const char *word = rz_str_word_get0(arg, w);
1740  if (word && *word) {
1741  wordlen = strlen(word);
1742  if ((i + wordlen + 1) >= sizeof(cmd)) {
1743  return -1;
1744  }
1745  memcpy(cmd + i, word, wordlen + 1);
1746  i += wordlen - 1;
1747  j++;
1748  } else {
1749  eprintf("Undefined argument %d\n", w);
1750  }
1751  } else if (ptr[j + 1] == '@') {
1752  char off[32];
1753  int offlen;
1754  offlen = snprintf(off, sizeof(off), "%d",
1755  mac->counter);
1756  if ((i + offlen + 1) >= sizeof(cmd)) {
1757  return -1;
1758  }
1759  memcpy(cmd + i, off, offlen + 1);
1760  i += offlen - 1;
1761  j++;
1762  } else {
1763  cmd[i] = ptr[j];
1764  cmd[i + 1] = '\0';
1765  }
1766  } else {
1767  cmd[i] = ptr[j];
1768  cmd[i + 1] = '\0';
1769  }
1770  }
1771  for (pcmd = cmd; *pcmd && (*pcmd == ' ' || *pcmd == '\t'); pcmd++) {
1772  ;
1773  }
1774  // eprintf ("-pre %d\n", (int)mac->num->value);
1775  int xx = (*pcmd == ')') ? 0 : mac->cmd(mac->user, pcmd);
1776  // eprintf ("-pos %p %d\n", mac->num, (int)mac->num->value);
1777  return xx;
1778 }
#define w
Definition: crypto_rc6.c:13
snprintf
Definition: kernel.h:364
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int off
Definition: pal.c:13
#define RZ_CMD_MAXLEN
Definition: rz_cmd.h:18
RzCoreCmd cmd
Definition: rz_cmd.h:142
void * user
Definition: rz_cmd.h:144

References args, rz_cmd_macro_t::cmd, cmd, rz_cmd_macro_t::counter, eprintf, i, memcpy(), off, RZ_CMD_MAXLEN, rz_str_word_get0(), snprintf, rz_cmd_macro_t::user, and w.

Referenced by macro_call().

◆ rz_cmd_macro_fini()

RZ_API void rz_cmd_macro_fini ( RzCmdMacro mac)

Definition at line 1551 of file cmd_api.c.

1551  {
1552  rz_list_free(mac->macros);
1553  mac->macros = NULL;
1554 }

References rz_cmd_macro_t::macros, NULL, and rz_list_free().

Referenced by rz_cmd_free().

◆ rz_cmd_macro_init()

RZ_API void rz_cmd_macro_init ( RzCmdMacro mac)

Definition at line 1540 of file cmd_api.c.

1540  {
1541  mac->counter = 0;
1542  mac->_brk_value = 0;
1543  mac->brk_value = &mac->_brk_value;
1544  mac->cb_printf = (void *)printf;
1545  mac->num = NULL;
1546  mac->user = NULL;
1547  mac->cmd = NULL;
1549 }
RZ_API void rz_cmd_macro_item_free(RzCmdMacroItem *item)
Definition: cmd_api.c:1530
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
PrintfCallback cb_printf
Definition: rz_cmd.h:143

References rz_cmd_macro_t::_brk_value, rz_cmd_macro_t::brk_value, rz_cmd_macro_t::cb_printf, rz_cmd_macro_t::cmd, rz_cmd_macro_t::counter, rz_cmd_macro_t::macros, NULL, rz_cmd_macro_t::num, printf(), rz_cmd_macro_item_free(), rz_list_newf(), and rz_cmd_macro_t::user.

Referenced by rz_cmd_new().

◆ rz_cmd_macro_item_free()

RZ_API void rz_cmd_macro_item_free ( RzCmdMacroItem item)

Definition at line 1530 of file cmd_api.c.

1530  {
1531  if (!item) {
1532  return;
1533  }
1534  free(item->name);
1535  free(item->args);
1536  free(item->code);
1537  free(item);
1538 }

References rz_cmd_macro_item_t::args, rz_cmd_macro_item_t::code, free(), and rz_cmd_macro_item_t::name.

Referenced by rz_cmd_macro_init().

◆ rz_cmd_macro_item_new()

RZ_API RzCmdMacroItem* rz_cmd_macro_item_new ( void  )

macro.c

Definition at line 1526 of file cmd_api.c.

1526  {
1527  return RZ_NEW0(RzCmdMacroItem);
1528 }

References RZ_NEW0.

Referenced by rz_cmd_macro_add().

◆ rz_cmd_macro_label_process()

RZ_API char* rz_cmd_macro_label_process ( RzCmdMacro mac,
RzCmdMacroLabel labels,
int labels_n,
char *  ptr 
)

Definition at line 1780 of file cmd_api.c.

1780  {
1781  int i;
1782  for (; *ptr == ' '; ptr++) {
1783  ;
1784  }
1785  if (ptr[strlen(ptr) - 1] == ':' && !strchr(ptr, ' ')) {
1786  /* label detected */
1787  if (ptr[0] == '.') {
1788  // eprintf("---> GOTO '%s'\n", ptr+1);
1789  /* goto */
1790  for (i = 0; i < *labels_n; i++) {
1791  // eprintf("---| chk '%s'\n", labels[i].name);
1792  if (!strcmp(ptr + 1, labels[i].name)) {
1793  return labels[i].ptr;
1794  }
1795  }
1796  return NULL;
1797  } else
1798  /* conditional goto */
1799  if (ptr[0] == '?' && ptr[1] == '!' && ptr[2] != '?') {
1800  if (mac->num && mac->num->value != 0) {
1801  char *label = ptr + 3;
1802  for (; *label == ' ' || *label == '.'; label++) {
1803  ;
1804  }
1805  // eprintf("===> GOTO %s\n", label);
1806  /* goto label ptr+3 */
1807  for (i = 0; i < *labels_n; i++) {
1808  if (!strcmp(label, labels[i].name)) {
1809  return labels[i].ptr;
1810  }
1811  }
1812  return NULL;
1813  }
1814  } else
1815  /* conditional goto */
1816  if (ptr[0] == '?' && ptr[1] == '?' && ptr[2] != '?') {
1817  if (mac->num->value == 0) {
1818  char *label = ptr + 3;
1819  for (; label[0] == ' ' || label[0] == '.'; label++) {
1820  ;
1821  }
1822  // eprintf("===> GOTO %s\n", label);
1823  /* goto label ptr+3 */
1824  for (i = 0; i < *labels_n; i++) {
1825  if (!strcmp(label, labels[i].name)) {
1826  return labels[i].ptr;
1827  }
1828  }
1829  return NULL;
1830  }
1831  } else {
1832  for (i = 0; i < *labels_n; i++) {
1833  // eprintf("---| chk '%s'\n", labels[i].name);
1834  if (!strcmp(ptr + 1, labels[i].name)) {
1835  i = 0;
1836  break;
1837  }
1838  }
1839  /* Add label */
1840  // eprintf("===> ADD LABEL(%s)\n", ptr);
1841  if (i == 0) {
1842  strncpy(labels[*labels_n].name, ptr, 64);
1843  labels[*labels_n].ptr = ptr + strlen(ptr) + 1;
1844  *labels_n = *labels_n + 1;
1845  }
1846  }
1847  return ptr + strlen(ptr) + 1;
1848  }
1849  return ptr;
1850 }
Definition: dis.h:35

References i, NULL, rz_cmd_macro_t::num, rz_cmd_macro_label_t::ptr, and rz_num_t::value.

Referenced by macro_call().

◆ rz_cmd_macro_list()

RZ_API void rz_cmd_macro_list ( RzCmdMacro mac)

Definition at line 1680 of file cmd_api.c.

1680  {
1681  RzCmdMacroItem *m;
1682  int j, idx = 0;
1683  RzListIter *iter;
1684  rz_list_foreach (mac->macros, iter, m) {
1685  mac->cb_printf("%d (%s %s; ", idx, m->name, m->args);
1686  for (j = 0; m->code[j]; j++) {
1687  if (m->code[j] == '\n') {
1688  mac->cb_printf("; ");
1689  } else {
1690  mac->cb_printf("%c", m->code[j]);
1691  }
1692  }
1693  mac->cb_printf(")\n");
1694  idx++;
1695  }
1696 }

References rz_cmd_macro_t::cb_printf, setup::idx, regress::m, and rz_cmd_macro_t::macros.

Referenced by rz_cmd_macro(), and rz_cmd_macro_add().

◆ rz_cmd_macro_meta()

RZ_API void rz_cmd_macro_meta ( RzCmdMacro mac)

Definition at line 1699 of file cmd_api.c.

1699  {
1700  RzCmdMacroItem *m;
1701  int j;
1702  RzListIter *iter;
1703  rz_list_foreach (mac->macros, iter, m) {
1704  mac->cb_printf("(%s %s, ", m->name, m->args);
1705  for (j = 0; m->code[j]; j++) {
1706  if (m->code[j] == '\n') {
1707  mac->cb_printf("; ");
1708  } else {
1709  mac->cb_printf("%c", m->code[j]);
1710  }
1711  }
1712  mac->cb_printf(")\n");
1713  }
1714 }

References rz_cmd_macro_t::cb_printf, regress::m, and rz_cmd_macro_t::macros.

Referenced by rz_cmd_macro().

◆ rz_cmd_macro_rm()

RZ_API int rz_cmd_macro_rm ( RzCmdMacro mac,
const char *  _name 
)

Definition at line 1655 of file cmd_api.c.

1655  {
1656  RzListIter *iter;
1657  RzCmdMacroItem *m;
1658  char *name = strdup(_name);
1659  if (!name) {
1660  return false;
1661  }
1662  char *ptr = strchr(name, ')');
1663  if (ptr) {
1664  *ptr = '\0';
1665  }
1666  bool ret = false;
1667  rz_list_foreach (mac->macros, iter, m) {
1668  if (!strcmp(m->name, name)) {
1669  rz_list_delete(mac->macros, iter);
1670  eprintf("Macro '%s' removed.\n", name);
1671  ret = true;
1672  break;
1673  }
1674  }
1675  free(name);
1676  return ret;
1677 }
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162

References eprintf, free(), regress::m, rz_cmd_macro_t::macros, rz_list_delete(), and strdup().

Referenced by rz_cmd_macro().

◆ rz_cmd_new()

RZ_API RzCmd* rz_cmd_new ( bool  has_cons)

Definition at line 190 of file cmd_api.c.

190  {
191  int i;
192  RzCmd *cmd = RZ_NEW0(RzCmd);
193  if (!cmd) {
194  return cmd;
195  }
196  cmd->has_cons = has_cons;
197  for (i = 0; i < NCMDS; i++) {
198  cmd->cmds[i] = NULL;
199  }
200  cmd->nullcallback = cmd->data = NULL;
201  cmd->ht_cmds = ht_pp_new0();
202  cmd->root_cmd_desc = create_cmd_desc(cmd, NULL, RZ_CMD_DESC_TYPE_GROUP, "", &root_help, true);
203  rz_cmd_macro_init(&cmd->macro);
205  return cmd;
206 }
static const RzCmdDescHelp root_help
Definition: cmd_api.c:51
RZ_API void rz_cmd_macro_init(RzCmdMacro *mac)
Definition: cmd_api.c:1540
RZ_API void rz_cmd_alias_init(RzCmd *cmd)
Definition: cmd_api.c:184

References cmd, create_cmd_desc(), i, NCMDS, NULL, root_help, rz_cmd_alias_init(), RZ_CMD_DESC_TYPE_GROUP, rz_cmd_macro_init(), and RZ_NEW0.

Referenced by rz_core_cmd_new().

◆ rz_cmd_parsed_args_addarg()

RZ_API bool rz_cmd_parsed_args_addarg ( RzCmdParsedArgs a,
const char *  arg 
)

Definition at line 2081 of file cmd_api.c.

2081  {
2082  char **tmp = realloc(a->argv, sizeof(a->argv[0]) * (a->argc + 2));
2083  if (!tmp) {
2084  return false;
2085  }
2086 
2087  a->argv = tmp;
2088  a->argv[a->argc] = strdup(arg);
2089  a->argv[a->argc + 1] = NULL;
2090  a->argc++;
2091  return true;
2092 }

References a, NULL, realloc(), strdup(), and autogen_x86imm::tmp.

Referenced by args_preprocessing().

◆ rz_cmd_parsed_args_argstr()

RZ_API char* rz_cmd_parsed_args_argstr ( RzCmdParsedArgs a)

Definition at line 2115 of file cmd_api.c.

2115  {
2116  rz_return_val_if_fail(a && a->argv && a->argv[0], NULL);
2117  RzStrBuf *sb = rz_strbuf_new("");
2119  return rz_strbuf_drain(sb);
2120 }
static void parsed_args_iterateargs(RzCmdParsedArgs *a, RzStrBuf *sb)
Definition: cmd_api.c:2105

References a, NULL, parsed_args_iterateargs(), rz_return_val_if_fail, rz_strbuf_drain(), rz_strbuf_new(), and sb.

Referenced by ts_node_handle_arg().

◆ rz_cmd_parsed_args_cmd()

RZ_API const char* rz_cmd_parsed_args_cmd ( RzCmdParsedArgs a)

Definition at line 2135 of file cmd_api.c.

2135  {
2136  rz_return_val_if_fail(a && a->argv && a->argv[0], NULL);
2137  return a->argv[0];
2138 }

References a, NULL, and rz_return_val_if_fail.

Referenced by argv_call_cb(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_cmd_call_parsed_args(), and rz_cmd_get_help().

◆ rz_cmd_parsed_args_execstr()

RZ_API char* rz_cmd_parsed_args_execstr ( RzCmdParsedArgs a)

Definition at line 2122 of file cmd_api.c.

2122  {
2123  rz_return_val_if_fail(a && a->argv && a->argv[0], NULL);
2124  RzStrBuf *sb = rz_strbuf_new(a->argv[0]);
2125  if (a->argc > 1 && a->has_space_after_cmd) {
2126  rz_strbuf_append(sb, " ");
2127  }
2129  if (a->extra) {
2130  rz_strbuf_append(sb, a->extra);
2131  }
2132  return rz_strbuf_drain(sb);
2133 }

References a, NULL, parsed_args_iterateargs(), rz_return_val_if_fail, rz_strbuf_append(), rz_strbuf_drain(), rz_strbuf_new(), and sb.

Referenced by call_cd().

◆ rz_cmd_parsed_args_free()

RZ_API void rz_cmd_parsed_args_free ( RzCmdParsedArgs a)

Definition at line 2036 of file cmd_api.c.

2036  {
2037  if (!a) {
2038  return;
2039  }
2040 
2041  int i;
2042  for (i = 0; i < a->argc; i++) {
2043  free(a->argv[i]);
2044  }
2045  free(a->argv);
2046  free(a);
2047 }

References a, free(), and i.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), get_help_wrong_cmd(), iter_offsets_common(), and ts_node_handle_arg().

◆ rz_cmd_parsed_args_new()

RZ_API RzCmdParsedArgs* rz_cmd_parsed_args_new ( const char *  cmd,
int  n_args,
char **  args 
)

Definition at line 2013 of file cmd_api.c.

2013  {
2014  rz_return_val_if_fail(cmd && n_args >= 0, NULL);
2016  res->has_space_after_cmd = true;
2017  res->argc = n_args + 1;
2018  res->argv = RZ_NEWS0(char *, res->argc + 1);
2019  res->argv[0] = strdup(cmd);
2020  int i;
2021  for (i = 1; i < res->argc; i++) {
2022  res->argv[i] = strdup(args[i - 1]);
2023  }
2024  res->argv[res->argc] = NULL;
2025  return res;
2026 }
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
bool has_space_after_cmd
Definition: rz_cmd.h:119

References rz_cmd_parsed_args_t::argc, args, rz_cmd_parsed_args_t::argv, cmd, rz_cmd_parsed_args_t::has_space_after_cmd, i, NULL, RZ_NEW0, RZ_NEWS0, rz_return_val_if_fail, and strdup().

Referenced by rz_cmd_parsed_args_newargs(), and rz_cmd_parsed_args_newcmd().

◆ rz_cmd_parsed_args_newargs()

RZ_API RzCmdParsedArgs* rz_cmd_parsed_args_newargs ( int  n_args,
char **  args 
)

Definition at line 2032 of file cmd_api.c.

2032  {
2033  return rz_cmd_parsed_args_new("", n_args, args);
2034 }
RZ_API RzCmdParsedArgs * rz_cmd_parsed_args_new(const char *cmd, int n_args, char **args)
Definition: cmd_api.c:2013

References args, and rz_cmd_parsed_args_new().

Referenced by parse_args().

◆ rz_cmd_parsed_args_newcmd()

RZ_API RzCmdParsedArgs* rz_cmd_parsed_args_newcmd ( const char *  cmd)

Definition at line 2028 of file cmd_api.c.

2028  {
2029  return rz_cmd_parsed_args_new(cmd, 0, NULL);
2030 }

References cmd, NULL, and rz_cmd_parsed_args_new().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), and get_help_wrong_cmd().

◆ rz_cmd_parsed_args_setargs()

RZ_API bool rz_cmd_parsed_args_setargs ( RzCmdParsedArgs a,
int  n_args,
char **  args 
)

Definition at line 2057 of file cmd_api.c.

2057  {
2058  rz_return_val_if_fail(a && a->argv && a->argv[0], false);
2059  char **tmp = RZ_NEWS0(char *, n_args + 2);
2060  if (!tmp) {
2061  return false;
2062  }
2063  tmp[0] = strdup(a->argv[0]);
2064  int i;
2065  for (i = 1; i < n_args + 1; i++) {
2066  tmp[i] = strdup(args[i - 1]);
2067  if (!tmp[i]) {
2068  goto err;
2069  }
2070  }
2071  tmp[n_args + 1] = NULL;
2072  free_array(a->argv, a->argc);
2073  a->argv = tmp;
2074  a->argc = n_args + 1;
2075  return true;
2076 err:
2077  free_array(tmp, n_args + 1);
2078  return false;
2079 }
static void free_array(char **arr, int n)
Definition: cmd_api.c:2049

References a, args, err, free_array(), i, NULL, RZ_NEWS0, rz_return_val_if_fail, strdup(), and autogen_x86imm::tmp.

◆ rz_cmd_parsed_args_setcmd()

RZ_API bool rz_cmd_parsed_args_setcmd ( RzCmdParsedArgs a,
const char *  cmd 
)

Definition at line 2094 of file cmd_api.c.

2094  {
2095  rz_return_val_if_fail(a && a->argv && a->argv[0], false);
2096  char *tmp = strdup(cmd);
2097  if (!tmp) {
2098  return false;
2099  }
2100  free(a->argv[0]);
2101  a->argv[0] = tmp;
2102  return true;
2103 }

References a, cmd, free(), rz_return_val_if_fail, strdup(), and autogen_x86imm::tmp.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL().

◆ rz_cmd_set_data()

RZ_API int rz_cmd_set_data ( RzCmd cmd,
void *  data 
)

Definition at line 523 of file cmd_api.c.

523  {
524  cmd->data = data;
525  return 1;
526 }

References cmd.

Referenced by rz_core_cmd_init().

◆ rz_cmd_state_output_array_end()

RZ_API void rz_cmd_state_output_array_end ( RzCmdStateOutput state)

Mark the end of an array of elements in the output.

Output modes that support arrays will use this to mark the end of an array (e.g. JSON). Used by command handlers after "printing" a list of elements.

Definition at line 2572 of file cmd_api.c.

2572  {
2574  if (state->mode == RZ_OUTPUT_MODE_JSON || state->mode == RZ_OUTPUT_MODE_LONG_JSON) {
2575  rz_return_if_fail(state->d.pj);
2576  pj_end(state->d.pj);
2577  }
2578 }
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_LONG_JSON
Definition: rz_types.h:45

References pj_end(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG_JSON, and rz_return_if_fail.

Referenced by cmd_debug_modules(), core_disassembly(), entries_initfini_print(), flag_zone_list(), open_maps_list(), print_source_info(), rz_analysis_basic_block_find_paths_handler(), rz_analysis_basic_block_list_handler(), rz_analysis_syscall_print_handler(), rz_analysis_var_global_list_show(), rz_cmd_debug_display_bt_handler(), rz_cmd_debug_list_bp_handler(), rz_cmd_disassemble_recursively_from_current_block_handler(), rz_cmd_disassemble_recursively_handler(), rz_cmd_disassemble_recursively_no_function_handler(), rz_cmd_disassemble_ropchain_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_basic_block_handler(), rz_cmd_info_demangle_list_handler(), rz_cmd_sizes_of_n_instructions_handler(), rz_core_analysis_bbs_info_print(), rz_core_asm_plugins_print(), rz_core_bin_archs_print(), rz_core_bin_basefind_print(), rz_core_bin_class_fields_print(), rz_core_bin_class_methods_print(), rz_core_bin_classes_print(), rz_core_bin_fields_print(), rz_core_bin_imports_print(), rz_core_bin_libs_print(), rz_core_bin_memory_print(), rz_core_bin_plugins_print(), rz_core_bin_print_source_line_info(), rz_core_bin_relocs_print(), rz_core_bin_resources_print(), rz_core_bin_sections_mapping_print(), rz_core_bin_sections_print(), rz_core_bin_segments_print(), rz_core_binfiles_print(), rz_core_core_plugins_print(), rz_core_debug_map_print(), rz_core_debug_plugins_print(), rz_core_disasm_pde(), rz_core_hash_plugins_print(), rz_core_io_plugins_print(), rz_core_lang_plugins_print(), rz_core_meta_print_list_all(), rz_core_meta_print_list_at(), rz_core_meta_print_list_in_function(), rz_core_parser_plugins_print(), rz_core_pdb_info_print(), rz_core_spaces_print(), rz_flag_describe_at_handler(), rz_flag_local_list_all_handler(), rz_flag_local_list_handler(), rz_flag_tag_list_handler(), rz_open_list_handler(), rz_seek_history_list_handler(), strings_print(), and symbols_print().

◆ rz_cmd_state_output_array_start()

RZ_API void rz_cmd_state_output_array_start ( RzCmdStateOutput state)

Mark the start of an array of elements in the output.

Output modes that support arrays will use this to mark the start of an array (e.g. JSON). Used by command handlers before "printing" a list of elements.

Definition at line 2558 of file cmd_api.c.

2558  {
2560  if (state->mode == RZ_OUTPUT_MODE_JSON || state->mode == RZ_OUTPUT_MODE_LONG_JSON) {
2561  rz_return_if_fail(state->d.pj);
2562  pj_a(state->d.pj);
2563  }
2564 }
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81

References pj_a(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG_JSON, and rz_return_if_fail.

Referenced by cmd_debug_modules(), core_disassembly(), entries_initfini_print(), flag_zone_list(), open_maps_list(), print_source_info(), rz_analysis_basic_block_find_paths_handler(), rz_analysis_basic_block_list_handler(), rz_analysis_syscall_print_handler(), rz_analysis_var_global_list_show(), rz_cmd_debug_display_bt_handler(), rz_cmd_debug_list_bp_handler(), rz_cmd_disassemble_recursively_from_current_block_handler(), rz_cmd_disassemble_recursively_handler(), rz_cmd_disassemble_recursively_no_function_handler(), rz_cmd_disassemble_ropchain_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_basic_block_handler(), rz_cmd_info_demangle_list_handler(), rz_cmd_sizes_of_n_instructions_handler(), rz_core_analysis_bbs_info_print(), rz_core_asm_plugins_print(), rz_core_bin_archs_print(), rz_core_bin_basefind_print(), rz_core_bin_class_fields_print(), rz_core_bin_class_methods_print(), rz_core_bin_classes_print(), rz_core_bin_fields_print(), rz_core_bin_imports_print(), rz_core_bin_libs_print(), rz_core_bin_memory_print(), rz_core_bin_plugins_print(), rz_core_bin_print_source_line_info(), rz_core_bin_relocs_print(), rz_core_bin_resources_print(), rz_core_bin_sections_mapping_print(), rz_core_bin_sections_print(), rz_core_bin_segments_print(), rz_core_binfiles_print(), rz_core_core_plugins_print(), rz_core_debug_map_print(), rz_core_debug_plugins_print(), rz_core_disasm_pde(), rz_core_hash_plugins_print(), rz_core_io_plugins_print(), rz_core_lang_plugins_print(), rz_core_meta_print_list_all(), rz_core_meta_print_list_at(), rz_core_meta_print_list_in_function(), rz_core_parser_plugins_print(), rz_core_pdb_info_print(), rz_core_spaces_print(), rz_flag_describe_at_handler(), rz_flag_local_list_all_handler(), rz_flag_local_list_handler(), rz_flag_tag_list_handler(), rz_open_list_handler(), rz_seek_history_list_handler(), strings_print(), and symbols_print().

◆ rz_cmd_state_output_fini()

RZ_API void rz_cmd_state_output_fini ( RZ_NONNULL RzCmdStateOutput state)

Clear the inner fields of RzCmdStateOutput structure, but do not free it.

Definition at line 2603 of file cmd_api.c.

2603  {
2605 
2606  switch (state->mode) {
2607  case RZ_OUTPUT_MODE_JSON:
2609  pj_free(state->d.pj);
2610  state->d.pj = NULL;
2611  break;
2612  case RZ_OUTPUT_MODE_TABLE:
2613  rz_table_free(state->d.t);
2614  state->d.t = NULL;
2615  break;
2616  default:
2617  break;
2618  }
2619 }
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114

References NULL, pj_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG_JSON, RZ_OUTPUT_MODE_TABLE, rz_return_if_fail, and rz_table_free().

Referenced by __listPlugins(), argv_call_cb(), cb_asmarch(), cb_asmcpu(), cb_dbgbackend(), get_bin_info(), rz_analysis_function_list_handler(), rz_cmd_debug_dmi(), rz_cmd_debug_map_current_handler(), rz_cmd_eval_color_highlight_list_current_handler(), rz_cmd_eval_color_highlight_list_handler(), rz_cmd_heap_chunks_graph_handler(), rz_cmd_state_output_free(), rz_core_visual_xrefs(), rz_eval_getset_handler(), rz_main_rizin(), rz_main_rz_asm(), and rz_main_rz_bin().

◆ rz_cmd_state_output_free()

RZ_API void rz_cmd_state_output_free ( RZ_NONNULL RzCmdStateOutput state)

Free the RzCmdStateOutput structure and its inner fields appropriately.

Definition at line 2624 of file cmd_api.c.

2624  {
2626 
2628  free(state);
2629 }

References free(), rz_cmd_state_output_fini(), and rz_return_if_fail.

Referenced by add_footer(), and rz_core_bin_print().

◆ rz_cmd_state_output_init()

RZ_API bool rz_cmd_state_output_init ( RZ_NONNULL RzCmdStateOutput state,
RzOutputMode  mode 
)

Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.

Definition at line 2634 of file cmd_api.c.

2634  {
2635  rz_return_val_if_fail(state, false);
2636 
2637  state->mode = mode;
2638  switch (state->mode) {
2639  case RZ_OUTPUT_MODE_TABLE:
2640  state->d.t = rz_table_new();
2641  if (!state->d.t) {
2642  return false;
2643  }
2644  break;
2645  case RZ_OUTPUT_MODE_JSON:
2647  state->d.pj = pj_new();
2648  if (!state->d.pj) {
2649  return false;
2650  }
2651  break;
2652  default:
2653  memset(&state->d, 0, sizeof(state->d));
2654  break;
2655  }
2656  return true;
2657 }
return memset(p, 0, total)
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103

References memset(), pj_new(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG_JSON, RZ_OUTPUT_MODE_TABLE, rz_return_val_if_fail, and rz_table_new().

Referenced by __listPlugins(), add_header(), argv_call_cb(), cb_asmarch(), cb_asmcpu(), cb_dbgbackend(), get_bin_info(), rz_analysis_function_list_handler(), rz_cmd_debug_dmi(), rz_cmd_debug_map_current_handler(), rz_cmd_eval_color_highlight_list_current_handler(), rz_cmd_eval_color_highlight_list_handler(), rz_cmd_heap_chunks_graph_handler(), rz_core_visual_xrefs(), rz_eval_getset_handler(), rz_main_rizin(), rz_main_rz_asm(), and rz_main_rz_bin().

◆ rz_cmd_state_output_print()

RZ_API void rz_cmd_state_output_print ( RZ_NONNULL RzCmdStateOutput state)

Print the output accumulated in state to RzCons, if necessary.

Some output modes like JSON and TABLE accumulate their output in their respective data structures, thus it is needed to print them to have the output on screen. This function takes care of that, doing nothing in case the output was already printed to console for those types that output as they go (e.g. STANDARD, QUIET).

Definition at line 2668 of file cmd_api.c.

2668  {
2670 
2671  char *s;
2672  switch (state->mode) {
2673  case RZ_OUTPUT_MODE_JSON:
2676  break;
2677  case RZ_OUTPUT_MODE_TABLE:
2678  s = rz_table_tostring(state->d.t);
2679  rz_cons_printf("%s", s);
2680  free(s);
2681  break;
2682  default:
2683  break;
2684  }
2685 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510

References free(), pj_string(), rz_cons_printf(), rz_cons_println(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG_JSON, RZ_OUTPUT_MODE_TABLE, rz_return_if_fail, rz_table_tostring(), and s.

Referenced by __listPlugins(), argv_call_cb(), cb_asmarch(), cb_asmcpu(), cb_dbgbackend(), get_bin_info(), rz_cmd_debug_dmi(), rz_cmd_debug_map_current_handler(), rz_cmd_eval_color_highlight_list_current_handler(), rz_cmd_eval_color_highlight_list_handler(), rz_cmd_heap_chunks_graph_handler(), rz_eval_getset_handler(), rz_main_rizin(), and rz_main_rz_asm().

◆ rz_cmd_state_output_set_columnsf()

RZ_API void rz_cmd_state_output_set_columnsf ( RzCmdStateOutput state,
const char *  fmt,
  ... 
)

Specify the columns of the command output.

Parameters
stateReference to RzCmdStateOutput
fmtString containing the numer and types of the columns (see RzTable for a reference of the possible types)
...Variable number of strings that specify the names of the columns. There should be enough string as characters in fmt .

Definition at line 2589 of file cmd_api.c.

2589  {
2591  va_list ap;
2592  va_start(ap, fmt);
2593  if (state->mode == RZ_OUTPUT_MODE_TABLE) {
2594  rz_return_if_fail(state->d.t);
2595  rz_table_set_vcolumnsf(state->d.t, fmt, ap);
2596  }
2597  va_end(ap);
2598 }
RZ_API void rz_table_set_vcolumnsf(RzTable *t, const char *fmt, va_list ap)
Specify the types and names of the referenced table.
Definition: table.c:193

References RZ_OUTPUT_MODE_TABLE, rz_return_if_fail, and rz_table_set_vcolumnsf().

Referenced by entries_initfini_print(), flag_print(), open_maps_list(), rz_analysis_basic_block_list_handler(), rz_cmd_debug_list_bp_handler(), rz_cmd_info_demangle_list_handler(), rz_core_analysis_bb_info_print(), rz_core_analysis_bbs_info_print(), rz_core_bin_archs_print(), rz_core_bin_basefind_print(), rz_core_bin_class_fields_print(), rz_core_bin_class_methods_print(), rz_core_bin_classes_print(), rz_core_bin_fields_print(), rz_core_bin_imports_print(), rz_core_bin_libs_print(), rz_core_bin_main_print(), rz_core_bin_memory_print(), rz_core_bin_plugin_print(), rz_core_bin_relocs_print(), rz_core_bin_resources_print(), rz_core_bin_sections_mapping_print(), rz_core_bin_segments_print(), rz_core_binfiles_print(), rz_core_binxtr_plugin_print(), rz_core_file_info_print(), rz_core_io_plugins_print(), rz_open_list_handler(), rz_open_maps_list_cur_handler(), rz_open_show_current_handler(), sections_headers_setup(), strings_print(), and symbols_print().

◆ rz_cmd_unescape_arg()

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_cmd  )

◆ rz_output_mode_to_char()

RZ_IPI int rz_output_mode_to_char ( RzOutputMode  mode)

Definition at line 73 of file cmd_api.c.

73  {
74  size_t i;
75  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
76  if (argv_modes[i].mode == mode) {
77  return argv_modes[i].suffix[0];
78  }
79  }
80  return -1;
81 }

References argv_modes, i, RZ_ARRAY_SIZE, and argv_modes_t::suffix.

Referenced by rz_cmd_debug_trace_graph_handler().

◆ rz_output_mode_to_summary()

RZ_IPI const char* rz_output_mode_to_summary ( RzOutputMode  mode)

Definition at line 83 of file cmd_api.c.

83  {
84  size_t i;
85  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
86  if (argv_modes[i].mode == mode) {
87  return argv_modes[i].summary_suffix;
88  }
89  }
90  return "";
91 }

References argv_modes, i, RZ_ARRAY_SIZE, and argv_modes_t::summary_suffix.

Referenced by fill_usage_strbuf().

◆ show_children_shortcut()

static bool show_children_shortcut ( const RzCmdDesc cd)
static

Definition at line 877 of file cmd_api.c.

877  {
878  return cd->n_children || cd->help->options || cd->type == RZ_CMD_DESC_TYPE_OLDINPUT ||
880 }

References cd, has_cd_submodes(), and RZ_CMD_DESC_TYPE_OLDINPUT.

Referenced by calc_padding_len(), do_print_child_help(), and fill_usage_strbuf().

◆ sort_groups()

static void sort_groups ( RzCmdDesc group)
static

Definition at line 244 of file cmd_api.c.

244  {
245  void **it_cd;
246 
247  if (group->help->sort_subcommands) {
248  rz_pvector_sort(&group->children, cd_sort);
249  }
250  rz_cmd_desc_children_foreach(group, it_cd) {
251  RzCmdDesc *cd = *(RzCmdDesc **)it_cd;
252  if (cd->n_children) {
253  sort_groups(cd);
254  }
255  }
256 }

References cd, cd_sort(), rz_cmd_desc_t::children, rz_cmd_desc_t::help, rz_pvector_sort(), and rz_cmd_desc_help_t::sort_subcommands.

Referenced by rz_cmd_batch_end().

◆ strbuf_append_calc()

static size_t strbuf_append_calc ( RzStrBuf sb,
const char *  s 
)
static

Definition at line 807 of file cmd_api.c.

807  {
809  return strlen(s);
810 }

References rz_strbuf_append(), s, and sb.

Referenced by do_print_child_help(), fill_children_chars(), and fill_usage_strbuf().

◆ strlen0()

static size_t strlen0 ( const char *  s)
static

Definition at line 803 of file cmd_api.c.

803  {
804  return s ? strlen(s) : 0;
805 }

References s.

Referenced by calc_padding_len(), and fill_details_do().

◆ suffix2mode()

static RzOutputMode suffix2mode ( const char *  suffix)
static

Definition at line 269 of file cmd_api.c.

269  {
270  size_t i;
271  for (i = 0; i < RZ_ARRAY_SIZE(argv_modes); i++) {
272  if (!strcmp(suffix, argv_modes[i].suffix)) {
273  return argv_modes[i].mode;
274  }
275  }
276  return 0;
277 }

References argv_modes, i, argv_modes_t::mode, RZ_ARRAY_SIZE, and suffix.

Referenced by cd_suffix2mode(), and is_valid_argv_modes().

◆ unescape_special_chars()

static char* unescape_special_chars ( const char *  s,
const char *  special_chars 
)
static

Definition at line 2493 of file cmd_api.c.

2493  {
2494  char *dst = RZ_NEWS(char, strlen(s) + 1);
2495  int i, j = 0;
2496 
2497  for (i = 0; s[i]; i++) {
2498  if (s[i] != '\\' || !strchr(special_chars, s[i + 1])) {
2499  dst[j++] = s[i];
2500  continue;
2501  }
2502  dst[j++] = s[++i];
2503  if (!s[i]) {
2504  break;
2505  }
2506  }
2507  dst[j++] = '\0';
2508  return dst;
2509 }

References dst, i, RZ_NEWS, and s.

Referenced by rz_cmd_unescape_arg().

◆ update_minmax_len()

static void update_minmax_len ( RzCmdDesc cd,
size_t max_len,
size_t min_len,
bool  show_children 
)
static

Definition at line 1074 of file cmd_api.c.

1074  {
1075  size_t val = calc_padding_len(cd, cd->name, show_children);
1076  *max_len = val > *max_len ? val : *max_len;
1077  *min_len = val < *min_len ? val : *min_len;
1078 }
ut16 val
Definition: armass64_const.h:6

References calc_padding_len(), cd, and val.

Referenced by fill_argv_modes_help_strbuf(), and group_get_help().

Variable Documentation

◆ argv_modes

const struct argv_modes_t argv_modes[]
static
Initial value:
= {
{ "j", " (JSON mode)", RZ_OUTPUT_MODE_JSON },
{ "*", " (rizin mode)", RZ_OUTPUT_MODE_RIZIN },
{ "q", " (quiet mode)", RZ_OUTPUT_MODE_QUIET },
{ "Q", " (quietest mode)", RZ_OUTPUT_MODE_QUIETEST },
{ "k", " (sdb mode)", RZ_OUTPUT_MODE_SDB },
{ "l", " (verbose mode)", RZ_OUTPUT_MODE_LONG },
{ "J", " (verbose JSON mode)", RZ_OUTPUT_MODE_LONG_JSON },
{ "t", " (table mode)", RZ_OUTPUT_MODE_TABLE },
}
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_SDB
Definition: rz_types.h:43
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41

Referenced by cmd_foreach_cmdname_modes(), fill_argv_modes_help_strbuf(), fill_modes_children_chars(), rz_output_mode_to_char(), rz_output_mode_to_summary(), and suffix2mode().

◆ not_defined_help

const RzCmdDescHelp not_defined_help
static
Initial value:
= {
.usage = "Usage not defined",
.summary = "Help summary not defined",
.description = "Help description not defined.",
}

Definition at line 45 of file cmd_api.c.

Referenced by create_cmd_desc().

◆ root_help

const RzCmdDescHelp root_help
static
Initial value:
= {
.usage = "[.][times][cmd][~grep][@[@iter]addr][|>pipe] ; ...",
.description = "",
.sort_subcommands = true,
}

Definition at line 51 of file cmd_api.c.

Referenced by rz_cmd_new().

◆ SPECIAL_CHARS_DOUBLE_QUOTED

const char* SPECIAL_CHARS_DOUBLE_QUOTED = "\"$()`"
static

Definition at line 42 of file cmd_api.c.

Referenced by rz_cmd_escape_arg(), and rz_cmd_unescape_arg().

◆ SPECIAL_CHARS_PF

const char* SPECIAL_CHARS_PF = "@;~$#|`\"'<>"
static

Definition at line 41 of file cmd_api.c.

Referenced by rz_cmd_escape_arg(), and rz_cmd_unescape_arg().

◆ SPECIAL_CHARS_REGULAR

const char* SPECIAL_CHARS_REGULAR = "@;~$#|`\"'()<>"
static

Definition at line 39 of file cmd_api.c.

Referenced by rz_cmd_escape_arg(), and rz_cmd_unescape_arg().

◆ SPECIAL_CHARS_REGULAR_SINGLE

const char* SPECIAL_CHARS_REGULAR_SINGLE = "@;~$#|`\"'()<> "
static

Definition at line 40 of file cmd_api.c.

Referenced by rz_cmd_escape_arg(), and rz_cmd_unescape_arg().

◆ SPECIAL_CHARS_SINGLE_QUOTED

const char* SPECIAL_CHARS_SINGLE_QUOTED = "'"
static

Definition at line 43 of file cmd_api.c.

Referenced by rz_cmd_escape_arg(), and rz_cmd_unescape_arg().

◆ value

int value = 0
static

Definition at line 93 of file cmd_api.c.

Referenced by __asm_equ_new(), _aeli_iter(), _insert_into_disk(), _restore_memory_cb(), _write_asm(), _zip_win32_named_op_create_temp_output(), aarch64_ext_addr_regoff(), aarch64_ext_aimm(), aarch64_ext_cond(), aarch64_ext_ft(), aarch64_ext_hint(), aarch64_ext_ldst_reglist(), aarch64_ext_ldst_reglist_r(), aarch64_ext_limm(), aarch64_ext_pstatefield(), aarch64_ext_reg_extended(), aarch64_ext_reg_shifted(), aarch64_ext_reglane(), aarch64_ext_sysins_op(), aarch64_find_alias_opcode(), aarch64_find_next_alias_opcode(), aarch64_find_next_opcode(), aarch64_logical_immediate_p(), aarch64_print_operand(), aarch64_wide_constant_p(), addr_hint_foreach_cb(), analBars(), anop32(), arc_aux_reg_name(), arc_opcode_init_tables(), arc_opcode_lookup_suffix(), avr_il_assign_bool(), basefind_array_has(), basefind_create_pointer_map(), be16(), be24(), bfd_getm32(), bflt_load_relocs(), bin_elf_versioninfo_versym(), bin_pe_init_sections(), bs_option(), cabd_param(), calculate_luhn(), cb_dirtmp(), cb_log_config_colors(), cb_log_config_file(), cb_log_config_srcinfo(), check_rom_exists(), cmd_print_bars(), common_write_value_handler(), convert_movebitmask_to_mov(), convert_movewide_to_mov(), create_temp_file(), cs_option(), decode_asimd_fcvt(), decode_fcvt(), decode_limm(), decode_parameter(), decode_sizeq(), decode_sve_aimm(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), deflatePrime(), do_handle_substitution_cmd(), do_misc_decoding(), do_special_decoding(), dofwd(), dump_element(), emit_equ(), extract_all_fields(), extract_field_2(), extract_fields(), extract_ld_offset(), extract_reg(), extract_st_offset(), flirt_write_module(), foreach_reg_set_or_clear(), format_reg_value(), from_oct(), gdbr_write_reg(), gdbr_write_register(), gdbr_write_registers(), get_arm64_hwwp_values(), get_arm_hwbp_values(), get_cond_from_value(), get_enum_type(), get_greg_qualifier_from_value(), get_regname(), get_top_bit(), get_union_type(), get_versym_entry_sdb_from_verdef(), get_versym_entry_sdb_from_verneed(), getarg(), getvalue(), hash_cfg_config_compare(), hash_print_crypto(), hash_print_digest(), hash_string(), hppa_field_adjust(), hppa_rebuild_insn(), inflatePrime(), insert(), insert_addr_wb(), insert_base(), insert_cond(), insert_field(), insert_field_2(), insert_jumpflags(), insert_nullify(), insert_offset(), insert_reg(), insert_reladdr(), insert_s12(), insert_s15(), insert_u16(), insert_u8(), insert_ul16(), insert_update(), insert_uu16(), is_pc_inside_module(), is_pc_inside_windmodule(), isMask(), isShiftedMask(), java_constant_pool_stringify(), lang_byte_array_c_cpp(), lang_byte_array_java(), lang_byte_array_kotlin(), lookup_value(), LZ4_write16(), LZ4_write32(), LZ4_writeLE16(), macro_call(), main(), main_print_var(), make_int_16(), make_int_8(), map_enum(), memlimit_show(), oabd_param(), p_b_symbol(), parse_array_type(), parse_atomic_type(), parse_attr_value(), parse_byte(), parse_codeview_fld_attribute(), parse_codeview_func_attribute(), parse_codeview_modifier(), parse_codeview_pointer_attribute(), parse_codeview_property(), parse_enumerate(), parse_enumerator(), parse_memlimit(), parse_options(), parse_struct_member(), parse_typedef(), prompt_offset_and_seek(), prompt_offset_and_seek_file(), qnxr_write_reg(), qnxr_write_register(), rc_direct(), rd_factor(), rd_value(), read_imm_16(), read_imm_32(), read_imm_64(), read_imm_8(), read_n_bits(), rebase_bytes_v1(), references_handler(), reg_has_changed(), reg_offset_cmp(), replace_cmd_kv(), replace_cmd_kv_file(), replace_seq(), resource_value(), restore_memory_cb(), rotate_left_32(), rsp_op(), rz_analysis_switch_op_add_case(), rz_analysis_value_free(), rz_analysis_value_to_string(), rz_asm_code_set_equ(), rz_asm_pseudo_fill(), rz_atomic_bool_get(), rz_atomic_bool_set(), rz_bin_elf_add_addr(), rz_bin_elf_add_off(), rz_bin_elf_mul_addr(), rz_bin_elf_mul_off(), rz_buf_sleb128(), rz_buf_uleb128(), rz_buf_write8(), rz_buf_write8_at(), rz_bv_new_from_st64(), rz_bv_new_from_ut64(), rz_bv_set_from_st64(), rz_bv_set_from_ut64(), rz_cf_key_value_new(), rz_cf_value_array_add(), rz_cf_value_array_print(), rz_cf_value_bool_new(), rz_cf_value_dict_parse(), rz_cf_value_free(), rz_cf_value_print(), rz_cmd_macro_break(), rz_config_eval(), rz_config_node_new(), rz_config_set(), rz_config_set_b(), rz_config_set_cb(), rz_core_analysis_hasrefs(), rz_core_analysis_hasrefs_to_depth(), rz_core_analysis_il_vm_set(), rz_core_cmd_foreach3(), rz_core_cmd_subst_i(), rz_core_flirt_arch_from_id(), rz_core_print_string_c_cpp(), rz_core_search_value_in_range(), rz_core_write_value_at(), rz_core_write_value_inc_at(), rz_debruijn_offset(), rz_egg_config_handler(), rz_eval_getset_handler(), rz_fletcher64_update(), rz_il_event_mem_read_new(), rz_il_event_var_read_new(), rz_il_handler_store(), rz_il_handler_storew(), rz_il_mem_store(), rz_il_mem_storew(), rz_il_op_effect_free(), rz_il_op_new_bitv(), rz_il_op_new_bitv_from_st64(), rz_il_op_new_bitv_from_ut64(), rz_il_op_new_store(), rz_il_op_new_storew(), rz_il_vm_mem_load(), rz_il_vm_mem_loadw(), rz_il_vm_mem_store(), rz_il_vm_mem_storew(), rz_il_vm_status_handler(), rz_interval_node_all_in(), rz_interval_tree_all_in(), rz_is_valid_input_num_value(), rz_lang_define(), rz_mod255_update(), rz_num_get_input_value(), rz_num_is_valid_input(), rz_reg_set_double(), rz_reg_set_longdouble(), rz_reg_set_value(), rz_regs_show_valgroup(), rz_serialize_analysis_switch_op_load(), rz_sleb128(), rz_sys_setenv(), rz_type_enum_bitfield_handler(), rz_type_format_uleb(), rz_type_print_value_handler(), rz_write_debruijn_find_handler(), rz_write_versioned_vle(), rz_xor16_update(), rz_xor8_update(), rzil_print_register_bool(), sdb_concat(), sdb_dump_dupnext(), sdb_get_len(), sdb_ht_insert(), sdb_ht_internal_insert(), sdb_ht_update(), sdb_uncat(), set_bcj(), set_delta(), set_lzma(), shared_ht_up_insert(), sign_extend(), sign_extend2(), sort_loclists(), sparc_decode_asi(), sparc_decode_membar(), sparc_decode_prefetch(), sparc_decode_sparclet_cpreg(), str_to_uint64(), symbols(), symbols_contain(), system_apply_env_var(), TAG_CALLBACK(), types_enum_member_find(), types_enum_member_find_all(), uint64_to_nicestr(), uint64_to_str(), update(), update_key(), uv__custom_sem_init(), uv__sem_init(), uv__socket_sockopt(), uv_key_get(), uv_key_set(), uv_os_setenv(), uv_recv_buffer_size(), uv_sem_init(), uv_send_buffer_size(), uv_tty_write_bufs(), uv_udp_set_broadcast(), uv_uptime(), valPrint(), value_aligned_p(), value_fit_signed_field_p(), value_fit_unsigned_field_p(), value_in_range_p(), vtable_addr_in_text_section(), vtable_is_addr_vtable_start_itanium(), vtable_is_value_in_text_section(), w32_hwbp_arm_add(), w32_hwbp_arm_del(), write_n_bits(), DotZLib.GZipStream::WriteByte(), zip_random_uint32(), and zip_set_archive_flag().