Skip to content
Snippets Groups Projects
Commit 8775e22b authored by Jakob Olsson's avatar Jakob Olsson
Browse files

working version of parse_args, add shared debug var

parent 2ff4568a
Branches
Tags
No related merge requests found
...@@ -49,7 +49,7 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb) ...@@ -49,7 +49,7 @@ struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
return bb; return bb;
} }
void set_debug(int debug_arg) void check_debug(void)
{ {
debug = debug_arg; printf("debug: %d\n", debug);
} }
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -20,7 +19,7 @@ ...@@ -20,7 +19,7 @@
#include <libubox/blobmsg.h> #include <libubox/blobmsg.h>
#include <libubus.h> #include <libubus.h>
int debug; extern int debug;
#define debug_print(...) \ #define debug_print(...) \
do \ do \
...@@ -58,5 +57,5 @@ int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, ...@@ -58,5 +57,5 @@ int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx,
*/ */
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb); struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb);
void set_debug(int debug_arg); void check_debug(void);
#endif #endif
#include <getopt.h>
#include "common.h" #include "common.h"
#include "dongle_apn.h" #include "dongle_apn.h"
#include "dongle_pin.h" #include "dongle_pin.h"
...@@ -15,30 +17,26 @@ int parse_args(int argc, char **argv) ...@@ -15,30 +17,26 @@ int parse_args(int argc, char **argv)
{ {
char ch; char ch;
printf("hallå1\n"); while ((ch = getopt_long(argc, argv, "d:", long_options, NULL)) != -1) {
while ((ch = getopt_long(argc, argv, ":d:", long_options, NULL)) != -1) {
int debug_arg;
printf("hallå2\n");
switch (ch) { switch (ch) {
case 'd': case 'd':
debug_arg = atoi(optarg); debug = atoi(optarg);
if (debug_arg > 1 || debug_arg < 0) { if (debug > 1 || debug < 0) {
debug_print("%s: option '-%c' is invalid.\n", argv[0], optopt); printf("%s: option '-%c' is invalid.\n", argv[0], optopt); //cant exactly do debug print in here...
goto fail;
}
break;
case ':':
debug_print(stderr, "%s: option '-%c' requires an argument\n", argv[0], optopt);
goto fail;
break;
case '?':
debug_print(stderr, "%s: option '-%c' is invalid: ignored\n", argv[0], optopt);
goto fail; goto fail;
} break;
printf("hallå3\n");
//set_debug(debug_arg);
break;
case ':':
debug_print(stderr, "%s: option '-%c' requires an argument\n", argv[0], optopt);
goto fail;
break;
case '?':
debug_print(stderr, "%s: option '-%c' is invalid: ignored\n", argv[0], optopt);
goto fail;
break;
} }
} }
return 0; return 0;
fail: fail:
return -1; return -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment