b0b7c4ef99c575de96398d6d65545a6c0d82e99c
[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 "des_internal.h"
21
22 extern void gen PROTOTYPE((FILE * stream));
23 extern int des_debug;
24 char const *whoami;
25
26 #ifndef DONT_INCL_MAIN
27
28 #include "AFS_component_version_number.c"
29
30 int main(argc, argv)
31     int argc;
32     char *argv[];
33 {
34     char *filename;
35     char *arg;
36     FILE * stream;
37
38     whoami = argv[0];
39     filename = (char *)NULL;
40
41     while (argc--, *++argv) {
42         arg = *argv;
43         if (*arg == '-') {
44             if (!strcmp(arg, "-d") && !strcmp(arg, "-debug"))
45                 des_debug++;
46             else {
47                 fprintf(stderr, "%s: unknown control argument %s\n",
48                         whoami, arg);
49                 goto usage;
50             }
51         }
52         else if (filename) {
53             fprintf(stderr,
54                     "%s: multiple file names provided: %s, %s\n",
55                     whoami, filename, arg);
56             goto usage;
57         }
58         else
59             filename = arg;
60     }
61
62     if (!filename) {
63         fprintf(stderr, "%s: no file name provided\n", whoami);
64         goto usage;
65     }
66
67     stream = fopen(filename, "w");
68     if (!stream) {
69         perror(filename);
70     usage:
71         fprintf(stderr, "usage: %s [-debug] filename\n", whoami);
72         exit(1);
73     }
74
75     fputs(
76       "/* This file is automatically generated.  Do not edit it. */\n",
77           stream);
78
79     /* This routine will generate the contents of the file. */
80     gen(stream);
81     if (fclose(stream) == EOF) {
82         perror(filename);
83         exit(1);
84     }
85     exit(0);
86 }
87 #endif  /* DONT_INCL_MAIN */