2
* $XConsortium: listres.c,v 1.32 94/04/17 20:43:22 dave Exp $
5
Copyright (c) 1989 X Consortium
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of the X Consortium shall not be
25
used in advertising or otherwise to promote the sale, use or other dealings
26
in this Software without prior written authorization from the X Consortium.
28
* Author: Jim Fulton, MIT X Consortium
30
/* $XFree86: xc/programs/listres/listres.c,v 1.4 2001/04/01 14:00:18 tsi Exp $ */
35
#include <X11/StringDefs.h>
36
#include <X11/IntrinsicP.h>
37
#include <X11/Xaw/Cardinals.h>
39
#include <X11/Xmu/CharSet.h>
40
#include <X11/Xmu/WidgetNode.h>
41
#include <X11/Xaw/AllWidgets.h>
43
#define widget_list XawWidgetArray /* or motif or ol or ... */
44
#define nwidgets XawWidgetCount
47
static XrmOptionDescRec Options[] = {
48
{ "-top", "*topObject", XrmoptionSepArg, (caddr_t) NULL },
49
{ "-format", "*resourceFormat", XrmoptionSepArg, (caddr_t) NULL },
50
{ "-tree", "*showTree", XrmoptionNoArg, (caddr_t) "on" },
51
{ "-nosuper", "*showSuper", XrmoptionNoArg, (caddr_t) "off" },
52
{ "-variable", "*showVariable", XrmoptionNoArg, (caddr_t) "on" },
58
Boolean show_variable;
59
Boolean show_superclass;
66
#define Offset(field) XtOffsetOf(OptionsRec, field)
68
static XtResource Resources[] = {
69
{ "showTree", "ShowTree", XtRBoolean, sizeof(Boolean),
70
Offset(show_tree), XtRImmediate, (XtPointer) FALSE },
71
{ "showSuper", "ShowSuper", XtRBoolean, sizeof(Boolean),
72
Offset(show_superclass), XtRImmediate, (caddr_t) TRUE },
73
{ "showVariable", "ShowVariable", XtRBoolean, sizeof(Boolean),
74
Offset(show_variable), XtRImmediate, (caddr_t) FALSE },
75
{ "topObject", "TopObject", XtRString, sizeof(char *),
76
Offset(top_object), XtRString, (caddr_t) "core" },
77
{ "resourceFormat", "ResourceFormat", XtRString, sizeof(char *),
78
Offset(format), XtRString, (caddr_t) " %-16s %20s %-20s %s" },
83
const char *ProgramName;
88
fprintf(stderr, "usage: %s [-options...]\n", ProgramName);
89
fprintf(stderr, "\nwhere options include:\n");
91
" -all list all known widget and object classes\n");
93
" -tree list all widgets and objects in a tree\n");
95
" -nosuper do not print superclass resources\n");
97
" -variable show variable name instead of class name\n");
99
" -top name object to be top of tree\n");
101
" -format string printf format for instance, class, type\n");
102
fprintf(stderr, "\n");
106
static void print_tree_level (wn, level)
107
register XmuWidgetNode *wn;
114
for (i = 0; i < level; i++) {
115
putchar (' '); putchar (' ');
117
printf ("%d: %s/%s\n", level, wn->label, XmuWnClassname(wn));
118
print_tree_level (wn->children, level + 1);
119
print_tree_level (wn->siblings, level);
122
static void tree_known_widgets ()
125
register XmuWidgetNode *wn;
127
for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
128
if (!wn->superclass) { /* list all rooted objects */
129
print_tree_level (wn, 0);
136
* print_classname - print out the superclass-to-subclass hierchy of names
137
* in the form super\sub\sub....
139
static int print_classname (node, topnode, level, showvar)
140
XmuWidgetNode *node, *topnode;
146
if (node && node != topnode) {
147
retval = print_classname (node->superclass, topnode, level + 1,
153
printf ("%s%s", showvar ? node->label : XmuWnClassname(node),
159
static void list_known_widgets ()
166
for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
167
int l = strlen (wn->label);
168
if (l > width) width = l;
170
sprintf (format, "%%-%ds ", width);
171
for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
172
printf (format, wn->label);
173
print_classname (wn, (XmuWidgetNode *) NULL, 0, False);
179
static void print_resources (node, format, topnode, showsuper, showvar)
182
XmuWidgetNode *topnode;
187
XtResourceList res = node->resources;
188
XmuWidgetNode **wn = node->resourcewn;
190
for (i = 0; i < node->nresources; i++, res++, wn++) {
191
if (!showsuper && *wn != node) continue;
192
printf (format, showvar ? (*wn)->label : XmuWnClassname(*wn),
193
res->resource_name, res->resource_class, res->resource_type);
196
if (node->nconstraints > 0) {
197
printf (format, "----", "----", "----", "----");
200
res = node->constraints;
201
wn = node->constraintwn;
202
for (i = 0; i < node->nconstraints; i++, res++, wn++) {
203
if (!showsuper && *wn != node) continue;
204
printf (format, showvar ? (*wn)->label : XmuWnClassname(*wn),
205
res->resource_name, res->resource_class, res->resource_type);
213
* list_resources - display resources of a widget, identifying class from
217
list_resources (node, format, topnode, toplevel, showsuper, showvar)
220
XmuWidgetNode *topnode;
225
static Bool first = True;
227
XmuWnFetchResources (node, toplevel, topnode);
229
printf (format, showvar ? "Variable" : "WidgetClass",
230
"Instance", "Class", "Type");
232
printf (format, showvar ? "--------" : "-----------",
233
"--------", "-----", "----");
237
printf ("%s: ", node->label);
238
print_classname (node, topnode, 0, showvar);
240
print_resources (node, format, topnode, showsuper, showvar);
252
XmuWidgetNode *topnode;
253
Widget toplevel, container;
255
ProgramName = argv[0];
257
XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
259
toplevel = XtAppInitialize (&appcon, "Listres", Options, XtNumber(Options),
260
&argc, argv, NULL, NULL, 0);
261
container = XtCreateWidget ("dummy", widgetClass, toplevel, NULL, ZERO);
263
XtGetApplicationResources (toplevel, (caddr_t) &options,
264
Resources, XtNumber(Resources), NULL, ZERO);
265
XmuWnInitializeNodes (widget_list, nwidgets);
267
if (options.show_tree) {
268
tree_known_widgets();
270
list_known_widgets();
275
topnode = XmuWnNameToNode (widget_list, nwidgets, options.top_object);
276
argc--, argv++; /* skip command */
278
if (argc > 0 && argv[0][0] == '-') {
279
int len = strlen (argv[0]);
280
if (len >= 2 && strncmp(argv[0], "-all", len) == 0) {
282
for (i = 0, wn = widget_list; i < nwidgets; i++, wn++) {
283
list_resources (wn, options.format, topnode, container,
284
(Bool) options.show_superclass,
285
(Bool) options.show_variable);
290
for (; argc > 0; argc--, argv++) {
293
if (argv[0][0] == '-') usage ();
294
node = XmuWnNameToNode (widget_list, nwidgets, *argv);
296
fprintf (stderr, "%s: unable to find widget \"%s\"\n",
300
list_resources (node, options.format, topnode, container,
301
(Bool) options.show_superclass,
302
(Bool) options.show_variable);