From b955d94d5cd7ca575d5fabd5d85c7c523d2a5e58 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 23 Oct 2001 14:16:59 +0000 Subject: Replace getopt_long with popt for parsing commandline options (This used to be commit 0be7bf421be5ccff295a0d36331e915fce31796f) --- source3/utils/net.c | 227 +++++++++++++++++++++------------------------------- 1 file changed, 91 insertions(+), 136 deletions(-) diff --git a/source3/utils/net.c b/source3/utils/net.c index 93214dda5a..ab798df616 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -36,7 +36,6 @@ /*****************************************************/ #include -#include /***********************************************************************/ /* Beginning of internationalization section. Translatable constants */ @@ -280,26 +279,6 @@ const char share_type[][6] = { #define MAXUSERS_USAGE "\t-M or --maxusers=\t\tmax users allowed for share\n" #define LONG_USAGE "\t-l or --long\t\t\tDisplay full information\n" -static struct option long_options[] = -{ - {"help", no_argument,NULL,'h'}, - {"workgroup",required_argument,NULL,'w'}, - {"myworkgroup",required_argument,NULL,'W'}, - {"user",required_argument,NULL,'U'}, - {"ipaddress",required_argument,NULL,'I'}, - {"port",required_argument,NULL,'p'}, - {"myname",required_argument,NULL,'n'}, - {"conf",required_argument,NULL,'s'}, - {"debug",required_argument,NULL,'d'}, - {"server",required_argument,NULL,'S'}, - {"comment",required_argument,NULL,'C'}, - {"maxusers",required_argument,NULL,'M'}, - {"flags", required_argument, NULL, 'M'}, - {"jobid",required_argument,NULL,'j'}, - {"long",no_argument,NULL,'l'}, - { 0, 0, 0, 0} -}; - #define ERRMSG_NOCONN_TARGET_SRVR "\nUnable to connect to target server\n" #define ERRMSG_NOCONN_BROWSE_MSTR "\nUnable to connect to browse master\n" #define ERRMSG_NOT_IMPLEMENTED "\nNot implemented\n" @@ -338,7 +317,7 @@ static pstring password; static pstring global_user_name; static pstring global_workgroup; static int port = SMB_PORT; -static BOOL long_list_entries = False; +static int long_list_entries = 0; static BOOL got_pass = False; static BOOL have_ip = False; struct in_addr dest_ip; @@ -757,7 +736,7 @@ void server_usage(void) printf(CONF_USAGE); } -int net_server(char * temp_workgroup, int subfunct, char * opt_parm) +int net_server(char * temp_workgroup, int subfunct) { /* try to find master browser for our domain - if we fail try to find pdc */ char our_workgroup[16]; @@ -1225,56 +1204,97 @@ int main(int argc,char *argv[]) int func = 0; int subfunc = LIST_SF; int argc_new = 0; - char * argv_new[50]; - pstring temp_arg; /* BB placeholder - need to delete */ - static pstring servicesf = CONFIGFILE; - static fstring target_workgroup; - fstring comment = ""; /* BB fix so this can be parsed from user input */ - int maxusers = -1; - int jobid = 0; - - target_workgroup[0] = 0; + char ** argv_new; + poptContext pc; + static char *servicesf = CONFIGFILE; + static char *target_workgroup = NULL; + static char *comment = ""; + static char *user_name = NULL; + static char *my_workgroup = NULL; + static char *requester_name = NULL; + static char *dest_host = NULL; + static int maxusers = -1; + static int flagsarg = -1; + static int jobid = 0; + static int debuglevel; + + static struct poptOption long_options[] = { + {"help", 'h', POPT_ARG_NONE, 0, 'h'}, + {"workgroup", 'w', POPT_ARG_STRING, &target_workgroup}, + {"myworkgroup", 'W', POPT_ARG_STRING, &my_workgroup}, + {"user", 'U', POPT_ARG_STRING, &user_name, 'U'}, + {"ipaddress", 'I', POPT_ARG_STRING, 0, 'I'}, + {"port", 'p', POPT_ARG_INT, &port}, + {"myname", 'n', POPT_ARG_STRING, &requester_name}, + {"conf", 's', POPT_ARG_STRING, &servicesf}, + {"debug", 'd', POPT_ARG_INT, &debuglevel, 'd'}, + {"server", 'S', POPT_ARG_STRING, &dest_host}, + {"comment", 'C', POPT_ARG_STRING, &comment}, + {"maxusers", 'M', POPT_ARG_INT, &maxusers}, + {"flags", 'F', POPT_ARG_INT, &flagsarg}, + {"jobid", 'j', POPT_ARG_INT, &jobid}, + {"long", 'l', POPT_ARG_NONE, &long_list_entries}, + { 0, 0, 0, 0} + }; + got_pass = 0; dest_ip = ipzero; - + host[0] = 0; dbf = x_stdout; setbuffer(stdout, NULL, 0); -/* charset_initialise(); */ /* BB do we need to add KANJI term_code processing? BB */ + pc = poptGetContext(NULL, argc, (const char **) argv, long_options, + POPT_CONTEXT_KEEP_FIRST); - for(i=0;i 3) - rc = net_user(subfunc,argv_new[3], comment, maxusers /* overloaded for user flags */); + rc = net_user(subfunc,argv_new[3], comment, flagsarg); break; case GROUPF: if (argc_new == 2) @@ -1489,7 +1444,7 @@ int main(int argc,char *argv[]) } break; case VALIDATEF: - rc = net_validate(temp_arg); + rc = net_validate(global_user_name); break; case PRINTQF: if (argc_new <= 3) -- cgit