2014-03-08 11:01:56 -06:00
|
|
|
/* Please use this file as a template when introducing new command to
|
|
|
|
* util-linux package.
|
|
|
|
* -- remove above */
|
|
|
|
/*
|
|
|
|
* fixme-command-name - purpose of it
|
|
|
|
*
|
|
|
|
* Copyright (c) 20nn Example Commercial, Inc
|
|
|
|
* Written by Your Name <you@example.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
#include "closestream.h"
|
|
|
|
#include "nls.h"
|
|
|
|
|
2017-06-23 18:24:38 -05:00
|
|
|
/*
|
|
|
|
* FIXME: remove this comment.
|
|
|
|
* Other usage() constants that are not demonstrated below:
|
|
|
|
* USAGE_FUNCTIONS USAGE_COMMANDS USAGE_COLUMNS
|
|
|
|
*/
|
2017-06-20 13:20:29 -05:00
|
|
|
static void __attribute__((__noreturn__)) usage(void)
|
2014-03-08 11:01:56 -06:00
|
|
|
{
|
2017-06-20 13:20:29 -05:00
|
|
|
FILE *out = stdout;
|
2014-03-08 11:01:56 -06:00
|
|
|
fputs(USAGE_HEADER, out);
|
|
|
|
fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
|
2017-06-21 04:25:55 -05:00
|
|
|
|
|
|
|
fputs(USAGE_SEPARATOR, out);
|
|
|
|
fputs(_("Short program description.\n"), out);
|
|
|
|
|
2014-03-08 11:01:56 -06:00
|
|
|
fputs(USAGE_OPTIONS, out);
|
|
|
|
fputs(_(" -n, --no-argument option does not use argument\n"), out);
|
2016-04-16 09:30:39 -05:00
|
|
|
fputs(_(" --optional[=<arg>] option argument is optional\n"), out);
|
2014-03-08 11:01:56 -06:00
|
|
|
fputs(_(" -r, --required <arg> option requires an argument\n"), out);
|
|
|
|
fputs(_(" -z no long option\n"), out);
|
|
|
|
fputs(_(" --xyzzy a long option only\n"), out);
|
2017-03-05 14:52:31 -06:00
|
|
|
fputs(_(" -e, --extremely-long-long-option\n"
|
|
|
|
" use next line for description when needed\n"), out);
|
|
|
|
fputs(_(" -l, --long-explanation an example of very verbose, and chatty option\n"
|
|
|
|
" description on two, or multiple lines, where the\n"
|
|
|
|
" consecutive lines are intended by two spaces\n"), out);
|
2014-03-08 11:01:56 -06:00
|
|
|
fputs(_(" -f, --foobar next option description resets indent\n"), out);
|
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2017-06-29 08:52:16 -05:00
|
|
|
printf(USAGE_HELP_OPTIONS(25)); /* char offset to align option descriptions */
|
|
|
|
printf(USAGE_MAN_TAIL("fixme-command-name(1)"));
|
2017-06-20 13:20:29 -05:00
|
|
|
exit(EXIT_SUCCESS);
|
2014-03-08 11:01:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
enum {
|
2016-04-16 09:30:39 -05:00
|
|
|
OPT_XYZZY = CHAR_MAX + 1,
|
|
|
|
OPT_OPTIONAL /* see howto-man-page.txt about short option */
|
2014-03-08 11:01:56 -06:00
|
|
|
};
|
|
|
|
static const struct option longopts[] = {
|
2017-02-11 14:23:26 -06:00
|
|
|
{ "no-argument", no_argument, NULL, 'n' },
|
|
|
|
{ "required", required_argument, NULL, 'r' },
|
|
|
|
{ "extremely-long-long-option", no_argument, NULL, 'e' },
|
|
|
|
{ "xyzzy", no_argument, NULL, OPT_XYZZY },
|
|
|
|
{ "long-explanation", no_argument, NULL, 'l' },
|
|
|
|
{ "foobar", no_argument, NULL, 'f' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
2014-03-08 11:01:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
atexit(close_stdout);
|
|
|
|
|
2017-03-05 14:52:31 -06:00
|
|
|
while ((c = getopt_long(argc, argv, "nr:zelfVh", longopts, NULL)) != -1)
|
2014-03-08 11:01:56 -06:00
|
|
|
switch (c) {
|
|
|
|
case 'n':
|
2016-04-16 09:30:39 -05:00
|
|
|
case OPT_OPTIONAL:
|
2014-03-08 11:01:56 -06:00
|
|
|
case 'r':
|
2017-03-05 14:52:31 -06:00
|
|
|
case 'z':
|
2014-03-08 11:01:56 -06:00
|
|
|
case OPT_XYZZY:
|
|
|
|
case 'e':
|
|
|
|
case 'l':
|
|
|
|
case 'f':
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf(UTIL_LINUX_VERSION);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case 'h':
|
2017-06-20 13:20:29 -05:00
|
|
|
usage();
|
2014-03-08 11:01:56 -06:00
|
|
|
default:
|
2016-12-19 06:13:34 -06:00
|
|
|
errtryhelp(EXIT_FAILURE);
|
2014-03-08 11:01:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|