157085Sakito /* 257085Sakito * Copyright (c) 1992 OMRON Corporation. 3*63199Sbostic * Copyright (c) 1992, 1993 4*63199Sbostic * The Regents of the University of California. All rights reserved. 557085Sakito * 657085Sakito * This code is derived from software contributed to Berkeley by 757085Sakito * OMRON Corporation. 857085Sakito * 957085Sakito * %sccs.include.redist.c% 1057085Sakito * 11*63199Sbostic * @(#)getline.c 8.1 (Berkeley) 06/10/93 1257085Sakito */ 1357085Sakito 1457085Sakito /* 1557085Sakito * getline -- simple getline function 1657085Sakito * by A.Fujita, Dec-11-1992 1757085Sakito */ 1857085Sakito 1957085Sakito int getline(prompt,buff)2057085Sakitogetline(prompt, buff) 2157085Sakito char *prompt, *buff; 2257085Sakito { 2357085Sakito register int c; 2457085Sakito register char *p = buff; 2557085Sakito 2657085Sakito printf("%s", prompt); 2757085Sakito 2857085Sakito for(;;) { 2957085Sakito c = cngetc() & 0x7F; 3057085Sakito 3157085Sakito switch (c) { 3257085Sakito case 0x0a: 3357085Sakito case 0x0d: 3457085Sakito cnputc('\r'); 3557085Sakito cnputc('\n'); 3657085Sakito *p = '\0'; 3757085Sakito goto outloop; 3857085Sakito 3957085Sakito case 0x08: 4057085Sakito case 0x7f: 4157085Sakito if (p > buff) { 4257085Sakito cnputc(0x08); 4357085Sakito cnputc(' '); 4457085Sakito cnputc(0x08); 4557085Sakito p--; 4657085Sakito } 4757085Sakito break; 4857085Sakito 4957085Sakito default: 5057085Sakito *p++ = c; 5157085Sakito cnputc(c); 5257085Sakito break; 5357085Sakito } 5457085Sakito } 5557085Sakito 5657085Sakito outloop: 5757085Sakito return(strlen(buff)); 5857085Sakito } 59