Home | History | Annotate | Line # | Download | only in common
tgets.c revision 1.2
      1 /*	$NetBSD: tgets.c,v 1.2 2003/08/07 16:27:43 agc Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)gets.c	8.1 (Berkeley) 6/11/93
     32  */
     33 
     34 int
     35 tgets(buf)
     36     char *buf;
     37 {
     38     register int c;
     39     int i;
     40     register char *lp = buf;
     41 
     42     for (i = 240000; i > 0; i--) {
     43         c = tgetchar() & 0177;
     44         if (c) {
     45             for (;;) {
     46                 switch (c) {
     47                 case '\n':
     48                 case '\r':
     49                     *lp = '\0';
     50                     putchar('\n');
     51                     return (1);
     52                 case '\b':
     53                 case '\177':
     54                     if (lp > buf) {
     55                         lp--;
     56                         putchar('\b');
     57                         putchar(' ');
     58                         putchar('\b');
     59                     }
     60                     break;
     61                 case '#':
     62                     if (lp > buf)
     63                         --lp;
     64                     break;
     65                 case 'r'&037: {
     66                     register char *p;
     67 
     68                     putchar('\n');
     69                     for (p = buf; p < lp; ++p)
     70                         putchar(*p);
     71                     break;
     72                 }
     73                 case '@':
     74                 case 'u'&037:
     75                 case 'w'&037:
     76                     lp = buf;
     77                     putchar('\n');
     78                     break;
     79                 default:
     80                     *lp++ = c;
     81                     putchar(c);
     82                 }
     83                 c = getchar() & 0177;
     84             }
     85         }
     86     }
     87     return (0);
     88 }
     89