Rizin
unix-like reverse engineering framework and cli tools
fortune.c File Reference
#include <rz_core.h>

Go to the source code of this file.

Functions

static char * rizin_fortune_file (const char *type)
 
RZ_API void rz_core_fortune_list_types (void)
 
RZ_API void rz_core_fortune_list (RzCore *core)
 
RZ_API RZ_OWN char * rz_core_fortune_get_random (RzCore *core)
 
RZ_API void rz_core_fortune_print_random (RzCore *core)
 

Variables

static const char * fortunes []
 

Function Documentation

◆ rizin_fortune_file()

static char* rizin_fortune_file ( const char *  type)
static

Definition at line 10 of file fortune.c.

10  {
11  if (!strncmp(type, "tips", 4) || !strncmp(type, "fun", 3)) {
12  char *fortunes_dir = rz_path_system(RZ_FORTUNES);
13  char buf[100];
14  char *res = rz_file_path_join(fortunes_dir, rz_strf(buf, "fortunes.%s", type));
15  free(fortunes_dir);
16  return res;
17  }
18  return RZ_STR_DUP(type);
19 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
int type
Definition: mipsasm.c:17
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
#define RZ_STR_DUP(x)
Definition: rz_str.h:69
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_FORTUNES
Definition: rz_userconf.h:77

References free(), rz_file_path_join(), RZ_FORTUNES, rz_path_system(), RZ_STR_DUP, rz_strf, and type.

Referenced by rz_core_fortune_get_random(), and rz_core_fortune_list().

◆ rz_core_fortune_get_random()

RZ_API RZ_OWN char* rz_core_fortune_get_random ( RzCore core)

Definition at line 49 of file fortune.c.

49  {
50  int lines = 0;
51  const char *types = (char *)rz_config_get(core->config, "cfg.fortunes.file");
52 
53  char *file = rizin_fortune_file(types);
55 
56  free(file);
57  return line;
58 }
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
static char * rizin_fortune_file(const char *type)
Definition: fortune.c:10
line
Definition: setup.py:34
insn_type_descr_t types[]
Definition: or1k_disas.c:7
RZ_API char * rz_file_slurp_random_line_count(const char *file, int *linecount)
Definition: file.c:630
Definition: gzappend.c:170
RzConfig * config
Definition: rz_core.h:300

References rz_core_t::config, free(), setup::line, lines(), rizin_fortune_file(), rz_config_get(), rz_file_slurp_random_line_count(), and types.

Referenced by __fortune_cb(), and rz_core_fortune_print_random().

◆ rz_core_fortune_list()

RZ_API void rz_core_fortune_list ( RzCore core)

Definition at line 28 of file fortune.c.

28  {
29  const char *types = (char *)rz_config_get(core->config, "cfg.fortunes.file");
30 
31  char *file = rizin_fortune_file(types);
32  char *str = rz_file_slurp(file, NULL);
33  if (!str) {
34  free(file);
35  return;
36  }
37  size_t j, beg;
38  for (j = 0, beg = 0; str[j]; j++) {
39  if (str[j] == '\n') {
40  str[j] = '\0';
41  rz_cons_printf("%s\n", str + beg);
42  beg = j + 1;
43  }
44  }
45  free(str);
46  free(file);
47 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454

References rz_core_t::config, free(), NULL, rizin_fortune_file(), rz_config_get(), rz_cons_printf(), rz_file_slurp(), cmd_descs_generate::str, and types.

Referenced by cb_cfg_fortunes().

◆ rz_core_fortune_list_types()

RZ_API void rz_core_fortune_list_types ( void  )

Definition at line 21 of file fortune.c.

21  {
22  size_t i;
23  for (i = 0; i < RZ_ARRAY_SIZE(fortunes); i++) {
24  rz_cons_printf("%s\n", fortunes[i]);
25  }
26 }
lzma_index ** i
Definition: index.h:629
static const char * fortunes[]
Definition: fortune.c:6
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300

References fortunes, i, RZ_ARRAY_SIZE, and rz_cons_printf().

Referenced by cb_cfg_fortunes_file().

◆ rz_core_fortune_print_random()

RZ_API void rz_core_fortune_print_random ( RzCore core)

Definition at line 60 of file fortune.c.

60  {
61  char *line = rz_core_fortune_get_random(core);
62  if (!line) {
64  }
65  if (line) {
66  if (rz_config_get_i(core->config, "cfg.fortunes.clippy")) {
67  rz_core_clippy(core, line);
68  } else {
69  rz_cons_printf(" -- %s\n", line);
70  }
71  free(line);
72  }
73 }
RZ_API void rz_core_clippy(RzCore *core, const char *msg)
Definition: cmd_help.c:385
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RZ_OWN char * rz_core_fortune_get_random(RzCore *core)
Definition: fortune.c:49

References rz_core_t::config, free(), setup::line, rz_config_get_i(), rz_cons_printf(), rz_core_clippy(), and rz_core_fortune_get_random().

Referenced by rz_cmd_shell_fortune_handler(), and rz_main_rizin().

Variable Documentation

◆ fortunes

const char* fortunes[]
static
Initial value:
= {
"tips", "fun"
}

Definition at line 6 of file fortune.c.

Referenced by rz_core_fortune_list_types().