- while ((c = getopt(argc, argv, "123")) !=-1) {
- switch (c) {
- case '1':
- firmware->flags = ntohl(0x10577050); // Motorola WR850G
- break;
- case '2':
- firmware->flags = ntohl(0x10577040); // Motorola WA840G
- break;
- case '3':
- firmware->flags = ntohl(0x10577000); // Motorola WE800G
+ if (ugh != NULL) {
+ fprintf(stderr, "%s\n", ugh);
+ exit(3);
+ } else {
+ // all is well, write the file without the prefix
+ if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0
+ || write(fd, trx + sizeof(struct motorola), len - sizeof(struct motorola)) != len - sizeof(struct motorola)
+ || close(fd) < 0)
+ {
+ fprintf(stderr, "Error storing file %s: %s\n", argv[3], strerror(errno));
+ exit(2);
+ }
+ }
+
+ } else {
+ // setup the firmware flags magic number
+ const struct model *m;
+ const char *df = argv[1];
+
+ if (*df != '-')
+ usage("first argument must start with -");
+ if (*++df == '-')
+ ++df; /* allow but don't require second - */
+
+ for (m = models; ; m++) {
+ if (m->digit == '\0')
+ usage("unrecognized device specified");
+ if ((df[0] == m->digit && df[1] == '\0') || strcasecmp(df, m->name) == 0) {
+ flags = m->flags;