Rizin
unix-like reverse engineering framework and cli tools
line.c File Reference
#include <rz_util.h>
#include <rz_cons.h>
#include "dietline.c"

Go to the source code of this file.

Macros

#define I   rz_line_instance
 

Functions

static void rz_line_nscompletion_init (RzLineNSCompletion *c)
 
RZ_API RzLinerz_line_singleton (void)
 
RZ_API RzLinerz_line_new (void)
 
RZ_API void rz_line_free (void)
 
RZ_API void rz_line_clipboard_push (const char *str)
 
RZ_API void rz_line_set_prompt (const char *prompt)
 
RZ_API RZ_OWN char * rz_line_get_prompt (void)
 
RZ_API void rz_line_completion_init (RzLineCompletion *completion, size_t args_limit)
 
RZ_API void rz_line_completion_fini (RzLineCompletion *completion)
 
RZ_API void rz_line_completion_push (RzLineCompletion *completion, const char *str)
 
RZ_API void rz_line_completion_set (RzLineCompletion *completion, int argc, const char **argv)
 
RZ_API void rz_line_completion_clear (RzLineCompletion *completion)
 
RZ_API RzLineNSCompletionResultrz_line_ns_completion_result_new (size_t start, size_t end, const char *end_string)
 
RZ_API void rz_line_ns_completion_result_free (RzLineNSCompletionResult *res)
 
RZ_API void rz_line_ns_completion_result_add (RzLineNSCompletionResult *res, const char *option)
 
RZ_API void rz_line_ns_completion_result_propose (RzLineNSCompletionResult *res, const char *option, const char *cur, size_t cur_len)
 Add a new option to the list of possible autocomplete-able value if it matches the given string. More...
 

Variables

static RzLine rz_line_instance
 

Macro Definition Documentation

◆ I

#define I   rz_line_instance

Definition at line 8 of file line.c.

Function Documentation

◆ rz_line_clipboard_push()

RZ_API void rz_line_clipboard_push ( const char *  str)

Definition at line 50 of file line.c.

50  {
51  I.kill_ring_ptr += 1;
52  rz_list_insert(I.kill_ring, I.kill_ring_ptr, strdup(str));
53 }
RZ_API RZ_BORROW RzListIter * rz_list_insert(RZ_NONNULL RzList *list, ut32 n, void *data)
Inserts a new element at the N-th position.
Definition: list.c:342
#define I
Definition: line.c:8
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 I, rz_list_insert(), cmd_descs_generate::str, and strdup().

Referenced by backward_kill_word(), kill_word(), rz_line_readline_cb(), and unix_word_rubout().

◆ rz_line_completion_clear()

RZ_API void rz_line_completion_clear ( RzLineCompletion completion)

Definition at line 109 of file line.c.

