iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit bc428475d5d8e678f99f9006aab8bc1d656c61b6
parent fa78594463743c4e84f2ad6dbcf599326f170539
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Sun,  2 Apr 2017 18:25:46 +0200

shuffled lines

Diffstat:
Mutf.c | 56++++++++++++++++++++++++++++----------------------------
Mutf.h | 2+-
2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/utf.c b/utf.c @@ -157,34 +157,6 @@ runetoutf(char *s, long r) /* - * Read a newly allocated string from `f` up to the first '\n' - * character or the end of the fifle. It is stored as a rune array, - * and `r` is set to point to it. - */ -int -getutf(long **r, FILE *f) -{ - int slen, rlen = 0, c, size = BUFSIZ; - char *s; - - if (!(s = malloc(size))) return -1; - for (slen = 0; (c = fgetc(f)) != EOF && (c != '\n'); slen++) { - s[slen] = c; - - if (slen >= size) - if (!(s = realloc(s, ++size))) return -1; - } - - if (!(*r = malloc(size * sizeof (long)))) return -1; - for (int i = 0; i < slen; rlen++) - i += utftorune(*r + rlen, s + i, slen - i); - - free(s); - return rlen; -} - - -/* * Returns 1 if the rune is a printable character and 0 if not. */ int @@ -243,6 +215,34 @@ runetoprint(char *s, long r, int col) } +/* + * Read a newly allocated string from `f` up to the first '\n' + * character or the end of the file. It is stored as a rune array, and + * `r` is set to point to it. The length of the string is returned, or + * -1 if malloc fails. + */ +int +getutf(long **r, FILE *f) +{ + int slen, rlen = 0, c, size = BUFSIZ; + char *s; + + if (!(s = malloc(size))) return -1; + for (slen = 0; (c = fgetc(f)) != EOF && (c != '\n'); slen++) { + if (slen > size) + if (!(s = realloc(s, ++size))) return -1; + s[slen] = c; + } + + if (!(*r = malloc(size * sizeof (long)))) return -1; + for (int i = 0; i < slen; rlen++) + i += utftorune(*r + rlen, s + i, slen - i); + + free(s); + return rlen; +} + + int main() { diff --git a/utf.h b/utf.h @@ -10,5 +10,5 @@ int runetoutf(char *, long); int isprintrune(long); /* stdin / stdout */ -int getutf(long **, FILE *); int runetoprint(char *, long, int); +int getutf(long **, FILE *);