Mercurial > hg > Members > kono > nitros9-code
view 3rdparty/packages/ed/egets.c @ 3295:6b7a7b233925 default tip
makefile: Allow PORTS with level1/2 mix
https://sourceforge.net/p/nitros9/feature-requests/10/
author | Tormod Volden <debian.tormod@gmail.com> |
---|---|
date | Tue, 19 Apr 2022 18:12:17 +0200 |
parents | bef1844de0dc |
children |
line wrap: on
line source
/* egets.c */ #include <stdio.h> #include "tools.h" #include "ed.h" int eightbit = 1; /* save eight bit */ int nonascii, nullchar, truncated; int egets(str, size, stream) char *str; int size; FILE *stream; { int c, count; char *cp; for (count = 0, cp = str; size > count;) { c = getc(stream); if (c == EOF) { *cp++ = '\n'; *cp = EOS; if (count) { printf("[Incomplete last line]\n"); } return(count); } if (c == NL) { *cp++ = c; *cp = EOS; return(++count); } if (c > 127) { if (!eightbit) /* if not saving eighth bit */ c = c & 127; /* strip eigth bit */ nonascii++; /* count it */ } if (c) { *cp++ = c; /* not null, keep it */ count++; } else nullchar++; /* count nulls */ } str[count - 1] = EOS; if (c != NL) { printf("truncating line\n"); truncated++; while ((c = getc(stream)) != EOF) if (c == NL) break; } return(count); }