zyxel-revert/zyxel-revert.c

61 lines
988 B
C
Raw Normal View History

2007-04-23 10:23:40 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include "context.h"
#include "event.h"
#include "serial.h"
static struct option opts[] = {
2007-05-02 20:32:36 +02:00
{"device", 1, 0, 'd'},
{"device", 1, 0, 'f'},
2007-04-23 10:23:40 +02:00
{0, 0, 0, 0}
};
int main(int argc, char *argv[])
{
2007-05-02 20:32:36 +02:00
char *devicename = NULL, *filename = NULL;
int code, arg = 0;
2007-04-23 10:23:40 +02:00
do {
2007-05-02 20:32:36 +02:00
code = getopt_long(argc, argv, "d:f:", opts, &arg);
2007-04-23 10:23:40 +02:00
switch (code) {
2007-05-02 20:32:36 +02:00
case 'd': devicename = optarg;
2007-04-23 10:23:40 +02:00
break;
2007-05-02 20:32:36 +02:00
case 'f': filename = optarg;
2007-04-23 10:23:40 +02:00
break;
case 'h': /* help */
2007-05-02 20:32:36 +02:00
printf("Usage: zyxel-revert -d <device> -f <file>\n");
2007-04-23 10:23:40 +02:00
exit(0);
break;
case '?': /* error */
exit(-1);
break;
default: /* unknown / all options parsed */
break;
}
} while (code != -1);
2007-05-02 20:42:12 +02:00
struct context *ctx = create_context(filename);
if (ctx == NULL)
2007-04-23 10:23:40 +02:00
exit(1);
2007-05-02 20:42:12 +02:00
if (devicename == NULL || serial_init(ctx, devicename)) {
2007-04-23 10:23:40 +02:00
context_close();
exit(1);
}
event_loop();
context_close();
return 0;
}