* src/pwck.c, man/pwck.8.xml: Add support for long options.

* src/pwck.c, man/pwck.8.xml: Add -h/--help option
	* src/grpck.c, man/grpck.8.xml: Add support for long options.
	* src/grpck.c, man/grpck.8.xml: Add -h/--help option
This commit is contained in:
nekral-guest
2011-11-06 18:39:36 +00:00
parent b9163f6348
commit 900943192f
5 changed files with 122 additions and 68 deletions

View File

@@ -39,6 +39,7 @@
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <getopt.h>
#include "chkname.h"
#include "commonio.h"
#include "defines.h"
@@ -55,6 +56,7 @@
*/
/*@-exitarg@*/
#define E_OKAY 0
#define E_SUCCESS 0
#define E_USAGE 1
#define E_BAD_ENTRY 2
#define E_CANT_OPEN 3
@@ -82,7 +84,7 @@ static bool sort_mode = false;
/* local function prototypes */
static void fail_exit (int status);
static void usage (void);
static /*@noreturn@*/void usage (int status);
static void delete_member (char **, const char *);
static void process_flags (int argc, char **argv);
static void open_files (void);
@@ -134,14 +136,28 @@ static void fail_exit (int status)
/*
* usage - print syntax message and exit
*/
static void usage (void)
static /*@noreturn@*/void usage (int status)
{
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
#ifdef SHADOWGRP
fprintf (stderr, _("Usage: %s [-r] [-s] [group [gshadow]]\n"), Prog);
#else
fprintf (stderr, _("Usage: %s [-r] [-s] [group]\n"), Prog);
#endif
exit (E_USAGE);
(void) fprintf (usageout,
_("Usage: %s [options] [group [gshadow]]\n"
"\n"
"Options:\n"),
Prog);
#else /* !SHADOWGRP */
(void) fprintf (usageout,
_("Usage: %s [options] [group]\n"
"\n"
"Options:\n"),
Prog);
#endif /* !SHADOWGRP */
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -r, --read-only display errors and warnings\n"
" but do not change files\n"), usageout);
(void) fputs (_(" -s, --sort sort entries by UID\n"), usageout);
(void) fputs ("\n", usageout);
exit (status);
}
/*
@@ -173,13 +189,24 @@ static void delete_member (char **list, const char *member)
*/
static void process_flags (int argc, char **argv)
{
int arg;
int c;
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"quiet", no_argument, NULL, 'q'},
{"read-only", no_argument, NULL, 'r'},
{"sort", no_argument, NULL, 's'},
{NULL, 0, NULL, '\0'}
};
/*
* Parse the command line arguments
*/
while ((arg = getopt (argc, argv, "qrs")) != EOF) {
switch (arg) {
while ((c = getopt_long (argc, argv, "hqrs",
long_options, NULL)) != -1) {
switch (c) {
case 'h':
usage (E_SUCCESS);
/*@notreached@*/break;
case 'q':
/* quiet - ignored for now */
break;
@@ -190,12 +217,12 @@ static void process_flags (int argc, char **argv)
sort_mode = true;
break;
default:
usage ();
usage (E_USAGE);
}
}
if (sort_mode && read_only) {
fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog);
fprintf (stderr, _("%s: -s and -r are incompatible\n"), Prog);
exit (E_USAGE);
}
@@ -208,7 +235,7 @@ static void process_flags (int argc, char **argv)
if (argc > (optind + 1))
#endif
{
usage ();
usage (E_USAGE);
}
/*