summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
authorGravatar Nicolas Haunold2010-05-14 16:15:39 +0200
committerGravatar Nicolas Haunold2010-05-14 16:15:39 +0200
commit2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08 (patch)
tree81781824d0b76aa87b5ed4183c30cc2a5f695f09 /src/irecovery.c
parent47d6d8f3289c705144629a2658079c4dae9fb0c3 (diff)
downloadlibirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.gz
libirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.bz2
Added shell with 'internal' commands using readline.
Diffstat (limited to 'src/irecovery.c')
-rw-r--r--src/irecovery.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/irecovery.c b/src/irecovery.c
index e2696d9..13d8be1 100644
--- a/src/irecovery.c
+++ b/src/irecovery.c
@@ -20,11 +20,49 @@
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <libirecovery.h> 22#include <libirecovery.h>
23#include <readline/readline.h>
24#include <readline/history.h>
23 25
24enum { 26enum {
25 kResetDevice, kSendCommand, kSendFile 27 kResetDevice, kStartShell, kSendCommand, kSendFile
26}; 28};
27 29
30void print_shell_usage() {
31 printf("Usage:\n");
32 printf("\t:f <file>\tSend file to device.\n");
33 printf("\t:h\t\tShow this help.\n");
34 printf("\t:q\t\tQuit interactive shell.\n");
35}
36
37void init_shell(irecv_device* device) {
38 int ret;
39
40 for(;;) {
41 char* cmd = readline("iRecovery> ");
42 if(cmd && *cmd) {
43 add_history(cmd);
44 if(cmd[0] == ':') {
45 strtok(cmd, " ");
46 char* arg = strtok(0, " ");
47
48 if(cmd[1] == 'q') {
49 break;
50 } else if(cmd[1] == 'h') {
51 print_shell_usage();
52 } else if(cmd[1] == 'f') {
53 ret = irecv_send_file(device, arg);
54 // TODO: error messages
55 }
56 } else {
57 ret = irecv_send_command(device, cmd);
58 // TODO: error messages
59 }
60
61 free(cmd);
62 }
63 }
64}
65
28void print_usage() { 66void print_usage() {
29 printf("iRecovery - iDevice Recovery Utility\n"); 67 printf("iRecovery - iDevice Recovery Utility\n");
30 printf("Usage: ./irecovery [args]\n"); 68 printf("Usage: ./irecovery [args]\n");
@@ -33,6 +71,7 @@ void print_usage() {
33 printf("\t-f <file>\tSend file to device.\n"); 71 printf("\t-f <file>\tSend file to device.\n");
34 printf("\t-h\t\tShow this help.\n"); 72 printf("\t-h\t\tShow this help.\n");
35 printf("\t-r\t\tReset device.\n"); 73 printf("\t-r\t\tReset device.\n");
74 printf("\t-s\t\tStart interactive shell.\n");
36 exit(1); 75 exit(1);
37} 76}
38 77
@@ -41,7 +80,7 @@ int main(int argc, char** argv) {
41 int action = 0; 80 int action = 0;
42 char* argument = NULL; 81 char* argument = NULL;
43 if(argc == 1) print_usage(); 82 if(argc == 1) print_usage();
44 while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { 83 while ((opt = getopt(argc, argv, "dhrsc:f:")) > 0) {
45 switch (opt) { 84 switch (opt) {
46 case 'd': 85 case 'd':
47 irecv_set_debug(1); 86 irecv_set_debug(1);
@@ -55,6 +94,10 @@ int main(int argc, char** argv) {
55 action = kResetDevice; 94 action = kResetDevice;
56 break; 95 break;
57 96
97 case 's':
98 action = kStartShell;
99 break;
100
58 case 'c': 101 case 'c':
59 action = kSendCommand; 102 action = kSendCommand;
60 argument = optarg; 103 argument = optarg;
@@ -95,6 +138,10 @@ int main(int argc, char** argv) {
95 irecv_send_command(device, argument); 138 irecv_send_command(device, argument);
96 break; 139 break;
97 140
141 case kStartShell:
142 init_shell(device);
143 break;
144
98 default: 145 default:
99 fprintf(stderr, "Unknown action\n"); 146 fprintf(stderr, "Unknown action\n");
100 break; 147 break;