radare2/libr/core/cmd_quit.c

79 lines
1.7 KiB
C
Raw Normal View History

/* radare - LGPL - Copyright 2009-2016 - pancake */
2016-05-03 02:52:41 +00:00
#include "r_core.h"
static const char *help_msg_q[] = {
"Usage:", "q[!][!] [retval]", "",
"q","","quit program",
"q!","","force quit (no questions)",
"q!!","","force quit without saving history",
2017-10-11 21:48:48 +00:00
"q!!!","","force quit without freeing anything",
"q"," 1","quit with return value 1",
"q"," a-b","quit with return value a-b",
"q[y/n][y/n]","","quit, chose to kill process, chose to save project ",
NULL
};
static void cmd_quit_init(RCore *core) {
DEFINE_CMD_DESCRIPTOR (core, q);
}
static int cmd_Quit(void *data, const char *input) {
RCore *core = (RCore *)data;
if (input[0] == '!') {
2017-10-11 21:48:48 +00:00
if (input[1] == '!') {
if (!r_sandbox_enable (false)) {
exit (0);
}
return -2;
}
r_config_set (core->config, "scr.histsave", "false");
}
2017-02-05 21:50:54 +00:00
if (IS_DIGIT (input[0]) || input[0] == ' ') {
core->num->value = r_num_math (core->num, input);
} else {
core->num->value = -1;
}
return -2;
}
static int cmd_quit(void *data, const char *input) {
RCore *core = (RCore *)data;
if (input)
switch (*input) {
case '?':
r_core_cmd_help (core, help_msg_q);
break;
case '!':
return cmd_Quit (core, input);
case '\0':
2014-11-09 17:28:10 +00:00
core->num->value = 0LL;
return -2;
default:
2016-07-10 14:29:20 +00:00
while (*input == ' ') {
2014-11-09 17:28:10 +00:00
input++;
2016-07-10 14:29:20 +00:00
}
if (*input) {
r_num_math (core->num, input);
2016-07-10 14:29:20 +00:00
} else {
core->num->value = 0LL;
}
2016-07-10 14:29:20 +00:00
if (*input == 'y') {
core->num->value = 5;
} else if (*input == 'n') {
core->num->value = 1;
}
2016-07-10 14:29:20 +00:00
if (input[1] == 'y') {
core->num->value += 10;
} else if (input[1] == 'n') {
core->num->value += 2;
}
//exit (*input?r_num_math (core->num, input+1):0);
2016-07-12 20:15:19 +00:00
//if (core->http_up) return false; // cancel quit when http is running
return -2;
}
2016-07-12 20:15:19 +00:00
return false;
}