--- rxvt-unicode/src/misc.C 2004/02/27 02:52:51 1.8 +++ rxvt-unicode/src/misc.C 2004/03/17 05:15:02 1.12 @@ -29,6 +29,28 @@ /* EXTPROTO */ char * +rxvt_wcstombs (const wchar_t *str, int len) +{ + mbstate mbs; + char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1); + + char *dst = r; + while (len--) + { + int l = wcrtomb (dst, *str++, mbs); + if (l < 0) + *dst++ = '?'; + else + dst += l; + } + + *dst++ = 0; + + return r; +} + +/* EXTPROTO */ +char * rxvt_strdup (const char *str) { return str ? strdup (str) : 0; @@ -48,18 +70,70 @@ */ /* EXTPROTO */ void -rxvt_print_error (const char *fmt,...) +rxvt_vlog (const char *fmt, va_list arg_ptr) +{ + char msg[1024]; + + vsnprintf (msg, sizeof msg, fmt, arg_ptr); + + if (GET_R && GET_R->log_hook) + (*GET_R->log_hook) (msg); + else + write (STDOUT_FILENO, msg, strlen (msg)); +} + +/* EXTPROTO */ +void +rxvt_log (const char *fmt,...) { va_list arg_ptr; va_start (arg_ptr, fmt); - fprintf (stderr, APL_NAME ": "); - vfprintf (stderr, fmt, arg_ptr); - fprintf (stderr, "\n"); + rxvt_vlog (fmt, arg_ptr); va_end (arg_ptr); } /* + * Print an error message + */ +/* EXTPROTO */ +void +rxvt_warn (const char *fmt,...) +{ + va_list arg_ptr; + + rxvt_log ("%s: ", RESNAME); + + va_start (arg_ptr, fmt); + rxvt_vlog (fmt, arg_ptr); + va_end (arg_ptr); +} + +/* EXTPROTO */ +void +rxvt_fatal (const char *fmt,...) +{ + va_list arg_ptr; + + rxvt_log ("%s: ", RESNAME); + + va_start (arg_ptr, fmt); + rxvt_vlog (fmt, arg_ptr); + va_end (arg_ptr); + + rxvt_exit_failure (); +} + +class rxvt_failure_exception rxvt_failure_exception; + +/* EXTPROTO */ +void +rxvt_exit_failure () +{ + throw (rxvt_failure_exception); +} + +/* * check that the first characters of S1 match S2 * * No Match