align CHAR_T string in log
[nvi.git] / motif_l / m_util.c
blob9810f5045a4fb8f476ef02ac3607d26e4c7e804b
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.10 1996/12/18 10:25:38 bostic Exp $ (Berkeley) $Date: 1996/12/18 10:25:38 $";
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 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "m_motif.h"
33 /* Widget hierarchy routines
35 * void XutShowWidgetTree( FILE *fp, Widget root, int indent )
36 * prints the widgets and sub-widgets beneath the named root widget
38 #ifdef DEBUG
39 #if defined(__STDC__)
40 void XutShowWidgetTree( FILE *fp, Widget root, int indent )
41 #else
42 void XutShowWidgetTree( fp, root, indent )
43 FILE *fp;
44 Widget root;
45 int indent;
46 #endif
48 #if ! defined(DECWINDOWS)
49 WidgetList l, l2;
50 int i, count = 0;
52 /* print where we are right now */
53 fprintf( fp,
54 "%*.*swidget => 0x%x name => \"%s\"\n\r",
55 indent,
56 indent,
57 "",
58 root,
59 XtName(root) );
61 /* get the correct widget values */
62 XtVaGetValues( root, XtNchildren, &l, 0 );
63 XtVaGetValues( root, XtNchildren, &l2, 0 );
64 XtVaGetValues( root, XtNnumChildren, &count, 0 );
66 /* print the sub-widgets */
67 for ( i=0; i<count; i++ ) {
68 XutShowWidgetTree( fp, l[i], indent+4 );
71 /* tidy up if this thing contained children */
72 if ( count > 0 ) {
73 /* we may or may not have to free the children */
74 if ( l != l2 ) {
75 XtFree( (char *) l );
76 XtFree( (char *) l2 );
79 #endif
81 #endif
84 /* Utilities for converting X resources...
86 * __XutConvertResources( Widget, String root, XutResource *, int count )
87 * The resource block is loaded with converted values
88 * If the X resource does not exist, no change is made to the value
89 * 'root' should be the application name.
91 * PUBLIC: void __XutConvertResources __P((Widget, String, XutResource *, int));
93 void __XutConvertResources(wid, root, resources, count)
94 Widget wid;
95 String root;
96 XutResource *resources;
97 int count;
99 int i;
100 XrmValue from, to;
101 String kind;
102 Boolean success = True;
104 /* for each resource */
105 for (i=0; i<count; i++) {
107 /* is there a value in the database? */
108 from.addr = XGetDefault( XtDisplay(wid), root, resources[i].name );
109 if ( from.addr == NULL || *from.addr == '\0' )
110 continue;
112 /* load common parameters */
113 from.size = strlen( from.addr );
114 to.addr = resources[i].value;
116 /* load type-specific parameters */
117 switch ( resources[i].kind ) {
118 case XutRKinteger:
119 to.size = sizeof(int);
120 kind = XtRInt;
121 break;
123 case XutRKboolean:
124 /* String to Boolean */
125 to.size = sizeof(Boolean);
126 kind = XtRBoolean;
127 break;
129 case XutRKfont:
130 /* String to Font structure */
131 to.size = sizeof(XFontStruct *);
132 kind = XtRFontStruct;
133 break;
135 case XutRKpixelBackup:
136 /* String to Pixel backup algorithm */
137 if ( success ) continue;
138 /* FALL through */
140 case XutRKpixel:
141 /* String to Pixel */
142 to.size = sizeof(Pixel);
143 kind = XtRPixel;
144 break;
146 case XutRKcursor:
147 /* String to Cursor */
148 to.size = sizeof(int);
149 kind = XtRCursor;
150 break;
152 default:
153 return;
156 /* call the converter */
157 success = XtConvertAndStore( wid, XtRString, &from, kind, &to );