Add r_sys_tts and cfg.fortunes.tts (only for OSX atm)

This commit is contained in:
pancake 2016-12-21 01:46:19 +01:00
parent a8515ec1d8
commit 4cb9df1cc5
6 changed files with 21 additions and 4 deletions

View File

@ -43,7 +43,7 @@ Move the comments to the right changing their margin with asm.cmtmargin
Execute a command on the visual prompt with cmd.vprompt
Reduce the delta where flag resolving by address is used with cfg.delta
Disable these messages with 'e cfg.fortunes = false' in your ~/.radare2rc
Change your fortune types with 'e cfg.fortunetype = fun,tips,nsfw' in your ~/.radare2rc
Change your fortune types with 'e cfg.fortunes.type = fun,tips,nsfw' in your ~/.radare2rc
Show offsets in graphs with 'e graph.offset = true'
Execute a command every time a breakpoint is hit with 'e cmd.bp = !my-program'
Disassemble in intel syntax with 'e asm.syntax = intel'.

View File

@ -1874,7 +1874,8 @@ R_API int r_core_config_init(RCore *core) {
r_config_desc (cfg, "cfg.editor", "Select default editor program");
SETPREF("cfg.user", r_sys_whoami (buf), "Set current username/pid");
SETPREF("cfg.fortunes", "true", "If enabled show tips at start");
SETPREF("cfg.fortunetype", "tips,fun", "Type of fortunes to show (tips, fun, nsfw)");
SETPREF("cfg.fortunes.type", "tips,fun", "Type of fortunes to show (tips, fun, nsfw)");
SETPREF("cfg.fortunes.tts", "true", "Speak out the fortune");
SETI("cfg.hashlimit", SLURP_LIMIT, "If the file is bigger than hashlimit, do not compute hashes");
SETPREF("cfg.prefixdump", "dump", "Filename prefix for automated dumps");
SETCB("cfg.sandbox", "false", &cb_cfgsanbox, "Sandbox mode disables systems and open on upper directories");

View File

@ -598,7 +598,7 @@ eprintf ("WTF 'f .xxx' adds a variable to the function? ?!!?(%s)\n");
const char *fortunes_fuun = R2_PREFIX "/share/doc/radare2/fortunes.fun";
const char *fortunes_nsfw = R2_PREFIX "/share/doc/radare2/fortunes.nsfw";
const char *fortunes_crep = R2_PREFIX "/share/doc/radare2/fortunes.creepy";
const char *types = (char *)r_config_get (core->config, "cfg.fortunetype");
const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type");
char *line = NULL, *templine = NULL;
int i = 0;
if (strstr (types, "tips")) {
@ -628,6 +628,9 @@ eprintf ("WTF 'f .xxx' adds a variable to the function? ?!!?(%s)\n");
}
if (line) {
r_cons_printf (" -- %s\n", line);
if (r_config_get_i (core->config, "cfg.fortunes.tts")) {
r_sys_tts (line, true);
}
free (line);
}
}

View File

@ -50,4 +50,5 @@ R_API char *r_sys_cmd_str(const char *cmd, const char *input, int *len);
R_API char *r_sys_cmd_strf(const char *cmd, ...);
//#define r_sys_cmd_str(cmd, input, len) r_sys_cmd_str_full(cmd, input, len, 0)
R_API void r_sys_backtrace(void);
R_API bool r_sys_tts(const char *txt, bool bg);
#endif // R_SYS_H

View File

@ -1521,7 +1521,7 @@ R_API char *r_str_ansi_crop(const char *str, unsigned int x, unsigned int y,
ch++;
cw = 0;
} else if (*str == 0x1b && str + 1 && *(str + 1) == '[') {
const char *ptr;
const char *ptr = str;
if ((r_end - r) > 3) {
/* copy 0x1b and [ */
*r++ = *str++;

View File

@ -879,3 +879,15 @@ R_API int r_sys_getpid() {
return -1;
#endif
}
R_API bool r_sys_tts(const char *txt, bool bg) {
// XXX: This is OSX-specific. must be ported to linux and windows
#if __APPLE__
char *line = r_str_replace (strdup (txt), "\"", "'", 1);
r_sys_cmdf ("say \"%s\"%s", line, bg? " &": "");
free (line);
return true;
#else
return false;
#endif
}