Mercurial > hg > Members > kono > nitros9-code
view 3rdparty/packages/ed/egets.c @ 3158:927ba5ebc06e
mc09 l2: move MMU bit-field defines to defs file.
author | Neal Crook <foofoobedoo@gmail.com> |
---|---|
date | Thu, 06 Apr 2017 21:43:58 +0100 (2017-04-06) |
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); }