Minor fixes
[unix-history] / usr / src / games / battlestar / getcom.c
CommitLineData
fdc7d56f 1/*
e95fc82a
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
a6547b1d 5 * %sccs.include.redist.c%
fdc7d56f
EW
6 */
7
124d2372 8#ifndef lint
a6547b1d 9static char sccsid[] = "@(#)getcom.c 5.3 (Berkeley) %G%";
e95fc82a 10#endif /* not lint */
124d2372
EW
11
12#include <stdio.h>
13#include <ctype.h>
14
15char *
16getcom(buf, size, prompt, error)
17 char *buf;
18 int size;
19 char *prompt, *error;
20{
21 for (;;) {
22 fputs(prompt, stdout);
d0adb698
EW
23 if (fgets(buf, size, stdin) == 0) {
24 clearerr(stdin);
25 continue;
26 }
124d2372
EW
27 while (isspace(*buf))
28 buf++;
29 if (*buf)
30 break;
31 if (error)
32 puts(error);
33 }
34 return (buf);
35}
36
d0adb698
EW
37
38/*
39 * shifts to UPPERCASE if flag > 0, lowercase if flag < 0,
40 * and leaves it unchanged if flag = 0
41 */
124d2372
EW
42char *
43getword(buf1, buf2, flag)
d0adb698
EW
44 register char *buf1, *buf2;
45 register flag;
124d2372 46{
124d2372
EW
47 while (isspace(*buf1))
48 buf1++;
49 if (*buf1 != ',') {
50 if (!*buf1) {
51 *buf2 = 0;
52 return (0);
53 }
54 while (*buf1 && !isspace(*buf1) && *buf1 != ',')
d0adb698
EW
55 if (flag < 0)
56 if (isupper(*buf1))
57 *buf2++ = tolower(*buf1++);
58 else
59 *buf2++ = *buf1++;
60 else if (flag > 0)
61 if (islower(*buf1))
62 *buf2++ = toupper(*buf1++);
63 else
64 *buf2++ = *buf1++;
65 else
66 *buf2++ = *buf1++;
124d2372
EW
67 } else
68 *buf2++ = *buf1++;
69 *buf2 = 0;
70 while (isspace(*buf1))
71 buf1++;
72 return (*buf1 ? buf1 : 0);
73}