summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FC/FGETL.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FC/FGETL.C')
-rw-r--r--v4.0/src/CMD/FC/FGETL.C52
1 files changed, 52 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FC/FGETL.C b/v4.0/src/CMD/FC/FGETL.C
new file mode 100644
index 0000000..a425b39
--- /dev/null
+++ b/v4.0/src/CMD/FC/FGETL.C
@@ -0,0 +1,52 @@
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 */
6fgetl (buf, len, fh)
7char *buf;
8int len;
9FILE *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 */
42fputl (buf, len, fh)
43char *buf;
44int len;
45FILE *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}