122
123
myfgetws(wchar_t *s, int size, FILE *stream)
124
125
static int utf8mode = 0;
126
static char *filename = NULL;
125
129
char buf[2048 + 1], *p;
128
132
if (fgets(buf, sizeof(buf), stream) == NULL)
135
/* Keep a count of line numbers for printing errors. */
131
138
if ((p = strchr(buf, '\n')) != NULL)
134
141
while ((ch = getchar()) != '\n' && ch != EOF);
136
143
/* handle special directives */
137
if (strncmp(buf, "# 1 \"", 5) == 0) {
139
(void) setlocale(LC_ALL, "");
144
if (strncmp(buf, "# ", 2) == 0) {
148
line = strtol(buf + 2, &end, 10) - 1;
150
/* Skip whitespace and the opening double quote. */
151
while (isspace(*end))
155
/* Copy the filename to a buffer for printing errors. */
156
for (n = 0, p = end; *p && *p != '"'; p++)
158
if ((newfile = (char *) malloc(n + 1)) == NULL)
160
strncpy(newfile, end, n);
163
/* If this is a new file, clear file-specific state. */
164
if (!filename || strcmp(newfile, filename) != 0) {
168
for (i = 0; i < NUMEV; i++)
171
spev[i].uname = NULL;
173
(void) setlocale(LC_ALL, "");
140
178
} else if (strncmp(buf, "LANG=utf-8", 10) == 0) {
142
180
(void) setlocale(LC_ALL, "C");
149
187
/* convert the line */
151
if (utf8towcs(s, buf, size) == -1)
152
err(1, "while reading input");
154
if (mbstowcs(s, buf, size) == -1)
155
errx(1, "invalid multibyte sequence encountered in input file");
189
r = utf8towcs(s, buf, size);
191
r = mbstowcs(s, buf, size);
194
if (!filename || strcmp(filename, "<stdin>") == 0)
195
err(1, "%s:%d", calendarPath, line);
197
err(1, "%s:%d", filename, line);