Commit | Line | Data |
---|---|---|
fdc7d56f | 1 | /* |
e95fc82a KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
28c5bacc KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
fdc7d56f EW |
16 | */ |
17 | ||
124d2372 | 18 | #ifndef lint |
28c5bacc | 19 | static char sccsid[] = "@(#)getcom.c 5.2 (Berkeley) %G%"; |
e95fc82a | 20 | #endif /* not lint */ |
124d2372 EW |
21 | |
22 | #include <stdio.h> | |
23 | #include <ctype.h> | |
24 | ||
25 | char * | |
26 | getcom(buf, size, prompt, error) | |
27 | char *buf; | |
28 | int size; | |
29 | char *prompt, *error; | |
30 | { | |
31 | for (;;) { | |
32 | fputs(prompt, stdout); | |
d0adb698 EW |
33 | if (fgets(buf, size, stdin) == 0) { |
34 | clearerr(stdin); | |
35 | continue; | |
36 | } | |
124d2372 EW |
37 | while (isspace(*buf)) |
38 | buf++; | |
39 | if (*buf) | |
40 | break; | |
41 | if (error) | |
42 | puts(error); | |
43 | } | |
44 | return (buf); | |
45 | } | |
46 | ||
d0adb698 EW |
47 | |
48 | /* | |
49 | * shifts to UPPERCASE if flag > 0, lowercase if flag < 0, | |
50 | * and leaves it unchanged if flag = 0 | |
51 | */ | |
124d2372 EW |
52 | char * |
53 | getword(buf1, buf2, flag) | |
d0adb698 EW |
54 | register char *buf1, *buf2; |
55 | register flag; | |
124d2372 | 56 | { |
124d2372 EW |
57 | while (isspace(*buf1)) |
58 | buf1++; | |
59 | if (*buf1 != ',') { | |
60 | if (!*buf1) { | |
61 | *buf2 = 0; | |
62 | return (0); | |
63 | } | |
64 | while (*buf1 && !isspace(*buf1) && *buf1 != ',') | |
d0adb698 EW |
65 | if (flag < 0) |
66 | if (isupper(*buf1)) | |
67 | *buf2++ = tolower(*buf1++); | |
68 | else | |
69 | *buf2++ = *buf1++; | |
70 | else if (flag > 0) | |
71 | if (islower(*buf1)) | |
72 | *buf2++ = toupper(*buf1++); | |
73 | else | |
74 | *buf2++ = *buf1++; | |
75 | else | |
76 | *buf2++ = *buf1++; | |
124d2372 EW |
77 | } else |
78 | *buf2++ = *buf1++; | |
79 | *buf2 = 0; | |
80 | while (isspace(*buf1)) | |
81 | buf1++; | |
82 | return (*buf1 ? buf1 : 0); | |
83 | } |