/[ascend]/trunk/tcltk98/generic/interface/BrowLogRel_io.c
ViewVC logotype

Annotation of /trunk/tcltk98/generic/interface/BrowLogRel_io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (hide annotations) (download) (as text)
Wed Nov 30 16:31:29 2005 UTC (16 years, 6 months ago) by johnpye
File MIME type: text/x-csrc
File size: 10508 byte(s)
Standardised the "if seen" #defines to [ASC|ASCTK|ASCPY|ASCXX]_FILENAME_H
Fixed compile on FC3
1 aw0a 1 /*
2     * BrowLogRel_io.c
3     * by Kirk Abbott and Ben Allan
4     * Created: 1/94
5     * Version: $Revision: 1.11 $
6     * Version control file: $RCSfile: BrowLogRel_io.c,v $
7     * Date last modified: $Date: 2003/08/23 18:43:04 $
8     * Last modified by: $Author: ballan $
9     *
10     * This file is part of the ASCEND Tcl/Tk interface
11     *
12     * Copyright 1997, Carnegie Mellon University
13     *
14     * The ASCEND Tcl/Tk interface is free software; you can redistribute
15     * it and/or modify it under the terms of the GNU General Public License as
16     * published by the Free Software Foundation; either version 2 of the
17     * License, or (at your option) any later version.
18     *
19     * The ASCEND Tcl/Tk interface is distributed in hope that it will be
20     * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22     * General Public License for more details.
23     *
24     * You should have received a copy of the GNU General Public License
25     * along with the program; if not, write to the Free Software Foundation,
26     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27     * COPYING. COPYING is found in ../compiler.
28     */
29    
30    
31     /*
32     * Browser Logical Relation Output Routines
33     */
34    
35     #include "tcl.h"
36     #include "utilities/ascConfig.h"
37     #include "utilities/ascMalloc.h"
38     #include "general/list.h"
39     #include "general/dstring.h"
40     #include "compiler/compiler.h"
41     #include "compiler/fractions.h"
42     #include "compiler/dimen.h"
43     #include "compiler/types.h"
44     #include "compiler/exprs.h"
45     #include "compiler/instance.h"
46     #include "compiler/instance_enum.h"
47     #include "compiler/symtab.h"
48     #include "compiler/instance_io.h"
49     #include "compiler/instquery.h"
50     #include "compiler/visitinst.h"
51     #include "compiler/mathinst.h"
52     #include "compiler/extfunc.h"
53     #include "compiler/find.h"
54     #include "compiler/functype.h"
55     #include "compiler/safe.h"
56     #include "compiler/func.h"
57     #include "compiler/extcall.h"
58     #include "compiler/logical_relation.h"
59     #include "compiler/logrelation.h"
60     #include "compiler/logrel_util.h"
61     #include "compiler/logrel_io.h"
62     #include "compiler/instance_name.h"
63 johnpye 67 #include "compiler/qlfdid.h"
64 aw0a 1 #include "solver/slv_types.h"
65     #include "interface/HelpProc.h"
66     #include "interface/BrowserProc.h"
67     #include "interface/BrowLogRel_io.h"
68     #include "interface/Qlfdid.h"
69     #include "interface/BrowserQuery.h"
70    
71    
72     #ifndef lint
73     static CONST char BrowLogRelIOID[] = "$Id: BrowLogRel_io.c,v 1.11 2003/08/23 18:43:04 ballan Exp $";
74     #endif
75    
76    
77     /**************************************************************************/
78    
79     static struct gl_list_t *g_brow_lrellist = NULL;
80     static struct gl_list_t *g_brow_condlrellist = NULL;
81    
82     /**************************************************************************/
83    
84     /* Get a list of pointers to logical relations and
85     * a list of pointer to conditional logical relations
86     */
87    
88     static
89     void BrowGetLogRelations(struct Instance *i)
90     {
91     CONST struct logrelation *lrel;
92    
93     if (i) {
94     switch(InstanceKind(i)) {
95     case LREL_INST:
96     lrel = GetInstanceLogRelOnly(i);
97     if (!LogRelIsCond(lrel)) {
98     gl_append_ptr(g_brow_lrellist,i);
99     } else { /* conditional */
100     gl_append_ptr(g_brow_condlrellist,i);
101     }
102     break;
103     default:
104     break;
105     }
106     }
107     }
108    
109    
110     /* This functions sends to the interpreter the list of logical relations
111     * and then the list of conditional ligcal relations if required
112     */
113    
114     int Asc_BrowWriteLogRelListCmd(ClientData cdata,Tcl_Interp *interp,
115     int argc, CONST84 char *argv[])
116     {
117     struct Instance *i, *lrel_inst;
118     unsigned long len, c;
119     int save=0;
120    
121     (void)cdata; /* stop gcc whine about unused parameter */
122    
123     if (( argc < 2 ) || ( argc > 3 )) {
124     Tcl_AppendResult(interp,"wrong # args : ",
125     "Usage \"bgetlogrels\" ?cur?search? save",(char *)NULL);
126     return TCL_ERROR;
127     }
128     if (strncmp(argv[1],"current",3)==0) {
129     i = g_curinst;
130     } else {
131     if (strncmp(argv[1],"search",3)==0) {
132     i = g_search_inst;
133     } else {
134     Tcl_SetResult(interp, "invalid args to \"bgetlogrels\"", TCL_STATIC);
135     return TCL_ERROR;
136     }
137     }
138    
139     if (argc==3) {
140     if (strncmp(argv[2],"save",4)==0) {
141     save = 1;
142     }
143     }
144    
145     if (!i) {
146     return TCL_ERROR;
147     }
148    
149     if (!g_brow_lrellist) {
150     g_brow_lrellist = gl_create(40L);
151     }
152     if (!g_brow_condlrellist) {
153     g_brow_condlrellist = gl_create(40L);
154     }
155    
156     VisitInstanceTree(i,BrowGetLogRelations,0,0);
157    
158     /* Logical Relation */
159     len = gl_length(g_brow_lrellist);
160     for (c=1;c<=len;c++) {
161     char *tmp;
162     lrel_inst = (struct Instance *)gl_fetch(g_brow_lrellist,c);
163     Tcl_AppendResult(interp,"{",(char *)NULL);
164     tmp = WriteLogRelToString(lrel_inst,NULL);
165     Tcl_AppendResult(interp,tmp,(char *)NULL);
166     ascfree(tmp);
167     Tcl_AppendResult(interp,"} ",(char *)NULL);
168     }
169    
170     /* Conditional Logical Relation if the case */
171     len = gl_length(g_brow_condlrellist);
172     if (len) {
173     Tcl_AppendResult(interp,"{The following LogRels are Conditional: } ",
174     (char *)NULL);
175     for (c=1;c<=len;c++) {
176     char *tmp;
177     lrel_inst = (struct Instance *)gl_fetch(g_brow_condlrellist,c);
178     Tcl_AppendResult(interp,"{",(char *)NULL);
179     tmp = WriteLogRelToString(lrel_inst,NULL);
180     Tcl_AppendResult(interp,tmp,(char *)NULL);
181     ascfree(tmp);
182     Tcl_AppendResult(interp,"} ",(char *)NULL);
183     }
184     }
185     if (!save) {
186     gl_destroy(g_brow_lrellist);
187     g_brow_lrellist=NULL;
188     gl_destroy(g_brow_condlrellist);
189     g_brow_condlrellist=NULL;
190     }
191     return TCL_OK;
192     }
193    
194    
195     /* This function is particular for conditional logical relations */
196    
197     int Asc_BrowWriteCondLogRelListCmd(ClientData cdata,Tcl_Interp *interp,
198     int argc, CONST84 char *argv[])
199     {
200     struct Instance *i, *lrel_inst;
201     unsigned long len, c;
202     int save=0;
203    
204     (void)cdata; /* stop gcc whine about unused parameter */
205    
206     if (( argc < 2 ) || ( argc > 3 )) {
207     Tcl_AppendResult(interp,"wrong # args : ",
208     "Usage \"bgetcondlogrels\" ?cur?search? save",(char *)NULL);
209     return TCL_ERROR;
210     }
211    
212     if (strncmp(argv[1],"current",3)==0) {
213     i = g_curinst;
214     } else {
215     if (strncmp(argv[1],"search",3)==0) {
216     i = g_search_inst;
217     } else {
218     Tcl_SetResult(interp, "invalid args to \"bgetcondlogrels\"", TCL_STATIC);
219     return TCL_ERROR;
220     }
221     }
222    
223     if (argc==3) {
224     if (strncmp(argv[2],"save",4)==0) {
225     save = 1;
226     }
227     }
228     if (!i) {
229     return TCL_ERROR;
230     }
231    
232     if (!g_brow_lrellist) {
233     g_brow_lrellist = gl_create(40L);
234     }
235     if (!g_brow_condlrellist) {
236     g_brow_condlrellist = gl_create(40L);
237     }
238    
239     VisitInstanceTree(i,BrowGetLogRelations,0,0);
240    
241     len = gl_length(g_brow_condlrellist);
242     if (len) {
243     for (c=1;c<=len;c++) {
244     char *tmp;
245     lrel_inst = (struct Instance *)gl_fetch(g_brow_condlrellist,c);
246     Tcl_AppendResult(interp,"{",(char *)NULL);
247     tmp = WriteLogRelToString(lrel_inst,NULL);
248     Tcl_AppendResult(interp,tmp,(char *)NULL);
249     ascfree(tmp);
250     Tcl_AppendResult(interp,"} ",(char *)NULL);
251     }
252     }
253     if (!save) {
254     gl_destroy(g_brow_lrellist);
255     g_brow_lrellist=NULL;
256     gl_destroy(g_brow_condlrellist);
257     g_brow_condlrellist=NULL;
258     }
259     return TCL_OK;
260     }
261    
262    
263    
264    
265     /* For postfix representation */
266    
267     int Asc_BrowWriteLogRelListPostfixCmd(ClientData cdata,Tcl_Interp *interp,
268     int argc, CONST84 char *argv[])
269     {
270     struct Instance *i, *lrel_inst;
271     unsigned long len, c;
272     int save=0;
273    
274     (void)cdata; /* stop gcc whine about unused parameter */
275    
276     if (( argc < 2 ) || ( argc > 3 )) {
277     Tcl_AppendResult(interp,"wrong # args : ",
278     "Usage \"bgetlogrelspf\" ?cur?search? save",(char *)NULL);
279     return TCL_ERROR;
280     }
281    
282     if (strncmp(argv[1],"current",3)==0) {
283     i = g_curinst;
284     } else {
285     if (strncmp(argv[1],"search",3)==0) {
286     i = g_search_inst;
287     } else {
288     Tcl_SetResult(interp, "invalid args to \"bgetlogrelspf\"", TCL_STATIC);
289     return TCL_ERROR;
290     }
291     }
292    
293     if (argc==3) {
294     if (strncmp(argv[2],"save",4)==0) {
295     save = 1;
296     }
297     }
298    
299     if (!i) {
300     return TCL_ERROR;
301     }
302    
303    
304     if (!g_brow_lrellist) {
305     g_brow_lrellist = gl_create(40L);
306     }
307     if (!g_brow_condlrellist) {
308     g_brow_condlrellist = gl_create(40L);
309     }
310    
311     VisitInstanceTree(i,BrowGetLogRelations,0,0);
312    
313     len = gl_length(g_brow_lrellist);
314     for (c=1;c<=len;c++) {
315     char *tmp;
316     lrel_inst = (struct Instance *)gl_fetch(g_brow_lrellist,c);
317     Tcl_AppendResult(interp,"{",(char *)NULL);
318     tmp = WriteLogRelPostfixToString(lrel_inst,NULL);
319     Tcl_AppendResult(interp,tmp,(char *)NULL);
320     ascfree(tmp);
321     Tcl_AppendResult(interp,"} ",(char *)NULL);
322     }
323     if (!save) {
324     gl_destroy(g_brow_lrellist);
325     g_brow_lrellist=NULL;
326     gl_destroy(g_brow_condlrellist);
327     g_brow_condlrellist=NULL;
328     }
329     return TCL_OK;
330     }
331    
332    
333     /* Get a list of logical relations involving the current
334     * boolean instance
335     */
336    
337     int Asc_BrowWriteLogRelsForAtomCmd(ClientData cdata,Tcl_Interp *interp,
338     int argc, CONST84 char *argv[])
339     {
340     CONST struct logrelation *lrel;
341     struct Instance *i, *lrel_inst;
342     unsigned long nlrels, c;
343    
344     (void)cdata; /* stop gcc whine about unused parameter */
345    
346     if ( argc != 2 ) {
347     Tcl_AppendResult(interp,"wrong # args : ",
348     "Usage :__brow_lrelsforatom ?cur?search?",(char *)NULL);
349     return TCL_ERROR;
350     }
351    
352     if (strncmp(argv[1],"current",3)==0) {
353     i = g_curinst;
354     } else {
355     if (strncmp(argv[1],"search",3)==0) {
356     i = g_search_inst;
357     } else {
358     Tcl_SetResult(interp, "invalid args to \"__brow_lrelsforatom\"",
359     TCL_STATIC);
360     return TCL_ERROR;
361     }
362     }
363    
364     if (!i) {
365     return TCL_ERROR;
366     }
367    
368     if ( (InstanceKind(i)!= BOOLEAN_ATOM_INST ) &&
369     (InstanceKind(i)!= BOOLEAN_CONSTANT_INST ) ) {
370     Tcl_AppendResult(interp,"Only boolean atoms are allowed",
371     "in logical relations",(char *)NULL);
372     return TCL_ERROR;
373     }
374    
375     nlrels = LogRelationsCount(i);
376     for (c=1;c<=nlrels;c++) {
377     char *tmp;
378     lrel_inst = LogRelationsForInstance(i,c);
379     lrel = GetInstanceLogRelOnly(lrel_inst);
380     Tcl_AppendResult(interp,"{",(char *)NULL);
381     tmp = WriteLogRelToString(lrel_inst,NULL);
382     Tcl_AppendResult(interp,tmp,(char *)NULL);
383     ascfree(tmp);
384     if (LogRelIsCond(lrel)) {
385     Tcl_AppendResult(interp," Conditional Logical Relation",(char *)NULL);
386     }
387     Tcl_AppendResult(interp,"} ",(char *)NULL);
388     }
389     return TCL_OK;
390     }
391    
392    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22