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