des-warning-cleanup-20011005
[openafs.git] / src / des / main.c
1 /*
2  * Copyright 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information,
5  * please seethe file <mit-cpyright.h>.
6  *
7  * This file contains most of the routines needed by the various
8  * make_foo programs, to account for bit- and byte-ordering on
9  * different machine types.  It also contains other routines useful in
10  * generating the intermediate source files.
11  */
12
13 #include <afsconfig.h>
14 #include <afs/param.h>
15
16 RCSID("$Header$");
17
18 #include <mit-cpyright.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #else
25 #ifdef HAVE_STRINGS_H
26 #include <strings.h>
27 #endif
28 #endif
29
30 #include "des_internal.h"
31
32 extern void gen PROTOTYPE((FILE * stream));
33 extern int des_debug;
34 char const *whoami;
35
36 #ifndef DONT_INCL_MAIN
37
38 #include "AFS_component_version_number.c"
39
40 int main(argc, argv)
41     int argc;
42     char *argv[];
43 {
44     char *filename;
45     char *arg;
46     FILE * stream;
47
48     whoami = argv[0];
49     filename = (char *)NULL;
50
51     while (argc--, *++argv) {
52         arg = *argv;
53         if (*arg == '-') {
54             if (!strcmp(arg, "-d") && !strcmp(arg, "-debug"))
55                 des_debug++;
56             else {
57                 fprintf(stderr, "%s: unknown control argument %s\n",
58                         whoami, arg);
59                 goto usage;
60             }
61         }
62         else if (filename) {
63             fprintf(stderr,
64                     "%s: multiple file names provided: %s, %s\n",
65                     whoami, filename, arg);
66             goto usage;
67         }
68         else
69             filename = arg;
70     }
71
72     if (!filename) {
73         fprintf(stderr, "%s: no file name provided\n", whoami);
74         goto usage;
75     }
76
77     stream = fopen(filename, "w");
78     if (!stream) {
79         perror(filename);
80     usage:
81         fprintf(stderr, "usage: %s [-debug] filename\n", whoami);
82         exit(1);
83     }
84
85     fputs(
86       "/* This file is automatically generated.  Do not edit it. */\n",
87           stream);
88
89     /* This routine will generate the contents of the file. */
90     gen(stream);
91     if (fclose(stream) == EOF) {
92         perror(filename);
93         exit(1);
94     }
95     exit(0);
96 }
97 #endif  /* DONT_INCL_MAIN */