1
#include <unicode/ustdio.h>
6
void lazystring(const char *name)
8
FILE *ufp = fopen(name, "r");
9
const size_t bufsize = sizeof(char) * 32 * 1024;
10
char *str = malloc(bufsize);
15
n = fread(str, sizeof(char), bufsize, ufp);
22
void lazytext(const char *name)
24
UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
25
const size_t bufsize = sizeof(UChar) * 32 * 1024;
26
UChar *str = malloc(bufsize);
31
n = u_file_read(str, bufsize, ufp);
38
void text(const char *name)
40
UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
41
FILE *fp = u_fgetfile(ufp);
46
fseek(fp, 0, SEEK_END);
50
str = malloc(sizeof(*str) * fsize);
52
n = u_file_read(str, fsize, ufp);
57
void string(const char *name)
59
FILE *fp = fopen(name, "r");
64
fseek(fp, 0, SEEK_END);
66
fseek(fp, 0, SEEK_SET);
68
str = malloc(sizeof(*str) * fsize);
70
n = fread(str, sizeof(char), fsize, fp);
75
int main(int argc, char **argv)
78
fprintf(stderr, "Usage: %s handler filename\n", argv[0]);
82
if (strcmp(argv[1], "lazystring") == 0)
84
else if (strcmp(argv[1], "lazytext") == 0)
86
else if (strcmp(argv[1], "string") == 0)
88
else if (strcmp(argv[1], "text") == 0)
91
fprintf(stderr, "no matching handler\n");