1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* fgetl.c - expand tabs and return lines w/o separators */
#include "tools.h"
/* returns line from file (no CRLFs); returns NULL if EOF */
fgetl (buf, len, fh)
char *buf;
int len;
FILE *fh;
{
register int c;
register char *p;
/* remember NUL at end */
len--;
p = buf;
while (len) {
c = getc (fh);
if (c == EOF || c == '\n')
break;
#if MSDOS
if (c != '\r')
#endif
if (c != '\t') {
*p++ = c;
len--;
}
else {
c = min (8 - ((p-buf) & 0x0007), len);
Fill (p, ' ', c);
p += c;
len -= c;
}
}
*p = 0;
return ! ( (c == EOF) && (p == buf) );
}
/* writes a line to file (with trailing CRLFs) from buf, return <> 0 if
* writes fail
*/
fputl (buf, len, fh)
char *buf;
int len;
FILE *fh;
{
#if MSDOS
return (fwrite (buf, 1, len, fh) != len || fputs ("\r\n", fh) == EOF) ? EOF : 0;
#else
return (fwrite (buf, 1, len, fh) != len || fputs ("\n", fh) == EOF) ? EOF : 0;
#endif
}
|