109  {
110  rz_return_if_fail(completion);
111  completion->quit = false;
112  rz_pvector_clear(&completion->args);
113 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API void rz_pvector_clear(RzPVector *vec)
Definition: vector.c:326
RzPVector args
Definition: rz_cons.h:1047

References rz_line_comp_t::args, rz_line_comp_t::quit, rz_pvector_clear(), and rz_return_if_fail.

Referenced by find_autocomplete(), rz_core_autocomplete(), rz_line_completion_fini(), and rz_line_completion_set().

◆ rz_line_completion_fini()

RZ_API void rz_line_completion_fini ( RzLineCompletion completion)

Definition at line 75 of file line.c.

75  {
76  rz_line_completion_clear(completion);
77 }
RZ_API void rz_line_completion_clear(RzLineCompletion *completion)
Definition: line.c:109

References rz_line_completion_clear().

Referenced by rz_line_free().

◆ rz_line_completion_init()

RZ_API void rz_line_completion_init ( RzLineCompletion completion,
size_t  args_limit 
)

Definition at line 68 of file line.c.

68  {
69  completion->run = NULL;
70  completion->run_user = NULL;
71  completion->args_limit = args_limit;
72  rz_pvector_init(&completion->args, free);
73 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298
size_t args_limit
Definition: rz_cons.h:1045
RzLineCompletionCb run
Definition: rz_cons.h:1048
void * run_user
Definition: rz_cons.h:1049

References rz_line_comp_t::args, rz_line_comp_t::args_limit, free(), NULL, rz_line_comp_t::run, rz_line_comp_t::run_user, and rz_pvector_init().

Referenced by rz_line_new().

◆ rz_line_completion_push()

RZ_API void rz_line_completion_push ( RzLineCompletion completion,
const char *  str 
)

Definition at line 79 of file line.c.

79  {
80  rz_return_if_fail(completion && str);
81  if (completion->quit) {
82  return;
83  }
84  if (rz_pvector_len(&completion->args) < completion->args_limit) {
85  char *s = strdup(str);
86  if (s) {
87  rz_pvector_push(&completion->args, (void *)s);
88  }
89  } else {
90  completion->quit = true;
91  eprintf("WARNING: Maximum completion capacity reached, increase scr.maxtab");
92  }
93 }
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
static size_t rz_pvector_len(const RzPVector *vec)
Definition: rz_vector.h:231
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300

References rz_line_comp_t::args, rz_line_comp_t::args_limit, eprintf, rz_line_comp_t::quit, rz_pvector_len(), rz_pvector_push(), rz_return_if_fail, s, cmd_descs_generate::str, and strdup().

Referenced by add_argv(), autocomplete_breakpoints(), autocomplete_default(), autocomplete_evals(), autocomplete_flagspaces(), autocomplete_functions(), autocomplete_macro(), autocomplete_minus(), autocomplete_process_path(), autocomplete_sdb(), autocomplete_theme(), find_autocomplete(), find_e_opts(), rz_core_autocomplete(), and rz_line_completion_set().

◆ rz_line_completion_set()

RZ_API void rz_line_completion_set ( RzLineCompletion completion,
int  argc,
const char **  argv 
)

Definition at line 95 of file line.c.

95  {
96  rz_return_if_fail(completion && (argc >= 0));
97  rz_line_completion_clear(completion);
98  if (argc > completion->args_limit) {
99  eprintf("WARNING: Maximum completion capacity reached, increase scr.maxtab");
100  }
101  size_t count = RZ_MIN(argc, completion->args_limit);
102  rz_pvector_reserve(&completion->args, count);
103  int i;
104  for (i = 0; i < count; i++) {
105  rz_line_completion_push(completion, argv[i]);
106  }
107 }
lzma_index ** i
Definition: index.h:629
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
RZ_API void rz_line_completion_push(RzLineCompletion *completion, const char *str)
Definition: line.c:79
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define RZ_MIN(x, y)
static void ** rz_pvector_reserve(RzPVector *vec, size_t capacity)
Definition: rz_vector.h:312

References rz_line_comp_t::args, rz_line_comp_t::args_limit, argv, count, eprintf, i, rz_line_completion_clear(), rz_line_completion_push(), RZ_MIN, rz_pvector_reserve(), and rz_return_if_fail.

Referenced by rz_core_fgets().

◆ rz_line_free()

RZ_API void rz_line_free ( void  )

Definition at line 41 of file line.c.

41  {
42  // XXX: prompt out of the heap?
43  free((void *)I.prompt);
44  I.prompt = NULL;
45  rz_list_free(I.kill_ring);
47  rz_line_completion_fini(&I.completion);
48 }
RZ_API void rz_line_hist_free(void)
Definition: dietline.c:455
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_line_completion_fini(RzLineCompletion *completion)
Definition: line.c:75

References free(), I, NULL, rz_line_completion_fini(), rz_line_hist_free(), and rz_list_free().

Referenced by rz_cons_free().

◆ rz_line_get_prompt()

RZ_API RZ_OWN char* rz_line_get_prompt ( void  )

Definition at line 64 of file line.c.

64  {
65  return strdup(I.prompt);
66 }

References I, and strdup().

Referenced by rz_cons_input().

◆ rz_line_new()

RZ_API RzLine* rz_line_new ( void  )

Definition at line 19 of file line.c.

19  {
20  I.hist_up = NULL;
21  I.hist_down = NULL;
22  I.prompt = strdup("> ");
23  I.contents = NULL;
24  I.enable_vi_mode = false;
25  I.clipboard = NULL;
26  I.kill_ring = rz_list_newf(free);
27  I.kill_ring_ptr = -1;
28 #if __WINDOWS__
29  I.vtmode = rz_cons_detect_vt_mode();
30 #else
32 #endif
33  if (!rz_line_dietline_init()) {
34  eprintf("error: rz_line_dietline_init\n");
35  }
36  rz_line_completion_init(&I.completion, 4096);
37  rz_line_nscompletion_init(&I.ns_completion);
38  return &I;
39 }
RZ_API int rz_line_dietline_init(void)
Definition: dietline.c:147
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
static void rz_line_nscompletion_init(RzLineNSCompletion *c)
Definition: line.c:10
RZ_API void rz_line_completion_init(RzLineCompletion *completion, size_t args_limit)
Definition: line.c:68
@ RZ_VIRT_TERM_MODE_COMPLETE
All the sequences goes through VT (Windows Terminal, mintty, all OSs)
Definition: rz_cons.h:451

References eprintf, free(), I, NULL, rz_line_completion_init(), rz_line_dietline_init(), rz_line_nscompletion_init(), rz_list_newf(), RZ_VIRT_TERM_MODE_COMPLETE, and strdup().

Referenced by rz_cons_new().

◆ rz_line_ns_completion_result_add()

RZ_API void rz_line_ns_completion_result_add ( RzLineNSCompletionResult res,
const char *  option 
)

Add a new option to the list of possible autocomplete-able values.

Definition at line 156 of file line.c.

156  {
157  if (ht_pp_find(res->options_ht, option, NULL)) {
158  return;
159  }
160  char *dup = strdup(option);
161  rz_pvector_push(&res->options, dup);
162  ht_pp_insert(res->options_ht, dup, dup);
163 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode dup
Definition: sflib.h:68
Definition: getopt.h:84
HtPP * options_ht
Hash table to keep track of duplicated autocompletion suggestions.
Definition: rz_cons.h:1061
RzPVector options
Vector of options that can be used for autocompletion.
Definition: rz_cons.h:1060

References dup, NULL, rz_line_ns_completion_result_t::options, rz_line_ns_completion_result_t::options_ht, rz_pvector_push(), and strdup().

Referenced by autocmplt_arch(), autocmplt_at_stmt(), autocmplt_bits_plugin(), autocmplt_cmd_arg_alias_type(), autocmplt_cmd_arg_any_type(), autocmplt_cmd_arg_choices(), autocmplt_cmd_arg_enum_type(), autocmplt_cmd_arg_env(), autocmplt_cmd_arg_eval_full(), autocmplt_cmd_arg_eval_key(), autocmplt_cmd_arg_fcn(), autocmplt_cmd_arg_fcn_var(), autocmplt_cmd_arg_file(), autocmplt_cmd_arg_flag(), autocmplt_cmd_arg_global_var(), autocmplt_cmd_arg_help_var(), autocmplt_cmd_arg_macro(), autocmplt_cmd_arg_struct_type(), autocmplt_cmd_arg_union_type(), autocmplt_flag_space(), autocmplt_reg(), do_autocmplt_cmdidentifier(), offset_prompt_add_flag(), and rz_line_ns_completion_result_propose().

◆ rz_line_ns_completion_result_free()

RZ_API void rz_line_ns_completion_result_free ( RzLineNSCompletionResult res)

Free a previously allocated RzLineNSCompletionResult

Definition at line 144 of file line.c.

144  {
145  if (!res) {
146  return;
147  }
148  ht_pp_free(res->options_ht);
149  rz_pvector_fini(&res->options);
150  free(res);
151 }
RZ_API void rz_pvector_fini(RzPVector *vec)
Definition: vector.c:331

References free(), rz_line_ns_completion_result_t::options, rz_line_ns_completion_result_t::options_ht, and rz_pvector_fini().

Referenced by rz_line_autocomplete().

◆ rz_line_ns_completion_result_new()

RZ_API RzLineNSCompletionResult* rz_line_ns_completion_result_new ( size_t  start,
size_t  end,
const char *  end_string 
)

Create an empty completion result with no available options.

Parameters
startValue for RzLineNSCompletionResult.start
endValue for RzLineNSCompletionResult.end
end_stringText that should be inserted after the only option available is autocompleted. When NULL, it defaults to " " (without quotes)

Definition at line 122 of file line.c.

122  {
124  if (!res) {
125  return NULL;
126  }
128  HtPPOptions opt = { 0 };
129  opt.cmp = (HtPPListComparator)strcmp;
130  opt.hashfn = (HtPPHashFunction)sdb_hash;
131  res->options_ht = ht_pp_new_opt(&opt);
132  res->start = start;
133  res->end = end;
134  if (!end_string) {
135  end_string = " ";
136  }
137  res->end_string = end_string;
138  return res;
139 }
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
#define RZ_NEW0(x)
Definition: rz_types.h:284
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43
RZ_API ut32 sdb_hash(const char *key)
Definition: util.c:22
size_t start
First byte that was considered for autocompletion. Everything before this will be left intact.
Definition: rz_cons.h:1062
const char * end_string
String to place after the only option available is autocompleted. By default a space is used.
Definition: rz_cons.h:1064
size_t end
Last byte that was considered for autocompletion. Everything after this will be left intact.
Definition: rz_cons.h:1063

References rz_line_ns_completion_result_t::end, test_evm::end, rz_line_ns_completion_result_t::end_string, free(), NULL, rz_line_ns_completion_result_t::options, rz_line_ns_completion_result_t::options_ht, RZ_NEW0, rz_pvector_init(), sdb_hash(), rz_line_ns_completion_result_t::start, and start.

Referenced by fill_autocmplt_data(), and fill_autocmplt_data_cmdarg().

◆ rz_line_ns_completion_result_propose()

RZ_API void rz_line_ns_completion_result_propose ( RzLineNSCompletionResult res,
const char *  option,
const char *  cur,
size_t  cur_len 
)

Add a new option to the list of possible autocomplete-able value if it matches the given string.

Parameters
optionthe option to be added
curcurrently entered prefix

Definition at line 170 of file line.c.

170  {
171  if (strncmp(option, cur, cur_len)) {
172  return;
173  }
175 }
RZ_API void rz_line_ns_completion_result_add(RzLineNSCompletionResult *res, const char *option)
Definition: line.c:156

References rz_line_ns_completion_result_add().

Referenced by autocmplt_cmd_arg_reg_filter(), and autocmplt_cmd_arg_reg_type().

◆ rz_line_nscompletion_init()

static void rz_line_nscompletion_init ( RzLineNSCompletion c)
static

Definition at line 10 of file line.c.

10  {
11  c->run = NULL;
12  c->run_user = NULL;
13 }
#define c(i)
Definition: sha256.c:43

References c, and NULL.

Referenced by rz_line_new().

◆ rz_line_set_prompt()

◆ rz_line_singleton()

RZ_API RzLine* rz_line_singleton ( void  )

Definition at line 15 of file line.c.

15  {
16  return &rz_line_instance;
17 }
static RzLine rz_line_instance
Definition: line.c:7

References rz_line_instance.

Referenced by cb_scrprompt(), and rz_lang_prompt().

Variable Documentation

◆ rz_line_instance

RzLine rz_line_instance
static

Definition at line 7 of file line.c.

Referenced by rz_line_singleton().