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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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