1*57085Sakito /* 2*57085Sakito * Copyright (c) 1992 OMRON Corporation. 3*57085Sakito * Copyright (c) 1992 The Regents of the University of California. 4*57085Sakito * All rights reserved. 5*57085Sakito * 6*57085Sakito * This code is derived from software contributed to Berkeley by 7*57085Sakito * OMRON Corporation. 8*57085Sakito * 9*57085Sakito * %sccs.include.redist.c% 10*57085Sakito * 11*57085Sakito * @(#)getline.c 7.1 (Berkeley) 12/13/92 12*57085Sakito */ 13*57085Sakito 14*57085Sakito /* 15*57085Sakito * getline -- simple getline function 16*57085Sakito * by A.Fujita, Dec-11-1992 17*57085Sakito */ 18*57085Sakito 19*57085Sakito int 20*57085Sakito getline(prompt, buff) 21*57085Sakito char *prompt, *buff; 22*57085Sakito { 23*57085Sakito register int c; 24*57085Sakito register char *p = buff; 25*57085Sakito 26*57085Sakito printf("%s", prompt); 27*57085Sakito 28*57085Sakito for(;;) { 29*57085Sakito c = cngetc() & 0x7F; 30*57085Sakito 31*57085Sakito switch (c) { 32*57085Sakito case 0x0a: 33*57085Sakito case 0x0d: 34*57085Sakito cnputc('\r'); 35*57085Sakito cnputc('\n'); 36*57085Sakito *p = '\0'; 37*57085Sakito goto outloop; 38*57085Sakito 39*57085Sakito case 0x08: 40*57085Sakito case 0x7f: 41*57085Sakito if (p > buff) { 42*57085Sakito cnputc(0x08); 43*57085Sakito cnputc(' '); 44*57085Sakito cnputc(0x08); 45*57085Sakito p--; 46*57085Sakito } 47*57085Sakito break; 48*57085Sakito 49*57085Sakito default: 50*57085Sakito *p++ = c; 51*57085Sakito cnputc(c); 52*57085Sakito break; 53*57085Sakito } 54*57085Sakito } 55*57085Sakito 56*57085Sakito outloop: 57*57085Sakito return(strlen(buff)); 58*57085Sakito } 59