[db75e18] | 1 | /* > message.c |
---|
| 2 | * Fairly general purpose message and error routines |
---|
[704ad2b] | 3 | * Copyright (C) 1993-2001 Olly Betts |
---|
[846746e] | 4 | * |
---|
[89231c4] | 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
[846746e] | 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[89231c4] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
[846746e] | 14 | * |
---|
[89231c4] | 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[60f7018] | 18 | */ |
---|
| 19 | |
---|
[55de792] | 20 | /*#define DEBUG 1*/ |
---|
| 21 | |
---|
[db75e18] | 22 | #ifdef HAVE_CONFIG_H |
---|
| 23 | # include <config.h> |
---|
| 24 | #endif |
---|
[60f7018] | 25 | |
---|
| 26 | #include <stdio.h> |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <ctype.h> |
---|
| 30 | #include <limits.h> |
---|
| 31 | #include <errno.h> |
---|
[f764581] | 32 | #include <locale.h> |
---|
[60f7018] | 33 | |
---|
| 34 | #include "whichos.h" |
---|
[4432f2e] | 35 | #include "filename.h" |
---|
| 36 | #include "message.h" |
---|
[60f7018] | 37 | #include "osdepend.h" |
---|
| 38 | #include "filelist.h" |
---|
| 39 | #include "debug.h" |
---|
| 40 | |
---|
[a4140e9] | 41 | #ifdef AVEN |
---|
| 42 | #include "aven.h" |
---|
| 43 | #endif |
---|
| 44 | |
---|
[60f7018] | 45 | #ifdef HAVE_SIGNAL |
---|
| 46 | # ifdef HAVE_SETJMP |
---|
| 47 | # include <setjmp.h> |
---|
| 48 | static jmp_buf jmpbufSignal; |
---|
| 49 | # include <signal.h> |
---|
| 50 | # else |
---|
| 51 | # undef HAVE_SIGNAL |
---|
| 52 | # endif |
---|
| 53 | #endif |
---|
| 54 | |
---|
[6754d07] | 55 | #if (OS==WIN32) |
---|
| 56 | #include <windows.h> |
---|
| 57 | #endif |
---|
| 58 | |
---|
[2163157] | 59 | #if (OS==RISCOS) |
---|
| 60 | #include "oslib/wimpreadsy.h" |
---|
| 61 | #endif |
---|
| 62 | |
---|
[647407d] | 63 | /* This is the name of the default language. Add -DDEFAULTLANG to CFLAGS |
---|
| 64 | * e.g. with `CFLAGS="-DDEFAULTLANG=fr" ./configure' |
---|
[60f7018] | 65 | */ |
---|
| 66 | #ifndef DEFAULTLANG |
---|
[d5bd3a7] | 67 | # define DEFAULTLANG en |
---|
[60f7018] | 68 | #endif |
---|
| 69 | |
---|
| 70 | /* For funcs which want to be immune from messing around with different |
---|
| 71 | * calling conventions */ |
---|
| 72 | #ifndef CDECL |
---|
[2ca296b] | 73 | # define CDECL |
---|
[60f7018] | 74 | #endif |
---|
| 75 | |
---|
[25ab06b] | 76 | int msg_warnings = 0; /* keep track of how many warnings we've given */ |
---|
| 77 | int msg_errors = 0; /* and how many (non-fatal) errors */ |
---|
[60f7018] | 78 | |
---|
[a4140e9] | 79 | /* in case osmalloc() fails before appname_copy is set up */ |
---|
| 80 | static const char *appname_copy = "anonymous program"; |
---|
[60f7018] | 81 | |
---|
| 82 | /* error code for failed osmalloc and osrealloc calls */ |
---|
[db75e18] | 83 | static void |
---|
| 84 | outofmem(OSSIZE_T size) |
---|
| 85 | { |
---|
[bd1913f] | 86 | fatalerror(/*Out of memory (couldn't find %lu bytes).*/1, |
---|
| 87 | (unsigned long)size); |
---|
[60f7018] | 88 | } |
---|
| 89 | |
---|
[a420b49] | 90 | #ifdef TOMBSTONES |
---|
| 91 | #define TOMBSTONE_SIZE 16 |
---|
[bd1913f] | 92 | static const char tombstone[TOMBSTONE_SIZE] = "012345\xfftombstone"; |
---|
[a420b49] | 93 | #endif |
---|
| 94 | |
---|
[60f7018] | 95 | /* malloc with error catching if it fails. Also allows us to write special |
---|
| 96 | * versions easily eg for DOS EMS or MS Windows. |
---|
| 97 | */ |
---|
[bd1913f] | 98 | void FAR * |
---|
[db75e18] | 99 | osmalloc(OSSIZE_T size) |
---|
| 100 | { |
---|
[60f7018] | 101 | void FAR *p; |
---|
[a420b49] | 102 | #ifdef TOMBSTONES |
---|
| 103 | size += TOMBSTONE_SIZE * 2; |
---|
| 104 | p = malloc(size); |
---|
| 105 | #else |
---|
[db75e18] | 106 | p = xosmalloc(size); |
---|
[a420b49] | 107 | #endif |
---|
[2ca296b] | 108 | if (p == NULL) outofmem(size); |
---|
[a420b49] | 109 | #ifdef TOMBSTONES |
---|
[bd1913f] | 110 | printf("osmalloc truep=%p truesize=%d\n", p, size); |
---|
[a420b49] | 111 | memcpy(p, tombstone, TOMBSTONE_SIZE); |
---|
| 112 | memcpy(p + size - TOMBSTONE_SIZE, tombstone, TOMBSTONE_SIZE); |
---|
| 113 | *(size_t *)p = size; |
---|
| 114 | p += TOMBSTONE_SIZE; |
---|
| 115 | #endif |
---|
[60f7018] | 116 | return p; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /* realloc with error catching if it fails. */ |
---|
[bd1913f] | 120 | void FAR * |
---|
[db75e18] | 121 | osrealloc(void *p, OSSIZE_T size) |
---|
| 122 | { |
---|
[a420b49] | 123 | /* some pre-ANSI realloc implementations don't cope with a NULL pointer */ |
---|
| 124 | if (p == NULL) { |
---|
| 125 | p = xosmalloc(size); |
---|
| 126 | } else { |
---|
| 127 | #ifdef TOMBSTONES |
---|
| 128 | int true_size; |
---|
| 129 | size += TOMBSTONE_SIZE * 2; |
---|
| 130 | p -= TOMBSTONE_SIZE; |
---|
| 131 | true_size = *(size_t *)p; |
---|
[bd1913f] | 132 | printf("osrealloc (in truep=%p truesize=%d)\n", p, true_size); |
---|
[a420b49] | 133 | if (memcmp(p + sizeof(size_t), tombstone + sizeof(size_t), |
---|
| 134 | TOMBSTONE_SIZE - sizeof(size_t)) != 0) { |
---|
| 135 | printf("start tombstone for block %p, size %d corrupted!", |
---|
[cb3d1e2] | 136 | p + TOMBSTONE_SIZE, true_size - TOMBSTONE_SIZE * 2); |
---|
[a420b49] | 137 | } |
---|
| 138 | if (memcmp(p + true_size - TOMBSTONE_SIZE, tombstone, |
---|
| 139 | TOMBSTONE_SIZE) != 0) { |
---|
| 140 | printf("end tombstone for block %p, size %d corrupted!", |
---|
[cb3d1e2] | 141 | p + TOMBSTONE_SIZE, true_size - TOMBSTONE_SIZE * 2); |
---|
[a420b49] | 142 | } |
---|
| 143 | p = realloc(p, size); |
---|
| 144 | if (p == NULL) outofmem(size); |
---|
[bd1913f] | 145 | printf("osrealloc truep=%p truesize=%d\n", p, size); |
---|
[a420b49] | 146 | memcpy(p, tombstone, TOMBSTONE_SIZE); |
---|
| 147 | memcpy(p + size - TOMBSTONE_SIZE, tombstone, TOMBSTONE_SIZE); |
---|
| 148 | *(size_t *)p = size; |
---|
| 149 | p += TOMBSTONE_SIZE; |
---|
| 150 | #else |
---|
| 151 | p = xosrealloc(p, size); |
---|
| 152 | #endif |
---|
| 153 | } |
---|
[2ca296b] | 154 | if (p == NULL) outofmem(size); |
---|
[60f7018] | 155 | return p; |
---|
| 156 | } |
---|
| 157 | |
---|
[b2c945f] | 158 | char FAR * |
---|
[db75e18] | 159 | osstrdup(const char *str) |
---|
| 160 | { |
---|
[60f7018] | 161 | char *p; |
---|
[db75e18] | 162 | OSSIZE_T len; |
---|
| 163 | len = strlen(str) + 1; |
---|
[0a3c5fa] | 164 | p = osmalloc(len); |
---|
[db75e18] | 165 | memcpy(p, str, len); |
---|
[60f7018] | 166 | return p; |
---|
| 167 | } |
---|
| 168 | |
---|
[a420b49] | 169 | /* osfree is usually just a macro in osalloc.h */ |
---|
| 170 | #ifdef TOMBSTONES |
---|
[bd1913f] | 171 | void |
---|
[a420b49] | 172 | osfree(void *p) |
---|
| 173 | { |
---|
| 174 | int true_size; |
---|
| 175 | if (!p) return; |
---|
| 176 | p -= TOMBSTONE_SIZE; |
---|
| 177 | true_size = *(size_t *)p; |
---|
[bd1913f] | 178 | printf("osfree truep=%p truesize=%d\n", p, true_size); |
---|
[a420b49] | 179 | if (memcmp(p + sizeof(size_t), tombstone + sizeof(size_t), |
---|
| 180 | TOMBSTONE_SIZE - sizeof(size_t)) != 0) { |
---|
| 181 | printf("start tombstone for block %p, size %d corrupted!", |
---|
[cb3d1e2] | 182 | p + TOMBSTONE_SIZE, true_size - TOMBSTONE_SIZE * 2); |
---|
[a420b49] | 183 | } |
---|
| 184 | if (memcmp(p + true_size - TOMBSTONE_SIZE, tombstone, |
---|
| 185 | TOMBSTONE_SIZE) != 0) { |
---|
| 186 | printf("end tombstone for block %p, size %d corrupted!", |
---|
[cb3d1e2] | 187 | p + TOMBSTONE_SIZE, true_size - TOMBSTONE_SIZE * 2); |
---|
[a420b49] | 188 | } |
---|
| 189 | free(p); |
---|
| 190 | } |
---|
| 191 | #endif |
---|
[60f7018] | 192 | |
---|
| 193 | #ifdef HAVE_SIGNAL |
---|
| 194 | |
---|
| 195 | static int sigReceived; |
---|
| 196 | |
---|
| 197 | /* for systems not using autoconf, assume the signal handler returns void |
---|
| 198 | * unless specified elsewhere */ |
---|
| 199 | #ifndef RETSIGTYPE |
---|
[2ca296b] | 200 | # define RETSIGTYPE void |
---|
[60f7018] | 201 | #endif |
---|
| 202 | |
---|
[bd1913f] | 203 | static CDECL RETSIGTYPE FAR |
---|
| 204 | report_sig(int sig) |
---|
| 205 | { |
---|
[db75e18] | 206 | sigReceived = sig; |
---|
[2ca296b] | 207 | longjmp(jmpbufSignal, 1); |
---|
[60f7018] | 208 | } |
---|
| 209 | |
---|
[db75e18] | 210 | static void |
---|
| 211 | init_signals(void) |
---|
| 212 | { |
---|
[60f7018] | 213 | int en; |
---|
| 214 | if (!setjmp(jmpbufSignal)) { |
---|
[0a3c5fa] | 215 | #if 1 /* disable these to get a core dump */ |
---|
[db75e18] | 216 | signal(SIGABRT, report_sig); /* abnormal termination eg abort() */ |
---|
| 217 | signal(SIGFPE, report_sig); /* arithmetic error eg /0 or overflow */ |
---|
| 218 | signal(SIGILL, report_sig); /* illegal function image eg illegal instruction */ |
---|
| 219 | signal(SIGSEGV, report_sig); /* illegal storage access eg access outside memory limits */ |
---|
| 220 | #endif |
---|
[60f7018] | 221 | # ifdef SIGSTAK /* only on RISC OS AFAIK */ |
---|
[db75e18] | 222 | signal(SIGSTAK, report_sig); /* stack overflow */ |
---|
[60f7018] | 223 | # endif |
---|
| 224 | return; |
---|
| 225 | } |
---|
[db75e18] | 226 | |
---|
[60f7018] | 227 | switch (sigReceived) { |
---|
[bd1913f] | 228 | case SIGABRT: en = /*Abnormal termination*/90; break; |
---|
| 229 | case SIGFPE: en = /*Arithmetic error*/91; break; |
---|
| 230 | case SIGILL: en = /*Illegal instruction*/92; break; |
---|
| 231 | case SIGSEGV: en = /*Bad memory access*/94; break; |
---|
[60f7018] | 232 | # ifdef SIGSTAK |
---|
[bd1913f] | 233 | case SIGSTAK: en = /*Stack overflow*/96; break; |
---|
[60f7018] | 234 | # endif |
---|
[bd1913f] | 235 | default: en = /*Unknown signal received*/97; break; |
---|
[60f7018] | 236 | } |
---|
[db75e18] | 237 | fputsnl(msg(en), STDERR); |
---|
[ea816ec] | 238 | |
---|
[c0a9908] | 239 | /* Any of the signals we catch indicates a bug */ |
---|
| 240 | fatalerror(/*Bug in program detected! Please report this to the authors*/11); |
---|
[db75e18] | 241 | |
---|
[60f7018] | 242 | exit(EXIT_FAILURE); |
---|
| 243 | } |
---|
| 244 | #endif |
---|
| 245 | |
---|
[bd1913f] | 246 | static int |
---|
| 247 | default_charset(void) |
---|
| 248 | { |
---|
[8769f9f] | 249 | #if (OS==RISCOS) |
---|
[ea816ec] | 250 | /* RISCOS 3.1 and above CHARSET_RISCOS31 (ISO_8859_1 + extras in 128-159) |
---|
| 251 | * RISCOS < 3.1 is ISO_8859_1 */ |
---|
[2163157] | 252 | int version; |
---|
[ea816ec] | 253 | if (xwimpreadsysinfo_version(&version) != NULL) { |
---|
| 254 | /* RISC OS 2 or some error (don't care which) */ |
---|
| 255 | return CHARSET_ISO_8859_1; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | /* oddly wimp_VERSION_RO3 is RISC OS 3.1 */ |
---|
| 259 | if (version < wimp_VERSION_RO3) return CHARSET_ISO_8859_1; |
---|
[2163157] | 260 | |
---|
[2ca296b] | 261 | return CHARSET_RISCOS31; |
---|
[60f7018] | 262 | #elif (OS==MSDOS) |
---|
| 263 | return CHARSET_DOSCP850; |
---|
[a4140e9] | 264 | #elif (OS==WIN32) |
---|
[d5bd3a7] | 265 | # ifdef AVEN |
---|
[dc639a8] | 266 | return CHARSET_WINCP1252; |
---|
[d5bd3a7] | 267 | # else |
---|
| 268 | switch (GetConsoleOutputCP()) { |
---|
[dc639a8] | 269 | case 1252: return CHARSET_WINCP1252; |
---|
| 270 | case 850: return CHARSET_DOSCP850; |
---|
[d5bd3a7] | 271 | } |
---|
| 272 | return CHARSET_USASCII; |
---|
| 273 | # endif |
---|
[a4140e9] | 274 | #elif (OS==UNIX) |
---|
| 275 | #if defined(XCAVEROT) || defined(AVEN) |
---|
[8769f9f] | 276 | return CHARSET_ISO_8859_1; |
---|
[a4140e9] | 277 | #else |
---|
| 278 | char *p = strchr(msg_lang, '.'); |
---|
| 279 | if (p) { |
---|
| 280 | char *chset = ++p; |
---|
| 281 | size_t name_len; |
---|
| 282 | |
---|
| 283 | while (*p != '\0' && *p != '@') p++; |
---|
| 284 | |
---|
| 285 | name_len = p - chset; |
---|
| 286 | |
---|
| 287 | if (name_len) { |
---|
| 288 | int only_digit = 1; |
---|
| 289 | size_t cnt; |
---|
| 290 | |
---|
| 291 | for (cnt = 0; cnt < name_len; ++cnt) |
---|
| 292 | if (isalpha(chset[cnt])) { |
---|
| 293 | only_digit = 0; |
---|
| 294 | break; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | if (only_digit) goto iso; |
---|
| 298 | |
---|
| 299 | switch (tolower(chset[0])) { |
---|
| 300 | case 'i': |
---|
| 301 | if (tolower(chset[1]) == 's' && tolower(chset[2]) == 'o') { |
---|
| 302 | chset += 3; |
---|
| 303 | iso: |
---|
| 304 | if (strncmp(chset, "8859", 4) == 0) { |
---|
| 305 | chset += 4; |
---|
| 306 | while (chset < p && *chset && !isdigit(*chset)) chset++; |
---|
| 307 | switch (atoi(chset)) { |
---|
| 308 | case 1: return CHARSET_ISO_8859_1; |
---|
[f8e03f3] | 309 | case 15: return CHARSET_ISO_8859_15; |
---|
[a4140e9] | 310 | default: return CHARSET_USASCII; |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | break; |
---|
| 315 | case 'u': |
---|
| 316 | if (tolower(chset[1]) == 't' && tolower(chset[2]) == 'f') { |
---|
| 317 | chset += 3; |
---|
| 318 | while (chset < p && *chset && !isdigit(*chset)) chset++; |
---|
| 319 | switch (atoi(chset)) { |
---|
| 320 | case 8: return CHARSET_UTF8; |
---|
| 321 | default: return CHARSET_USASCII; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | return CHARSET_USASCII; |
---|
| 328 | #endif |
---|
| 329 | #else |
---|
| 330 | # error Do not know operating system 'OS' |
---|
[60f7018] | 331 | #endif |
---|
| 332 | } |
---|
| 333 | |
---|
[dc639a8] | 334 | #if (OS==MSDOS || OS==WIN32) |
---|
[db75e18] | 335 | static int |
---|
| 336 | xlate_dos_cp850(int unicode) |
---|
| 337 | { |
---|
[48e4121] | 338 | switch (unicode) { |
---|
[d41b1353] | 339 | #include "uni2dos.h" |
---|
[48e4121] | 340 | } |
---|
| 341 | return 0; |
---|
| 342 | } |
---|
| 343 | #endif |
---|
| 344 | |
---|
[a4140e9] | 345 | /* It seems that Swedish and maybe some other scandanavian languages don't |
---|
| 346 | * transliterate ä to ae - but it seems there may be conflicting views |
---|
| 347 | * on this... |
---|
| 348 | */ |
---|
| 349 | #define umlaut_to_e() 1 |
---|
| 350 | |
---|
[db75e18] | 351 | static int |
---|
[55de792] | 352 | add_unicode(int charset, unsigned char *p, int value) |
---|
[db75e18] | 353 | { |
---|
[55de792] | 354 | #ifdef DEBUG |
---|
| 355 | fprintf(stderr, "add_unicode(%d, %p, %d)\n", charset, p, value); |
---|
| 356 | #endif |
---|
[4432f2e] | 357 | if (value == 0) return 0; |
---|
[48e4121] | 358 | switch (charset) { |
---|
[db75e18] | 359 | case CHARSET_USASCII: |
---|
[6a4871e] | 360 | if (value < 0x80) { |
---|
[48e4121] | 361 | *p = value; |
---|
| 362 | return 1; |
---|
| 363 | } |
---|
| 364 | break; |
---|
[db75e18] | 365 | case CHARSET_ISO_8859_1: |
---|
[6a4871e] | 366 | if (value < 0x100) { |
---|
[48e4121] | 367 | *p = value; |
---|
| 368 | return 1; |
---|
| 369 | } |
---|
[ea816ec] | 370 | break; |
---|
[f8e03f3] | 371 | case CHARSET_ISO_8859_15: |
---|
| 372 | switch (value) { |
---|
| 373 | case 0xa4: case 0xa6: case 0xb0: case 0xc4: |
---|
| 374 | case 0xd0: case 0xd4: case 0xd5: case 0xd6: |
---|
| 375 | goto donthave; |
---|
| 376 | case 0x152: value = 0xd4; break; /* Œ */ |
---|
| 377 | case 0x153: value = 0xd5; break; /* œ */ |
---|
| 378 | #if 0 |
---|
| 379 | case 0x0: value = 0xa4; break; /* euro */ |
---|
| 380 | case 0x0: value = 0xa6; break; /* Scaron */ |
---|
| 381 | case 0x0: value = 0xb0; break; /* scaron */ |
---|
| 382 | case 0x0: value = 0xc4; break; /* Zcaron */ |
---|
| 383 | case 0x0: value = 0xd0; break; /* zcaron */ |
---|
| 384 | case 0x0: value = 0xd6; break; /* Ydiersis */ |
---|
| 385 | #endif |
---|
| 386 | } |
---|
| 387 | if (value < 0x100) { |
---|
| 388 | *p = value; |
---|
| 389 | return 1; |
---|
| 390 | } |
---|
| 391 | donthave: |
---|
| 392 | break; |
---|
[48e4121] | 393 | #if (OS==RISCOS) |
---|
[ea816ec] | 394 | case CHARSET_RISCOS31: |
---|
| 395 | /* RISC OS 3.1 (and later) extensions to ISO-8859-1 */ |
---|
| 396 | switch (value) { |
---|
| 397 | case 0x152: value = 0x9a; break; /* Œ */ |
---|
| 398 | case 0x153: value = 0x9b; break; /* œ */ |
---|
[f8e03f3] | 399 | #if 0 |
---|
[ea816ec] | 400 | case 0x174: value = 0x81; break; /* Ŵ */ |
---|
| 401 | case 0x175: value = 0x82; break; /* ŵ */ |
---|
| 402 | case 0x176: value = 0x85; break; /* Ŷ */ |
---|
| 403 | case 0x177: value = 0x86; break; /* ŷ */ |
---|
[f8e03f3] | 404 | #endif |
---|
[ea816ec] | 405 | } |
---|
| 406 | if (value < 0x100) { |
---|
| 407 | *p = value; |
---|
| 408 | return 1; |
---|
| 409 | } |
---|
[48e4121] | 410 | break; |
---|
[a4140e9] | 411 | #elif (OS==WIN32) |
---|
| 412 | case CHARSET_WINCP1252: |
---|
| 413 | /* MS Windows extensions to ISO-8859-1 */ |
---|
| 414 | switch (value) { |
---|
| 415 | case 0x152: value = 0x8c; break; /* Œ */ |
---|
| 416 | case 0x153: value = 0x9c; break; /* œ */ |
---|
[f8e03f3] | 417 | #if 0 |
---|
| 418 | /* there are a few other obscure ones we don't currently need */ |
---|
| 419 | #endif |
---|
[a4140e9] | 420 | } |
---|
| 421 | if (value < 0x100) { |
---|
| 422 | *p = value; |
---|
| 423 | return 1; |
---|
| 424 | } |
---|
[e2ae719] | 425 | break; |
---|
| 426 | #endif |
---|
| 427 | #if (OS==MSDOS || OS==WIN32) |
---|
[db75e18] | 428 | case CHARSET_DOSCP850: |
---|
[48e4121] | 429 | value = xlate_dos_cp850(value); |
---|
| 430 | if (value) { |
---|
| 431 | *p = value; |
---|
| 432 | return 1; |
---|
| 433 | } |
---|
| 434 | break; |
---|
| 435 | #endif |
---|
[4432f2e] | 436 | } |
---|
[a4140e9] | 437 | /* Transliterate characters we can't represent */ |
---|
| 438 | #ifdef DEBUG |
---|
| 439 | fprintf(stderr, "transliterate `%c' 0x%x\n", value, value); |
---|
| 440 | #endif |
---|
| 441 | switch (value) { |
---|
| 442 | case 160: |
---|
| 443 | *p = ' '; return 1; |
---|
| 444 | case 161 /* ¡ */: |
---|
| 445 | *p = '!'; return 1; |
---|
| 446 | case 171 /* « */: |
---|
| 447 | p[1] = *p = '<'; return 2; |
---|
| 448 | case 187 /* » */: |
---|
| 449 | p[1] = *p = '>'; return 2; |
---|
| 450 | case 191 /* ¿ */: |
---|
| 451 | *p = '?'; return 1; |
---|
| 452 | case 192 /* À */: case 193 /* Á */: case 194 /* Â */: case 195 /* Ã */: |
---|
| 453 | *p = 'A'; return 1; |
---|
| 454 | case 197 /* Å */: |
---|
| 455 | p[1] = *p = 'A'; return 2; |
---|
| 456 | case 196 /* Ä */: /* Ä */ |
---|
| 457 | *p = 'A'; |
---|
| 458 | if (!umlaut_to_e()) return 1; |
---|
| 459 | p[1] = 'E'; return 2; |
---|
| 460 | case 198 /* Æ */: |
---|
| 461 | *p = 'A'; p[1] = 'E'; return 2; |
---|
| 462 | case 199 /* Ç */: |
---|
| 463 | *p = 'C'; return 1; |
---|
| 464 | case 200 /* È */: case 201 /* É */: case 202 /* Ê */: case 203 /* Ë */: |
---|
| 465 | *p = 'E'; return 1; |
---|
| 466 | case 204 /* Ì */: case 205 /* Í */: case 206 /* Î */: case 207 /* Ï */: |
---|
| 467 | *p = 'I'; return 1; |
---|
| 468 | case 208 /* Ð */: case 222 /* Þ */: |
---|
| 469 | *p = 'T'; p[1] = 'H'; return 2; |
---|
| 470 | case 209 /* Ñ */: |
---|
| 471 | *p = 'N'; return 1; |
---|
| 472 | case 210 /* Ò */: case 211 /* Ó */: case 212 /* Ô */: case 213 /* Õ */: |
---|
| 473 | *p = 'O'; return 1; |
---|
| 474 | case 214 /* Ö */: /* Ö */ case 0x152: /* Œ */ |
---|
| 475 | *p = 'O'; p[1] = 'E'; return 2; |
---|
| 476 | case 217 /* Ù */: case 218 /* Ú */: case 219 /* Û */: |
---|
| 477 | *p = 'U'; return 1; |
---|
| 478 | case 220 /* Ü */: /* Ü */ |
---|
| 479 | *p = 'U'; p[1] = 'E'; return 2; |
---|
| 480 | case 221 /* Ý */: |
---|
| 481 | *p = 'Y'; return 1; |
---|
| 482 | case 223 /* ß */: |
---|
| 483 | p[1] = *p = 's'; return 2; |
---|
| 484 | case 224 /* à */: case 225 /* á */: case 226 /* â */: case 227 /* ã */: |
---|
| 485 | *p = 'a'; return 1; |
---|
| 486 | case 228 /* ä */: /* ä */ case 230 /* æ */: |
---|
| 487 | *p = 'a'; p[1] = 'e'; return 2; |
---|
| 488 | case 229 /* å */: |
---|
| 489 | p[1] = *p = 'a'; return 2; |
---|
| 490 | case 231 /* ç */: |
---|
| 491 | *p = 'c'; return 1; |
---|
| 492 | case 232 /* è */: case 233 /* é */: case 234 /* ê */: case 235 /* ë */: |
---|
| 493 | *p = 'e'; return 1; |
---|
| 494 | case 236 /* ì */: case 237 /* í */: case 238 /* î */: case 239 /* ï */: |
---|
| 495 | *p = 'i'; return 1; |
---|
| 496 | case 241 /* ñ */: |
---|
| 497 | *p = 'n'; return 1; |
---|
| 498 | case 240 /* ð */: case 254 /* þ */: |
---|
| 499 | *p = 't'; p[1] = 'h'; return 2; |
---|
| 500 | case 242 /* ò */: case 243 /* ó */: case 244 /* ô */: case 245 /* õ */: |
---|
| 501 | *p = 'o'; return 1; |
---|
| 502 | case 246 /* ö */: /* ö */ case 0x153: /* œ */ |
---|
| 503 | *p = 'o'; p[1] = 'e'; return 2; |
---|
| 504 | case 249 /* ù */: case 250 /* ú */: case 251 /* û */: |
---|
| 505 | *p = 'u'; return 1; |
---|
| 506 | case 252 /* ü */: /* ü */ |
---|
| 507 | *p = 'u'; p[1] = 'e'; return 2; |
---|
| 508 | case 253 /* ý */: case 255 /* ÿ */: |
---|
| 509 | *p = 'y'; return 1; |
---|
| 510 | } |
---|
| 511 | #ifdef DEBUG |
---|
| 512 | fprintf(stderr, "failed to transliterate\n"); |
---|
| 513 | #endif |
---|
[f1a5201] | 514 | return 0; |
---|
[4432f2e] | 515 | } |
---|
| 516 | |
---|
[f2a6ce4] | 517 | /* fall back on looking in the current directory */ |
---|
| 518 | static const char *pth_cfg_files = ""; |
---|
| 519 | |
---|
[db75e18] | 520 | static int num_msgs = 0; |
---|
[55de792] | 521 | static char **msg_array = NULL; |
---|
[db75e18] | 522 | |
---|
[b83f907] | 523 | const char *msg_lang = NULL; |
---|
[c0a9908] | 524 | const char *msg_lang2 = NULL; |
---|
[b83f907] | 525 | |
---|
[d5bd3a7] | 526 | static char ** |
---|
| 527 | parse_msgs(int n, unsigned char *p, int charset_code) { |
---|
| 528 | int i; |
---|
| 529 | |
---|
| 530 | char **msgs = osmalloc(n * sizeof(char *)); |
---|
| 531 | |
---|
| 532 | for (i = 0; i < n; i++) { |
---|
| 533 | unsigned char *to = p; |
---|
| 534 | int ch; |
---|
| 535 | msgs[i] = (char *)p; |
---|
| 536 | |
---|
| 537 | /* If we want UTF8 anyway, we just need to find the start of each |
---|
| 538 | * message */ |
---|
| 539 | if (charset_code == CHARSET_UTF8) { |
---|
| 540 | p += strlen((char *)p) + 1; |
---|
| 541 | continue; |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | while ((ch = *p++) != 0) { |
---|
| 545 | /* A byte in the range 0x80-0xbf or 0xf0-0xff isn't valid in |
---|
| 546 | * this state, (0xf0-0xfd mean values > 0xffff) so treat as |
---|
| 547 | * literal and try to resync so we cope better when fed |
---|
| 548 | * non-utf-8 data. Similarly we abandon a multibyte sequence |
---|
| 549 | * if we hit an invalid character. */ |
---|
| 550 | if (ch >= 0xc0 && ch < 0xf0) { |
---|
| 551 | int ch1 = *p; |
---|
| 552 | if ((ch1 & 0xc0) != 0x80) goto resync; |
---|
| 553 | |
---|
| 554 | if (ch < 0xe0) { |
---|
| 555 | /* 2 byte sequence */ |
---|
| 556 | ch = ((ch & 0x1f) << 6) | (ch1 & 0x3f); |
---|
| 557 | p++; |
---|
| 558 | } else { |
---|
| 559 | /* 3 byte sequence */ |
---|
| 560 | int ch2 = p[1]; |
---|
| 561 | if ((ch2 & 0xc0) != 0x80) goto resync; |
---|
| 562 | ch = ((ch & 0x1f) << 12) | ((ch1 & 0x3f) << 6) | (ch2 & 0x3f); |
---|
| 563 | p += 2; |
---|
| 564 | } |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | resync: |
---|
| 568 | |
---|
| 569 | if (ch < 127) { |
---|
| 570 | *to++ = (char)ch; |
---|
| 571 | } else { |
---|
| 572 | /* We assume an N byte UTF-8 code never transliterates to more |
---|
| 573 | * than N characters (so we can't transliterate © to (C) or |
---|
| 574 | * ® to (R) for example) */ |
---|
| 575 | to += add_unicode(charset_code, to, ch); |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | *to++ = '\0'; |
---|
| 579 | } |
---|
| 580 | return msgs; |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | /* No point extracting these errors as they won't get used if file opens */ |
---|
| 584 | #define HDR(D) "../lib/"STRING(D)".h" |
---|
| 585 | #include HDR(DEFAULTLANG) |
---|
| 586 | |
---|
| 587 | static char **dontextract = NULL; |
---|
| 588 | |
---|
[db75e18] | 589 | static void |
---|
| 590 | parse_msg_file(int charset_code) |
---|
| 591 | { |
---|
| 592 | FILE *fh; |
---|
| 593 | unsigned char header[20]; |
---|
[d5bd3a7] | 594 | int i; |
---|
[db75e18] | 595 | unsigned len; |
---|
[55de792] | 596 | unsigned char *p; |
---|
[b164c18] | 597 | char *fnm, *s; |
---|
[d5bd3a7] | 598 | int n; |
---|
[cb3d1e2] | 599 | |
---|
[55de792] | 600 | #ifdef DEBUG |
---|
| 601 | fprintf(stderr, "parse_msg_file(%d)\n", charset_code); |
---|
| 602 | #endif |
---|
[db75e18] | 603 | |
---|
[d5bd3a7] | 604 | /* sort out messages we need to print if we can't open the message file */ |
---|
| 605 | dontextract = parse_msgs(N_DONTEXTRACTMSGS, dontextractmsgs, charset_code); |
---|
| 606 | |
---|
[0a3c5fa] | 607 | fnm = osstrdup(msg_lang); |
---|
[b164c18] | 608 | /* trim off charset from stuff like "de_DE.iso8859_1" */ |
---|
| 609 | s = strchr(fnm, '.'); |
---|
| 610 | if (s) *s = '\0'; |
---|
[a2f9d5c] | 611 | |
---|
[b164c18] | 612 | fh = fopenWithPthAndExt(pth_cfg_files, fnm, EXT_SVX_MSG, "rb", NULL); |
---|
[db75e18] | 613 | |
---|
| 614 | if (!fh) { |
---|
| 615 | /* e.g. if 'en-COCKNEY' is unknown, see if we know 'en' */ |
---|
[b164c18] | 616 | if (strlen(fnm) > 3 && fnm[2] == '-') { |
---|
| 617 | fnm[2] = '\0'; |
---|
| 618 | fh = fopenWithPthAndExt(pth_cfg_files, fnm, EXT_SVX_MSG, "rb", NULL); |
---|
| 619 | if (!fh) fnm[2] = '-'; /* for error reporting */ |
---|
[db75e18] | 620 | } |
---|
[48e4121] | 621 | } |
---|
[db75e18] | 622 | |
---|
| 623 | if (!fh) { |
---|
[b07f165] | 624 | fatalerror(/*Can't open message file `%s' using path `%s'*/1000, |
---|
| 625 | fnm, pth_cfg_files); |
---|
[4432f2e] | 626 | } |
---|
[db75e18] | 627 | |
---|
| 628 | if (fread(header, 1, 20, fh) < 20 || |
---|
| 629 | memcmp(header, "Svx\nMsg\r\n\xfe\xff", 12) != 0) { |
---|
[b07f165] | 630 | fatalerror(/*Problem with message file `%s'*/1001, fnm); |
---|
[db75e18] | 631 | } |
---|
| 632 | |
---|
[b07f165] | 633 | if (header[12] != 0) |
---|
| 634 | fatalerror(/*I don't understand this message file version*/1002); |
---|
[db75e18] | 635 | |
---|
[d5bd3a7] | 636 | n = (header[14] << 8) | header[15]; |
---|
[db75e18] | 637 | |
---|
| 638 | len = 0; |
---|
| 639 | for (i = 16; i < 20; i++) len = (len << 8) | header[i]; |
---|
| 640 | |
---|
[0a3c5fa] | 641 | p = osmalloc(len); |
---|
[b07f165] | 642 | if (fread(p, 1, len, fh) < len) |
---|
| 643 | fatalerror(/*Message file truncated?*/1003); |
---|
[2163157] | 644 | |
---|
[a420b49] | 645 | fclose(fh); |
---|
[db75e18] | 646 | |
---|
[55de792] | 647 | #ifdef DEBUG |
---|
[d5bd3a7] | 648 | fprintf(stderr, "fnm = `%s', n = %d, len = %d\n", fnm, n, len); |
---|
[55de792] | 649 | #endif |
---|
[b164c18] | 650 | osfree(fnm); |
---|
[55de792] | 651 | |
---|
[d5bd3a7] | 652 | msg_array = parse_msgs(n, p, charset_code); |
---|
| 653 | num_msgs = n; |
---|
[4432f2e] | 654 | } |
---|
| 655 | |
---|
[f2a6ce4] | 656 | const char * |
---|
| 657 | msg_cfgpth(void) |
---|
| 658 | { |
---|
| 659 | return pth_cfg_files; |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | void |
---|
| 663 | msg_init(const char *argv0) |
---|
[db75e18] | 664 | { |
---|
| 665 | char *p; |
---|
| 666 | |
---|
| 667 | #ifdef HAVE_SIGNAL |
---|
| 668 | init_signals(); |
---|
| 669 | #endif |
---|
[0a3c5fa] | 670 | /* Point to argv0 itself so we report a more helpful error if the code to work |
---|
| 671 | * out the clean appname generates a signal */ |
---|
[a4140e9] | 672 | appname_copy = argv0; |
---|
[0a3c5fa] | 673 | #if (OS == UNIX) |
---|
| 674 | /* use name as-is on Unix - programs run from path get name as supplied */ |
---|
[a4140e9] | 675 | appname_copy = osstrdup(argv0); |
---|
[0a3c5fa] | 676 | #else |
---|
| 677 | /* use the lower-cased leafname on other platforms */ |
---|
[a4140e9] | 678 | appname_copy = p = leaf_from_fnm(argv0); |
---|
[4bfc8a7] | 679 | while (*p) { |
---|
| 680 | *p = tolower(*p); |
---|
| 681 | p++; |
---|
| 682 | } |
---|
[0a3c5fa] | 683 | #endif |
---|
[db75e18] | 684 | |
---|
| 685 | /* Look for env. var. "SURVEXHOME" or the like */ |
---|
| 686 | p = getenv("SURVEXHOME"); |
---|
| 687 | if (p && *p) { |
---|
[0a3c5fa] | 688 | pth_cfg_files = osstrdup(p); |
---|
[18f4759] | 689 | #if (OS==UNIX) && defined(DATADIR) && defined(PACKAGE) |
---|
[a420b49] | 690 | } else { |
---|
| 691 | /* under Unix, we compile in the configured path */ |
---|
[18f4759] | 692 | pth_cfg_files = DATADIR "/" PACKAGE; |
---|
[a420b49] | 693 | #else |
---|
[db75e18] | 694 | } else if (argv0) { |
---|
| 695 | /* else try the path on argv[0] */ |
---|
[f2a6ce4] | 696 | pth_cfg_files = path_from_fnm(argv0); |
---|
[a420b49] | 697 | #endif |
---|
[db75e18] | 698 | } |
---|
| 699 | |
---|
[b164c18] | 700 | msg_lang = getenv("SURVEXLANG"); |
---|
| 701 | #ifdef DEBUG |
---|
[74044b7] | 702 | fprintf(stderr, "msg_lang = %p (= \"%s\")\n", msg_lang, msg_lang?msg_lang:"(null)"); |
---|
[b164c18] | 703 | #endif |
---|
| 704 | |
---|
| 705 | if (!msg_lang || !*msg_lang) { |
---|
| 706 | msg_lang = getenv("LANG"); |
---|
[74044b7] | 707 | if (!msg_lang || !*msg_lang) { |
---|
| 708 | #if (OS==WIN32) |
---|
| 709 | LCID locid; |
---|
| 710 | #endif |
---|
[d5bd3a7] | 711 | msg_lang = STRING(DEFAULTLANG); |
---|
[74044b7] | 712 | #if (OS==WIN32) |
---|
| 713 | locid = GetUserDefaultLCID(); |
---|
| 714 | if (locid) { |
---|
| 715 | WORD langid = LANGIDFROMLCID(locid); |
---|
| 716 | switch (PRIMARYLANGID(langid)) { |
---|
| 717 | case LANG_CATALAN: |
---|
| 718 | msg_lang = "ca"; |
---|
| 719 | break; |
---|
| 720 | case LANG_ENGLISH: |
---|
| 721 | if (SUBLANGID(langid) == SUBLANG_ENGLISH_US) |
---|
| 722 | msg_lang = "en_US"; |
---|
| 723 | else |
---|
| 724 | msg_lang = "en"; |
---|
| 725 | break; |
---|
| 726 | case LANG_FRENCH: |
---|
| 727 | msg_lang = "fr"; |
---|
| 728 | break; |
---|
| 729 | case LANG_GERMAN: |
---|
| 730 | switch (SUBLANGID(langid)) { |
---|
| 731 | case SUBLANG_GERMAN_SWISS: |
---|
| 732 | msg_lang = "de_CH"; |
---|
| 733 | break; |
---|
| 734 | case SUBLANG_GERMAN: |
---|
| 735 | msg_lang = "de_DE"; |
---|
| 736 | break; |
---|
| 737 | default: |
---|
| 738 | msg_lang = "de"; |
---|
| 739 | } |
---|
| 740 | break; |
---|
| 741 | case LANG_ITALIAN: |
---|
| 742 | msg_lang = "it"; |
---|
| 743 | break; |
---|
| 744 | case LANG_PORTUGUESE: |
---|
| 745 | if (SUBLANGID(langid) == SUBLANG_PORTUGUESE_BRAZILIAN) |
---|
| 746 | msg_lang = "pt_BR"; |
---|
| 747 | else |
---|
| 748 | msg_lang = "pt"; |
---|
| 749 | break; |
---|
| 750 | case LANG_SPANISH: |
---|
| 751 | msg_lang = "es"; |
---|
| 752 | break; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | #endif |
---|
| 756 | } |
---|
[b164c18] | 757 | } |
---|
| 758 | #ifdef DEBUG |
---|
| 759 | fprintf(stderr, "msg_lang = %p (= \"%s\")\n", msg_lang, msg_lang?msg_lang:"(null)"); |
---|
| 760 | #endif |
---|
| 761 | |
---|
| 762 | /* On Mandrake LANG defaults to C */ |
---|
| 763 | if (strcmp(msg_lang, "C") == 0) msg_lang = "en"; |
---|
| 764 | |
---|
[0a3c5fa] | 765 | msg_lang = osstrdup(msg_lang); |
---|
[b164c18] | 766 | |
---|
| 767 | /* Convert en-us to en_US, etc */ |
---|
| 768 | p = strchr(msg_lang, '-'); |
---|
| 769 | if (p) { |
---|
| 770 | *p++ = '_'; |
---|
| 771 | while (*p) { |
---|
| 772 | *p = toupper(*p); |
---|
| 773 | p++; |
---|
| 774 | } |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | p = strchr(msg_lang, '_'); |
---|
| 778 | if (p) { |
---|
| 779 | *p = '\0'; |
---|
[0a3c5fa] | 780 | msg_lang2 = osstrdup(msg_lang); |
---|
[b164c18] | 781 | *p = '_'; |
---|
| 782 | } |
---|
| 783 | |
---|
| 784 | #ifdef LC_MESSAGES |
---|
| 785 | /* try to setlocale() appropriately too */ |
---|
| 786 | if (!setlocale(LC_MESSAGES, msg_lang)) { |
---|
| 787 | if (msg_lang2) setlocale(LC_MESSAGES, msg_lang2); |
---|
| 788 | } |
---|
| 789 | #endif |
---|
| 790 | |
---|
[db75e18] | 791 | select_charset(default_charset()); |
---|
| 792 | } |
---|
| 793 | |
---|
[d5bd3a7] | 794 | /* Message may be overwritten by next call |
---|
[bd1913f] | 795 | * (but not in current implementation) */ |
---|
| 796 | const char * |
---|
[db75e18] | 797 | msg(int en) |
---|
| 798 | { |
---|
[eee67ab] | 799 | /* NB can't use ASSERT here! */ |
---|
| 800 | static char badbuf[256]; |
---|
[d5bd3a7] | 801 | if (en >= 1000 && en < 1000 + N_DONTEXTRACTMSGS) |
---|
[b07f165] | 802 | return dontextract[en - 1000]; |
---|
[55de792] | 803 | if (!msg_array) { |
---|
[eee67ab] | 804 | if (en != 1) { |
---|
| 805 | sprintf(badbuf, "Message %d requested before msg_array initialised\n", en); |
---|
| 806 | return badbuf; |
---|
| 807 | } |
---|
[d5bd3a7] | 808 | /* this should be the only other message which can be requested before |
---|
[a420b49] | 809 | * the message file is opened and read... */ |
---|
[d5bd3a7] | 810 | if (!dontextract) return "Out of memory (couldn't find %lu bytes)."; |
---|
| 811 | return dontextract[4]; |
---|
[db75e18] | 812 | } |
---|
| 813 | |
---|
[eee67ab] | 814 | if (en < 0 || en >= num_msgs) { |
---|
| 815 | sprintf(badbuf, "Message %d out of range\n", en); |
---|
| 816 | return badbuf; |
---|
| 817 | } |
---|
[db75e18] | 818 | |
---|
[55de792] | 819 | return msg_array[en]; |
---|
[db75e18] | 820 | } |
---|
| 821 | |
---|
| 822 | /* returns persistent copy of message */ |
---|
[bd1913f] | 823 | const char * |
---|
[db75e18] | 824 | msgPerm(int en) |
---|
| 825 | { |
---|
| 826 | return msg(en); |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | void |
---|
| 830 | v_report(int severity, const char *fnm, int line, int en, va_list ap) |
---|
| 831 | { |
---|
[1f316f3] | 832 | #ifdef AVEN |
---|
[2e18955] | 833 | aven_v_report(severity, fnm, line, en, ap); |
---|
[2163157] | 834 | #else |
---|
[db75e18] | 835 | if (fnm) { |
---|
| 836 | fputs(fnm, STDERR); |
---|
| 837 | if (line) fprintf(STDERR, ":%d", line); |
---|
| 838 | } else { |
---|
[a4140e9] | 839 | fputs(appname_copy, STDERR); |
---|
[cb3d1e2] | 840 | } |
---|
[db75e18] | 841 | fputs(": ", STDERR); |
---|
| 842 | |
---|
| 843 | if (severity == 0) { |
---|
| 844 | fputs(msg(/*warning*/4), STDERR); |
---|
| 845 | fputs(": ", STDERR); |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | vfprintf(STDERR, msg(en), ap); |
---|
| 849 | fputnl(STDERR); |
---|
[1f316f3] | 850 | #endif |
---|
[cb3d1e2] | 851 | |
---|
[db75e18] | 852 | switch (severity) { |
---|
| 853 | case 0: |
---|
[25ab06b] | 854 | msg_warnings++; |
---|
[db75e18] | 855 | break; |
---|
| 856 | case 1: |
---|
[25ab06b] | 857 | msg_errors++; |
---|
| 858 | if (msg_errors == 50) |
---|
[db75e18] | 859 | fatalerror_in_file(fnm, 0, /*Too many errors - giving up*/19); |
---|
| 860 | break; |
---|
| 861 | case 2: |
---|
| 862 | exit(EXIT_FAILURE); |
---|
| 863 | } |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | void |
---|
| 867 | warning(int en, ...) |
---|
| 868 | { |
---|
| 869 | va_list ap; |
---|
| 870 | va_start(ap, en); |
---|
| 871 | v_report(0, NULL, 0, en, ap); |
---|
| 872 | va_end(ap); |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | void |
---|
| 876 | error(int en, ...) |
---|
| 877 | { |
---|
| 878 | va_list ap; |
---|
| 879 | va_start(ap, en); |
---|
| 880 | v_report(1, NULL, 0, en, ap); |
---|
| 881 | va_end(ap); |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | void |
---|
| 885 | fatalerror(int en, ...) |
---|
| 886 | { |
---|
| 887 | va_list ap; |
---|
| 888 | va_start(ap, en); |
---|
| 889 | v_report(2, NULL, 0, en, ap); |
---|
| 890 | va_end(ap); |
---|
| 891 | } |
---|
| 892 | |
---|
| 893 | void |
---|
| 894 | warning_in_file(const char *fnm, int line, int en, ...) |
---|
| 895 | { |
---|
| 896 | va_list ap; |
---|
| 897 | va_start(ap, en); |
---|
| 898 | v_report(0, fnm, line, en, ap); |
---|
| 899 | va_end(ap); |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | void |
---|
| 903 | error_in_file(const char *fnm, int line, int en, ...) |
---|
| 904 | { |
---|
| 905 | va_list ap; |
---|
| 906 | va_start(ap, en); |
---|
| 907 | v_report(1, fnm, line, en, ap); |
---|
| 908 | va_end(ap); |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | void |
---|
| 912 | fatalerror_in_file(const char *fnm, int line, int en, ...) |
---|
| 913 | { |
---|
| 914 | va_list ap; |
---|
| 915 | va_start(ap, en); |
---|
| 916 | v_report(2, fnm, line, en, ap); |
---|
| 917 | va_end(ap); |
---|
| 918 | } |
---|
| 919 | |
---|
| 920 | /* Code to support switching character set at runtime (e.g. for a printer |
---|
| 921 | * driver to support different character sets on screen and on the printer) |
---|
| 922 | */ |
---|
| 923 | typedef struct charset_li { |
---|
| 924 | struct charset_li *next; |
---|
| 925 | int code; |
---|
[55de792] | 926 | char **msg_array; |
---|
[db75e18] | 927 | } charset_li; |
---|
| 928 | |
---|
| 929 | static charset_li *charset_head = NULL; |
---|
| 930 | |
---|
| 931 | static int charset = CHARSET_BAD; |
---|
| 932 | |
---|
| 933 | int |
---|
| 934 | select_charset(int charset_code) |
---|
| 935 | { |
---|
| 936 | int old_charset = charset; |
---|
| 937 | charset_li *p; |
---|
| 938 | |
---|
[55de792] | 939 | #ifdef DEBUG |
---|
[bd1913f] | 940 | fprintf(stderr, "select_charset(%d), old charset = %d\n", charset_code, |
---|
| 941 | charset); |
---|
[55de792] | 942 | #endif |
---|
[cb3d1e2] | 943 | |
---|
[db75e18] | 944 | charset = charset_code; |
---|
| 945 | |
---|
| 946 | /* check if we've already parsed messages for new charset */ |
---|
| 947 | for (p = charset_head; p; p = p->next) { |
---|
[55de792] | 948 | #ifdef DEBUG |
---|
| 949 | printf("%p: code %d msg_array %p\n", p, p->code, p->msg_array); |
---|
| 950 | #endif |
---|
[db75e18] | 951 | if (p->code == charset) { |
---|
[55de792] | 952 | msg_array = p->msg_array; |
---|
[db75e18] | 953 | return old_charset; |
---|
| 954 | } |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | /* nope, got to reparse message file */ |
---|
| 958 | parse_msg_file(charset_code); |
---|
| 959 | |
---|
| 960 | /* add to list */ |
---|
| 961 | p = osnew(charset_li); |
---|
| 962 | p->code = charset; |
---|
[55de792] | 963 | p->msg_array = msg_array; |
---|
[db75e18] | 964 | p->next = charset_head; |
---|
| 965 | charset_head = p; |
---|
| 966 | |
---|
| 967 | return old_charset; |
---|
| 968 | } |
---|