mirror of
git://git.suckless.org/sbase
synced 2024-12-22 23:13:44 +00:00
47 lines
735 B
C
47 lines
735 B
C
/* 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;
|
|
for (i = 1; ;) {
|
|
if ((c = fgetc(fp)) == EOF) {
|
|
if (ferror(fp)) {
|
|
fprintf(stderr, "%s: read error: %s\n",
|
|
file, strerror(errno));
|
|
exit(1);
|
|
}
|
|
return 0;
|
|
}
|
|
buf[i++] = c;
|
|
if (fullrune(buf, i)) {
|
|
chartorune(r, buf);
|
|
break;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|