File: TclUiSet.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (288 lines) | stat: -rw-r--r-- 7,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*-----------------------------------------------------------------------------------*/
/* INRIA 2005 */
/* Allan CORNET */
/*-----------------------------------------------------------------------------------*/
#include "TclUiSet.h"
/*-----------------------------------------------------------------------------------*/
#define NBRSTYLE 9
char *UiStyleInternalName[NBRSTYLE] = {"button",
					           "checkbutton",
					           "checkbutton",
					           "entry",
					           "label",
		                       "scale",
					           "frame",
					           "scrolllistbox",
					           "popupmenu"};
char *UiStyleExternalName[NBRSTYLE] = {"pushbutton",
                               "radiobutton",
                               "checkbox",
                               "edit",
                               "text",
                               "slider",
                               "frame",
                               "listbox",
				               "popupmenu"};
/*-----------------------------------------------------------------------------------*/
int GetStyleInternalName(char *StyleStr);
int SetVarStrings(Tcl_Interp *TCLinterpreter,char *VarName,char **Str,int m,int n);
int SetVarAString(Tcl_Interp *TCLinterpreter,char *VarName,char **Str);
int SetVarMatrix(Tcl_Interp *TCLinterpreter,char *VarName,int ptrValues,int m,int n);
int SetVarScalar(Tcl_Interp *TCLinterpreter,char *VarName,double VarValue);
/*-----------------------------------------------------------------------------------*/
int InterfaceScilabToUiSet(int Handle,int RhsPropertieField,int RhsPropertieValue)
{
	int bOK=0;

	if (Handle>0)
	{
		if (GetType(RhsPropertieField)==sci_strings)
		{
			static int l1,n1,m1;
			char *StrField=NULL;

			GetRhsVar(RhsPropertieField,"c",&m1,&n1,&l1);
			StrField=cstk(l1);
			nocase(StrField);

			if (strcmp(StrField,"userdata")==0)
			{
				if (GetType(RhsPropertieValue)==sci_strings)
				{
					char **Str=NULL;
					char VarName[64];

					GetRhsVar(RhsPropertieValue,"S",&m1,&n1,&Str);
					sprintf(VarName,"USERDATA_%d",Handle);

					/* Efface valeur precedente */
					Tcl_UnsetVar(TCLinterp, VarName, TCL_GLOBAL_ONLY);

					if ( (m1==1) && (n1==1) )
					{
						SetVarAString(TCLinterp,VarName,Str);
					}
					else
					{
						SetVarStrings(TCLinterp,VarName,Str,m1,n1);
					}
					FreeRhsSVar(Str);
				}
				else if (GetType(RhsPropertieValue)==sci_matrix)
				{
					char VarName[64];

					sprintf(VarName,"USERDATA_%d",Handle);

					GetRhsVar(RhsPropertieValue,"d",&m1,&n1,&l1);

					if ( (m1==0) && (n1==0) )
					{
						Scierror(999,"[] doesn''t work with TCL");
						return 0;
					}

					if ( (m1==1) && (n1==1) )
					{
						SetVarScalar(TCLinterp,VarName,(double)*stk(l1));
					}
				else 
					{
						SetVarMatrix(TCLinterp,VarName,l1,m1,n1);
					}
				}
				else
				{
					Scierror(999,TCL_ERROR8);
					return 0;
				}
			}
			else
			{
				if(strcmp(StrField,"string")==0)
				{
					if (GetType(RhsPropertieValue)==sci_strings)
					{
						char **Str=NULL;
						char VarName[64];

						GetRhsVar(RhsPropertieValue,"S",&m1,&n1,&Str);
						sprintf(VarName,"STRING_%d",Handle);

						/* Efface valeur precedente */
						Tcl_UnsetVar(TCLinterp, VarName, TCL_GLOBAL_ONLY);

						if ( (m1==1) && (n1==1) )
						{
							/* Les donnees sont dans STRING_%d */
							SetVarAString(TCLinterp,VarName,Str);

							/* Block inutile apres modifications dans set.tcl */
							{
								#define CommandLenMax 2048	
							
								int LenStr=0;

								char MyTclCommand[CommandLenMax];
								sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,StrField,Str[0]);

								if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
								{
									Scierror(999,TCL_ERROR4,TCLinterp->result);
									return 0;
								}
							}
						}
						else
						{
							SetVarStrings(TCLinterp,VarName,Str,m1,n1);

							/* Block inutil apres modifications dans set.tcl */
							{
								#define CommandLenMax 2048	
								int bOK=0;
								int LenStr=0;

								char MyTclCommand[CommandLenMax];
								sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,StrField,Str[0]);

								if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
								{
									Scierror(999,TCL_ERROR4,TCLinterp->result);
									return 0;
								}
							}
						}
						FreeRhsSVar(Str);
						bOK=1;
					}
					else
					{
						/* doit une chaine ou matrice de chaine */
						Scierror(999,TCL_ERROR9);
						return 0;
					}

				}
				else
				{
					/* Cas general */
					char *PropertieField=NULL;
					char *PropertieValue=NULL;

					PropertieField=(char*)MALLOC((strlen(StrField)+1)*sizeof(char));
					sprintf(PropertieField,"%s",StrField);

					if (GetType(RhsPropertieValue) == sci_strings)
					{
						char *TmpCharValue=NULL;

						GetRhsVar(RhsPropertieValue,"c",&m1,&n1,&l1);
						TmpCharValue=cstk(l1);

						PropertieValue=(char*)MALLOC((strlen(TmpCharValue)+1)*sizeof(char));
						sprintf(PropertieValue,"%s",TmpCharValue);
					}
					else if (GetType(RhsPropertieValue) == sci_matrix)
					{
						if (PropertieValue){FREE(PropertieValue);PropertieValue=NULL;}
						PropertieValue=Matrix2String(RhsPropertieValue);
					}
					else
					{
						Scierror(999,TCL_ERROR8);
						return 0;
					}
					bOK=TCL_UiSet(Handle,PropertieField,PropertieValue);

					if (PropertieField){FREE(PropertieField);PropertieField=NULL;}
					if (PropertieValue){FREE(PropertieValue);PropertieValue=NULL;}
				}
			}
		}
		else
		{
			/* champ propertie doit etre une chaine */
			Scierror(999,TCL_ERROR22);
			return 0;
		}
	}
	else
	{
		/* Handle numero incorrect */
		Scierror(999,TCL_ERROR34);
		return 0;
	}
	return bOK;
}
/*-----------------------------------------------------------------------------------*/
int TCL_UiSet(int Handle,char *PropertieField,char *PropertieValue)
{
	#define CommandLenMax 2048	
	int bOK=0;
	int LenStr=0;
	
	char MyTclCommand[CommandLenMax];

	LenStr=(strlen(PropertieField)+strlen(PropertieValue)+strlen("SetField              ")+1);

	if (LenStr >= CommandLenMax)
	{
		Scierror(999,TCL_ERROR32,CommandLenMax);
		return 0;
	}
	nocase(PropertieField);

	if ( CheckPropertyField(PropertieField) )
	{
		if (strcmp(PropertieField,"style")==0)
		{
			int StyleValue=-1;

			StyleValue=GetStyleInternalName(PropertieValue);
			if (StyleValue!=-1)
			{
				sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,PropertieField,UiStyleExternalName[StyleValue]);
			}
			else
			{
				Scierror(999,TCL_ERROR33);
				return 0;
			}
		}
		else
		{
			sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,PropertieField,PropertieValue);
		}

		if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
		{
			Scierror(999,TCL_ERROR4,TCLinterp->result);
			return 0;
		}
		bOK=1;
	}
	else
	{
		Scierror(999,TCL_ERROR30,PropertieField);
		return 0;
	}
	
	return bOK;
}
/*-----------------------------------------------------------------------------------*/
int GetStyleInternalName(char *StyleStr)
{
	int IndexInternalName=-1;
	int i=0;
	for(i=0;i<NBRSTYLE;i++)
	{
		if ( strcmp(StyleStr,UiStyleExternalName[i])==0 )
		{
			IndexInternalName=i;
			return IndexInternalName;
		}
	}
	return IndexInternalName;
}
/*-----------------------------------------------------------------------------------*/