1 /* Names v2.01 Copyright 1995 by Michael Harvey */
28 #define ready() move(21,1)
31 #define getkey() getchar()
36 #define getkey() getch()
37 #define kb_init() /**/
38 #define kb_wait() /**/
39 #define kb_done() /**/
41 #define clear() clrscr()
42 #define move(y,x) gotoxy(x,y)
45 enum { O_PS
, O_PMS
, O_N
, O_X
, O_NA
, O_XA
, O_NX
};
47 char scr
[LINES
][COLUMNS
][BUFLEN
];
48 int saved
[LINES
][COLUMNS
];
56 if (ansi
) printf("\033c");
60 void move(int y
, int x
)
62 if (ansi
) printf("\033[%d;%df",y
,x
);
70 puts("\nPress SPACE to generate a screenful of names.");
71 puts("Individual names can be saved to the output file by pressing");
72 puts("the appropriate key. ENTER quits the program.");
73 puts("\nOther commands:\n");
74 puts(" ! invoke a shell");
75 puts(" ? this help screen");
79 char * cap(char *buf
) /* capitalize one word */
84 dprint2("cap(%s)",buf
);
88 if (*p
>= 'a' && *p
<= 'z')
90 dprint2("=\"%s\"\n",buf
);
92 if (strlen(buf
)==0) dprint("==========> cap() buf=\"%s\"\n",buf
);
96 void cap2(char *buf
) /* capitalize everything in buffer */
105 else if (newword
) /* capitalize */
107 if (*p
>= 'a' && *p
<= 'z')
115 char * plur(char *buf
)
119 if (!plurs
) return buf
;
120 dprint2("plur(%s)",buf
);
122 for (p
=buf
; *p
; p
++) ; /* find end of string */
123 p
--; /* find last char */
125 if (*p
=='a' || *p
=='e' || *p
=='i' || *p
=='o' || *p
=='u') {
127 } else if (*p
=='y') {
129 if (*p
=='a' || *p
=='e' || *p
=='i' || *p
=='o' || *p
=='u') {
136 } else if (*p
=='s') {
138 if (*p
=='s') strcat(buf
,"es");
139 } else if (*p
=='h') {
141 if (*p
=='t' || *p
=='s' || *p
=='c' || *p
=='r' || *p
=='z')
143 else strcat(buf
,"s");
147 if (strncmp(p
,"aff",3)==0)
149 else if (strncmp(p
,"arf",3)==0)
150 strcpy(p
,"arves"); /* or "arrows" */
151 else if (strncmp(p
,"elf",3)==0)
153 } else if (*p
!='c' && *p
!='j' && *p
!='v' && *p
!='x' && *p
!='z')
156 dprint2("=\"%s\"\n",buf
);
157 if (strlen(buf
)==0) dprint("==========> plur() buf=\"%s\"\n",buf
);
165 dprint("error: rnd(0)\n");
171 char * my_select(int n
)
176 if (n
>=NONE
) dprint("error: n==NONE\n");
180 if (i
<0 || i
>=siz
[n
])
182 dprint("error: i==%d siz[%d]==%d\n",i
,siz
[n
],n
);
189 dprint("###### data[%2d][%d] = \"%s\"\n",n
,i
,p
);
194 dprint("error: data[%d][%d]==NULL\n",n
,i
);
197 dprint1("my_select(%d): data[%d][%d]='%s'\n",n
,n
,i
,p
);
201 char * number(char *buf
, char *n1
)
205 case 0: sprintf(buf
,"No %s",plur(n1
)); break;
206 case 1: sprintf(buf
,"One %s",n1
); break;
207 case 2: sprintf(buf
,"Two %s",plur(n1
)); break;
208 case 3: sprintf(buf
,"Three %s",plur(n1
)); break;
209 case 4: sprintf(buf
,"Four %s",plur(n1
)); break;
210 case 5: sprintf(buf
,"Five %s",plur(n1
)); break;
211 case 6: sprintf(buf
,"Six %s",plur(n1
)); break;
212 case 7: sprintf(buf
,"Seven %s",plur(n1
)); break;
213 case 8: sprintf(buf
,"Eight %s",plur(n1
)); break;
214 case 9: sprintf(buf
,"Nine %s",plur(n1
)); break;
215 case 10: sprintf(buf
,"Ten %s",plur(n1
)); break;
216 case 11: sprintf(buf
,"Eleven %s",plur(n1
)); break;
217 case 12: sprintf(buf
,"Twelve %s",plur(n1
)); break;
219 case 13: sprintf(buf
,"Hundred %s",plur(n1
)); break;
220 case 14: sprintf(buf
,"Lone %s",n1
); break;
221 case 15: sprintf(buf
,"Many %s",plur(n1
)); break;
223 if (strlen(buf
)==0) dprint("==========> number() buf=\"%s\"\n",buf
);
227 void type1(char *buf
, char *n1
, char *n2
) /* noun / noun */
237 case 0: sprintf(buf
,"%s%s",cap(n1
),n2
);
240 case 1: sprintf(buf
,"%s and %s",cap(n1
), cap(n2
));
242 case 0: strcat(buf
," Inn"); break;
243 case 1: strcat(buf
," Tavern"); break;
245 dprint2("(n and n x)");
247 case 2: if (rnd(2)) {
248 sprintf(buf
,"%s of %s",plur(cap(n1
)),cap(n2
));
249 dprint2("(ns of n)");
251 sprintf(buf
,"%s of %s",cap(n1
),plur(cap(n2
)));
252 dprint2("(n of ns)");
254 case 3: switch(rnd(3)) {
256 sprintf(buf
,"%s of the %s",cap(n1
),plur(cap(n2
)));
257 dprint2("(n of the ns)");
260 sprintf(buf
,"%s of the %s",plur(cap(n1
)),cap(n2
));
261 dprint2("(ns of the n)");
263 case 2: sprintf(buf
,"%s of the %s",plur(cap(n1
)),plur(cap(n2
)));
264 dprint2("(ns of the ns)");
267 case 4: number(buf
,cap(n1
));
269 case 2: strcat(buf
," Inn"); break;
270 case 3: strcat(buf
," Harbor"); break;
271 case 4: strcat(buf
," Tower"); break;
273 dprint2("(# ns [x])");
276 if (strlen(buf
)==0) dprint("==========> type1() buf=\"%s\"\n",buf
);
279 void type2(char *buf
, char *n
, char *a
) /* noun / adj */
285 if (simple
) i
= rnd(2);
290 case 0: sprintf(buf
,"%s%s",a
,n
);
294 case 1: sprintf(buf
,"%s %s",a
,n
);
298 case 2: sprintf(buf
,"%s %s",cap(a
),cap(n
));
299 dprint2("(n a [x])");
302 /* 0,1,2 leave as is */
303 case 3: strcat(buf
," Inn"); break;
304 case 4: strcat(buf
," Town"); break;
305 case 5: strcat(buf
," Tower"); break;
309 case 3: sprintf(tmp
,"%s %s",cap(a
), cap(n
));
314 if (strlen(buf
)==0) dprint("==========> type2() buf=\"%s\"\n",buf
);
318 void newname(char *buf
)
324 if (siz
[PRE
] && siz
[SUF
]) option
[numopt
++]=O_PS
;
325 if (siz
[PRE
] && siz
[MID
] && siz
[SUF
]) option
[numopt
++]=O_PMS
;
326 if (siz
[NOUN
]) option
[numopt
++]=O_N
;
327 if (siz
[NADJ
]) option
[numopt
++]=O_X
;
328 if (siz
[NOUN
] && siz
[ADJ
]) option
[numopt
++]=O_NA
;
329 if (siz
[NOUN
] && siz
[NADJ
]) option
[numopt
++]=O_NX
;
330 if (siz
[NADJ
] && siz
[ADJ
]) option
[numopt
++]=O_XA
;
332 if(debug
) for (opt
=0; opt
<numopt
; opt
++)
333 dprint3("%c", "PMNX123"[option
[opt
]]);
335 opt
= option
[rnd(numopt
)];
336 dprint3(" -> %c ","PMNX123"[opt
]);
344 strcpy(buf
,my_select(PRE
));
345 if (opt
==O_PMS
) strcat(buf
,my_select(MID
));
346 strcat(buf
,my_select(SUF
));
352 strcpy(buf1
,my_select(NOUN
));
353 strcpy(buf2
,my_select(NOUN
));
354 type1(buf
,buf1
,buf2
);
359 strcpy(buf1
,my_select(NADJ
));
360 strcpy(buf2
,my_select(NADJ
));
361 type1(buf
,buf1
,buf2
);
366 strcpy(buf1
,my_select(NOUN
));
367 strcpy(buf2
,my_select(ADJ
));
368 type2(buf
,buf1
,buf2
);
373 strcpy(buf1
,my_select(NOUN
));
375 strcpy(buf2
,my_select(ADJ
));
376 else strcpy(buf2
,my_select(NADJ
));
377 type2(buf
,buf1
,buf2
);
383 strcpy(buf1
,my_select(NOUN
));
384 else strcpy(buf1
,my_select(NADJ
));
385 strcpy(buf2
,my_select(ADJ
));
386 type2(buf
,buf1
,buf2
);
404 for (lin
=0; lin
<LINES
; lin
++)
405 for (col
=0; col
<COLUMNS
; col
++)
407 dprint1("gen: [%2d][%d]\n",lin
,col
);
408 newname(scr
[lin
][col
]);
409 dprint1(" = \"%s\"\n",scr
[lin
][col
]);
417 static char tmp
[200],*p
;
420 for (lin
=0; lin
<LINES
; lin
++)
424 /* this should be a tad faster on slow terminals */
427 (saved
[lin
][0]?SAVED
:lin
+'a'), scr
[lin
][0]);
431 (saved
[lin
][1]?SAVED
:lin
+'A'), scr
[lin
][1]);
435 printf("(%c) %-35s (%c) %-35s\n",
436 (saved
[lin
][0]?SAVED
:lin
+'a'), scr
[lin
][0],
437 (saved
[lin
][1]?SAVED
:lin
+'A'), scr
[lin
][1]);
442 sprintf(tmp
,"(%c) %-35s (%c) %-35s\n",
443 (saved
[lin
][0]?SAVED
:lin
+'a'), scr
[lin
][0],
444 (saved
[lin
][1]?SAVED
:lin
+'A'), scr
[lin
][1]);
450 if (*p
=='\n') putchar('\n');
451 else if (*p
<' ') switch(*p
)
453 case '\a': printf("\\a"); break;
454 case '\b': printf("\\b"); break;
455 case '\f': printf("\\f"); break;
456 case '\r': printf("\\r"); break;
457 case '\t': printf("\\t"); break;
458 case '\v': printf("\\v"); break;
459 default: printf("[%d]",*p
); break;
466 move(LINES
+2,1); printf("(SPACE) more (ENTER) quit (?) help\n");
470 void savename(int row
, int col
)
472 if (saved
[row
][col
]) return;
473 if (row
<0 || col
<0 || row
>=LINES
|| col
>=COLUMNS
)
475 putchar(7); /* beep */
479 /* open output file if it isn't already open */
482 outfp
= fopen(outfile
,"a"); /* append */
487 /* if its open, write the name */
490 fprintf(outfp
,"%s\n",scr
[row
][col
]);
491 saved
[row
][col
] = 1; /* remember we saved this one */
492 move(row
+1,(col
*40)+2);
541 if (c
>='a' && c
<=('a'+19))
545 else if (c
>='A' && c
<=('A'+19))
555 if (isopen
) fclose(outfp
);