annotate src/xmu.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* This file contains compatibility routines for systems without Xmu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 * You would be better served by installing Xmu on your machine or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 * yelling at your vendor to ship it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 /* XEmacs changes: rindex -> strrchr */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 #ifndef HAVE_XMU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 * Copyright 1989 Massachusetts Institute of Technology
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 * Permission to use, copy, modify, and distribute this software and its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 * documentation for any purpose and without fee is hereby granted, provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 * that the above copyright notice appear in all copies and that both that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * copyright notice and this permission notice appear in supporting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 * documentation, and that the name of M.I.T. not be used in advertising
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 * or publicity pertaining to distribution of the software without specific,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * written prior permission. M.I.T. makes no representations about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 * suitability of this software for any purpose. It is provided "as is"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * without express or implied warranty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <X11/cursorfont.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <X11/Xos.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <X11/Xlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include <X11/Xutil.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include <X11/Intrinsic.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 /* for XmuCopyISOLatin1Lowered */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #define XK_LATIN1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include <X11/keysymdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #undef XK_LATIN1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #if (XtSpecificationRelease >= 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * Don't know why, but this works with X11R5, not X11R4.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * Anyway, _XExtension is defined in Xlib.h in X11R4, so we do not need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * Xlibint in that case...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <X11/Xlibint.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include <X11/Xproto.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include <ctype.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 int XmuCursorNameToIndex (const char *name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 static const struct _CursorName {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 const char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 unsigned int shape;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 } cursor_names[] = {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 {"x_cursor", XC_X_cursor},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 {"arrow", XC_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 {"based_arrow_down", XC_based_arrow_down},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 {"based_arrow_up", XC_based_arrow_up},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 {"boat", XC_boat},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {"bogosity", XC_bogosity},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 {"bottom_left_corner", XC_bottom_left_corner},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 {"bottom_right_corner", XC_bottom_right_corner},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 {"bottom_side", XC_bottom_side},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 {"bottom_tee", XC_bottom_tee},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 {"box_spiral", XC_box_spiral},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {"center_ptr", XC_center_ptr},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 {"circle", XC_circle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 {"clock", XC_clock},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {"coffee_mug", XC_coffee_mug},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 {"cross", XC_cross},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {"cross_reverse", XC_cross_reverse},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 {"crosshair", XC_crosshair},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {"diamond_cross", XC_diamond_cross},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 {"dot", XC_dot},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 {"dotbox", XC_dotbox},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 {"double_arrow", XC_double_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 {"draft_large", XC_draft_large},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {"draft_small", XC_draft_small},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 {"draped_box", XC_draped_box},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 {"exchange", XC_exchange},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 {"fleur", XC_fleur},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {"gobbler", XC_gobbler},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {"gumby", XC_gumby},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 {"hand1", XC_hand1},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 {"hand2", XC_hand2},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 {"heart", XC_heart},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 {"icon", XC_icon},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 {"iron_cross", XC_iron_cross},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 {"left_ptr", XC_left_ptr},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 {"left_side", XC_left_side},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 {"left_tee", XC_left_tee},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 {"leftbutton", XC_leftbutton},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 {"ll_angle", XC_ll_angle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 {"lr_angle", XC_lr_angle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {"man", XC_man},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {"middlebutton", XC_middlebutton},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 {"mouse", XC_mouse},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 {"pencil", XC_pencil},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 {"pirate", XC_pirate},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 {"plus", XC_plus},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 {"question_arrow", XC_question_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 {"right_ptr", XC_right_ptr},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {"right_side", XC_right_side},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 {"right_tee", XC_right_tee},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 {"rightbutton", XC_rightbutton},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 {"rtl_logo", XC_rtl_logo},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 {"sailboat", XC_sailboat},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {"sb_down_arrow", XC_sb_down_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {"sb_h_double_arrow", XC_sb_h_double_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {"sb_left_arrow", XC_sb_left_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 {"sb_right_arrow", XC_sb_right_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 {"sb_up_arrow", XC_sb_up_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 {"sb_v_double_arrow", XC_sb_v_double_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 {"shuttle", XC_shuttle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 {"sizing", XC_sizing},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 {"spider", XC_spider},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 {"spraycan", XC_spraycan},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 {"star", XC_star},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 {"target", XC_target},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 {"tcross", XC_tcross},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {"top_left_arrow", XC_top_left_arrow},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 {"top_left_corner", XC_top_left_corner},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {"top_right_corner", XC_top_right_corner},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 {"top_side", XC_top_side},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 {"top_tee", XC_top_tee},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {"trek", XC_trek},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {"ul_angle", XC_ul_angle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 {"umbrella", XC_umbrella},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {"ur_angle", XC_ur_angle},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {"watch", XC_watch},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 {"xterm", XC_xterm},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 const struct _CursorName *table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 char tmp[40];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 if (strlen (name) >= sizeof tmp) return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 for (i=0; i<strlen(name); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (isupper((unsigned char) name[i]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 tmp[i] = tolower((unsigned char) name[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 tmp[i] = name[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 tmp[i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 for (i=0, table=cursor_names; i < XtNumber(cursor_names); i++, table++ ) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (strcmp(tmp, table->name) == 0) return table->shape;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 * Based on an optimized version provided by Jim Becker, Auguest 5, 1988.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 #define MAX_SIZE 255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 /* shared data for the image read/parse logic */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 static short hexTable[256]; /* conversion value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 static Bool initialized = False; /* easier to fill in at run time */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 * Table index for the hex values. Initialized once, first time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 * Used for translation value or delimiter significance lookup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 static void initHexTable()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 * We build the table at run time for several reasons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 * 1. portable to non-ASCII machines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 * 2. still reentrant since we set the init flag after setting table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 * 3. easier to extend.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 * 4. less prone to bugs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 hexTable['0'] = 0; hexTable['1'] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 hexTable['2'] = 2; hexTable['3'] = 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 hexTable['4'] = 4; hexTable['5'] = 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 hexTable['6'] = 6; hexTable['7'] = 7;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 hexTable['8'] = 8; hexTable['9'] = 9;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 hexTable['A'] = 10; hexTable['B'] = 11;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 hexTable['C'] = 12; hexTable['D'] = 13;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 hexTable['E'] = 14; hexTable['F'] = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 hexTable['a'] = 10; hexTable['b'] = 11;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 hexTable['c'] = 12; hexTable['d'] = 13;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 hexTable['e'] = 14; hexTable['f'] = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 /* delimiters of significance are flagged w/ negative value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 hexTable[' '] = -1; hexTable[','] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 hexTable['}'] = -1; hexTable['\n'] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 hexTable['\t'] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 initialized = True;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 * read next hex value in the input stream, return -1 if EOF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 static int NextInt (fstream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 FILE *fstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 int ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 int value = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 int gotone = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 int done = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 /* loop, accumulate hex value until find delimiter */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /* skip any initial delimiters found in read stream */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 while (!done) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ch = getc(fstream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (ch == EOF) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 value = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 done++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 /* trim high bits, check type and accumulate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ch &= 0xff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 if (isascii(ch) && isxdigit(ch)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 value = (value << 4) + hexTable[ch];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 gotone++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 } else if ((hexTable[ch]) < 0 && gotone)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 done++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 return value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 * The data returned by the following routine is always in left-most byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 * first and left-most bit first. If it doesn't return BitmapSuccess then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 * its arguments won't have been touched. This routine should look as much
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 * like the Xlib routine XReadBitmapfile as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 int XmuReadBitmapData (fstream, width, height, datap, x_hot, y_hot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 FILE *fstream; /* handle on file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 unsigned int *width, *height; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 unsigned char **datap; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 int *x_hot, *y_hot; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 unsigned char *data = NULL; /* working variable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 char line[MAX_SIZE]; /* input line from file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 int size; /* number of bytes of data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 char name_and_type[MAX_SIZE]; /* an input line */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 char *type; /* for parsing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 int value; /* from an input line */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 int version10p; /* boolean, old format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 int padding; /* to handle alignment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 int bytes_per_line; /* per scanline of data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 unsigned int ww = 0; /* width */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 unsigned int hh = 0; /* height */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 int hx = -1; /* x hotspot */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 int hy = -1; /* y hotspot */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 #ifndef Xmalloc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 #define Xmalloc(size) malloc(size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /* first time initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 if (initialized == False) initHexTable();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 /* error cleanup and return macro */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 #define RETURN(code) { if (data) free (data); return code; }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 while (fgets(line, MAX_SIZE, fstream)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 if (strlen(line) == MAX_SIZE-1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 RETURN (BitmapFileInvalid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 if (!(type = strrchr(name_and_type, '_')))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 type = name_and_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 type++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (!strcmp("width", type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ww = (unsigned int) value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 if (!strcmp("height", type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 hh = (unsigned int) value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 if (!strcmp("hot", type)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 if (type-- == name_and_type || type-- == name_and_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 if (!strcmp("x_hot", type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 hx = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 if (!strcmp("y_hot", type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 hy = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 if (sscanf(line, "static short %s = {", name_and_type) == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 version10p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 version10p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 version10p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 if (!(type = strrchr(name_and_type, '_')))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 type = name_and_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 type++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 if (strcmp("bits[]", type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 if (!ww || !hh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 RETURN (BitmapFileInvalid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 if ((ww % 16) && ((ww % 16) < 9) && version10p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 padding = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 padding = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 bytes_per_line = (ww+7)/8 + padding;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 size = bytes_per_line * hh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 data = (unsigned char *) Xmalloc ((unsigned int) size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 if (!data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 RETURN (BitmapNoMemory);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 if (version10p) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 unsigned char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 int bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 if ((value = NextInt(fstream)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 RETURN (BitmapFileInvalid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 *(ptr++) = value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 if (!padding || ((bytes+2) % bytes_per_line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 *(ptr++) = value >> 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 unsigned char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 int bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 if ((value = NextInt(fstream)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 RETURN (BitmapFileInvalid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 *ptr=value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 } /* end while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if (data == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 RETURN (BitmapFileInvalid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 *datap = data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 data = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 *width = ww;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 *height = hh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (x_hot) *x_hot = hx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (y_hot) *y_hot = hy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 RETURN (BitmapSuccess);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #if NeedFunctionPrototypes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 int XmuReadBitmapDataFromFile (const char *filename, unsigned int *width,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 unsigned int *height, unsigned char **datap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 int *x_hot, int *y_hot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 int XmuReadBitmapDataFromFile (filename, width, height, datap, x_hot, y_hot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 char *filename;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 unsigned int *width, *height; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 unsigned char **datap; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 int *x_hot, *y_hot; /* RETURNED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 FILE *fstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 if ((fstream = fopen (filename, "r")) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 return BitmapOpenFailed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 status = XmuReadBitmapData (fstream, width, height, datap, x_hot, y_hot);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 fclose (fstream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 return status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 * message. Returns 1 if the caller should consider exitting else 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 int XmuPrintDefaultErrorMessage (dpy, event, fp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 Display *dpy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 XErrorEvent *event;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 FILE *fp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 char buffer[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 char mesg[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 char number[32];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 char *mtype = "XlibMessage";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 _XExtension *ext = (_XExtension *)NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (void) fprintf(fp, "%s: %s\n ", mesg, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (void) fprintf(fp, mesg, event->request_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 if (event->request_code < 128) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 sprintf(number, "%d", event->request_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 /* XXX this is non-portable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 for (ext = dpy->ext_procs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ext && (ext->codes.major_opcode != event->request_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ext = ext->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 if (ext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 strcpy(buffer, ext->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 buffer[0] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (void) fprintf(fp, " (%s)", buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 #if (XtSpecificationRelease >= 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (event->request_code >= 128) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (void) fprintf(fp, mesg, event->minor_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 if (ext) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (void) fprintf(fp, " (%s)", buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 if (event->error_code >= 128) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 /* let extensions try to print the values */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 /* XXX this is non-portable code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 for (ext = dpy->ext_procs; ext; ext = ext->next) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 if (ext->error_values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (*ext->error_values)(dpy, event, fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 /* the rest is a fallback, providing a simple default */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 /* kludge, try to find the extension that caused it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 buffer[0] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 for (ext = dpy->ext_procs; ext; ext = ext->next) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 if (ext->error_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (*ext->error_string)(dpy, event->error_code, &ext->codes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 buffer, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 if (buffer[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 if (buffer[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 sprintf(buffer, "%s.%d", ext->name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 event->error_code - ext->codes.first_error);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 strcpy(buffer, "Value");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 if (*mesg) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (void) fprintf(fp, mesg, event->resourceid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 } else if ((event->error_code == BadWindow) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (event->error_code == BadPixmap) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (event->error_code == BadCursor) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (event->error_code == BadFont) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (event->error_code == BadDrawable) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (event->error_code == BadColor) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (event->error_code == BadGC) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (event->error_code == BadIDChoice) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (event->error_code == BadValue) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (event->error_code == BadAtom)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 if (event->error_code == BadValue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 else if (event->error_code == BadAtom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (void) fprintf(fp, mesg, event->resourceid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 #elif (XtSpecificationRelease == 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (void) fprintf(fp, mesg, event->minor_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (ext) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (void) fprintf(fp, " (%s)", buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (void) fprintf(fp, mesg, event->resourceid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ERROR! Unsupported release of X11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (void) fprintf(fp, mesg, event->serial);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 fputs("\n ", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 mesg, BUFSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (void) fprintf(fp, mesg, NextRequest(dpy)-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 fputs("\n", fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (event->error_code == BadImplementation) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 * XmuSimpleErrorHandler - ignore errors for XQueryTree, XGetWindowAttributes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 * and XGetGeometry; print a message for everything else. In all case, do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 * not exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 int XmuSimpleErrorHandler (dpy, errorp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 Display *dpy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 XErrorEvent *errorp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 switch (errorp->request_code) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 case X_QueryTree:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 case X_GetWindowAttributes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 if (errorp->error_code == BadWindow) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 case X_GetGeometry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 if (errorp->error_code == BadDrawable) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 /* got a "real" X error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 return XmuPrintDefaultErrorMessage (dpy, errorp, stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 void XmuCopyISOLatin1Lowered(char *dst, char *src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 unsigned char *dest, *source;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 for (dest = (unsigned char *)dst, source = (unsigned char *)src;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 *source;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 source++, dest++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 if ((*source >= XK_A) && (*source <= XK_Z))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 *dest = *source + (XK_a - XK_A);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 *dest = *source + (XK_agrave - XK_Agrave);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 *dest = *source + (XK_oslash - XK_Ooblique);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 *dest = *source;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 *dest = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 #endif /* !HAVE_XMU */