TMprint.c revision fdf6a26f
1444c061aSmrg/***********************************************************
2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
27444c061aSmrgPermission to use, copy, modify, and distribute this software and its
28444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
30444c061aSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
33444c061aSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg
45444c061aSmrg/*
46444c061aSmrg
47444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
48444c061aSmrg
49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
51444c061aSmrgthe above copyright notice appear in all copies and that both that
52444c061aSmrgcopyright notice and this permission notice appear in supporting
53444c061aSmrgdocumentation.
54444c061aSmrg
55444c061aSmrgThe above copyright notice and this permission notice shall be included in
56444c061aSmrgall copies or substantial portions of the Software.
57444c061aSmrg
58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64444c061aSmrg
65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
67444c061aSmrgin this Software without prior written authorization from The Open Group.
68444c061aSmrg
69444c061aSmrg*/
70444c061aSmrg
71444c061aSmrg#ifdef HAVE_CONFIG_H
72444c061aSmrg#include <config.h>
73444c061aSmrg#endif
74444c061aSmrg#include "IntrinsicI.h"
75444c061aSmrg#include <stdio.h>
76444c061aSmrg
77a3bd7f05Smrgtypedef struct _TMStringBufRec {
78a3bd7f05Smrg    _XtString start;
79a3bd7f05Smrg    _XtString current;
80a3bd7f05Smrg    Cardinal max;
81a3bd7f05Smrg} TMStringBufRec, *TMStringBuf;
82444c061aSmrg
83444c061aSmrg#define STR_THRESHOLD 25
84444c061aSmrg#define STR_INCAMOUNT 100
85a3bd7f05Smrg
86444c061aSmrg#define CHECK_STR_OVERFLOW(sb) \
87a3bd7f05Smrg    if (sb->current - sb->start > (int)sb->max - STR_THRESHOLD)           \
88a3bd7f05Smrg    {                                                                     \
89a3bd7f05Smrg        _XtString old = sb->start;                                        \
90a3bd7f05Smrg        sb->start = XtRealloc(old, (Cardinal)(sb->max += STR_INCAMOUNT)); \
91a3bd7f05Smrg        sb->current = sb->current - old + sb->start;                      \
92a3bd7f05Smrg    }
93444c061aSmrg
94a3bd7f05Smrg#define ExpandForChars(sb, nchars )                                       \
950568f49bSmrg    if ((unsigned)(sb->current - sb->start) > (sb->max - STR_THRESHOLD - (Cardinal) nchars)) { \
96a3bd7f05Smrg        _XtString old = sb->start;                                        \
97a3bd7f05Smrg        sb->start = XtRealloc(old,                                        \
98a3bd7f05Smrg            (Cardinal)(sb->max = (Cardinal)(sb->max + STR_INCAMOUNT + (Cardinal) nchars)));     \
99a3bd7f05Smrg        sb->current = sb->current - old + sb->start;                      \
100444c061aSmrg    }
101444c061aSmrg
102444c061aSmrg#define ExpandToFit(sb, more) \
103a3bd7f05Smrg{                                                               \
104a3bd7f05Smrg        size_t l = strlen(more);                                \
105a3bd7f05Smrg        ExpandForChars(sb, l);                                  \
106444c061aSmrg      }
107444c061aSmrg
108a3bd7f05Smrgstatic void
109a3bd7f05SmrgPrintModifiers(TMStringBuf sb, unsigned long mask, unsigned long mod)
110444c061aSmrg{
111444c061aSmrg    Boolean notfirst = False;
112a3bd7f05Smrg
113444c061aSmrg    CHECK_STR_OVERFLOW(sb);
114444c061aSmrg
115444c061aSmrg    if (mask == ~0UL && mod == 0) {
116a3bd7f05Smrg        *sb->current++ = '!';
117a3bd7f05Smrg        *sb->current = '\0';
118a3bd7f05Smrg        return;
119444c061aSmrg    }
120444c061aSmrg
121a3bd7f05Smrg#define PRINTMOD(modmask,modstring)                     \
122a3bd7f05Smrg    if (mask & modmask) {                               \
123a3bd7f05Smrg        if (! (mod & modmask)) {                        \
124a3bd7f05Smrg            *sb->current++ = '~';                       \
125a3bd7f05Smrg            notfirst = True;                            \
126a3bd7f05Smrg        }                                               \
127a3bd7f05Smrg        else if (notfirst)                              \
128a3bd7f05Smrg            *sb->current++ = ' ';                       \
129a3bd7f05Smrg        else notfirst = True;                           \
130a3bd7f05Smrg        strcpy(sb->current, modstring);                 \
131a3bd7f05Smrg        sb->current += strlen(sb->current);             \
132444c061aSmrg    }
133444c061aSmrg
134444c061aSmrg    PRINTMOD(ShiftMask, "Shift");
135a3bd7f05Smrg    PRINTMOD(ControlMask, "Ctrl");      /* name is not CtrlMask... */
136444c061aSmrg    PRINTMOD(LockMask, "Lock");
137444c061aSmrg    PRINTMOD(Mod1Mask, "Mod1");
138444c061aSmrg    CHECK_STR_OVERFLOW(sb);
139444c061aSmrg    PRINTMOD(Mod2Mask, "Mod2");
140444c061aSmrg    PRINTMOD(Mod3Mask, "Mod3");
141444c061aSmrg    PRINTMOD(Mod4Mask, "Mod4");
142444c061aSmrg    PRINTMOD(Mod5Mask, "Mod5");
143444c061aSmrg    CHECK_STR_OVERFLOW(sb);
144444c061aSmrg    PRINTMOD(Button1Mask, "Button1");
145444c061aSmrg    PRINTMOD(Button2Mask, "Button2");
146444c061aSmrg    PRINTMOD(Button3Mask, "Button3");
147444c061aSmrg    CHECK_STR_OVERFLOW(sb);
148444c061aSmrg    PRINTMOD(Button4Mask, "Button4");
149444c061aSmrg    PRINTMOD(Button5Mask, "Button5");
1500568f49bSmrg    (void) notfirst;
151444c061aSmrg
152444c061aSmrg#undef PRINTMOD
153444c061aSmrg}
154444c061aSmrg
155a3bd7f05Smrgstatic void
156a3bd7f05SmrgPrintEventType(TMStringBuf sb, unsigned long event)
157444c061aSmrg{
158444c061aSmrg    CHECK_STR_OVERFLOW(sb);
159444c061aSmrg    switch (event) {
160444c061aSmrg#define PRINTEVENT(event, name) case event: (void) strcpy(sb->current, name); break;
161a3bd7f05Smrg        PRINTEVENT(KeyPress, "<KeyPress>")
162a3bd7f05Smrg            PRINTEVENT(KeyRelease, "<KeyRelease>")
163a3bd7f05Smrg            PRINTEVENT(ButtonPress, "<ButtonPress>")
164a3bd7f05Smrg            PRINTEVENT(ButtonRelease, "<ButtonRelease>")
165a3bd7f05Smrg            PRINTEVENT(MotionNotify, "<MotionNotify>")
166a3bd7f05Smrg            PRINTEVENT(EnterNotify, "<EnterNotify>")
167a3bd7f05Smrg            PRINTEVENT(LeaveNotify, "<LeaveNotify>")
168a3bd7f05Smrg            PRINTEVENT(FocusIn, "<FocusIn>")
169a3bd7f05Smrg            PRINTEVENT(FocusOut, "<FocusOut>")
170a3bd7f05Smrg            PRINTEVENT(KeymapNotify, "<KeymapNotify>")
171a3bd7f05Smrg            PRINTEVENT(Expose, "<Expose>")
172a3bd7f05Smrg            PRINTEVENT(GraphicsExpose, "<GraphicsExpose>")
173a3bd7f05Smrg            PRINTEVENT(NoExpose, "<NoExpose>")
174a3bd7f05Smrg            PRINTEVENT(VisibilityNotify, "<VisibilityNotify>")
175a3bd7f05Smrg            PRINTEVENT(CreateNotify, "<CreateNotify>")
176a3bd7f05Smrg            PRINTEVENT(DestroyNotify, "<DestroyNotify>")
177a3bd7f05Smrg            PRINTEVENT(UnmapNotify, "<UnmapNotify>")
178a3bd7f05Smrg            PRINTEVENT(MapNotify, "<MapNotify>")
179a3bd7f05Smrg            PRINTEVENT(MapRequest, "<MapRequest>")
180a3bd7f05Smrg            PRINTEVENT(ReparentNotify, "<ReparentNotify>")
181a3bd7f05Smrg            PRINTEVENT(ConfigureNotify, "<ConfigureNotify>")
182a3bd7f05Smrg            PRINTEVENT(ConfigureRequest, "<ConfigureRequest>")
183a3bd7f05Smrg            PRINTEVENT(GravityNotify, "<GravityNotify>")
184a3bd7f05Smrg            PRINTEVENT(ResizeRequest, "<ResizeRequest>")
185a3bd7f05Smrg            PRINTEVENT(CirculateNotify, "<CirculateNotify>")
186a3bd7f05Smrg            PRINTEVENT(CirculateRequest, "<CirculateRequest>")
187a3bd7f05Smrg            PRINTEVENT(PropertyNotify, "<PropertyNotify>")
188a3bd7f05Smrg            PRINTEVENT(SelectionClear, "<SelectionClear>")
189a3bd7f05Smrg            PRINTEVENT(SelectionRequest, "<SelectionRequest>")
190a3bd7f05Smrg            PRINTEVENT(SelectionNotify, "<SelectionNotify>")
191a3bd7f05Smrg            PRINTEVENT(ColormapNotify, "<ColormapNotify>")
192a3bd7f05Smrg            PRINTEVENT(ClientMessage, "<ClientMessage>")
193a3bd7f05Smrg    case _XtEventTimerEventType:
194a3bd7f05Smrg        (void) strcpy(sb->current, "<EventTimer>");
195a3bd7f05Smrg        break;
196a3bd7f05Smrg    default:
197a3bd7f05Smrg        (void) sprintf(sb->current, "<0x%x>", (int) event);
198444c061aSmrg#undef PRINTEVENT
199444c061aSmrg    }
200444c061aSmrg    sb->current += strlen(sb->current);
201444c061aSmrg}
202444c061aSmrg
203a3bd7f05Smrgstatic void
204a3bd7f05SmrgPrintCode(TMStringBuf sb, unsigned long mask, unsigned long code)
205444c061aSmrg{
206444c061aSmrg    CHECK_STR_OVERFLOW(sb);
207444c061aSmrg    if (mask != 0) {
208a3bd7f05Smrg        if (mask != ~0UL)
209a3bd7f05Smrg            (void) sprintf(sb->current, "0x%lx:0x%lx", mask, code);
210a3bd7f05Smrg        else
211a3bd7f05Smrg            (void) sprintf(sb->current, /*"0x%lx" */ "%u", (unsigned) code);
212a3bd7f05Smrg        sb->current += strlen(sb->current);
213444c061aSmrg    }
214444c061aSmrg}
215444c061aSmrg
216a3bd7f05Smrgstatic void
217a3bd7f05SmrgPrintKeysym(TMStringBuf sb, KeySym keysym)
218444c061aSmrg{
219444c061aSmrg    String keysymName;
220444c061aSmrg
221a3bd7f05Smrg    if (keysym == 0)
222a3bd7f05Smrg        return;
223444c061aSmrg
224444c061aSmrg    CHECK_STR_OVERFLOW(sb);
225444c061aSmrg    keysymName = XKeysymToString(keysym);
226444c061aSmrg    if (keysymName == NULL)
227a3bd7f05Smrg        PrintCode(sb, ~0UL, (unsigned long) keysym);
228444c061aSmrg    else {
229a3bd7f05Smrg        ExpandToFit(sb, keysymName);
230a3bd7f05Smrg        strcpy(sb->current, keysymName);
231a3bd7f05Smrg        sb->current += strlen(sb->current);
232444c061aSmrg    }
233444c061aSmrg}
234444c061aSmrg
235a3bd7f05Smrgstatic void
236a3bd7f05SmrgPrintAtom(TMStringBuf sb, Display *dpy, Atom atom)
237444c061aSmrg{
2380568f49bSmrg    _XtString atomName;
239444c061aSmrg
240a3bd7f05Smrg    if (atom == 0)
241a3bd7f05Smrg        return;
242444c061aSmrg
243444c061aSmrg    atomName = (dpy ? XGetAtomName(dpy, atom) : NULL);
244444c061aSmrg
245a3bd7f05Smrg    if (!atomName)
246a3bd7f05Smrg        PrintCode(sb, ~0UL, (unsigned long) atom);
247444c061aSmrg    else {
248a3bd7f05Smrg        ExpandToFit(sb, atomName);
249a3bd7f05Smrg        strcpy(sb->current, atomName);
250a3bd7f05Smrg        sb->current += strlen(sb->current);
251a3bd7f05Smrg        XFree(atomName);
252444c061aSmrg    }
253444c061aSmrg}
254444c061aSmrg
255a3bd7f05Smrgstatic void
256a3bd7f05SmrgPrintLateModifiers(TMStringBuf sb, LateBindingsPtr lateModifiers)
257444c061aSmrg{
258444c061aSmrg    for (; lateModifiers->keysym; lateModifiers++) {
259a3bd7f05Smrg        CHECK_STR_OVERFLOW(sb);
260a3bd7f05Smrg        if (lateModifiers->knot) {
261a3bd7f05Smrg            *sb->current++ = '~';
262a3bd7f05Smrg        }
263a3bd7f05Smrg        else {
264a3bd7f05Smrg            *sb->current++ = ' ';
265a3bd7f05Smrg        }
266a3bd7f05Smrg        strcpy(sb->current, XKeysymToString(lateModifiers->keysym));
267a3bd7f05Smrg        sb->current += strlen(sb->current);
268a3bd7f05Smrg        if (lateModifiers->pair) {
269a3bd7f05Smrg            *(sb->current -= 2) = '\0'; /* strip "_L" */
270a3bd7f05Smrg            lateModifiers++;    /* skip _R keysym */
271a3bd7f05Smrg        }
272444c061aSmrg    }
273444c061aSmrg}
274444c061aSmrg
275a3bd7f05Smrgstatic void
276a3bd7f05SmrgPrintEvent(TMStringBuf sb,
277a3bd7f05Smrg           register TMTypeMatch typeMatch,
278a3bd7f05Smrg           register TMModifierMatch modMatch,
279a3bd7f05Smrg           Display *dpy)
280444c061aSmrg{
281a3bd7f05Smrg    if (modMatch->standard)
282a3bd7f05Smrg        *sb->current++ = ':';
283444c061aSmrg
284444c061aSmrg    PrintModifiers(sb, modMatch->modifierMask, modMatch->modifiers);
285444c061aSmrg    if (modMatch->lateModifiers != NULL)
286a3bd7f05Smrg        PrintLateModifiers(sb, modMatch->lateModifiers);
287444c061aSmrg    PrintEventType(sb, typeMatch->eventType);
288444c061aSmrg    switch (typeMatch->eventType) {
289a3bd7f05Smrg    case KeyPress:
290a3bd7f05Smrg    case KeyRelease:
291a3bd7f05Smrg        PrintKeysym(sb, (KeySym) typeMatch->eventCode);
292a3bd7f05Smrg        break;
293a3bd7f05Smrg
294a3bd7f05Smrg    case PropertyNotify:
295a3bd7f05Smrg    case SelectionClear:
296a3bd7f05Smrg    case SelectionRequest:
297a3bd7f05Smrg    case SelectionNotify:
298a3bd7f05Smrg    case ClientMessage:
299a3bd7f05Smrg        PrintAtom(sb, dpy, (Atom) typeMatch->eventCode);
300a3bd7f05Smrg        break;
301a3bd7f05Smrg
302a3bd7f05Smrg    default:
303a3bd7f05Smrg        PrintCode(sb, typeMatch->eventCodeMask, typeMatch->eventCode);
304444c061aSmrg    }
305444c061aSmrg}
306444c061aSmrg
307a3bd7f05Smrgstatic void
308a3bd7f05SmrgPrintParams(TMStringBuf sb, String *params, Cardinal num_params)
309444c061aSmrg{
310444c061aSmrg    register Cardinal i;
311a3bd7f05Smrg
312a3bd7f05Smrg    for (i = 0; i < num_params; i++) {
313a3bd7f05Smrg        ExpandToFit(sb, params[i]);
314a3bd7f05Smrg        if (i != 0) {
315a3bd7f05Smrg            *sb->current++ = ',';
316a3bd7f05Smrg            *sb->current++ = ' ';
317a3bd7f05Smrg        }
318a3bd7f05Smrg        *sb->current++ = '"';
319a3bd7f05Smrg        strcpy(sb->current, params[i]);
320a3bd7f05Smrg        sb->current += strlen(sb->current);
321a3bd7f05Smrg        *sb->current++ = '"';
322444c061aSmrg    }
323444c061aSmrg    *sb->current = '\0';
324444c061aSmrg}
325444c061aSmrg
326a3bd7f05Smrgstatic void
327a3bd7f05SmrgPrintActions(TMStringBuf sb,
328a3bd7f05Smrg             register ActionPtr actions,
329a3bd7f05Smrg             XrmQuark *quarkTbl,
330a3bd7f05Smrg             Widget accelWidget)
331444c061aSmrg{
332444c061aSmrg    while (actions != NULL) {
333a3bd7f05Smrg        String proc;
334a3bd7f05Smrg
335a3bd7f05Smrg        *sb->current++ = ' ';
336a3bd7f05Smrg
337a3bd7f05Smrg        if (accelWidget) {
338a3bd7f05Smrg            /* accelerator */
339a3bd7f05Smrg            String name = XtName(accelWidget);
340a3bd7f05Smrg            int nameLen = (int) strlen(name);
341a3bd7f05Smrg
342a3bd7f05Smrg            ExpandForChars(sb, nameLen);
343a3bd7f05Smrg            XtMemmove(sb->current, name, nameLen);
344a3bd7f05Smrg            sb->current += nameLen;
345a3bd7f05Smrg            *sb->current++ = '`';
346a3bd7f05Smrg        }
347a3bd7f05Smrg        proc = XrmQuarkToString(quarkTbl[actions->idx]);
348a3bd7f05Smrg        ExpandToFit(sb, proc);
349a3bd7f05Smrg        strcpy(sb->current, proc);
350a3bd7f05Smrg        sb->current += strlen(proc);
351a3bd7f05Smrg        *sb->current++ = '(';
352a3bd7f05Smrg        PrintParams(sb, actions->params, actions->num_params);
353a3bd7f05Smrg        *sb->current++ = ')';
354a3bd7f05Smrg        actions = actions->next;
355444c061aSmrg    }
356444c061aSmrg    *sb->current = '\0';
357444c061aSmrg}
358444c061aSmrg
359a3bd7f05Smrgstatic Boolean
360a3bd7f05SmrgLookAheadForCycleOrMulticlick(register StatePtr state,
361a3bd7f05Smrg                              StatePtr *state_return, /* state to print, usually startState */
362a3bd7f05Smrg                              int *countP,
363a3bd7f05Smrg                              StatePtr *nextLevelP)
364444c061aSmrg{
365444c061aSmrg    int repeatCount = 0;
366a3bd7f05Smrg    StatePtr startState = state;
367a3bd7f05Smrg    Boolean isCycle = startState->isCycleEnd;
368444c061aSmrg    TMTypeMatch sTypeMatch;
369444c061aSmrg    TMModifierMatch sModMatch;
370444c061aSmrg
371444c061aSmrg    LOCK_PROCESS;
372444c061aSmrg    sTypeMatch = TMGetTypeMatch(startState->typeIndex);
373444c061aSmrg    sModMatch = TMGetModifierMatch(startState->modIndex);
374444c061aSmrg
375444c061aSmrg    *state_return = startState;
376444c061aSmrg
377444c061aSmrg    for (state = state->nextLevel; state != NULL; state = state->nextLevel) {
378a3bd7f05Smrg        TMTypeMatch typeMatch = TMGetTypeMatch(state->typeIndex);
379a3bd7f05Smrg        TMModifierMatch modMatch = TMGetModifierMatch(state->modIndex);
380a3bd7f05Smrg
381a3bd7f05Smrg        /* try to pick up the correct state with actions, to be printed */
382a3bd7f05Smrg        /* This is to accommodate <ButtonUp>(2+), for example */
383a3bd7f05Smrg        if (state->isCycleStart)
384a3bd7f05Smrg            *state_return = state;
385a3bd7f05Smrg
386a3bd7f05Smrg        if (state->isCycleEnd) {
387a3bd7f05Smrg            *countP = repeatCount;
388a3bd7f05Smrg            UNLOCK_PROCESS;
389a3bd7f05Smrg            return True;
390a3bd7f05Smrg        }
391a3bd7f05Smrg        if ((startState->typeIndex == state->typeIndex) &&
392a3bd7f05Smrg            (startState->modIndex == state->modIndex)) {
393a3bd7f05Smrg            repeatCount++;
394a3bd7f05Smrg            *nextLevelP = state;
395a3bd7f05Smrg        }
396a3bd7f05Smrg        else if (typeMatch->eventType == _XtEventTimerEventType)
397a3bd7f05Smrg            continue;
398a3bd7f05Smrg        else {                  /* not same event as starting event and not timer */
399a3bd7f05Smrg
400a3bd7f05Smrg            unsigned int type = (unsigned) sTypeMatch->eventType;
401a3bd7f05Smrg            unsigned int t = (unsigned) typeMatch->eventType;
402a3bd7f05Smrg
403a3bd7f05Smrg            if ((type == ButtonPress && t != ButtonRelease)
404a3bd7f05Smrg                || (type == ButtonRelease && t != ButtonPress)
405a3bd7f05Smrg                || (type == KeyPress && t != KeyRelease)
406a3bd7f05Smrg                || (type == KeyRelease && t != KeyPress)
407a3bd7f05Smrg                || typeMatch->eventCode != sTypeMatch->eventCode
408a3bd7f05Smrg                || modMatch->modifiers != sModMatch->modifiers
409a3bd7f05Smrg                || modMatch->modifierMask != sModMatch->modifierMask
410a3bd7f05Smrg                || modMatch->lateModifiers != sModMatch->lateModifiers
411a3bd7f05Smrg                || typeMatch->eventCodeMask != sTypeMatch->eventCodeMask
412a3bd7f05Smrg                || typeMatch->matchEvent != sTypeMatch->matchEvent
413a3bd7f05Smrg                || modMatch->standard != sModMatch->standard)
414a3bd7f05Smrg                /* not inverse of starting event, either */
415a3bd7f05Smrg                break;
416a3bd7f05Smrg        }
417444c061aSmrg    }
418444c061aSmrg    *countP = repeatCount;
419444c061aSmrg    UNLOCK_PROCESS;
420444c061aSmrg    return isCycle;
421444c061aSmrg}
422444c061aSmrg
423a3bd7f05Smrgstatic void
424a3bd7f05SmrgPrintComplexState(TMStringBuf sb,
425a3bd7f05Smrg                  Boolean includeRHS,
426a3bd7f05Smrg                  StatePtr state,
427a3bd7f05Smrg                  TMStateTree stateTree,
428a3bd7f05Smrg                  Widget accelWidget,
429a3bd7f05Smrg                  Display *dpy)
430444c061aSmrg{
431a3bd7f05Smrg    int clickCount = 0;
432a3bd7f05Smrg    Boolean cycle;
433a3bd7f05Smrg    StatePtr nextLevel = NULL;
434a3bd7f05Smrg    StatePtr triggerState = NULL;
435444c061aSmrg
436444c061aSmrg    /* print the current state */
437a3bd7f05Smrg    if (!state)
438a3bd7f05Smrg        return;
439444c061aSmrg    LOCK_PROCESS;
440444c061aSmrg    cycle = LookAheadForCycleOrMulticlick(state, &triggerState, &clickCount,
441a3bd7f05Smrg                                          &nextLevel);
442444c061aSmrg
443444c061aSmrg    PrintEvent(sb, TMGetTypeMatch(triggerState->typeIndex),
444a3bd7f05Smrg               TMGetModifierMatch(triggerState->modIndex), dpy);
445444c061aSmrg
446444c061aSmrg    if (cycle || clickCount) {
447a3bd7f05Smrg        if (clickCount)
448a3bd7f05Smrg            sprintf(sb->current, "(%d%s)", clickCount + 1, cycle ? "+" : "");
449a3bd7f05Smrg        else
450a3bd7f05Smrg            (void) strncpy(sb->current, "(+)", 4);
451a3bd7f05Smrg        sb->current += strlen(sb->current);
452a3bd7f05Smrg        if (!state->actions && nextLevel)
453a3bd7f05Smrg            state = nextLevel;
454a3bd7f05Smrg        while (!state->actions && !state->isCycleEnd)
455a3bd7f05Smrg            state = state->nextLevel;   /* should be trigger state */
456444c061aSmrg    }
457444c061aSmrg
458444c061aSmrg    if (state->actions) {
459a3bd7f05Smrg        if (includeRHS) {
460a3bd7f05Smrg            CHECK_STR_OVERFLOW(sb);
461a3bd7f05Smrg            *sb->current++ = ':';
462a3bd7f05Smrg            PrintActions(sb,
463a3bd7f05Smrg                         state->actions,
464a3bd7f05Smrg                         ((TMSimpleStateTree) stateTree)->quarkTbl,
465a3bd7f05Smrg                         accelWidget);
466a3bd7f05Smrg            *sb->current++ = '\n';
467a3bd7f05Smrg        }
468444c061aSmrg    }
469444c061aSmrg    else {
470a3bd7f05Smrg        if (state->nextLevel && !cycle && !clickCount)
471a3bd7f05Smrg            *sb->current++ = ',';
472a3bd7f05Smrg        else {
473a3bd7f05Smrg            /* no actions are attached to this production */
474a3bd7f05Smrg            *sb->current++ = ':';
475a3bd7f05Smrg            *sb->current++ = '\n';
476a3bd7f05Smrg        }
477444c061aSmrg    }
478444c061aSmrg    *sb->current = '\0';
479444c061aSmrg
480444c061aSmrg    /* print succeeding states */
481444c061aSmrg    if (state->nextLevel && !cycle && !clickCount)
482a3bd7f05Smrg        PrintComplexState(sb, includeRHS, state->nextLevel,
483a3bd7f05Smrg                          stateTree, accelWidget, dpy);
484444c061aSmrg    UNLOCK_PROCESS;
485444c061aSmrg}
486444c061aSmrg
487a3bd7f05Smrgtypedef struct {
488a3bd7f05Smrg    TMShortCard tIndex;
489a3bd7f05Smrg    TMShortCard bIndex;
490a3bd7f05Smrg} PrintRec, *Print;
491a3bd7f05Smrg
492a3bd7f05Smrgstatic int
493a3bd7f05SmrgFindNextMatch(PrintRec *printData,
494a3bd7f05Smrg              TMShortCard numPrints,
495a3bd7f05Smrg              XtTranslations xlations,
496a3bd7f05Smrg              TMBranchHead branchHead,
497a3bd7f05Smrg              StatePtr nextLevel,
498a3bd7f05Smrg              TMShortCard startIndex)
499444c061aSmrg{
500a3bd7f05Smrg    TMShortCard i;
501a3bd7f05Smrg    StatePtr currState, candState;
502a3bd7f05Smrg    Boolean noMatch = True;
503444c061aSmrg
504444c061aSmrg    for (i = startIndex; noMatch && i < numPrints; i++) {
505a3bd7f05Smrg        TMBranchHead prBranchHead;
506a3bd7f05Smrg        TMComplexStateTree stateTree;
507a3bd7f05Smrg
508a3bd7f05Smrg        stateTree = (TMComplexStateTree)
509a3bd7f05Smrg            xlations->stateTreeTbl[printData[i].tIndex];
510a3bd7f05Smrg        prBranchHead = &(stateTree->branchHeadTbl[printData[i].bIndex]);
511a3bd7f05Smrg
512a3bd7f05Smrg        if ((prBranchHead->typeIndex == branchHead->typeIndex) &&
513a3bd7f05Smrg            (prBranchHead->modIndex == branchHead->modIndex)) {
514a3bd7f05Smrg            if (prBranchHead->isSimple) {
515a3bd7f05Smrg                if (!nextLevel)
516a3bd7f05Smrg                    return i;
517a3bd7f05Smrg            }
518a3bd7f05Smrg            else {
519a3bd7f05Smrg                currState = TMComplexBranchHead(stateTree, prBranchHead);
520a3bd7f05Smrg                currState = currState->nextLevel;
521a3bd7f05Smrg                candState = nextLevel;
522a3bd7f05Smrg                for (;
523a3bd7f05Smrg                     ((currState && !currState->isCycleEnd) &&
524a3bd7f05Smrg                      (candState && !candState->isCycleEnd));
525a3bd7f05Smrg                     currState = currState->nextLevel,
526a3bd7f05Smrg                     candState = candState->nextLevel) {
527a3bd7f05Smrg                    if ((currState->typeIndex != candState->typeIndex) ||
528a3bd7f05Smrg                        (currState->modIndex != candState->modIndex))
529a3bd7f05Smrg                        break;
530a3bd7f05Smrg                }
531a3bd7f05Smrg                if (candState == currState) {
532a3bd7f05Smrg                    return i;
533a3bd7f05Smrg                }
534a3bd7f05Smrg            }
535a3bd7f05Smrg        }
536444c061aSmrg    }
537444c061aSmrg    return TM_NO_MATCH;
538444c061aSmrg}
539444c061aSmrg
540a3bd7f05Smrgstatic void
541a3bd7f05SmrgProcessLaterMatches(PrintRec *printData,
542a3bd7f05Smrg                    XtTranslations xlations,
543a3bd7f05Smrg                    TMShortCard tIndex,
544a3bd7f05Smrg                    int bIndex,
545a3bd7f05Smrg                    TMShortCard *numPrintsRtn)
546444c061aSmrg{
547a3bd7f05Smrg    TMComplexStateTree stateTree;
548a3bd7f05Smrg    int i, j;
549a3bd7f05Smrg    TMBranchHead branchHead, matchBranch = NULL;
550a3bd7f05Smrg
551a3bd7f05Smrg    for (i = tIndex; i < (int) xlations->numStateTrees; i++) {
552a3bd7f05Smrg        stateTree = (TMComplexStateTree) xlations->stateTreeTbl[i];
553a3bd7f05Smrg        if (i == tIndex) {
554a3bd7f05Smrg            matchBranch = &stateTree->branchHeadTbl[bIndex];
555a3bd7f05Smrg            j = bIndex + 1;
556a3bd7f05Smrg        }
557a3bd7f05Smrg        else
558a3bd7f05Smrg            j = 0;
559a3bd7f05Smrg        for (branchHead = &stateTree->branchHeadTbl[j];
560a3bd7f05Smrg             j < (int) stateTree->numBranchHeads; j++, branchHead++) {
561a3bd7f05Smrg            if ((branchHead->typeIndex == matchBranch->typeIndex) &&
562a3bd7f05Smrg                (branchHead->modIndex == matchBranch->modIndex)) {
563a3bd7f05Smrg                StatePtr state;
564a3bd7f05Smrg
565a3bd7f05Smrg                if (!branchHead->isSimple)
566a3bd7f05Smrg                    state = TMComplexBranchHead(stateTree, branchHead);
567a3bd7f05Smrg                else
568a3bd7f05Smrg                    state = NULL;
569a3bd7f05Smrg                if ((!branchHead->isSimple || branchHead->hasActions) &&
570a3bd7f05Smrg                    (FindNextMatch(printData,
571a3bd7f05Smrg                                   *numPrintsRtn,
572a3bd7f05Smrg                                   xlations,
573a3bd7f05Smrg                                   branchHead,
574a3bd7f05Smrg                                   (state ? state->nextLevel : NULL),
575a3bd7f05Smrg                                   0) == TM_NO_MATCH)) {
576a3bd7f05Smrg                    printData[*numPrintsRtn].tIndex = (TMShortCard) i;
577a3bd7f05Smrg                    printData[*numPrintsRtn].bIndex = (TMShortCard) j;
578a3bd7f05Smrg                    (*numPrintsRtn)++;
579a3bd7f05Smrg                }
580a3bd7f05Smrg            }
581a3bd7f05Smrg        }
582444c061aSmrg    }
583444c061aSmrg}
584444c061aSmrg
585a3bd7f05Smrgstatic void
586a3bd7f05SmrgProcessStateTree(PrintRec *printData,
587a3bd7f05Smrg                 XtTranslations xlations,
588a3bd7f05Smrg                 TMShortCard tIndex,
589a3bd7f05Smrg                 TMShortCard *numPrintsRtn)
590444c061aSmrg{
591444c061aSmrg    TMComplexStateTree stateTree;
592a3bd7f05Smrg    int i;
593a3bd7f05Smrg    TMBranchHead branchHead;
594444c061aSmrg
595a3bd7f05Smrg    stateTree = (TMComplexStateTree) xlations->stateTreeTbl[tIndex];
596444c061aSmrg
597444c061aSmrg    for (i = 0, branchHead = stateTree->branchHeadTbl;
598a3bd7f05Smrg         i < (int) stateTree->numBranchHeads; i++, branchHead++) {
599a3bd7f05Smrg        StatePtr state;
600a3bd7f05Smrg
601a3bd7f05Smrg        if (!branchHead->isSimple)
602a3bd7f05Smrg            state = TMComplexBranchHead(stateTree, branchHead);
603a3bd7f05Smrg        else
604a3bd7f05Smrg            state = NULL;
605a3bd7f05Smrg        if (FindNextMatch(printData, *numPrintsRtn, xlations, branchHead,
606a3bd7f05Smrg                          (state ? state->nextLevel : NULL), 0)
607a3bd7f05Smrg            == TM_NO_MATCH) {
608a3bd7f05Smrg            if (!branchHead->isSimple || branchHead->hasActions) {
609a3bd7f05Smrg                printData[*numPrintsRtn].tIndex = tIndex;
610a3bd7f05Smrg                printData[*numPrintsRtn].bIndex = (TMShortCard) i;
611a3bd7f05Smrg                (*numPrintsRtn)++;
612a3bd7f05Smrg            }
613a3bd7f05Smrg            LOCK_PROCESS;
614a3bd7f05Smrg            if (_XtGlobalTM.newMatchSemantics == False)
615a3bd7f05Smrg                ProcessLaterMatches(printData,
616a3bd7f05Smrg                                    xlations, tIndex, i, numPrintsRtn);
617a3bd7f05Smrg            UNLOCK_PROCESS;
618a3bd7f05Smrg        }
619444c061aSmrg    }
620444c061aSmrg}
621444c061aSmrg
622a3bd7f05Smrgstatic void
623a3bd7f05SmrgPrintState(TMStringBuf sb,
624a3bd7f05Smrg           TMStateTree tree,
625a3bd7f05Smrg           TMBranchHead branchHead,
626a3bd7f05Smrg           Boolean includeRHS,
627a3bd7f05Smrg           Widget accelWidget,
628a3bd7f05Smrg           Display *dpy)
629444c061aSmrg{
630a3bd7f05Smrg    TMComplexStateTree stateTree = (TMComplexStateTree) tree;
631a3bd7f05Smrg
632444c061aSmrg    LOCK_PROCESS;
633444c061aSmrg    if (branchHead->isSimple) {
634a3bd7f05Smrg        PrintEvent(sb,
635a3bd7f05Smrg                   TMGetTypeMatch(branchHead->typeIndex),
636a3bd7f05Smrg                   TMGetModifierMatch(branchHead->modIndex), dpy);
637a3bd7f05Smrg        if (includeRHS) {
638a3bd7f05Smrg            ActionRec actRec;
639a3bd7f05Smrg
640a3bd7f05Smrg            CHECK_STR_OVERFLOW(sb);
641a3bd7f05Smrg            *sb->current++ = ':';
642a3bd7f05Smrg            actRec.idx = TMBranchMore(branchHead);
643a3bd7f05Smrg            actRec.num_params = 0;
644a3bd7f05Smrg            actRec.params = NULL;
645a3bd7f05Smrg            actRec.next = NULL;
646a3bd7f05Smrg            PrintActions(sb, &actRec, stateTree->quarkTbl, accelWidget);
647a3bd7f05Smrg            *sb->current++ = '\n';
648a3bd7f05Smrg        }
649a3bd7f05Smrg        else
650a3bd7f05Smrg            *sb->current++ = ',';
651444c061aSmrg#ifdef TRACE_TM
652a3bd7f05Smrg        if (!branchHead->hasActions)
653a3bd7f05Smrg            printf(" !! no actions !! ");
654444c061aSmrg#endif
655444c061aSmrg    }
656a3bd7f05Smrg    else {                      /* it's a complex branchHead */
657a3bd7f05Smrg        StatePtr state = TMComplexBranchHead(stateTree, branchHead);
658a3bd7f05Smrg
659a3bd7f05Smrg        PrintComplexState(sb,
660a3bd7f05Smrg                          includeRHS,
661a3bd7f05Smrg                          state, tree, accelWidget, (Display *) NULL);
662a3bd7f05Smrg    }
663444c061aSmrg    *sb->current = '\0';
664444c061aSmrg    UNLOCK_PROCESS;
665444c061aSmrg}
666444c061aSmrg
667a3bd7f05Smrg_XtString
668a3bd7f05Smrg_XtPrintXlations(Widget w,
669a3bd7f05Smrg                 XtTranslations xlations,
670a3bd7f05Smrg                 Widget accelWidget,
671a3bd7f05Smrg                 _XtBoolean includeRHS)
672444c061aSmrg{
673a3bd7f05Smrg    register Cardinal i;
674a3bd7f05Smrg
675444c061aSmrg#define STACKPRINTSIZE 250
676a3bd7f05Smrg    PrintRec stackPrints[STACKPRINTSIZE];
677a3bd7f05Smrg    PrintRec *prints;
678a3bd7f05Smrg    TMStringBufRec sbRec, *sb = &sbRec;
679a3bd7f05Smrg    TMShortCard numPrints, maxPrints;
680a3bd7f05Smrg
681444c061aSmrg#ifdef TRACE_TM
682a3bd7f05Smrg    TMBindData bindData = (TMBindData) w->core.tm.proc_table;
683a3bd7f05Smrg    Boolean hasAccel = (accelWidget ? True : False);
684a3bd7f05Smrg#endif                          /* TRACE_TM */
685a3bd7f05Smrg    if (xlations == NULL)
686a3bd7f05Smrg        return NULL;
687444c061aSmrg
688a3bd7f05Smrg    sb->current = sb->start = __XtMalloc((Cardinal) 1000);
689444c061aSmrg    sb->max = 1000;
690444c061aSmrg    maxPrints = 0;
691444c061aSmrg    for (i = 0; i < xlations->numStateTrees; i++)
692a3bd7f05Smrg        maxPrints = (TMShortCard) (maxPrints +
693a3bd7f05Smrg                                   ((TMSimpleStateTree)
694a3bd7f05Smrg                                    (xlations->stateTreeTbl[i]))->
695a3bd7f05Smrg                                   numBranchHeads);
696444c061aSmrg    prints = (PrintRec *)
697a3bd7f05Smrg        XtStackAlloc(maxPrints * sizeof(PrintRec), stackPrints);
698444c061aSmrg
699444c061aSmrg    numPrints = 0;
700444c061aSmrg    for (i = 0; i < xlations->numStateTrees; i++)
701a3bd7f05Smrg        ProcessStateTree(prints, xlations, (TMShortCard) i, &numPrints);
702444c061aSmrg
703444c061aSmrg    for (i = 0; i < numPrints; i++) {
704a3bd7f05Smrg        TMSimpleStateTree stateTree = (TMSimpleStateTree)
705a3bd7f05Smrg            xlations->stateTreeTbl[prints[i].tIndex];
706a3bd7f05Smrg        TMBranchHead branchHead = &stateTree->branchHeadTbl[prints[i].bIndex];
707a3bd7f05Smrg
708444c061aSmrg#ifdef TRACE_TM
709a3bd7f05Smrg        TMComplexBindProcs complexBindProcs;
710a3bd7f05Smrg
711a3bd7f05Smrg        if (hasAccel == False) {
712a3bd7f05Smrg            accelWidget = NULL;
713a3bd7f05Smrg            if (bindData->simple.isComplex) {
714a3bd7f05Smrg                complexBindProcs = TMGetComplexBindEntry(bindData, 0);
715a3bd7f05Smrg                accelWidget = complexBindProcs[prints[i].tIndex].widget;
716a3bd7f05Smrg            }
717a3bd7f05Smrg        }
718a3bd7f05Smrg#endif                          /* TRACE_TM */
719a3bd7f05Smrg        PrintState(sb, (TMStateTree) stateTree, branchHead,
720a3bd7f05Smrg                   (Boolean) includeRHS, accelWidget, XtDisplay(w));
721444c061aSmrg    }
722a3bd7f05Smrg    XtStackFree((XtPointer) prints, (XtPointer) stackPrints);
723444c061aSmrg    return (sb->start);
724444c061aSmrg}
725444c061aSmrg
726444c061aSmrg#ifndef NO_MIT_HACKS
727a3bd7f05Smrgvoid
728a3bd7f05Smrg_XtDisplayTranslations(Widget widget,
729a3bd7f05Smrg                       XEvent *event _X_UNUSED,
730a3bd7f05Smrg                       String *params _X_UNUSED,
731a3bd7f05Smrg                       Cardinal *num_params _X_UNUSED)
732444c061aSmrg{
733a3bd7f05Smrg    _XtString xString;
734444c061aSmrg
735a3bd7f05Smrg    xString = _XtPrintXlations(widget,
736a3bd7f05Smrg                               widget->core.tm.translations, NULL, True);
7372265a131Smrg    if (xString) {
738a3bd7f05Smrg        printf("%s\n", xString);
739a3bd7f05Smrg        XtFree(xString);
7402265a131Smrg    }
741444c061aSmrg}
742444c061aSmrg
743a3bd7f05Smrgvoid
744a3bd7f05Smrg_XtDisplayAccelerators(Widget widget,
745a3bd7f05Smrg                       XEvent *event _X_UNUSED,
746a3bd7f05Smrg                       String *params _X_UNUSED,
747a3bd7f05Smrg                       Cardinal *num_params _X_UNUSED)
748444c061aSmrg{
749a3bd7f05Smrg    _XtString xString;
750444c061aSmrg
751a3bd7f05Smrg    xString = _XtPrintXlations(widget, widget->core.accelerators, NULL, True);
7522265a131Smrg    if (xString) {
753a3bd7f05Smrg        printf("%s\n", xString);
754a3bd7f05Smrg        XtFree(xString);
7552265a131Smrg    }
756444c061aSmrg}
757444c061aSmrg
758a3bd7f05Smrgvoid
759a3bd7f05Smrg_XtDisplayInstalledAccelerators(Widget widget,
760a3bd7f05Smrg                                XEvent *event,
761a3bd7f05Smrg                                String *params _X_UNUSED,
762a3bd7f05Smrg                                Cardinal *num_params _X_UNUSED)
763444c061aSmrg{
764444c061aSmrg    Widget eventWidget
765a3bd7f05Smrg        = XtWindowToWidget(event->xany.display, event->xany.window);
766a3bd7f05Smrg    register Cardinal i;
767a3bd7f05Smrg    TMStringBufRec sbRec, *sb = &sbRec;
768a3bd7f05Smrg    XtTranslations xlations;
769a3bd7f05Smrg
770444c061aSmrg#define STACKPRINTSIZE 250
771a3bd7f05Smrg    PrintRec stackPrints[STACKPRINTSIZE];
772a3bd7f05Smrg    PrintRec *prints;
773a3bd7f05Smrg    TMShortCard numPrints, maxPrints;
774a3bd7f05Smrg    TMBindData bindData;
775a3bd7f05Smrg    TMComplexBindProcs complexBindProcs;
776444c061aSmrg
777a3bd7f05Smrg    if ((eventWidget == NULL) || (eventWidget->core.tm.translations == NULL))
778a3bd7f05Smrg        return;
779249c3046Smrg
780249c3046Smrg    xlations = eventWidget->core.tm.translations;
781249c3046Smrg    bindData = (TMBindData) eventWidget->core.tm.proc_table;
782249c3046Smrg    if (bindData->simple.isComplex == False)
783a3bd7f05Smrg        return;
784444c061aSmrg
785a3bd7f05Smrg    sb->current = sb->start = __XtMalloc((Cardinal) 1000);
786444c061aSmrg    sb->start[0] = '\0';
787444c061aSmrg    sb->max = 1000;
788444c061aSmrg    maxPrints = 0;
789444c061aSmrg    for (i = 0; i < xlations->numStateTrees; i++)
790a3bd7f05Smrg        maxPrints = (TMShortCard) (maxPrints +
791a3bd7f05Smrg                                   ((TMSimpleStateTree) xlations->
792a3bd7f05Smrg                                    stateTreeTbl[i])->numBranchHeads);
793444c061aSmrg    prints = (PrintRec *)
794a3bd7f05Smrg        XtStackAlloc(maxPrints * sizeof(PrintRec), stackPrints);
795444c061aSmrg
796444c061aSmrg    numPrints = 0;
797444c061aSmrg
798444c061aSmrg    complexBindProcs = TMGetComplexBindEntry(bindData, 0);
799a3bd7f05Smrg    for (i = 0; i < xlations->numStateTrees; i++, complexBindProcs++) {
800a3bd7f05Smrg        if (complexBindProcs->widget) {
801a3bd7f05Smrg            ProcessStateTree(prints, xlations, (TMShortCard) i, &numPrints);
802a3bd7f05Smrg        }
803444c061aSmrg    }
804444c061aSmrg    for (i = 0; i < numPrints; i++) {
805a3bd7f05Smrg        TMSimpleStateTree stateTree = (TMSimpleStateTree)
806a3bd7f05Smrg            xlations->stateTreeTbl[prints[i].tIndex];
807a3bd7f05Smrg        TMBranchHead branchHead = &stateTree->branchHeadTbl[prints[i].bIndex];
808444c061aSmrg
809a3bd7f05Smrg        complexBindProcs = TMGetComplexBindEntry(bindData, 0);
810444c061aSmrg
811a3bd7f05Smrg        PrintState(sb, (TMStateTree) stateTree, branchHead, True,
812a3bd7f05Smrg                   complexBindProcs[prints[i].tIndex].widget,
813a3bd7f05Smrg                   XtDisplay(widget));
814444c061aSmrg    }
815a3bd7f05Smrg    XtStackFree((XtPointer) prints, (XtPointer) stackPrints);
816444c061aSmrg    printf("%s\n", sb->start);
817444c061aSmrg    XtFree(sb->start);
818444c061aSmrg}
819a3bd7f05Smrg#endif                          /*NO_MIT_HACKS */
820444c061aSmrg
821a3bd7f05SmrgString
822a3bd7f05Smrg_XtPrintActions(register ActionRec *actions, XrmQuark *quarkTbl)
823444c061aSmrg{
824a3bd7f05Smrg    TMStringBufRec sbRec, *sb = &sbRec;
825444c061aSmrg
826444c061aSmrg    sb->max = 1000;
827a3bd7f05Smrg    sb->current = sb->start = __XtMalloc((Cardinal) 1000);
828a3bd7f05Smrg    PrintActions(sb, actions, quarkTbl, (Widget) NULL);
829444c061aSmrg    return sb->start;
830444c061aSmrg}
831444c061aSmrg
832a3bd7f05SmrgString
833a3bd7f05Smrg_XtPrintState(TMStateTree stateTree, TMBranchHead branchHead)
834444c061aSmrg{
835a3bd7f05Smrg    TMStringBufRec sbRec, *sb = &sbRec;
836444c061aSmrg
837a3bd7f05Smrg    sb->current = sb->start = __XtMalloc((Cardinal) 1000);
838444c061aSmrg    sb->max = 1000;
839444c061aSmrg    PrintState(sb, stateTree, branchHead,
840a3bd7f05Smrg               True, (Widget) NULL, (Display *) NULL);
841444c061aSmrg    return sb->start;
842444c061aSmrg}
843444c061aSmrg
844a3bd7f05SmrgString
845a3bd7f05Smrg_XtPrintEventSeq(register EventSeqPtr eventSeq, Display *dpy)
846444c061aSmrg{
847a3bd7f05Smrg    TMStringBufRec sbRec, *sb = &sbRec;
848a3bd7f05Smrg
849444c061aSmrg#define MAXSEQS 100
850a3bd7f05Smrg    EventSeqPtr eventSeqs[MAXSEQS];
851a3bd7f05Smrg    TMShortCard i, j;
852a3bd7f05Smrg    Boolean cycle = False;
853444c061aSmrg
854a3bd7f05Smrg    sb->current = sb->start = __XtMalloc((Cardinal) 1000);
855444c061aSmrg    sb->max = 1000;
856444c061aSmrg    for (i = 0;
857a3bd7f05Smrg         i < MAXSEQS && eventSeq != NULL && !cycle;
858a3bd7f05Smrg         eventSeq = eventSeq->next, i++) {
859a3bd7f05Smrg        eventSeqs[i] = eventSeq;
860a3bd7f05Smrg        for (j = 0; j < i && !cycle; j++)
861a3bd7f05Smrg            if (eventSeqs[j] == eventSeq)
862a3bd7f05Smrg                cycle = True;
863a3bd7f05Smrg    }
864444c061aSmrg    LOCK_PROCESS;
865444c061aSmrg    for (j = 0; j < i; j++) {
866a3bd7f05Smrg        TMTypeMatch typeMatch;
867a3bd7f05Smrg        TMModifierMatch modMatch;
868a3bd7f05Smrg
869a3bd7f05Smrg        typeMatch = TMGetTypeMatch(_XtGetTypeIndex(&eventSeqs[j]->event));
870a3bd7f05Smrg        modMatch =
871a3bd7f05Smrg            TMGetModifierMatch(_XtGetModifierIndex(&eventSeqs[j]->event));
872a3bd7f05Smrg        PrintEvent(sb, typeMatch, modMatch, dpy);
873fdf6a26fSmrg        *sb->current++ = ',';
874444c061aSmrg    }
875444c061aSmrg    UNLOCK_PROCESS;
876444c061aSmrg    return sb->start;
877444c061aSmrg}
878