Last change
on this file since 9519422 was 7258c6a, checked in by Thomas Lopatic <thomas@…>, 7 years ago |
Use standard integer types.
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | /*
|
---|
2 | =============================================================================
|
---|
3 | fgets.c -- get a string from an ASCII stream file
|
---|
4 | Version 2 -- 1987-07-09 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "stdio.h"
|
---|
9 | #include "stddefs.h"
|
---|
10 |
|
---|
11 | #define EATCHAR '\n' /* character to be "eaten" on input */
|
---|
12 |
|
---|
13 | int16_t agetc(FILE *ptr)
|
---|
14 | {
|
---|
15 | register int16_t c;
|
---|
16 |
|
---|
17 | top:
|
---|
18 | if ((c = getc(ptr)) NE EOF) {
|
---|
19 |
|
---|
20 | switch (c &= 0x7F) {
|
---|
21 |
|
---|
22 | case 0x1a: /* {x}DOS EOF */
|
---|
23 | --ptr->_bp;
|
---|
24 | return(EOF);
|
---|
25 |
|
---|
26 | case EATCHAR: /* CR or LF */
|
---|
27 | case 0: /* NUL */
|
---|
28 | goto top;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | return(c);
|
---|
33 | }
|
---|
34 |
|
---|
35 | int8_t *gets(int8_t *line)
|
---|
36 | {
|
---|
37 | register int8_t *cp;
|
---|
38 | register int16_t i;
|
---|
39 |
|
---|
40 | cp = line;
|
---|
41 |
|
---|
42 | while ((i = getchar()) NE EOF AND i NE '\n')
|
---|
43 | *cp++ = i;
|
---|
44 |
|
---|
45 | *cp = 0; /* terminate the line */
|
---|
46 |
|
---|
47 | if ((i EQ EOF) AND (cp EQ line))
|
---|
48 | return(NULL);
|
---|
49 |
|
---|
50 | return(line);
|
---|
51 | }
|
---|
52 |
|
---|
53 | int8_t *fgets(int8_t *s, int16_t n, FILE *fp)
|
---|
54 | {
|
---|
55 | register int16_t c;
|
---|
56 | register int8_t *cp;
|
---|
57 |
|
---|
58 | cp = s;
|
---|
59 |
|
---|
60 | while (--n > 0 AND (c = agetc(fp)) NE EOF) {
|
---|
61 |
|
---|
62 | *cp++ = c;
|
---|
63 |
|
---|
64 | if (c EQ '\n')
|
---|
65 | break;
|
---|
66 | }
|
---|
67 |
|
---|
68 | *cp = 0;
|
---|
69 |
|
---|
70 | if (c EQ EOF AND cp EQ s)
|
---|
71 | return(NULL);
|
---|
72 |
|
---|
73 | return(s);
|
---|
74 | }
|
---|
75 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.