Works with letters, added trimmed Lovecraft
[name-generation.git] / element-lists / names-2.0.1 / src / main.c
1 /* Names v2.01 Copyright 1995 by Michael Harvey */
2
3 #include <stdlib.h>
4 #include <string.h>
5
6 #ifdef MSDOS
7 #include "getopt.h"
8 #else
9 #include <getopt.h>
10 #endif
11
12 #include "names.h"
13
14 void init(void);
15 void names(void);
16
17 void version(void)
18 {
19 printf("Names version %s\n",VERSION);
20 puts(COPYRIGHT);
21 puts("Permission granted for unrestricted noncommercial use.");
22 }
23
24 int main(int argc, char ** argv)
25 {
26 FILE *f;
27 int c,i,ok=0;
28 int err=0, use=0;
29 char path[200],*p,*s;
30
31 ansi=1;
32 caps=1;
33 cvt=0;
34 debug=0;
35 forever=0;
36 plurs=1;
37 simple=0;
38
39 init();
40
41 while ((c = getopt(argc,argv,"acCdDf:Fhlpsv")) != -1)
42 {
43 switch(c)
44 {
45 case 'a':
46 ansi=0;
47 break;
48 case 'c':
49 caps=0;
50 break;
51 case 'C':
52 caps=2;
53 break;
54 case 'd':
55 debug++;
56 ansi=0;
57 break;
58 case 'D':
59 debug=99;
60 ansi=0;
61 break;
62 case 'f':
63 strcpy(outfile,optarg);
64 break;
65 case 'F':
66 forever=1;
67 break;
68 case 'h':
69 use++;
70 break;
71 case 'l':
72 cvt=1;
73 break;
74 case 'p':
75 plurs=0;
76 break;
77 case 's':
78 simple=1;
79 break;
80 case 'v':
81 version();
82 return 0;
83 default:
84 err++;
85 break;
86 }
87 }
88 if (use || err)
89 {
90 printf("usage: %s [-acCdFhlpsv] [-f outfile] [infile...]\n", argv[0]);
91 puts(" -a suppress ansi control codes");
92 puts(" -c suppress capitalization");
93 puts(" -C force capitalization");
94 puts(" (default is selective capitalization)");
95 puts(" -d debug (-D full debug)");
96 printf(" -f file specify output file, default \"%s\"\n",OUTFILE);
97 puts(" -F forever (default when reading from pipe)");
98 puts(" -h help");
99 puts(" -l convert all data to lowercase");
100 puts(" -p suppress pluralization");
101 puts(" -s simple output");
102 puts(" -v version info");
103 return err;
104 }
105
106 /* read data files */
107 if (optind==argc)
108 {
109 dprint("Reading from stdin:\n");
110 readdata(stdin);
111 forever=1;
112 }
113 else
114 {
115 p = getenv("ELE_DIR");
116 if (p && *p) {
117 for (s=p; *s; s++) ;
118 --s;
119 }
120
121 while (optind < argc)
122 {
123 dprint("READING [%d] '%s'\n",optind,argv[optind]);
124
125 strcpy(path,argv[optind]);
126 if ((f = fopen(path,"r")) != NULL) goto okay;
127
128 strcat(path,".ele");
129 if ((f = fopen(path,"r")) != NULL) goto okay;
130
131 if (!p) goto error;
132 strcpy(path,p);
133 if (*s != '/') strcat(path,"/");
134 strcat(path,argv[optind]);
135 if ((f = fopen(path,"r")) != NULL) goto okay;
136
137 strcat(path,".ele");
138 f = fopen(path,"r");
139
140 okay:
141 if (f)
142 {
143 readdata(f);
144 fclose(f);
145 }
146 else
147 error: fprintf(stderr,"Unable to read %s\n",path);
148 optind++;
149 }
150 }
151
152 dprint5("DICTIONARY:\n");
153 for (c=0; c<NONE; c++)
154 {
155 if (siz[c]) ok=1;
156
157 dprint5("[%d] %d\n",c,siz[c]);
158 for (i=0; i<siz[c]; i++)
159 {
160 dprint5(" data[%2d][%d]=\"%s\"\n", c,i,data[c][i]);
161 if (strlen(data[c][i])==0)
162 dprint("---------> data[%2d][%d]=\"%s\"\n",
163 c,i,data[c][i]);
164 }
165 }
166
167 if (ok) names();
168 return 0;
169 }
170