2 * Copyright 1993 Open Software Foundation, Inc., Cambridge, Massachusetts.
6 #pragma ident "%Z%%M% %I% %E% SMI"
8 * Open Software Foundation, Inc.
10 * Permission is hereby granted to use, copy, modify and freely distribute
11 * the software in this file and its documentation for any purpose without
12 * fee, provided that the above copyright notice appears in all copies and
13 * that both the copyright notice and this permission notice appear in
14 * supporting documentation. Further, provided that the name of Open
15 * Software Foundation, Inc. ("OSF") not be used in advertising or
16 * publicity pertaining to distribution of the software without prior
17 * written permission from OSF. OSF makes no representations about the
18 * suitability of this software for any purpose. It is provided "as is"
19 * without express or implied warranty.
22 * Copyright (c) 1996 X Consortium
23 * Copyright (c) 1995, 1996 Dalrymple Consulting
25 * Permission is hereby granted, free of charge, to any person obtaining a copy
26 * of this software and associated documentation files (the "Software"), to deal
27 * in the Software without restriction, including without limitation the rights
28 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 * copies of the Software, and to permit persons to whom the Software is
30 * furnished to do so, subject to the following conditions:
32 * The above copyright notice and this permission notice shall be included in
33 * all copies or substantial portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 * X CONSORTIUM OR DALRYMPLE CONSULTING BE LIABLE FOR ANY CLAIM, DAMAGES OR
39 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
40 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
41 * OTHER DEALINGS IN THE SOFTWARE.
43 * Except as contained in this notice, the names of the X Consortium and
44 * Dalrymple Consulting shall not be used in advertising or otherwise to
45 * promote the sale, use or other dealings in this Software without prior
46 * written authorization.
48 /* ________________________________________________________________________
50 * Functions for printing information about an instance in the 'instant'
51 * program. Most of these are fairly short and simple.
53 * Entry points for this module:
54 * PrintElemSummary(elem) print summary info of each element
55 * PrintContext(elem) print context of each element
56 * PrintElemTree(elem) print tree of document
57 * PrintStats(elem) print statistics about doc tree
58 * PrintIDList(elem) print list of IDs and element context
59 * Most Print*() functions start at subtree pointed to by 'elem'.
60 * ________________________________________________________________________
65 "$Header: /usr/src/docbook-to-man/Instant/RCS/info.c,v 1.2 1996/06/02 21:46:10 fld Exp $";
75 /* ______________________________________________________________________ */
76 /* Print a summary of each tag use in the instance. Things like depth in
77 * the tree, number of children, parent, attributes.
80 /* Do the actual printing. Print the info about the node. If null,
81 * print a header for the columns.
83 * Pointer to element structure of the node to print.
91 char *hfmt
="%-18.18s %4s %5s %4s %4s %s\n";
92 char *fmt
="%-18.18s %4d %5d %4d %4d %s\n";
95 fprintf(outfp
, hfmt
, "Element", "Att", "Data", "Chd", "Dep", "Parent");
98 for (i
=0,n
=0; i
<e
->ncont
; i
++) if (IsContElem(e
,i
)) n
++;
99 for (i
=0,dsize
=0; i
<e
->ncont
; i
++)
100 if (IsContElem(e
,i
)) dsize
+= strlen(e
->cont
[i
].ch
.data
);
101 fprintf(outfp
, fmt
, e
->gi
, e
->natts
, dsize
, n
, e
->depth
,
102 e
->parent
? e
->parent
->gi
: "-");
104 for (i
=0; i
<e
->natts
; i
++) {
105 fprintf(outfp
, "%45d: %s = %s\n", i
, e
->atts
[i
].name
,
106 e
->atts
[i
].sval
? e
->atts
[i
].sval
: "empty");
110 /* Descend the tree, calling processing routine.
112 * Pointer to element structure at top of tree to traverse.
120 DescendTree(e
, print_summ
, 0, 0, 0);
123 /* ______________________________________________________________________ */
124 /* Print the context of each tag in the instance (i.e. the tag with its
128 /* Do the actual printing. Print the context of the node.
130 * Pointer to element structure of the node to print.
139 fprintf(outfp
, "%-22s %s\n", e
->gi
, FindContext(e
, 10, buf
));
142 /* Descend the tree, calling processing routine.
144 * Pointer to element structure at top of tree to traverse.
151 fprintf(outfp
, "%-22s %s\n", "Element", "Context");
152 fprintf(outfp
, "%-22s %s\n", "---------------", "-----------");
153 DescendTree(e
, print_context
, 0, 0, 0);
158 /* ______________________________________________________________________ */
159 /* Print tree of the instance. GI's are printed indented by their depth
163 /* Do the actual printing. Print the element name, indented the right amount.
165 * Pointer to element structure of the node to print.
173 for(i
=0; i
<e
->depth
; i
++) fputs(". ", outfp
);
174 for(i
=0,ne
=0; i
<e
->ncont
; i
++) if (IsContElem(e
,i
)) ne
++;
175 for(i
=0,nd
=0; i
<e
->ncont
; i
++) if IsContData(e
,i
) nd
++;
176 fprintf(outfp
, "%s (%d,%d)\n", e
->gi
, ne
, nd
);
179 /* Descend the tree, calling processing routine.
181 * Pointer to element structure at top of tree to traverse.
188 DescendTree(e
, print_indent
, 0, 0, 0);
192 /* ______________________________________________________________________ */
193 /* Print some statistics about the instance.
196 /* Accumulate the totals for the statistics.
198 * Pointer to element structure of the node to print.
199 * Pointer to the total number of elements.
200 * Pointer to the total amount of content data.
201 * Pointer to the maximum depth of tree.
212 for(i
=0; i
<e
->necont
; i
++)
213 acc_tots(e
->econt
[i
], tot_el
, tot_data
, max_depth
);
214 for (i
=0; i
<e
->necont
; i
++) (*tot_el
)++;
215 for (i
=0; i
<e
->ndcont
; i
++) (*tot_data
) += strlen(e
->dcont
[i
]);
216 if (e
->depth
> (*max_depth
)) *max_depth
= e
->depth
;
219 /* Descend the tree (recursively), collecting the statistics.
221 * Pointer to element structure of the node to print.
222 * Pointer to the total number of elements.
223 * Pointer to the total amount of content data.
224 * Pointer to the maximum depth of tree.
235 if (!strcmp(name
, e
->gi
)) {
237 for (i
=0; i
<e
->ncont
; i
++)
238 if (IsContData(e
,i
)) (*nchars
) += strlen(ContData(e
,i
));
240 for(i
=0; i
<e
->necont
; i
++)
241 elem_usage(e
->econt
[i
], name
, n_used
, nchars
);
244 /* Descend the tree, calling processing routine.
246 * Pointer to element structure at top of tree to traverse.
254 int dif_el
=0, tot_el
=0, tot_data
=0, nchars
, max_depth
=0;
257 fprintf(outfp
, "%-22s %s %s\n", "Element name", "Occurrances", "Character Content");
258 fprintf(outfp
, "%-22s %s %s\n", "---------------", "-----------", "-----------------");
260 acc_tots(top
, &tot_el
, &tot_data
, &max_depth
);
262 for (i
=0; i
<nUsedElem
; i
++) {
265 elem_usage(top
, UsedElem
[i
], &n
, &nchars
);
267 pct
= 100.0 * (float)n
/ (float)tot_el
;
268 fprintf(outfp
, "%-22s %4d %4.1f%% %6d %4d\n", UsedElem
[i
],
269 n
, pct
, nchars
, (nchars
/n
));
274 fprintf(outfp
, "\nTotal of %d elements used, %d different ones.\n",
276 fprintf(outfp
, "Total character data: %d.\n", tot_data
);
277 fprintf(outfp
, "Maximum element depth: %d.\n", max_depth
);
281 /* ______________________________________________________________________ */
282 /* Print list of: ID, GI, input file, line number, separated by colons.
283 * This is better for other programs to manipulate (like for keeping a
284 * database of IDs in documents) than humans to read.
293 for (id
=IDList
; id
; id
=id
->next
) {
295 fprintf(outfp
, "%s:%s:%s:%d\n", id
->id
, ep
->gi
,
296 ep
->infile
?ep
->infile
:"-", ep
->lineno
);
300 /* ______________________________________________________________________ */