Rizin
unix-like reverse engineering framework and cli tools
fortune.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_core.h>
5 
6 static const char *fortunes[] = {
7  "tips", "fun"
8 };
9 
10 static char *rizin_fortune_file(const char *type) {
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 }
20 
22  size_t i;
23  for (i = 0; i < RZ_ARRAY_SIZE(fortunes); i++) {
24  rz_cons_printf("%s\n", fortunes[i]);
25  }
26 }
27 
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 }
48 
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 }
59 
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 }
lzma_index ** i
Definition: index.h:629
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
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_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define RZ_API
#define NULL
Definition: cris-opc.c:27
static char * rizin_fortune_file(const char *type)
Definition: fortune.c:10
static const char * fortunes[]
Definition: fortune.c:6
RZ_API void rz_core_fortune_list(RzCore *core)
Definition: fortune.c:28
RZ_API void rz_core_fortune_list_types(void)
Definition: fortune.c:21
RZ_API RZ_OWN char * rz_core_fortune_get_random(RzCore *core)
Definition: fortune.c:49
RZ_API void rz_core_fortune_print_random(RzCore *core)
Definition: fortune.c:60
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
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
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
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_OWN
Definition: rz_types.h:62
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define RZ_FORTUNES
Definition: rz_userconf.h:77
Definition: gzappend.c:170
RzConfig * config
Definition: rz_core.h:300