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