Code

src/Makefile.am: Link foobar against libfoobar.
[template.git] / src / foobar.c
1 /*
2  * foobar - src/foobar.c
3  * Copyright (C) 2008 Sebastian Harl <sh@tokkee.org>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
19 /*
20  * A short description of this module...
21  */
23 #if HAVE_CONFIG_H
24 #       include "config.h"
25 #endif /* HAVE_CONFIG_H */
27 #include "foobar.h"
29 #if HAVE_LIBGEN_H
30 #       include <libgen.h>
31 #else /* HAVE_LIBGEN_H */
32 #       define basename(path) (path)
33 #endif /* ! HAVE_LIBGEN_H */
35 #include <stdio.h>
36 #include <stdlib.h>
38 #include <unistd.h>
40 static void exit_usage(char *name, int status)
41 {
42         printf("Usage: %s <options>\n"
44                         "\nOptions:\n"
45                         "  -h    display this help and exit\n"
46                         "  -V    display the version number and copyright\n"
48                         "\nfoobar "VERSION", http://tokkee.org\n", basename(name));
49         exit(status);
50 } /* exit_usage */
52 static void exit_version(void)
53 {
54         printf("foobar version "VERSION", built "BUILD_DATE"\n"
55                         "Copyright (C) 2008 Sebastian Harl <sh@tokkee.org>\n"
57                         "\nThis is free software under the terms of the GNU GPLv2; see "
58                         "the source for\ncopying conditions. There is NO WARRANTY; not "
59                         "even for MERCHANTABILITY or\nFITNESS FOR A PARTICULAR "
60                         "PURPOSE.\n");
61         exit(0);
62 } /* exit_version */
64 int main(int argc, char **argv)
65 {
66         while (42) {
67                 int opt = getopt(argc, argv, "hV");
69                 if (-1 == opt)
70                         break;
72                 switch (opt) {
73                         case 'h':
74                                 exit_usage(argv[0], 0);
75                                 break;
76                         case 'V':
77                                 exit_version();
78                                 break;
79                         default:
80                                 exit_usage(argv[0], 1);
81                 }
82         }
84         if (optind < argc)
85                 exit_usage(argv[0], 1);
86         return 0;
87 } /* main */
89 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */