diff options
| author | 2024-04-25 21:24:10 +0100 | |
|---|---|---|
| committer | 2024-04-25 22:32:27 +0000 | |
| commit | 2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch) | |
| tree | 80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/CMD/FC/FGETL.C | |
| parent | Merge pull request #430 from jpbaltazar/typoptbr (diff) | |
| download | ms-dos-main.tar.gz ms-dos-main.tar.xz ms-dos-main.zip | |
Diffstat (limited to 'v4.0/src/CMD/FC/FGETL.C')
| -rw-r--r-- | v4.0/src/CMD/FC/FGETL.C | 52 |
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 */ | ||
| 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 | } | ||