ISCSI-INQ: convert to getopt_long instead of popt
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <popt.h>
|
#include <getopt.h>
|
||||||
#include "iscsi.h"
|
#include "iscsi.h"
|
||||||
#include "scsi-lowlevel.h"
|
#include "scsi-lowlevel.h"
|
||||||
|
|
||||||
@@ -219,40 +219,52 @@ void print_help(void)
|
|||||||
fprintf(stderr, " \"ipv6-address\" [fce0::1]\n");
|
fprintf(stderr, " \"ipv6-address\" [fce0::1]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
poptContext pc;
|
|
||||||
struct iscsi_context *iscsi;
|
struct iscsi_context *iscsi;
|
||||||
const char **extra_argv;
|
|
||||||
int extra_argc = 0;
|
|
||||||
const char *url = NULL;
|
const char *url = NULL;
|
||||||
struct iscsi_url *iscsi_url = NULL;
|
struct iscsi_url *iscsi_url = NULL;
|
||||||
int evpd = 0, pagecode = 0;
|
int evpd = 0, pagecode = 0;
|
||||||
int show_help = 0, show_usage = 0, debug = 0;
|
int show_help = 0, show_usage = 0, debug = 0;
|
||||||
int res;
|
int c;
|
||||||
|
|
||||||
struct poptOption popt_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL },
|
{"help", no_argument, NULL, 'h'},
|
||||||
{ "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL },
|
{"usage", no_argument, NULL, 'u'},
|
||||||
{ "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" },
|
{"debug", no_argument, NULL, 'd'},
|
||||||
{ "evpd", 'e', POPT_ARG_INT, &evpd, 0, "evpd", "integer" },
|
{"initiator_name", required_argument, NULL, 'i'},
|
||||||
{ "pagecode", 'c', POPT_ARG_INT, &pagecode, 0, "page code", "integer" },
|
{"evpd", required_argument, NULL, 'e'},
|
||||||
{ "debug", 'd', POPT_ARG_INT, &debug, 0, "Debugging level", "integer" },
|
{"pagecode", required_argument, NULL, 'c'},
|
||||||
POPT_TABLEEND
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
int option_index;
|
||||||
|
|
||||||
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_POSIXMEHARDER);
|
while ((c = getopt_long(argc, argv, "h?udi:e:c:", long_options,
|
||||||
if ((res = poptGetNextOpt(pc)) < -1) {
|
&option_index)) != -1) {
|
||||||
fprintf(stderr, "Failed to parse option : %s %s\n",
|
switch (c) {
|
||||||
poptBadOption(pc, 0), poptStrerror(res));
|
case 'h':
|
||||||
exit(10);
|
case '?':
|
||||||
}
|
show_help = 1;
|
||||||
extra_argv = poptGetArgs(pc);
|
break;
|
||||||
if (extra_argv) {
|
case 'u':
|
||||||
url = strdup(*extra_argv);
|
show_usage = 1;
|
||||||
extra_argv++;
|
break;
|
||||||
while (extra_argv[extra_argc]) {
|
case 'd':
|
||||||
extra_argc++;
|
debug = 1;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
initiator = optarg;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
evpd = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
pagecode = atoi(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Unrecognized option '%c'\n\n", c);
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,8 +278,6 @@ int main(int argc, const char *argv[])
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
poptFreeContext(pc);
|
|
||||||
|
|
||||||
iscsi = iscsi_create_context(initiator);
|
iscsi = iscsi_create_context(initiator);
|
||||||
if (iscsi == NULL) {
|
if (iscsi == NULL) {
|
||||||
fprintf(stderr, "Failed to create context\n");
|
fprintf(stderr, "Failed to create context\n");
|
||||||
@@ -279,6 +289,7 @@ int main(int argc, const char *argv[])
|
|||||||
iscsi_set_log_fn(iscsi, iscsi_log_to_stderr);
|
iscsi_set_log_fn(iscsi, iscsi_log_to_stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
url = strdup(argv[optind]);
|
||||||
if (url == NULL) {
|
if (url == NULL) {
|
||||||
fprintf(stderr, "You must specify the URL\n");
|
fprintf(stderr, "You must specify the URL\n");
|
||||||
print_usage();
|
print_usage();
|
||||||
|
|||||||
Reference in New Issue
Block a user