best makefile
[ascii.git] / skel.c
1 /* depend: */
2 /* cflags: */
3 /* linker: */
4
5 #include <assert.h>
6 #include <getopt.h>
7 #include <malloc.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 /* macros */
12
13 #define CEIL(x, y) (((x) + (y) - 1) / (y))
14 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
15 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
16 #define VERBOSE(level, statement...) do { if (level <= verbose) { statement; } } while(0)
17
18 /* gobal variables */
19
20 char *progname = NULL;
21 int verbose = 0;
22
23 /* help function */
24
25 void usage (int ret)
26 {
27 FILE *fd = ret ? stderr : stdout;
28 fprintf (fd, "usage: %s\n", progname);
29 fprintf (fd, " -h : help message\n");
30 fprintf (fd, " -v : verbose level (%d)\n", verbose);
31
32 exit (ret);
33 }
34
35 /* main function */
36
37 int main (int argc, char *argv[])
38 {
39
40 progname = argv[0];
41
42 int c;
43 while ((c = getopt(argc, argv, "hv:")) != EOF) {
44 switch (c) {
45 case 'v':
46 verbose = atoi (optarg);
47 break;
48 case 'h':
49 default:
50 usage (c != 'h');
51 }
52 }
53 if (argc - optind != 0) {
54 fprintf (stderr, "%s: invalid option -- %s\n", progname, argv[optind]);
55 usage (1);
56 }
57
58 printf ("work in progress...\n");
59
60 return 0;
61 }
62
63 // test: skel.exe -h
64 // test: skel.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
65 // test: skel.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
66 // test: skel.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
67
68 /* vim: set ts=4 sw=4 et */