common/log.c: minor whitespace change
[nvi.git] / motif_l / m_util.c
blob5c6ed2d5032ffe36ddaa9e51e802ee5b76c57438
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_util.c,v 8.12 2003/11/05 17:10:00 skimo Exp $ (Berkeley) $Date: 2003/11/05 17:10:00 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
21 #include <X11/Shell.h>
22 #include <X11/Xatom.h>
24 #include <bitstring.h>
25 #include <stdio.h>
26 #include <string.h>
28 #undef LOCK_SUCCESS
29 #include "../common/common.h"
30 #include "../ipc/ip.h"
31 #include "m_motif.h"
34 /* Widget hierarchy routines
36 * void XutShowWidgetTree( FILE *fp, Widget root, int indent )
37 * prints the widgets and sub-widgets beneath the named root widget
39 #ifdef DEBUG
40 #if defined(__STDC__)
41 void XutShowWidgetTree( FILE *fp, Widget root, int indent )
42 #else
43 void XutShowWidgetTree( fp, root, indent )
44 FILE *fp;
45 Widget root;
46 int indent;
47 #endif
49 #if ! defined(DECWINDOWS)
50 WidgetList l, l2;
51 int i, count = 0;
53 /* print where we are right now */
54 fprintf( fp,
55 "%*.*swidget => 0x%x name => \"%s\"\n\r",
56 indent,
57 indent,
58 "",
59 root,
60 XtName(root) );
62 /* get the correct widget values */
63 XtVaGetValues( root, XtNchildren, &l, 0 );
64 XtVaGetValues( root, XtNchildren, &l2, 0 );
65 XtVaGetValues( root, XtNnumChildren, &count, 0 );
67 /* print the sub-widgets */
68 for ( i=0; i<count; i++ ) {
69 XutShowWidgetTree( fp, l[i], indent+4 );
72 /* tidy up if this thing contained children */
73 if ( count > 0 ) {
74 /* we may or may not have to free the children */
75 if ( l != l2 ) {
76 XtFree( (char *) l );
77 XtFree( (char *) l2 );
80 #endif
82 #endif
85 /* Utilities for converting X resources...
87 * __XutConvertResources( Widget, String root, XutResource *, int count )
88 * The resource block is loaded with converted values
89 * If the X resource does not exist, no change is made to the value
90 * 'root' should be the application name.
92 * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int));
94 void __XutConvertResources(Widget wid, String root, XutResource *resources, int count)
96 int i;
97 XrmValue from, to;
98 String kind;
99 Boolean success = True;
101 /* for each resource */
102 for (i=0; i<count; i++) {
104 /* is there a value in the database? */
105 from.addr = XGetDefault( XtDisplay(wid), root, resources[i].name );
106 if ( from.addr == NULL || *from.addr == '\0' )
107 continue;
109 /* load common parameters */
110 from.size = strlen( from.addr );
111 to.addr = resources[i].value;
113 /* load type-specific parameters */
114 switch ( resources[i].kind ) {
115 case XutRKinteger:
116 to.size = sizeof(int);
117 kind = XtRInt;
118 break;
120 case XutRKboolean:
121 /* String to Boolean */
122 to.size = sizeof(Boolean);
123 kind = XtRBoolean;
124 break;
126 case XutRKfont:
127 /* String to Font structure */
128 to.size = sizeof(XFontStruct *);
129 kind = XtRFontStruct;
130 break;
132 case XutRKpixelBackup:
133 /* String to Pixel backup algorithm */
134 if ( success ) continue;
135 /* FALL through */
137 case XutRKpixel:
138 /* String to Pixel */
139 to.size = sizeof(Pixel);
140 kind = XtRPixel;
141 break;
143 case XutRKcursor:
144 /* String to Cursor */
145 to.size = sizeof(int);
146 kind = XtRCursor;
147 break;
149 default:
150 return;
153 /* call the converter */
154 success = XtConvertAndStore( wid, XtRString, &from, kind, &to );