2014-11-21 16:20:15 +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
|
|
|
|
readrune(const char *file, FILE *fp, Rune *r)
|
|
|
|
{
|
|
|
|
char buf[UTFmax];
|
|
|
|
int c, i;
|
|
|
|
|
|
|
|
if ((c = fgetc(fp)) == EOF) {
|
|
|
|
if (ferror(fp)) {
|
|
|
|
fprintf(stderr, "%s: read error: %s\n",
|
|
|
|
file, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c < Runeself) {
|
|
|
|
*r = (Rune)c;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = c;
|
2015-02-01 03:20:02 +00:00
|
|
|
for (i = 1; i < UTFmax; ) {
|
2014-11-21 16:20:15 +00:00
|
|
|
if ((c = fgetc(fp)) == EOF) {
|
|
|
|
if (ferror(fp)) {
|
|
|
|
fprintf(stderr, "%s: read error: %s\n",
|
|
|
|
file, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-02-01 02:54:56 +00:00
|
|
|
*r = Runeerror;
|
|
|
|
return i;
|
2014-11-21 16:20:15 +00:00
|
|
|
}
|
|
|
|
buf[i++] = c;
|
|
|
|
if (fullrune(buf, i)) {
|
|
|
|
chartorune(r, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-01 02:43:54 +00:00
|
|
|
return i;
|
2014-11-21 16:20:15 +00:00
|
|
|
}
|