Commit | Line | Data |
---|---|---|
3f62363f KB |
1 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
11 | * | |
efd2fb19 | 12 | * @(#)gets.c 7.2 (Berkeley) %G% |
3f62363f KB |
13 | */ |
14 | ||
15 | gets(buf) | |
16 | char *buf; | |
17 | { | |
18 | register int c; | |
19 | register char *lp; | |
20 | ||
21 | for (lp = buf;;) | |
22 | switch(c = getchar() & 0177) { | |
23 | case '\n': | |
24 | case '\r': | |
25 | *lp = '\0'; | |
26 | return; | |
27 | case '\b': | |
28 | if (lp > buf) { | |
29 | lp--; | |
30 | putchar('\b'); | |
31 | putchar(' '); | |
32 | putchar('\b'); | |
33 | } | |
34 | break; | |
35 | case '#': | |
36 | case '\177': | |
37 | if (lp > buf) | |
38 | --lp; | |
39 | break; | |
efd2fb19 KB |
40 | case 'r'&037: { |
41 | register char *p; | |
42 | ||
43 | putchar('\n'); | |
44 | for (p = buf; p < lp; ++p) | |
45 | putchar(*p); | |
46 | break; | |
47 | } | |
3f62363f KB |
48 | case '@': |
49 | case 'u'&037: | |
efd2fb19 | 50 | case 'w'&037: |
3f62363f KB |
51 | lp = buf; |
52 | putchar('\n'); | |
53 | break; | |
54 | default: | |
55 | *lp++ = c; | |
56 | } | |
57 | /*NOTREACHED*/ | |
58 | } |