2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * Copyright 1993 Open Software Foundation, Inc., Cambridge, Massachusetts.
25 * All rights reserved.
29 * Open Software Foundation, Inc.
31 * Permission is hereby granted to use, copy, modify and freely distribute
32 * the software in this file and its documentation for any purpose without
33 * fee, provided that the above copyright notice appears in all copies and
34 * that both the copyright notice and this permission notice appear in
35 * supporting documentation. Further, provided that the name of Open
36 * Software Foundation, Inc. ("OSF") not be used in advertising or
37 * publicity pertaining to distribution of the software without prior
38 * written permission from OSF. OSF makes no representations about the
39 * suitability of this software for any purpose. It is provided "as is"
40 * without express or implied warranty.
42 /* ________________________________________________________________________
44 * Functions for printing information about an instance in the 'instant'
45 * program. Most of these are fairly short and simple.
47 * Entry points for this module:
48 * PrintElemSummary(elem) print summary info of each element
49 * PrintContext(elem) print context of each element
50 * PrintElemTree(elem) print tree of document
51 * PrintStats(elem) print statistics about doc tree
52 * PrintIDList(elem) print list of IDs and element context
53 * Most Print*() functions start at subtree pointed to by 'elem'.
54 * ________________________________________________________________________
59 "$XConsortium: info.c /main/3 1996/06/19 17:13:13 drk $";
69 /* ______________________________________________________________________ */
70 /* Print a summary of each tag use in the instance. Things like depth in
71 * the tree, number of children, parent, attributes.
74 /* Do the actual printing. Print the info about the node. If null,
75 * print a header for the columns.
77 * Pointer to element structure of the node to print.
85 char *hfmt="%-18.18s %4s %5s %4s %4s %s\n";
86 char *fmt ="%-18.18s %4d %5d %4d %4d %s\n";
89 fprintf(outfp, hfmt, "Element", "Att", "Data", "Chd", "Dep", "Parent");
92 for (i=0,n=0; i<e->ncont; i++) if (IsContElem(e,i)) n++;
93 for (i=0,dsize=0; i<e->ncont; i++)
94 if (IsContElem(e,i)) dsize += strlen(e->cont[i].ch.data);
95 fprintf(outfp, fmt, e->gi, e->natts, dsize, n, e->depth,
96 e->parent ? e->parent->gi : "-");
98 for (i=0; i<e->natts; i++) {
99 fprintf(outfp, "%45d: %s = %s\n", i, e->atts[i].name,
100 e->atts[i].sval ? e->atts[i].sval : "empty");
104 /* Descend the tree, calling processing routine.
106 * Pointer to element structure at top of tree to traverse.
114 DescendTree(e, print_summ, 0, 0, 0);
117 /* ______________________________________________________________________ */
118 /* Print the context of each tag in the instance (i.e. the tag with its
122 /* Do the actual printing. Print the context of the node.
124 * Pointer to element structure of the node to print.
133 fprintf(outfp, "%-22s %s\n", e->gi, FindContext(e, 10, buf));
136 /* Descend the tree, calling processing routine.
138 * Pointer to element structure at top of tree to traverse.
145 fprintf(outfp, "%-22s %s\n", "Element", "Context");
146 fprintf(outfp, "%-22s %s\n", "---------------", "-----------");
147 DescendTree(e, print_context, 0, 0, 0);
152 /* ______________________________________________________________________ */
153 /* Print tree of the instance. GI's are printed indented by their depth
157 /* Do the actual printing. Print the element name, indented the right amount.
159 * Pointer to element structure of the node to print.
167 for(i=0; i<e->depth; i++) fputs(". ", outfp);
168 for(i=0,ne=0; i<e->ncont; i++) if (IsContElem(e,i)) ne++;
169 for(i=0,nd=0; i<e->ncont; i++) if IsContData(e,i) nd++;
170 fprintf(outfp, "%s (%d,%d)\n", e->gi, ne, nd);
173 /* Descend the tree, calling processing routine.
175 * Pointer to element structure at top of tree to traverse.
182 DescendTree(e, print_indent, 0, 0, 0);
186 /* ______________________________________________________________________ */
187 /* Print some statistics about the instance.
190 /* Accumulate the totals for the statistics.
192 * Pointer to element structure of the node to print.
193 * Pointer to the total number of elements.
194 * Pointer to the total amount of content data.
195 * Pointer to the maximum depth of tree.
206 for(i=0; i<e->necont; i++)
207 acc_tots(e->econt[i], tot_el, tot_data, max_depth);
208 for (i=0; i<e->necont; i++) (*tot_el)++;
209 for (i=0; i<e->ndcont; i++) (*tot_data) += strlen(e->dcont[i]);
210 if (e->depth > (*max_depth)) *max_depth = e->depth;
213 /* Descend the tree (recursively), collecting the statistics.
215 * Pointer to element structure of the node to print.
216 * Pointer to the total number of elements.
217 * Pointer to the total amount of content data.
218 * Pointer to the maximum depth of tree.
229 if (!strcmp(name, e->gi)) {
231 for (i=0; i<e->ncont; i++)
232 if (IsContData(e,i)) (*nchars) += strlen(ContData(e,i));
234 for(i=0; i<e->necont; i++)
235 elem_usage(e->econt[i], name, n_used, nchars);
238 /* Descend the tree, calling processing routine.
240 * Pointer to element structure at top of tree to traverse.
248 int dif_el=0, tot_el=0, tot_data=0, nchars, max_depth=0;
251 fprintf(outfp, "%-22s %s %s\n", "Element name", "Occurrances", "Character Content");
252 fprintf(outfp, "%-22s %s %s\n", "---------------", "-----------", "-----------------");
254 acc_tots(top, &tot_el, &tot_data, &max_depth);
256 for (i=0; i<nUsedElem; i++) {
259 elem_usage(top, UsedElem[i], &n, &nchars);
261 pct = 100.0 * (float)n / (float)tot_el;
262 fprintf(outfp, "%-22s %4d %4.1f%% %6d %4d\n", UsedElem[i],
263 n, pct, nchars, (nchars/n));
268 fprintf(outfp, "\nTotal of %d elements used, %d different ones.\n",
270 fprintf(outfp, "Total character data: %d.\n", tot_data);
271 fprintf(outfp, "Maximum element depth: %d.\n", max_depth);
275 /* ______________________________________________________________________ */
276 /* Print list of: ID, GI, input file, line number, separated by colons.
277 * This is better for other programs to manipulate (like for keeping a
278 * database of IDs in documents) than humans to read.
287 for (id=IDList; id; id=id->next) {
289 fprintf(outfp, "%s:%s:%s:%d\n", id->id, ep->gi,
290 ep->infile?ep->infile:"-", ep->lineno);
294 /* ______________________________________________________________________ */