-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtemplate.c
91 lines (77 loc) · 1.55 KB
/
template.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <inttypes.h>
#include <limits.h>
#include <pwd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/**
*** May need these:
*** extern char *optarg;
*** extern int optind, opterr, optopt;
***
*** or this:
*** opterr = 0; /* (in main) */
**/
/* Keep/remove leading colon as desired, or s/:/?/ */
static char OPTS[] = ":abcx:y:z:";
char *Prog;
void manpage (void);
void processArgs (int, char *[]);
void usage (FILE *);
int main(int argc, char *argv[])
{
/* Make the program name pretty */
Prog = strrchr(argv[0], '/');
if (Prog == NULL) {
Prog = &argv[0][0];
} else {
++Prog;
}
/* Parse the command line */
processArgs(argc, argv);
} /* main */
void manpage()
{
return;
} /* manpage */
void processArgs(int argc, char *argv[])
{
int c;
/* Special handling for --man */
if ((argc > 1) && (strcmp(argv[1], "--man") == 0)) {
manpage();
exit(0);
}
while ((c = getopt(argc, argv, OPTS)) != -1) {
switch (c) {
case 'a':
a = atoi(optarg);
break;
case ':':
/* what goes here? */
break;
case '?':
(void) fprintf(stderr,"bad arg: %c\n",optopt);
usage(stderr);
exit(1);
default:
usage(stderr);
exit(1);
}
}
return;
} /* processArgs */
void usage(FILE *stream)
{
(void) fprintf(stream, "Usage: %s ...\n", Prog);
return;
} /* Usage */