994
|
1 /* egets.c */
|
|
2 #include <stdio.h>
|
|
3 #include "tools.h"
|
|
4 #include "ed.h"
|
|
5
|
|
6 int eightbit = 1; /* save eight bit */
|
|
7 int nonascii, nullchar, truncated;
|
|
8 int egets(str, size, stream)
|
|
9 char *str;
|
|
10 int size;
|
|
11 FILE *stream;
|
|
12 {
|
|
13 int c, count;
|
|
14 char *cp;
|
|
15
|
|
16 for (count = 0, cp = str; size > count;) {
|
|
17 c = getc(stream);
|
|
18 if (c == EOF) {
|
|
19 *cp++ = '\n';
|
|
20 *cp = EOS;
|
|
21 if (count) {
|
|
22 printf("[Incomplete last line]\n");
|
|
23 }
|
|
24 return(count);
|
|
25 }
|
|
26 if (c == NL) {
|
|
27 *cp++ = c;
|
|
28 *cp = EOS;
|
|
29 return(++count);
|
|
30 }
|
|
31 if (c > 127) {
|
|
32 if (!eightbit) /* if not saving eighth bit */
|
|
33 c = c & 127; /* strip eigth bit */
|
|
34 nonascii++; /* count it */
|
|
35 }
|
|
36 if (c) {
|
|
37 *cp++ = c; /* not null, keep it */
|
|
38 count++;
|
|
39 } else
|
|
40 nullchar++; /* count nulls */
|
|
41 }
|
|
42 str[count - 1] = EOS;
|
|
43 if (c != NL) {
|
|
44 printf("truncating line\n");
|
|
45 truncated++;
|
|
46 while ((c = getc(stream)) != EOF)
|
|
47 if (c == NL) break;
|
|
48 }
|
|
49 return(count);
|
|
50 }
|
|
51
|