]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/FC/FGETL.C

wirehaze git hosting

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