From 520c99d33e18009660f30bd38b31a2f1cd432fe6 Mon Sep 17 00:00:00 2001 From: Joshua Hill Date: Thu, 13 May 2010 08:58:46 -0400 Subject: Implemented command line argument parsing and irecv_command() function. --- src/irecovery.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'src/irecovery.c') diff --git a/src/irecovery.c b/src/irecovery.c index 90f975b..51320a5 100644 --- a/src/irecovery.c +++ b/src/irecovery.c @@ -17,9 +17,50 @@ **/ #include +#include +#include #include +enum { + kResetDevice, kSendCommand +}; + +void print_usage() { + printf("iRecovery - iDevice Recovery Utility\n"); + printf("Usage: ./irecovery [args]\n"); + exit(1); +} + int main(int argc, char** argv) { + int opt = 0; + int action = 0; + char* argument = NULL; + if(argc == 1) print_usage(); + while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { + switch (opt) { + case 'd': + irecv_set_debug(1); + break; + + case 'h': + print_usage(); + break; + + case 'r': + action = kResetDevice; + break; + + case 'c': + argument = optarg; + action = kSendCommand; + break; + + default: + fprintf(stderr, "Unknown argument\n"); + break; + } + } + irecv_device* device = NULL; if(irecv_init(&device) < 0) { fprintf(stderr, "Unable to initialize libirecovery\n"); @@ -31,27 +72,20 @@ int main(int argc, char** argv) { return -1; } - switch (device->mode) { - case kRecoveryMode: - printf("Found device in recovery mode\n"); + switch(action) { + case kResetDevice: + irecv_reset(device); break; - case kDfuMode: - printf("Found device in DFU mode\n"); - break; - - case kKernelMode: - printf("Found device in kernel mode\n"); + case kSendCommand: + irecv_command(device, argument); break; default: - printf("No device found\n"); + fprintf(stderr, "Unknown action\n"); break; } - printf("Sending USB reset...\n"); - irecv_reset(device); - irecv_exit(device); return 0; } -- cgit v1.1-32-gdbae