isolated out the actual parameter parsing code, in preparation for configuration file
This commit is contained in:
parent
9232797afd
commit
6684842b35
79
main.c
79
main.c
|
@ -1,6 +1,7 @@
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "fuse_local.h"
|
#include "fuse_local.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string);
|
void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string);
|
||||||
static void print_help(char *program_name, int long_help);
|
static void print_help(char *program_name, int long_help);
|
||||||
static void print_http_options();
|
static void print_http_options();
|
||||||
|
static int
|
||||||
|
parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc);
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -27,6 +30,35 @@ int main(int argc, char **argv)
|
||||||
/* initialise network configuration struct */
|
/* initialise network configuration struct */
|
||||||
network_config_init();
|
network_config_init();
|
||||||
|
|
||||||
|
/* Add the last remaining argument, which is the mountpoint */
|
||||||
|
add_arg(&fuse_argv, &fuse_argc, argv[argc-1]);
|
||||||
|
|
||||||
|
if (parse_arg_list(argc, argv, &fuse_argv, &fuse_argc)) {
|
||||||
|
goto fuse_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The second last remaining argument is the URL */
|
||||||
|
char *base_url = argv[argc-2];
|
||||||
|
if (strncmp(base_url, "http://", 7) && strncmp(base_url, "https://", 8)) {
|
||||||
|
fprintf(stderr, "Error: Please supply a valid URL.\n");
|
||||||
|
print_help(argv[0], 0);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
if(!network_init(base_url)) {
|
||||||
|
fprintf(stderr, "Error: Network initialisation failed.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fuse_start:
|
||||||
|
fuse_local_init(fuse_argc, fuse_argv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
|
||||||
|
{
|
||||||
char c;
|
char c;
|
||||||
int long_index = 0;
|
int long_index = 0;
|
||||||
const char *short_opts = "o:hVdfsp:u:P:";
|
const char *short_opts = "o:hVdfsp:u:P:";
|
||||||
|
@ -46,25 +78,24 @@ int main(int argc, char **argv)
|
||||||
&long_index)) != -1) {
|
&long_index)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'o':
|
case 'o':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-o");
|
add_arg(fuse_argv, fuse_argc, "-o");
|
||||||
add_arg(&fuse_argv, &fuse_argc, optarg);
|
add_arg(fuse_argv, fuse_argc, optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
print_help(argv[0], 1);
|
print_help(argv[0], 1);
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-h");
|
add_arg(fuse_argv, fuse_argc, "-h");
|
||||||
goto fuse_start;
|
return 1;
|
||||||
break;
|
|
||||||
case 'V':
|
case 'V':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-V");
|
add_arg(fuse_argv, fuse_argc, "-V");
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-d");
|
add_arg(fuse_argv, fuse_argc, "-d");
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-f");
|
add_arg(fuse_argv, fuse_argc, "-f");
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-s");
|
add_arg(fuse_argv, fuse_argc, "-s");
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
NETWORK_CONFIG.username = strndup(optarg, ARG_LEN_MAX);
|
NETWORK_CONFIG.username = strndup(optarg, ARG_LEN_MAX);
|
||||||
|
@ -89,38 +120,16 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Error: Invalid option\n");
|
fprintf(stderr, "Error: Invalid option\n");
|
||||||
add_arg(&fuse_argv, &fuse_argc, "--help");
|
add_arg(fuse_argv, fuse_argc, "--help");
|
||||||
goto fuse_start;
|
return 1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Error: Invalid option\n");
|
fprintf(stderr, "Error: Invalid option\n");
|
||||||
add_arg(&fuse_argv, &fuse_argc, "--help");
|
add_arg(fuse_argv, fuse_argc, "--help");
|
||||||
goto fuse_start;
|
return 1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Add the last remaining argument, which is the mountpoint */
|
|
||||||
add_arg(&fuse_argv, &fuse_argc, argv[argc-1]);
|
|
||||||
|
|
||||||
/* The second last remaining argument is the URL */
|
|
||||||
char *base_url = argv[argc-2];
|
|
||||||
if (strncmp(base_url, "http://", 7) && strncmp(base_url, "https://", 8)) {
|
|
||||||
fprintf(stderr, "Error: Please supply a valid URL.\n");
|
|
||||||
print_help(argv[0], 0);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else {
|
|
||||||
if(!network_init(base_url)) {
|
|
||||||
fprintf(stderr, "Error: Network initialisation failed.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fuse_start:
|
|
||||||
fuse_local_init(fuse_argc, fuse_argv);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue