]> git.ipfire.org Git - thirdparty/util-linux.git/blame - Documentation/boilerplate.c
Merge branch 'lscpu-json-types' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / Documentation / boilerplate.c
CommitLineData
a97b307a
SK
1/* Please use this file as a template when introducing new command to
2 * util-linux package.
3 * -- remove above */
4/*
5 * fixme-command-name - purpose of it
6 *
7 * Copyright (c) 20nn Example Commercial, Inc
8 * Written by Your Name <you@example.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it would be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#include <getopt.h>
25#include <stdio.h>
26#include <unistd.h>
27
28#include "c.h"
29#include "closestream.h"
30#include "nls.h"
31
610d0fbc
WP
32/*
33 * FIXME: remove this comment.
34 * Other usage() constants that are not demonstrated below:
35 * USAGE_FUNCTIONS USAGE_COMMANDS USAGE_COLUMNS
36 */
86be6a32 37static void __attribute__((__noreturn__)) usage(void)
a97b307a 38{
dc05716f
WP
39 fputs(USAGE_HEADER, stdout);
40 printf(_(" %s [options] file...\n"), program_invocation_short_name);
9e258f38 41
dc05716f
WP
42 fputs(USAGE_SEPARATOR, stdout);
43 puts(_("Short program description."));
9e258f38 44
dc05716f
WP
45 fputs(USAGE_OPTIONS, stdout);
46 puts(_(" -n, --no-argument option does not use argument"));
47 puts(_(" --optional[=<arg>] option argument is optional"));
48 puts(_(" -r, --required <arg> option requires an argument"));
49 puts(_(" -z no long option"));
50 puts(_(" --xyzzy a long option only"));
51 puts(_(" -e, --extremely-long-long-option\n"
52 " use next line for description when needed"));
53 puts(_(" -l, --long-explanation an example of very verbose, and chatty option\n"
54 " description on two, or multiple lines, where the\n"
55 " consecutive lines are intended by two spaces"));
56 puts(_(" -f, --foobar next option description resets indent"));
57 fputs(USAGE_SEPARATOR, stdout);
f45f3ec3
RM
58 printf(USAGE_HELP_OPTIONS(25)); /* char offset to align option descriptions */
59 printf(USAGE_MAN_TAIL("fixme-command-name(1)"));
86be6a32 60 exit(EXIT_SUCCESS);
a97b307a
SK
61}
62
63int main(int argc, char **argv)
64{
65 int c;
66
67 enum {
326c5c93
SK
68 OPT_XYZZY = CHAR_MAX + 1,
69 OPT_OPTIONAL /* see howto-man-page.txt about short option */
a97b307a
SK
70 };
71 static const struct option longopts[] = {
f636ef1f
SK
72 { "no-argument", no_argument, NULL, 'n' },
73 { "optional", optional_argument, NULL, OPT_OPTIONAL },
74 { "required", required_argument, NULL, 'r' },
75 { "extremely-long-long-option", no_argument, NULL, 'e' },
76 { "xyzzy", no_argument, NULL, OPT_XYZZY },
77 { "long-explanation", no_argument, NULL, 'l' },
78 { "foobar", no_argument, NULL, 'f' },
79 { "version", no_argument, NULL, 'V' },
80 { "help", no_argument, NULL, 'h' },
87918040 81 { NULL, 0, NULL, 0 }
a97b307a
SK
82 };
83
84 setlocale(LC_ALL, "");
85 bindtextdomain(PACKAGE, LOCALEDIR);
86 textdomain(PACKAGE);
2c308875 87 close_stdout_atexit();
a97b307a 88
6cb55736 89 while ((c = getopt_long(argc, argv, "nr:zelfVh", longopts, NULL)) != -1)
a97b307a
SK
90 switch (c) {
91 case 'n':
326c5c93 92 case OPT_OPTIONAL:
a97b307a 93 case 'r':
6cb55736 94 case 'z':
a97b307a
SK
95 case OPT_XYZZY:
96 case 'e':
97 case 'l':
98 case 'f':
99 break;
100 case 'V':
2c308875 101 print_version(EXIT_SUCCESS);
a97b307a 102 case 'h':
86be6a32 103 usage();
a97b307a 104 default:
677ec86c 105 errtryhelp(EXIT_FAILURE);
a97b307a
SK
106 }
107
108 return EXIT_SUCCESS;
109}