diff options
author | Nicolas Haunold | 2010-05-14 16:15:39 +0200 |
---|---|---|
committer | Nicolas Haunold | 2010-05-14 16:15:39 +0200 |
commit | 2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08 (patch) | |
tree | 81781824d0b76aa87b5ed4183c30cc2a5f695f09 /src | |
parent | 47d6d8f3289c705144629a2658079c4dae9fb0c3 (diff) | |
download | libirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.gz libirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.bz2 |
Added shell with 'internal' commands using readline.
Diffstat (limited to 'src')
-rw-r--r-- | src/irecovery.c | 51 |
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 @@ #include <stdlib.h> #include <unistd.h> #include <libirecovery.h> +#include <readline/readline.h> +#include <readline/history.h> enum { - kResetDevice, kSendCommand, kSendFile + kResetDevice, kStartShell, kSendCommand, kSendFile }; +void print_shell_usage() { + printf("Usage:\n"); + printf("\t:f <file>\tSend file to device.\n"); + printf("\t:h\t\tShow this help.\n"); + printf("\t:q\t\tQuit interactive shell.\n"); +} + +void init_shell(irecv_device* device) { + int ret; + + for(;;) { + char* cmd = readline("iRecovery> "); + if(cmd && *cmd) { + add_history(cmd); + if(cmd[0] == ':') { + strtok(cmd, " "); + char* arg = strtok(0, " "); + + if(cmd[1] == 'q') { + break; + } else if(cmd[1] == 'h') { + print_shell_usage(); + } else if(cmd[1] == 'f') { + ret = irecv_send_file(device, arg); + // TODO: error messages + } + } else { + ret = irecv_send_command(device, cmd); + // TODO: error messages + } + + free(cmd); + } + } +} + void print_usage() { printf("iRecovery - iDevice Recovery Utility\n"); printf("Usage: ./irecovery [args]\n"); @@ -33,6 +71,7 @@ void print_usage() { printf("\t-f <file>\tSend file to device.\n"); printf("\t-h\t\tShow this help.\n"); printf("\t-r\t\tReset device.\n"); + printf("\t-s\t\tStart interactive shell.\n"); exit(1); } @@ -41,7 +80,7 @@ int main(int argc, char** argv) { int action = 0; char* argument = NULL; if(argc == 1) print_usage(); - while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { + while ((opt = getopt(argc, argv, "dhrsc:f:")) > 0) { switch (opt) { case 'd': irecv_set_debug(1); @@ -55,6 +94,10 @@ int main(int argc, char** argv) { action = kResetDevice; break; + case 's': + action = kStartShell; + break; + case 'c': action = kSendCommand; argument = optarg; @@ -95,6 +138,10 @@ int main(int argc, char** argv) { irecv_send_command(device, argument); break; + case kStartShell: + init_shell(device); + break; + default: fprintf(stderr, "Unknown action\n"); break; |