52 #ifdef SUN5_0
53 #include <string.h> /* strerror() */
54 #endif
55
56 #if defined (HP_UX) || defined (linux)
57 #include <unistd.h>
58 #endif
59
60 /*
61 * Defined macros
62 */
63
64 /*
65 * typedefs & structs
66 */
67
68 /*
69 * Static variables
70 */
71 #ifdef SUN5_0
72 extern "C" void (*sigivalue)(int) = SIG_DFL;
73 extern "C" void (*sigqvalue)(int) = SIG_DFL;
74 extern "C" void (*sigtvalue)(int) = SIG_DFL;
75 extern "C" void (*sighvalue)(int) = SIG_DFL;
76 #else
77 static void (*sigivalue)(int) = (void (*) (int)) SIG_DFL;
78 static void (*sigqvalue)(int) = (void (*) (int)) SIG_DFL;
79 static void (*sigtvalue)(int) = (void (*) (int)) SIG_DFL;
80 static void (*sighvalue)(int) = (void (*) (int)) SIG_DFL;
81 #endif
82
83 long getname_bytes_count = 0;
84 long getname_names_count = 0;
85 long getname_struct_count = 0;
86
87 long freename_bytes_count = 0;
88 long freename_names_count = 0;
89 long freename_struct_count = 0;
90
91 long expandstring_count = 0;
92 long getwstring_count = 0;
93
94 /*
95 * File table of contents
308 #else
309 if (sighvalue != (void (*) (int)) SIG_IGN) {
310 #endif
311 (void) bsd_signal(SIGHUP, (SIG_PF) handler);
312 }
313 }
314
315 /*
316 * setup_char_semantics()
317 *
318 * Load the vector char_semantics[] with lexical markers
319 *
320 * Parameters:
321 *
322 * Global variables used:
323 * char_semantics The vector of character semantics that we set
324 */
325 void
326 setup_char_semantics(void)
327 {
328 char *s;
329 wchar_t wc_buffer[1];
330 int entry;
331
332 if (svr4) {
333 s = "@-";
334 } else {
335 s = "=@-?!+";
336 }
337 for (s; MBTOWC(wc_buffer, s); s++) {
338 entry = get_char_semantics_entry(*wc_buffer);
339 char_semantics[entry] |= (int) command_prefix_sem;
340 }
341 char_semantics[dollar_char_entry] |= (int) dollar_sem;
342 for (s = "#|=^();&<>*?[]:$`'\"\\\n"; MBTOWC(wc_buffer, s); s++) {
343 entry = get_char_semantics_entry(*wc_buffer);
344 char_semantics[entry] |= (int) meta_sem;
345 }
346 char_semantics[percent_char_entry] |= (int) percent_sem;
347 for (s = "@*<%?^"; MBTOWC(wc_buffer, s); s++) {
348 entry = get_char_semantics_entry(*wc_buffer);
396 return strerror(errnum);
397 #endif
398
399 }
400 #endif // linux
401 }
402
403 static char static_buf[MAXPATHLEN*3];
404
405 /*
406 * fatal_mksh(format, args...)
407 *
408 * Print a message and die
409 *
410 * Parameters:
411 * format printf type format string
412 * args Arguments to match the format
413 */
414 /*VARARGS*/
415 void
416 fatal_mksh(char * message, ...)
417 {
418 va_list args;
419 char *buf = static_buf;
420 char *mksh_fat_err = catgets(libmksdmsi18n_catd, 1, 128, "mksh: Fatal error: ");
421 char *cur_wrk_dir = catgets(libmksdmsi18n_catd, 1, 129, "Current working directory: ");
422 int mksh_fat_err_len = strlen(mksh_fat_err);
423
424 va_start(args, message);
425 (void) fflush(stdout);
426 (void) strcpy(buf, mksh_fat_err);
427 size_t buf_len = vsnprintf(static_buf + mksh_fat_err_len,
428 sizeof(static_buf) - mksh_fat_err_len,
429 message, args)
430 + mksh_fat_err_len
431 + strlen(cur_wrk_dir)
432 + strlen(get_current_path_mksh())
433 + 3; // "\n\n"
434 va_end(args);
435 if (buf_len >= sizeof(static_buf)) {
436 buf = getmem(buf_len);
451 (void) fputs(buf, stderr);
452 (void) fflush(stderr);
453 if (buf != static_buf) {
454 retmem_mb(buf);
455 }
456 #ifdef SUN5_0
457 exit_status = 1;
458 #endif
459 exit(1);
460 }
461
462 /*
463 * fatal_reader_mksh(format, args...)
464 *
465 * Parameters:
466 * format printf style format string
467 * args arguments to match the format
468 */
469 /*VARARGS*/
470 void
471 fatal_reader_mksh(char * pattern, ...)
472 {
473 va_list args;
474 char message[1000];
475
476 va_start(args, pattern);
477 /*
478 if (file_being_read != NULL) {
479 WCSTOMBS(mbs_buffer, file_being_read);
480 if (line_number != 0) {
481 (void) sprintf(message,
482 catgets(libmksdmsi18n_catd, 1, 130, "%s, line %d: %s"),
483 mbs_buffer,
484 line_number,
485 pattern);
486 } else {
487 (void) sprintf(message,
488 "%s: %s",
489 mbs_buffer,
490 pattern);
491 }
|
52 #ifdef SUN5_0
53 #include <string.h> /* strerror() */
54 #endif
55
56 #if defined (HP_UX) || defined (linux)
57 #include <unistd.h>
58 #endif
59
60 /*
61 * Defined macros
62 */
63
64 /*
65 * typedefs & structs
66 */
67
68 /*
69 * Static variables
70 */
71 #ifdef SUN5_0
72 extern "C" {
73 void (*sigivalue)(int) = SIG_DFL;
74 void (*sigqvalue)(int) = SIG_DFL;
75 void (*sigtvalue)(int) = SIG_DFL;
76 void (*sighvalue)(int) = SIG_DFL;
77 }
78 #else
79 static void (*sigivalue)(int) = (void (*) (int)) SIG_DFL;
80 static void (*sigqvalue)(int) = (void (*) (int)) SIG_DFL;
81 static void (*sigtvalue)(int) = (void (*) (int)) SIG_DFL;
82 static void (*sighvalue)(int) = (void (*) (int)) SIG_DFL;
83 #endif
84
85 long getname_bytes_count = 0;
86 long getname_names_count = 0;
87 long getname_struct_count = 0;
88
89 long freename_bytes_count = 0;
90 long freename_names_count = 0;
91 long freename_struct_count = 0;
92
93 long expandstring_count = 0;
94 long getwstring_count = 0;
95
96 /*
97 * File table of contents
310 #else
311 if (sighvalue != (void (*) (int)) SIG_IGN) {
312 #endif
313 (void) bsd_signal(SIGHUP, (SIG_PF) handler);
314 }
315 }
316
317 /*
318 * setup_char_semantics()
319 *
320 * Load the vector char_semantics[] with lexical markers
321 *
322 * Parameters:
323 *
324 * Global variables used:
325 * char_semantics The vector of character semantics that we set
326 */
327 void
328 setup_char_semantics(void)
329 {
330 const char *s;
331 wchar_t wc_buffer[1];
332 int entry;
333
334 if (svr4) {
335 s = "@-";
336 } else {
337 s = "=@-?!+";
338 }
339 for (s; MBTOWC(wc_buffer, s); s++) {
340 entry = get_char_semantics_entry(*wc_buffer);
341 char_semantics[entry] |= (int) command_prefix_sem;
342 }
343 char_semantics[dollar_char_entry] |= (int) dollar_sem;
344 for (s = "#|=^();&<>*?[]:$`'\"\\\n"; MBTOWC(wc_buffer, s); s++) {
345 entry = get_char_semantics_entry(*wc_buffer);
346 char_semantics[entry] |= (int) meta_sem;
347 }
348 char_semantics[percent_char_entry] |= (int) percent_sem;
349 for (s = "@*<%?^"; MBTOWC(wc_buffer, s); s++) {
350 entry = get_char_semantics_entry(*wc_buffer);
398 return strerror(errnum);
399 #endif
400
401 }
402 #endif // linux
403 }
404
405 static char static_buf[MAXPATHLEN*3];
406
407 /*
408 * fatal_mksh(format, args...)
409 *
410 * Print a message and die
411 *
412 * Parameters:
413 * format printf type format string
414 * args Arguments to match the format
415 */
416 /*VARARGS*/
417 void
418 fatal_mksh(const char *message, ...)
419 {
420 va_list args;
421 char *buf = static_buf;
422 char *mksh_fat_err = catgets(libmksdmsi18n_catd, 1, 128, "mksh: Fatal error: ");
423 char *cur_wrk_dir = catgets(libmksdmsi18n_catd, 1, 129, "Current working directory: ");
424 int mksh_fat_err_len = strlen(mksh_fat_err);
425
426 va_start(args, message);
427 (void) fflush(stdout);
428 (void) strcpy(buf, mksh_fat_err);
429 size_t buf_len = vsnprintf(static_buf + mksh_fat_err_len,
430 sizeof(static_buf) - mksh_fat_err_len,
431 message, args)
432 + mksh_fat_err_len
433 + strlen(cur_wrk_dir)
434 + strlen(get_current_path_mksh())
435 + 3; // "\n\n"
436 va_end(args);
437 if (buf_len >= sizeof(static_buf)) {
438 buf = getmem(buf_len);
453 (void) fputs(buf, stderr);
454 (void) fflush(stderr);
455 if (buf != static_buf) {
456 retmem_mb(buf);
457 }
458 #ifdef SUN5_0
459 exit_status = 1;
460 #endif
461 exit(1);
462 }
463
464 /*
465 * fatal_reader_mksh(format, args...)
466 *
467 * Parameters:
468 * format printf style format string
469 * args arguments to match the format
470 */
471 /*VARARGS*/
472 void
473 fatal_reader_mksh(const char * pattern, ...)
474 {
475 va_list args;
476 char message[1000];
477
478 va_start(args, pattern);
479 /*
480 if (file_being_read != NULL) {
481 WCSTOMBS(mbs_buffer, file_being_read);
482 if (line_number != 0) {
483 (void) sprintf(message,
484 catgets(libmksdmsi18n_catd, 1, 130, "%s, line %d: %s"),
485 mbs_buffer,
486 line_number,
487 pattern);
488 } else {
489 (void) sprintf(message,
490 "%s: %s",
491 mbs_buffer,
492 pattern);
493 }
|