-/* $NetBSD: getinp.c,v 1.4 1995/04/24 12:24:20 cgd Exp $ */
+/* $NetBSD: getinp.c,v 1.9 2000/07/10 10:19:26 itojun Exp $ */
/*
* Copyright (c) 1980, 1993
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)getinp.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: getinp.c,v 1.4 1995/04/24 12:24:20 cgd Exp $";
+__RCSID("$NetBSD: getinp.c,v 1.9 2000/07/10 10:19:26 itojun Exp $");
#endif
#endif /* not lint */
-# include <stdio.h>
-# include <string.h>
-# include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "monop.ext"
-# define reg register
-
-# define LINE 70
+#define LINE 70
static char buf[257];
-getinp(prompt, list)
-char *prompt, *list[]; {
+static int comp __P((const char *));
- reg int i, n_match, match;
- char *sp;
- int plen;
- static int comp();
+int
+getinp(prompt, list)
+ const char *prompt, *const list[];
+{
+ int i, n_match, match = 0;
+ char *sp;
+ int c;
for (;;) {
inter:
- printf(prompt);
- for (sp = buf; (*sp=getchar()) != '\n'; )
- if (*sp == -1) /* check for interupted system call */
+ printf("%s", prompt);
+ for (sp = buf; (c=getchar()) != '\n'; ) {
+ *sp = c;
+ if (c == -1) /* check for interupted system call */
goto inter;
else if (sp != buf || *sp != ' ')
sp++;
+ }
+ *sp = c;
if (buf[0] == '?' && buf[1] == '\n') {
printf("Valid inputs are: ");
for (i = 0, match = 18; list[i]; i++) {
printf("<RETURN>");
}
else
- printf(list[i]);
+ printf("%s", list[i]);
if (list[i+1])
printf(", ");
else
if (n_match == 1)
return match;
else if (buf[0] != '\0')
- printf("Illegal response: \"%s\". Use '?' to get list of valid answers\n", buf);
+ printf("Illegal response: \"%s\". "
+ "Use '?' to get list of valid answers\n", buf);
}
}
-static
+static int
comp(s1)
-char *s1; {
-
- reg char *sp, *tsp, c;
+ const char *s1;
+{
+ const char *sp, *tsp;
+ char c;
if (buf[0] != '\0')
for (sp = buf, tsp = s1; *sp; ) {