Skip to content

Display and control your Android device

Sort parameters by letter

Romain Vimontd3c76c004e92
diff --git a/app/src/main.c b/app/src/main.c
index 0a87fe55..189dc54e 100644
--- a/app/src/main.c
+++ b/app/src/main.c
@@ -102,40 +102,47 @@ static void print_version(void) {
static int parse_args(struct args *args, int argc, char *argv[]) {
static const struct option long_options[] = {
+ {"bit-rate", required_argument, NULL, 'b'},
{"help", no_argument, NULL, 'h'},
- {"port", required_argument, NULL, 'p'},
{"max-size", required_argument, NULL, 'm'},
- {"bit-rate", required_argument, NULL, 'b'},
+ {"port", required_argument, NULL, 'p'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0 },
};
int c;
- while ((c = getopt_long(argc, argv, "hvp:m:b:", long_options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "b:hm:p:v", long_options, NULL)) != -1) {
switch (c) {
- case 'h': {
- args->help = SDL_TRUE;
- break;
- }
- case 'v': {
- args->version = SDL_TRUE;
- break;
- }
- case 'p': {
+ case 'b': {
char *endptr;
if (*optarg == '\0') {
- LOGE("Invalid port parameter is empty");
+ LOGE("Bit-rate parameter is empty");
return -1;
}
long value = strtol(optarg, &endptr, 0);
+ int mul = 1;
if (*endptr != '\0') {
- LOGE("Invalid port: %s", optarg);
- return -1;
+ if (optarg == endptr) {
+ LOGE("Invalid bit-rate: %s", optarg);
+ return -1;
+ }
+ if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
+ mul = 1000000;
+ } else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
+ mul = 1000;
+ } else {
+ LOGE("Invalid bit-rate unit: %s", optarg);
+ return -1;
+ }
}
- if (value & ~0xffff) {
- LOGE("Port out of range: %ld", value);
+ if (value < 0 || ((Uint32) -1) / mul < value) {
+ LOGE("Bitrate must be positive and less than 2^32: %s", optarg);
return -1;
}
- args->port = (Uint16) value;
+ args->bit_rate = (Uint32) value * mul;
+ break;
+ }
+ case 'h': {
+ args->help = SDL_TRUE;
break;
}
case 'm': {
@@ -156,33 +163,26 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
args->max_size = (Uint16) value;
break;
}
- case 'b': {
+ case 'p': {
char *endptr;
if (*optarg == '\0') {
- LOGE("Bit-rate parameter is empty");
+ LOGE("Invalid port parameter is empty");
return -1;
}
long value = strtol(optarg, &endptr, 0);
- int mul = 1;
if (*endptr != '\0') {
- if (optarg == endptr) {
- LOGE("Invalid bit-rate: %s", optarg);
- return -1;
- }
- if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
- mul = 1000000;
- } else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
- mul = 1000;
- } else {
- LOGE("Invalid bit-rate unit: %s", optarg);
- return -1;
- }
+ LOGE("Invalid port: %s", optarg);
+ return -1;
}
- if (value < 0 || ((Uint32) -1) / mul < value) {
- LOGE("Bitrate must be positive and less than 2^32: %s", optarg);
+ if (value & ~0xffff) {
+ LOGE("Port out of range: %ld", value);
return -1;
}
- args->bit_rate = (Uint32) value * mul;
+ args->port = (Uint16) value;
+ break;
+ }
+ case 'v': {
+ args->version = SDL_TRUE;
break;
}
default: