ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/misc.C
(Generate patch)

Comparing rxvt-unicode/src/misc.C (file contents):
Revision 1.9 by pcg, Wed Mar 3 04:07:52 2004 UTC vs.
Revision 1.13 by pcg, Thu Apr 8 20:31:45 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: misc.c 2 * File: misc.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston 6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28#include "misc.intpro" /* PROTOS for internal routines */ 28#include "misc.intpro" /* PROTOS for internal routines */
29 29
30/* EXTPROTO */ 30/* EXTPROTO */
31char * 31char *
32rxvt_wcstombs (const wchar_t *str, int len)
33{
34 mbstate mbs;
35 char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1);
36
37 char *dst = r;
38 while (len--)
39 {
40 int l = wcrtomb (dst, *str++, mbs);
41 if (l < 0)
42 *dst++ = '?';
43 else
44 dst += l;
45 }
46
47 *dst++ = 0;
48
49 return r;
50}
51
52/* EXTPROTO */
53char *
32rxvt_strdup (const char *str) 54rxvt_strdup (const char *str)
33{ 55{
34 return str ? strdup (str) : 0; 56 return str ? strdup (str) : 0;
35} 57}
36 58
46/* 68/*
47 * Print an error message 69 * Print an error message
48 */ 70 */
49/* EXTPROTO */ 71/* EXTPROTO */
50void 72void
73rxvt_vlog (const char *fmt, va_list arg_ptr)
74{
75 char msg[1024];
76
77 vsnprintf (msg, sizeof msg, fmt, arg_ptr);
78
79 if (GET_R && GET_R->log_hook)
80 (*GET_R->log_hook) (msg);
81 else
82 write (STDOUT_FILENO, msg, strlen (msg));
83}
84
85/* EXTPROTO */
86void
51rxvt_print_error (const char *fmt,...) 87rxvt_log (const char *fmt,...)
52{ 88{
53 va_list arg_ptr; 89 va_list arg_ptr;
54 90
55 va_start (arg_ptr, fmt); 91 va_start (arg_ptr, fmt);
56 fprintf (stderr, RESNAME ": "); 92 rxvt_vlog (fmt, arg_ptr);
57 vfprintf (stderr, fmt, arg_ptr);
58 fprintf (stderr, "\n");
59 va_end (arg_ptr); 93 va_end (arg_ptr);
94}
95
96/*
97 * Print an error message
98 */
99/* EXTPROTO */
100void
101rxvt_warn (const char *fmt,...)
102{
103 va_list arg_ptr;
104
105 rxvt_log ("%s: ", RESNAME);
106
107 va_start (arg_ptr, fmt);
108 rxvt_vlog (fmt, arg_ptr);
109 va_end (arg_ptr);
110}
111
112/* EXTPROTO */
113void
114rxvt_fatal (const char *fmt,...)
115{
116 va_list arg_ptr;
117
118 rxvt_log ("%s: ", RESNAME);
119
120 va_start (arg_ptr, fmt);
121 rxvt_vlog (fmt, arg_ptr);
122 va_end (arg_ptr);
123
124 rxvt_exit_failure ();
125}
126
127class rxvt_failure_exception rxvt_failure_exception;
128
129/* EXTPROTO */
130void
131rxvt_exit_failure ()
132{
133 throw (rxvt_failure_exception);
60} 134}
61 135
62/* 136/*
63 * check that the first characters of S1 match S2 137 * check that the first characters of S1 match S2
64 * 138 *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines