radare2/libr/core/fortune.c
Filipe Laíns 163312bff3 fortunes: remove nsfw and creepy fortunes
These fortunes make a lot of people unconfortable and can be trigering
for some. Even if they are not active by default, they should have no
place here if you are trying to be a welcoming project.

There are a lot of other ways to be quirky and fun, I see no logical
reason to have these fortunes knowing they will negatively impact
people.

Signed-off-by: Filipe Laíns <lains@riseup.net>
2020-11-29 01:14:28 +01:00

85 lines
2.0 KiB
C

/* radare2 - LGPL - Copyright 2009-2020 - pancake */
#include <r_core.h>
static const char *fortunes[] = {
"tips", "fun",
};
static char *getFortuneFile(RCore *core, const char *type) {
return r_str_newf (R_JOIN_3_PATHS ("%s", R2_FORTUNES, "fortunes.%s"),
r_sys_prefix (NULL), type);
}
R_API void r_core_fortune_list_types(void) {
size_t i;
for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) {
r_cons_printf ("%s\n", fortunes[i]);
}
}
R_API void r_core_fortune_list(RCore *core) {
// TODO: use file.fortunes // can be dangerous in sandbox mode
const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type");
size_t i, j;
for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) {
if (strstr (types, fortunes[i])) {
char *file = getFortuneFile (core, fortunes[i]);
char *str = r_file_slurp (file, NULL);
if (!str) {
free (file);
continue;
}
for (j = 0; str[j]; j++) {
if (str[j] == '\n') {
if (i < j) {
str[j] = '\0';
r_cons_printf ("%s\n", str + i);
}
i = j + 1;
}
}
free (str);
free (file);
}
}
}
static char *getrandomline(RCore *core) {
size_t i;
const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type");
char *line = NULL, *templine;
for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) {
if (strstr (types, fortunes[i])) {
int lines = 0;
char *file = getFortuneFile(core, fortunes[i]);
templine = r_file_slurp_random_line_count (file, &lines);
if (templine && *templine) {
free (line);
line = templine;
}
free (file);
}
}
return line;
}
R_API void r_core_fortune_print_random(RCore *core) {
// TODO: use file.fortunes // can be dangerous in sandbox mode
char *line = getrandomline (core);
if (!line) {
line = getrandomline (core);
}
if (line) {
if (r_config_get_i (core->config, "cfg.fortunes.clippy")) {
r_core_clippy (core, line);
} else {
r_cons_printf (" -- %s\n", line);
}
if (r_config_get_i (core->config, "cfg.fortunes.tts")) {
r_sys_tts (line, true);
}
free (line);
}
}