Pull more fixes from OpenBSD/luna88k:

- Bring getline() - a.k.a libsa gets() with a prompt prefix - in par with libsa
  gets(), featurewise; this means support for ^u to clear the input.
- constify
This commit is contained in:
tsutsui 2014-01-03 06:37:13 +00:00
parent 86c3ed96a4
commit 795bcb0d40
3 changed files with 33 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: getline.c,v 1.2 2013/01/20 07:32:45 tsutsui Exp $ */
/* $NetBSD: getline.c,v 1.3 2014/01/03 06:37:13 tsutsui Exp $ */
/*
* Copyright (c) 1992 OMRON Corporation.
@ -79,40 +79,54 @@
#include <luna68k/stand/boot/samachdep.h>
int
getline(char *prompt, char *buff)
getline(const char *prompt, char *buff)
{
int c;
char *p = buff;
char *p, *lp = buff;
printf("%s", prompt);
for(;;) {
c = getchar() & 0x7F;
for (;;) {
c = getchar() & 0x7f;
switch (c) {
case 0x0a:
case 0x0d:
case '\n':
case '\r':
*lp = '\0';
putchar('\n');
*p = '\0';
goto outloop;
case 0x08:
case '\b':
case 0x7f:
if (p > buff) {
putchar(0x08);
if (lp > buff) {
lp--;
putchar('\b');
putchar(' ');
putchar(0x08);
p--;
putchar('\b');
}
break;
case 'r' & 0x1f:
putchar('\n');
printf("%s", prompt);
for (p = buff; p < lp; ++p)
putchar(*p);
break;
case 'u' & 0x1f:
case 'w' & 0x1f:
lp = buff;
printf("\n%s", prompt);
break;
default:
*p++ = c;
*lp++ = c;
putchar(c);
break;
}
}
outloop:
return(strlen(buff));
*lp = '\0';
return lp - buff;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.6 2013/03/05 15:34:53 tsutsui Exp $ */
/* $NetBSD: init_main.c,v 1.7 2014/01/03 06:37:13 tsutsui Exp $ */
/*
* Copyright (c) 1992 OMRON Corporation.
@ -112,7 +112,7 @@ char *argv[MAXARGS];
#define BOOT_TIMEOUT 10
int boot_timeout = BOOT_TIMEOUT;
char prompt[16] = "boot> ";
static const char prompt[] = "boot> ";
void
main(void)

View File

@ -1,4 +1,4 @@
/* $NetBSD: samachdep.h,v 1.12 2014/01/03 06:15:10 tsutsui Exp $ */
/* $NetBSD: samachdep.h,v 1.13 2014/01/03 06:37:13 tsutsui Exp $ */
/*
* Copyright (c) 1982, 1990, 1993
@ -103,7 +103,7 @@ int fsdump(int, char **);
int fsrestore(int, char **);
/* getline.c */
int getline(char *, char *);
int getline(const char *, char *);
/* if_le.c */
int leinit(void *);