/[ascend]/trunk/tcltk/generic/interface/BrowWhen_io.c
ViewVC logotype

Contents of /trunk/tcltk/generic/interface/BrowWhen_io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 702 - (show annotations) (download) (as text)
Mon Jun 26 13:37:58 2006 UTC (13 years, 11 months ago) by johnpye
File MIME type: text/x-csrc
File size: 7002 byte(s)
Missed another outstanding #include to instance.h
1 /*
2 * BrowWhen_io.c
3 * by Kirk Abbott and Ben Allan
4 * Created: 1/94
5 * Version: $Revision: 1.9 $
6 * Version control file: $RCSfile: BrowWhen_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 #include <tcl.h>
32 #include <utilities/ascConfig.h>
33 #include <utilities/ascMalloc.h>
34 #include <general/list.h>
35 #include <general/dstring.h>
36 #include <compiler/compiler.h>
37 #include <compiler/fractions.h>
38 #include <compiler/dimen.h>
39 #include <compiler/expr_types.h>
40 #include <compiler/exprs.h>
41 #include <compiler/instance_enum.h>
42 #include <compiler/symtab.h>
43 #include <compiler/instance_io.h>
44 #include <compiler/instquery.h>
45 #include <compiler/visitinst.h>
46 #include <compiler/mathinst.h>
47 #include <compiler/extfunc.h>
48 #include <compiler/find.h>
49 #include <compiler/functype.h>
50 #include <compiler/safe.h>
51 #include <compiler/func.h>
52 #include <compiler/extcall.h>
53 #include <compiler/stattypes.h>
54 #include <compiler/when.h>
55 #include <compiler/when_util.h>
56 #include <compiler/when_io.h>
57 #include <compiler/instance_name.h>
58 #include <compiler/qlfdid.h>
59 #include <solver/slv_types.h>
60 #include "HelpProc.h"
61 #include "BrowWhen_io.h"
62 #include "Qlfdid.h"
63 #include "BrowserQuery.h"
64 #include "BrowserProc.h"
65
66
67 #ifndef lint
68 static CONST char BrowWhenIOID[] = "$Id: BrowWhen_io.c,v 1.9 2003/08/23 18:43:04 ballan Exp $";
69 #endif
70
71
72 /**************************************************************************/
73
74 static struct gl_list_t *g_brow_whenlist = NULL;
75
76 /**************************************************************************/
77
78
79 /*
80 * To generate a gl_list of the when instances
81 * existing in a model, an array or a WHEN itself.
82 */
83 static
84 void BrowGetWhens(struct Instance *i)
85 {
86 if (i) {
87 switch(InstanceKind(i)) {
88 case WHEN_INST:
89 gl_append_ptr(g_brow_whenlist,i);
90 break;
91 default:
92 break;
93 }
94 }
95 }
96
97
98 /*
99 * Write a list of when statements to the Tcl interpreter
100 */
101 int Asc_BrowWriteWhenListCmd(ClientData cdata, Tcl_Interp *interp,
102 int argc, CONST84 char *argv[])
103 {
104 struct Instance *i, *when_inst;
105 unsigned long len, c;
106 int save=0;
107 unsigned long nwhens;
108
109 UNUSED_PARAMETER(cdata);
110
111 if (( argc < 2 )||( argc > 3 )) {
112 Tcl_AppendResult(interp,"wrong # args : ",
113 "Usage \"bgetwhens\" ?cur?search? save",(char *)NULL);
114 return TCL_ERROR;
115 }
116
117 if (strncmp(argv[1],"current",3)==0) {
118 i = g_curinst;
119 } else {
120 if (strncmp(argv[1],"search",3)==0) {
121 i = g_search_inst;
122 } else {
123 Tcl_SetResult(interp, "invalid args to \"bgetwhens\"", TCL_STATIC);
124 return TCL_ERROR;
125 }
126 }
127
128 if ( argc == 3 ) {
129 if (strncmp(argv[2],"save",4)==0) {
130 save = 1;
131 }
132 }
133
134 if (!i) {
135 return TCL_ERROR;
136 }
137
138 if (!g_brow_whenlist) {
139 g_brow_whenlist = gl_create(40L);
140 }
141
142 VisitInstanceTree(i,BrowGetWhens,0,0);
143 len = gl_length(g_brow_whenlist);
144
145 /* Writing the WHENs in the model, array or WHEN itself */
146 if (len) {
147 Tcl_AppendResult(interp,
148 "{WHENs in this Instance: } ",
149 (char *)NULL);
150 }
151 for (c=1;c<=len;c++) {
152 char *tmp;
153 when_inst = (struct Instance *)gl_fetch(g_brow_whenlist,c);
154 Tcl_AppendResult(interp,"{",(char *)NULL);
155 tmp = WriteWhenString(when_inst,NULL);
156 Tcl_AppendResult(interp,tmp,(char *)NULL);
157 ascfree(tmp);
158 Tcl_AppendResult(interp,"} ",(char *)NULL);
159 }
160
161 /* Writing the WHEN which include such MODEL or WHEN(nesting) */
162
163 switch (InstanceKind(i)) {
164 case MODEL_INST:
165 case WHEN_INST:
166 nwhens = WhensCount(i);
167 if (nwhens) {
168 Tcl_AppendResult(interp,
169 "{This Instance is used in CASEs OF: } ",
170 (char *)NULL);
171 for (c=1;c<=nwhens;c++) {
172 char *tmp;
173 when_inst = WhensForInstance(i,c);
174 Tcl_AppendResult(interp,"{",(char *)NULL);
175 tmp = WriteWhenString(when_inst,NULL);
176 Tcl_AppendResult(interp,tmp,(char *)NULL);
177 ascfree(tmp);
178 Tcl_AppendResult(interp,"} ",(char *)NULL);
179 }
180 }
181 break;
182 case ARRAY_INT_INST:
183 case ARRAY_ENUM_INST:
184 break;
185 default:
186 Tcl_AppendResult(interp,"Inappropriate instance called",
187 "in BrowWriteWhenList",(char *)NULL);
188 return TCL_ERROR;
189 }
190
191 if (!save) {
192 gl_destroy(g_brow_whenlist);
193 g_brow_whenlist=NULL;
194 }
195
196 return TCL_OK;
197 }
198
199
200 int Asc_BrowWriteWhensForInstanceCmd(ClientData cdata, Tcl_Interp *interp,
201 int argc, CONST84 char *argv[])
202 {
203 struct Instance *i, *when_inst;
204 unsigned long nwhens, c;
205
206 UNUSED_PARAMETER(cdata);
207
208 if ( argc != 2 ) {
209 Tcl_AppendResult(interp,"wrong # args : ",
210 "Usage :__brow_whensforinstance ?cur?search?",(char *)NULL);
211 return TCL_ERROR;
212 }
213
214 if (strncmp(argv[1],"current",3)==0) {
215 i = g_curinst;
216 } else {
217 if (strncmp(argv[1],"search",3)==0) {
218 i = g_search_inst;
219 } else {
220 Tcl_SetResult(interp, "invalid args to \"__brow_whensforinstance\"",
221 TCL_STATIC);
222 return TCL_ERROR;
223 }
224 }
225
226
227 if (!i) {
228 return TCL_ERROR;
229 }
230
231 switch (InstanceKind(i)) {
232 case BOOLEAN_ATOM_INST:
233 case BOOLEAN_CONSTANT_INST:
234 case INTEGER_ATOM_INST:
235 case INTEGER_CONSTANT_INST:
236 case SYMBOL_ATOM_INST:
237 case SYMBOL_CONSTANT_INST:
238 case REL_INST:
239 break;
240 default:
241 Tcl_AppendResult(interp,"Inappropriate instance called",
242 "in BrowWriteWhensForInstance",(char *)NULL);
243 return TCL_ERROR;
244 }
245
246 nwhens = WhensCount(i);
247 if (nwhens) {
248 Tcl_AppendResult(interp,"{WHENs including this instance are: } ",
249 (char *)NULL);
250
251 for (c=1;c<=nwhens;c++) {
252 char *tmp;
253 when_inst = WhensForInstance(i,c);
254 Tcl_AppendResult(interp,"{",(char *)NULL);
255 tmp = WriteWhenString(when_inst,NULL);
256 Tcl_AppendResult(interp,tmp,(char *)NULL);
257 ascfree(tmp);
258 Tcl_AppendResult(interp,"} ",(char *)NULL);
259 }
260 }
261
262 return TCL_OK;
263 }

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