1 | //
|
---|
2 | // ipv2_print.cc
|
---|
3 | //
|
---|
4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
5 | //
|
---|
6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
7 | // Maintainer: LPS
|
---|
8 | //
|
---|
9 | // This file is part of the SC Toolkit.
|
---|
10 | //
|
---|
11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
12 | // it under the terms of the GNU Library General Public License as published by
|
---|
13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
14 | // any later version.
|
---|
15 | //
|
---|
16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU Library General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU Library General Public License
|
---|
22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | //
|
---|
25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
26 | //
|
---|
27 |
|
---|
28 | #include <iostream>
|
---|
29 | #include <util/misc/formio.h>
|
---|
30 | #include <util/keyval/ipv2.h>
|
---|
31 |
|
---|
32 | using namespace std;
|
---|
33 | using namespace sc;
|
---|
34 |
|
---|
35 | void
|
---|
36 | IPV2::print_keyword(ostream&fp,ip_keyword_tree_t*st)
|
---|
37 | {
|
---|
38 | if (st) {
|
---|
39 | if (st->up) print_keyword(fp,st->up);
|
---|
40 | fp << st->keyword << ":";
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /* This prints out a keyword tree, tree. If tree is NULL then ip_tree
|
---|
45 | * is printed out. */
|
---|
46 | void
|
---|
47 | IPV2::print_tree(ostream&fp,ip_keyword_tree_t*tree)
|
---|
48 | {
|
---|
49 | if (!tree) tree = ip_tree;
|
---|
50 | if (!tree) return;
|
---|
51 |
|
---|
52 | print_tree_(fp,tree);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /* This prints out a keyword tree, tree. If tree is NULL then ip_tree
|
---|
57 | * is printed out. */
|
---|
58 | void
|
---|
59 | IPV2::print_tree_(ostream&fp,ip_keyword_tree_t*tree)
|
---|
60 | {
|
---|
61 | ip_keyword_tree_t *I;
|
---|
62 |
|
---|
63 | I=tree;
|
---|
64 | do {
|
---|
65 | //if (I->value && I->down) {
|
---|
66 | // warn("print_tree: tree has both value and subtrees - can't print");
|
---|
67 | // warn("keyword is %s, value is %s, subtree key is %s\n",
|
---|
68 | // I->keyword,I->value,I->down->keyword);
|
---|
69 | // }
|
---|
70 |
|
---|
71 | if (!I->keyword) {
|
---|
72 | warn("print_tree: tree has no keyword - impossible");
|
---|
73 | }
|
---|
74 |
|
---|
75 | fp << indent;
|
---|
76 | if (ip_special_characters(I->keyword)) {
|
---|
77 | fp << "\"" << I->keyword << "\"" << endl;
|
---|
78 | }
|
---|
79 | else {
|
---|
80 | fp << I->keyword << endl;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (I->classname) {
|
---|
84 | fp << "<" << I->keyword << ">" << endl;
|
---|
85 | }
|
---|
86 |
|
---|
87 | if (!(I->value || I->down || I->variable)) {
|
---|
88 | fp << ": (" << endl;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (I->variable) {
|
---|
92 | fp << " = $" << I->variable << endl;
|
---|
93 | }
|
---|
94 | if (I->truename) {
|
---|
95 | fp << "\"" << I->truename << "\"";
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (I->value) {
|
---|
99 | if (I->down) fp << " (= " << I->value << ")";
|
---|
100 | else fp << " = " << I->value << endl;
|
---|
101 | }
|
---|
102 | if (I->down) {
|
---|
103 | fp << ": (" << endl;
|
---|
104 | fp << incindent;
|
---|
105 | print_tree_(fp,I->down);
|
---|
106 | fp << decindent;
|
---|
107 | fp << indent << ")" << endl;
|
---|
108 | }
|
---|
109 |
|
---|
110 | } while ((I = I->across) != tree);
|
---|
111 |
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* This prints out a keyword tree, tree. If tree is NULL then ip_tree
|
---|
115 | * is printed out. */
|
---|
116 | void
|
---|
117 | IPV2::print_unseen(ostream&fp,ip_keyword_tree_t*I)
|
---|
118 | {
|
---|
119 | if (!I) I = ip_tree;
|
---|
120 | if (!I) return;
|
---|
121 | ip_keyword_tree_t *start = I;
|
---|
122 | do {
|
---|
123 | if (!I->seen) {
|
---|
124 | fp << indent;
|
---|
125 | print_keyword(fp,I->up);
|
---|
126 | fp << I->keyword << endl;
|
---|
127 | }
|
---|
128 | else if (I->down) {
|
---|
129 | print_unseen(fp,I->down);
|
---|
130 | }
|
---|
131 | } while ((I = I->across) != start);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /* This prints out a keyword tree, tree. If tree is NULL then ip_tree
|
---|
135 | * is printed out. */
|
---|
136 | int
|
---|
137 | IPV2::have_unseen(ip_keyword_tree_t*I)
|
---|
138 | {
|
---|
139 | if (!I) I = ip_tree;
|
---|
140 | if (!I) return 0;
|
---|
141 | ip_keyword_tree_t *start = I;
|
---|
142 | do {
|
---|
143 | if (!I->seen) {
|
---|
144 | return 1;
|
---|
145 | }
|
---|
146 | else if (I->down) {
|
---|
147 | if (have_unseen(I->down)) return 1;
|
---|
148 | }
|
---|
149 | } while ((I = I->across) != start);
|
---|
150 | return 0;
|
---|
151 | }
|
---|
152 |
|
---|
153 | int
|
---|
154 | IPV2::ip_special_characters(char*keyword)
|
---|
155 | {
|
---|
156 | char *ch=keyword;
|
---|
157 |
|
---|
158 | if (!keyword) return 0;
|
---|
159 | while (*ch) {
|
---|
160 | if (!( (*ch >= 'a' && *ch <= 'z')
|
---|
161 | ||(*ch >= 'A' && *ch <= 'Z')
|
---|
162 | ||(*ch >= '0' && *ch <= '9')
|
---|
163 | ||(*ch == '<')
|
---|
164 | ||(*ch == '>')
|
---|
165 | ||(*ch == '+')
|
---|
166 | ||(*ch == '-')
|
---|
167 | ||(*ch == '.')
|
---|
168 | ||(*ch == '_'))) return 1;
|
---|
169 |
|
---|
170 | ch++;
|
---|
171 | }
|
---|
172 |
|
---|
173 | return 0;
|
---|
174 | }
|
---|