1 /* radare - LGPL - Copyright 2009-2016 - pancake */
2
3 #include "r_core.h"
4
5 static const char *help_msg_q[] = {
6 "Usage:", "q[!][!] [retval]", "",
7 "q","","quit program",
8 "q!","","force quit (no questions)",
9 "q!!","","force quit without saving history",
10 "q!!!","","force quit without freeing anything",
11 "q"," 1","quit with return value 1",
12 "q"," a-b","quit with return value a-b",
13 "q[y/n][y/n]","","quit, chose to kill process, chose to save project ",
14 "Q","", "same as q!!",
15 NULL
16 };
17
cmd_quit_init(RCore * core,RCmdDesc * parent)18 static void cmd_quit_init(RCore *core, RCmdDesc *parent) {
19 DEFINE_CMD_DESCRIPTOR (core, q);
20 }
21
cmd_Quit(void * data,const char * input)22 static int cmd_Quit(void *data, const char *input) {
23 RCore *core = (RCore *)data;
24 if (input[0] == '!') {
25 if (input[1] == '!' || !input[1]) {
26 if (!r_sandbox_enable (false)) {
27 r_cons_flush ();
28 exit (0);
29 }
30 return -2;
31 }
32 r_config_set (core->config, "scr.histsave", "false");
33 }
34 if (IS_DIGIT (input[0]) || input[0] == ' ') {
35 core->num->value = r_num_math (core->num, input);
36 } else {
37 core->num->value = -1;
38 }
39 return -2;
40 }
41
cmd_quit(void * data,const char * input)42 static int cmd_quit(void *data, const char *input) {
43 RCore *core = (RCore *)data;
44 if (input)
45 switch (*input) {
46 case '?':
47 r_core_cmd_help (core, help_msg_q);
48 break;
49 case '!':
50 return cmd_Quit (core, input);
51 case '\0':
52 core->num->value = 0LL;
53 return -2;
54 default:
55 while (*input == ' ') {
56 input++;
57 }
58 if (*input) {
59 r_num_math (core->num, input);
60 } else {
61 core->num->value = 0LL;
62 }
63
64 if (*input == 'y') {
65 core->num->value = 5;
66 } else if (*input == 'n') {
67 core->num->value = 1;
68 }
69
70 if (input[1] == 'y') {
71 core->num->value += 10;
72 } else if (input[1] == 'n') {
73 core->num->value += 2;
74 }
75 //exit (*input?r_num_math (core->num, input+1):0);
76 //if (core->http_up) return false; // cancel quit when http is running
77 return -2;
78 }
79 return false;
80 }
81