2015-02-11 19:13:43 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../utf.h"
|
|
|
|
|
|
|
|
int
|
2015-02-11 20:14:28 +00:00
|
|
|
fgetrune(Rune *r, FILE *fp)
|
2015-02-11 19:13:43 +00:00
|
|
|
{
|
|
|
|
char buf[UTFmax];
|
2015-02-13 15:41:04 +00:00
|
|
|
int i = 0, c;
|
2015-02-11 19:13:43 +00:00
|
|
|
|
2015-02-13 15:41:04 +00:00
|
|
|
while (i < UTFmax && (c = fgetc(fp)) != EOF) {
|
|
|
|
buf[i++] = c;
|
2015-02-11 20:14:28 +00:00
|
|
|
if (charntorune(r, buf, i) > 0)
|
2015-02-11 19:13:43 +00:00
|
|
|
break;
|
2015-02-13 15:41:04 +00:00
|
|
|
}
|
2015-02-11 19:13:43 +00:00
|
|
|
if (ferror(fp))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-02-11 20:14:28 +00:00
|
|
|
efgetrune(Rune *r, FILE *fp, const char *file)
|
2015-02-11 19:13:43 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-02-11 20:14:28 +00:00
|
|
|
if ((ret = fgetrune(r, fp)) < 0) {
|
2015-02-11 19:13:43 +00:00
|
|
|
fprintf(stderr, "fgetrune %s: %s\n", file, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|