Use getopt_long() in awesome

Simplify getopt_long usage in awesome-message.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Hans Ulrich Niedermann 2008-01-31 18:34:59 +01:00 committed by Julien Danjou
parent a28876b5ce
commit c4345f1be4
2 changed files with 30 additions and 20 deletions

View File

@ -21,6 +21,7 @@
#define _GNU_SOURCE
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
@ -122,7 +123,7 @@ main(int argc, char **argv)
Bool running = True;
Area geometry = { 0, 0, 200, 50, NULL },
icon_geometry = { -1, -1, -1, -1, NULL };
int opt, option_index = 0;
int opt;
char *configfile = NULL;
static struct option long_options[] =
{
@ -137,7 +138,7 @@ main(int argc, char **argv)
globalconf.display = disp;
while((opt = getopt_long(argc, argv, "vhf:b:x:y:n:c:",
long_options, &option_index)) != -1)
long_options, NULL)) != -1)
switch(opt)
{
case 'v':

View File

@ -19,6 +19,9 @@
*
*/
#define _GNU_SOURCE
#include <getopt.h>
#include <errno.h>
#include <locale.h>
#include <stdio.h>
@ -214,30 +217,36 @@ main(int argc, char *argv[])
int i, cmdlen;
event_handler **handler;
struct sockaddr_un *addr;
int args_ok = 1;
int opt;
static struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'},
{NULL, 0, NULL, 0}
};
/* check args */
/* XXX switch to getopt */
if(argc >= 2)
while((opt = getopt_long(argc, argv, "vhkc:",
long_options, NULL)) != -1)
switch(opt)
{
args_ok = 0;
if(!a_strcmp("-v", argv[1]) || !a_strcmp("--version", argv[1]))
case 'v':
eprint_version("awesome");
else if(!a_strcmp("-h", argv[1]) || !a_strcmp("--help", argv[1]))
break;
case 'h':
exit_help(EXIT_SUCCESS);
else if(!a_strcmp("-c", argv[1]))
{
if(a_strlen(argv[2]))
confpath = argv[2], args_ok = 1;
break;
case 'c':
if(a_strlen(optarg))
confpath = optarg;
else
eprint("-c option requires a file name\n");
}
else if(!a_strcmp("-k", argv[1]))
break;
case 'k':
return config_check(confpath);
else
exit_help(EXIT_FAILURE);
break;
}
if(!args_ok)
if(argc - optind < 1)
exit_help(EXIT_FAILURE);
/* Text won't be printed correctly otherwise */