1 /**CFile***********************************************************************
7 Synopsis [Test program for the mtr package.]
13 Author [Fabio Somenzi]
15 Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions
23 Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
26 Redistributions in binary form must reproduce the above copyright
27 notice, this list of conditions and the following disclaimer in the
28 documentation and/or other materials provided with the distribution.
30 Neither the name of the University of Colorado nor the names of its
31 contributors may be used to endorse or promote products derived from
32 this software without specific prior written permission.
34 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
39 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
40 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 POSSIBILITY OF SUCH DAMAGE.]
47 ******************************************************************************/
52 /*---------------------------------------------------------------------------*/
53 /* Variable declarations */
54 /*---------------------------------------------------------------------------*/
57 static char rcsid
[] MTR_UNUSED
= "$Id: testmtr.c,v 1.3 2004/08/13 18:15:12 fabio Exp $";
60 /*---------------------------------------------------------------------------*/
61 /* Constant declarations */
62 /*---------------------------------------------------------------------------*/
64 #define TESTMTR_VERSION\
65 "TestMtr Version #0.5, Release date 8/26/99"
67 /**AutomaticStart*************************************************************/
69 /*---------------------------------------------------------------------------*/
70 /* Static function prototypes */
71 /*---------------------------------------------------------------------------*/
73 static void usage (char *prog
);
74 static FILE * open_file (char *filename
, char *mode
);
76 /**AutomaticEnd***************************************************************/
78 /*---------------------------------------------------------------------------*/
79 /* Definition of exported functions */
80 /*---------------------------------------------------------------------------*/
82 /**Function********************************************************************
84 Synopsis [Main program for testmtr.]
86 Description [Main program for testmtr. Performs initialization.
87 Reads command line options and network(s). Builds some simple trees
94 ******************************************************************************/
108 (void) printf("# %s\n", TESTMTR_VERSION
);
109 /* Echo command line and arguments. */
111 for(i
= 0; i
< argc
; i
++) {
112 (void) printf(" %s", argv
[i
]);
115 (void) fflush(stdout
);
117 while ((c
= getopt(argc
, argv
, "Mhp:")) != EOF
) {
121 (void) mnem_setrecording(0);
134 if (argc
- optind
== 0) {
136 } else if (argc
- optind
== 1) {
142 /* Create and print a simple tree. */
143 root
= Mtr_InitTree();
145 node
= Mtr_CreateFirstChild(root
);
147 node
= Mtr_CreateLastChild(root
);
149 node
= Mtr_CreateFirstChild(root
);
151 node
= Mtr_AllocNode();
153 Mtr_MakeNextSibling(root
->child
,node
);
156 (void) printf("#------------------------\n");
158 /* Create an initial tree in which all variables belong to one group. */
159 root
= Mtr_InitGroupTree(0,12);
160 Mtr_PrintTree(root
); (void) printf("# ");
161 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
162 node
= Mtr_MakeGroup(root
,0,6,MTR_DEFAULT
);
163 node
= Mtr_MakeGroup(root
,6,6,MTR_DEFAULT
);
164 Mtr_PrintTree(root
); (void) printf("# ");
165 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
166 for (i
= 0; i
< 6; i
+=2) {
167 node
= Mtr_MakeGroup(root
,(unsigned) i
,(unsigned) 2,MTR_DEFAULT
);
169 node
= Mtr_MakeGroup(root
,0,12,MTR_FIXED
);
170 Mtr_PrintTree(root
); (void) printf("# ");
171 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
172 /* Print a partial tree. */
174 Mtr_PrintGroups(root
->child
,pr
== 0); (void) printf("\n");
175 node
= Mtr_FindGroup(root
,0,6);
176 node
= Mtr_DissolveGroup(node
);
177 Mtr_PrintTree(root
); (void) printf("# ");
178 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
179 node
= Mtr_FindGroup(root
,4,2);
180 if (!Mtr_SwapGroups(node
,node
->younger
)) {
181 (void) printf("error in Mtr_SwapGroups\n");
184 Mtr_PrintTree(root
); (void) printf("# ");
185 Mtr_PrintGroups(root
,pr
== 0);
187 (void) printf("#------------------------\n");
189 /* Create a group tree with fixed subgroups. */
190 root
= Mtr_InitGroupTree(0,4);
191 Mtr_PrintTree(root
); (void) printf("# ");
192 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
193 node
= Mtr_MakeGroup(root
,0,2,MTR_FIXED
);
194 node
= Mtr_MakeGroup(root
,2,2,MTR_FIXED
);
195 Mtr_PrintTree(root
); (void) printf("# ");
196 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
198 (void) printf("#------------------------\n");
200 /* Open input file. */
201 fp
= open_file(file
, "r");
202 root
= Mtr_ReadGroups(fp
,12);
203 Mtr_PrintTree(root
); (void) printf("# ");
204 Mtr_PrintGroups(root
,pr
== 0); (void) printf("\n");
218 /**Function********************************************************************
220 Synopsis [Prints usage message and exits.]
228 ******************************************************************************/
233 (void) fprintf(stderr
, "usage: %s [options] [file]\n", prog
);
234 (void) fprintf(stderr
, " -M\t\tturns off memory allocation recording\n");
235 (void) fprintf(stderr
, " -h\t\tprints this message\n");
236 (void) fprintf(stderr
, " -p n\t\tcontrols verbosity\n");
242 /**Function********************************************************************
244 Synopsis [Opens a file.]
246 Description [Opens a file, or fails with an error message and exits.
247 Allows '-' as a synonym for standard input.]
253 ******************************************************************************/
261 if (strcmp(filename
, "-") == 0) {
262 return mode
[0] == 'r' ? stdin
: stdout
;
263 } else if ((fp
= fopen(filename
, mode
)) == NULL
) {
269 } /* end of open_file */