Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys move static function getstr() to cons.c, make it publica...



details:   https://anonhg.NetBSD.org/src/rev/22977bafcb4e
branches:  trunk
changeset: 485892:22977bafcb4e
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon May 08 16:30:57 2000 +0000

description:
move static function getstr() to cons.c, make it publically available
as cngetsn().  there will be other consumer.

diffstat:

 sys/dev/cons.c       |  50 ++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/cons.h       |   3 +-
 sys/kern/kern_subr.c |  60 +++------------------------------------------------
 3 files changed, 55 insertions(+), 58 deletions(-)

diffs (183 lines):

diff -r 185884bd4248 -r 22977bafcb4e sys/dev/cons.c
--- a/sys/dev/cons.c    Mon May 08 14:00:05 2000 +0000
+++ b/sys/dev/cons.c    Mon May 08 16:30:57 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cons.c,v 1.35 2000/03/30 12:45:27 augustss Exp $       */
+/*     $NetBSD: cons.c,v 1.36 2000/05/08 16:30:57 itojun Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -237,6 +237,54 @@
        return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
 }
 
+int
+cngetsn(cp, size)
+       char *cp;
+       int size;
+{
+       char *lp;
+       int c, len;
+
+       cnpollc(1);
+
+       lp = cp;
+       len = 0;
+       for (;;) {
+               c = cngetc();
+               switch (c) {
+               case '\n':
+               case '\r':
+                       printf("\n");
+                       *lp++ = '\0';
+                       cnpollc(0);
+                       return (len);
+               case '\b':
+               case '\177':
+               case '#':
+                       if (len) {
+                               --len;
+                               --lp;
+                               printf("\b \b");
+                       }
+                       continue;
+               case '@':
+               case 'u'&037:
+                       len = 0;
+                       lp = cp;
+                       printf("\n");
+                       continue;
+               default:
+                       if (len + 1 >= size || c < ' ') {
+                               printf("\007");
+                               continue;
+                       }
+                       printf("%c", c);
+                       ++len;
+                       *lp++ = c;
+               }
+       }
+}
+
 void
 cnputc(c)
        int c;
diff -r 185884bd4248 -r 22977bafcb4e sys/dev/cons.h
--- a/sys/dev/cons.h    Mon May 08 14:00:05 2000 +0000
+++ b/sys/dev/cons.h    Mon May 08 16:30:57 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cons.h,v 1.17 2000/03/06 21:36:12 thorpej Exp $        */
+/*     $NetBSD: cons.h,v 1.18 2000/05/08 16:30:58 itojun Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -84,6 +84,7 @@
 int    cnioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
 int    cnpoll __P((dev_t, int, struct proc *));
 int    cngetc __P((void));
+int    cngetsn __P((char *, int));
 void   cnputc __P((int));
 void   cnpollc __P((int));
 void   cnbell __P((u_int, u_int, u_int));
diff -r 185884bd4248 -r 22977bafcb4e sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c      Mon May 08 14:00:05 2000 +0000
+++ b/sys/kern/kern_subr.c      Mon May 08 16:30:57 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_subr.c,v 1.63 2000/03/30 09:27:12 augustss Exp $  */
+/*     $NetBSD: kern_subr.c,v 1.64 2000/05/08 16:30:59 itojun Exp $    */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -112,7 +112,6 @@
 static struct device *finddevice __P((const char *));
 static struct device *getdisk __P((char *, int, int, dev_t *, int));
 static struct device *parsedisk __P((char *, int, int, dev_t *));
-static int getstr __P((char *, int));
 
 int
 uiomove(buf, n, uio)
@@ -645,7 +644,7 @@
                                printf(")");
                        }
                        printf(": ");
-                       len = getstr(buf, sizeof(buf));
+                       len = cngetsn(buf, sizeof(buf));
                        if (len == 0 && bootdv != NULL) {
                                strcpy(buf, bootdv->dv_xname);
                                len = strlen(buf);
@@ -685,7 +684,7 @@
                                printf(" (default %sb)", defdumpdv->dv_xname);
                        }
                        printf(": ");
-                       len = getstr(buf, sizeof(buf));
+                       len = cngetsn(buf, sizeof(buf));
                        if (len == 0) {
                                if (defdumpdv != NULL) {
                                        ndumpdev = MAKEDISKDEV(major(nrootdev),
@@ -723,7 +722,7 @@
 
                for (;;) {
                        printf("file system (default %s): ", deffsname);
-                       len = getstr(buf, sizeof(buf));
+                       len = cngetsn(buf, sizeof(buf));
                        if (len == 0)
                                break;
                        if (len == 4 && strcmp(buf, "halt") == 0)
@@ -1026,57 +1025,6 @@
 }
 
 /*
- * XXX shouldn't this be a common function?
- */
-static int
-getstr(cp, size)
-       char *cp;
-       int size;
-{
-       char *lp;
-       int c, len;
-
-       cnpollc(1);
-
-       lp = cp;
-       len = 0;
-       for (;;) {
-               c = cngetc();
-               switch (c) {
-               case '\n':
-               case '\r':
-                       printf("\n");
-                       *lp++ = '\0';
-                       cnpollc(0);
-                       return (len);
-               case '\b':
-               case '\177':
-               case '#':
-                       if (len) {
-                               --len;
-                               --lp;
-                               printf("\b \b");
-                       }
-                       continue;
-               case '@':
-               case 'u'&037:
-                       len = 0;
-                       lp = cp;
-                       printf("\n");
-                       continue;
-               default:
-                       if (len + 1 >= size || c < ' ') {
-                               printf("\007");
-                               continue;
-                       }
-                       printf("%c", c);
-                       ++len;
-                       *lp++ = c;
-               }
-       }
-}
-
-/*
  * snprintf() `bytes' into `buf', reformatting it so that the number,
  * plus a possible `x' + suffix extension) fits into len bytes (including
  * the terminating NUL).



Home | Main Index | Thread Index | Old Index