1 // -*- mode:C++ ; compile-command: "g++-3.4 -I. -I.. -I../include -DHAVE_CONFIG_H -DIN_GIAC -g -c -Wall identificateur.cc" -*-
2 #include "giacPCH.h"
3 
4 /*
5  *  Copyright (C) 2000,14 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 using namespace std;
21 #include <cmath>
22 #if !defined GIAC_HAS_STO_38 && !defined NSPIRE && !defined FXCG && !defined POCKETCAS
23 #include <fstream>
24 #endif
25 #include <string>
26 //#include <unistd.h> // For reading arguments from file
27 #include "identificateur.h"
28 #include "gen.h"
29 #include "sym2poly.h"
30 #include "rpn.h"
31 #include "prog.h"
32 #include "usual.h"
33 #include "giacintl.h"
34 
35 #ifdef BESTA_OS
36 // Local replacement for strdup on BESTA OS.
strdup(char * str)37 static char* strdup(char* str)
38 {
39     if ( ! str )
40     {
41         return str;
42     }
43 
44     int len = strlen(str) + 2;
45     char* p = new char[len];
46     strcpy(p, str);
47     return p;
48 }
49 #endif
50 
51 #ifndef NO_NAMESPACE_GIAC
52 namespace giac {
53 #endif // ndef NO_NAMESPACE_GIAC
54 
55   // bool variables_are_files=true; // FIXME -> false and change rpn.cc at_VARS
56   int protection_level=0; // for local variables in null context
57 
58   struct int_string_shortint_bool {
59     int i;
60     const char * s;
61     short int b;
62     bool s_dynalloc;
63   };
64 
65 #ifdef DOUBLEVAL // #ifdef GIAC_GENERIC_CONSTANTS
66   const char string_euler_gamma[]="euler_gamma";
67   identificateur _IDNT_euler_gamma(string_euler_gamma,(double) .577215664901533);
68   gen cst_euler_gamma(_IDNT_euler_gamma);
69 
70   const char string_pi[]="pi";
_IDNT_pi()71   identificateur & _IDNT_pi(){
72     static identificateur * ans=new identificateur(string_pi,(double) M_PI);
73     return * ans;
74   }
75   // identificateur _IDNT_pi(string_pi,(double) M_PI);
76   alias_ref_identificateur ref_pi={-1,0,0,string_pi,0,0};
77 
78   gen cst_pi(_IDNT_pi());
79 
80   const char string_infinity[]="infinity";
_IDNT_infinity()81   identificateur & _IDNT_infinity(){
82     static identificateur * ans=new identificateur("infinity");
83     return * ans;
84   }
85   gen unsigned_inf(_IDNT_infinity());
86   alias_gen & alias_unsigned_inf = *(alias_gen *) & unsigned_inf;
87   alias_ref_identificateur ref_infinity={-1,0,0,string_infinity,0,0};
88 
89   const char string_undef[]="undef";
_IDNT_undef()90   identificateur & _IDNT_undef(){
91     static identificateur * ans=new identificateur("undef");
92     return * ans;
93   }
94   gen undef(_IDNT_undef());
95 
96 #else
97   const char string_euler_gamma[]="euler_gamma";
98   static const alias_ref_identificateur ref_euler_gamma={-1,0,0,string_euler_gamma,0,0};
99   const define_alias_gen(alias_cst_euler_gamma,_IDNT,0,&ref_euler_gamma);
100   const gen & cst_euler_gamma = * (gen *) & alias_cst_euler_gamma;
101 
102   const char string_pi[]="pi";
103   static const alias_identificateur alias_identificateur_pi={0,0,string_pi,0,0};
_IDNT_pi()104   const identificateur & _IDNT_pi(){
105     return *(const identificateur *) & alias_identificateur_pi;
106   }
107   const alias_ref_identificateur ref_pi={-1,0,0,string_pi,0,0};
108   const define_alias_gen(alias_cst_pi,_IDNT,0,&ref_pi);
109   const gen & cst_pi = * (gen *) & alias_cst_pi;
110 
111   const char string_infinity[]="infinity";
112   static const alias_identificateur alias_identificateur_infinity={0,0,string_infinity,0,0};
_IDNT_infinity()113   const identificateur & _IDNT_infinity(){
114     return * (const identificateur *) &alias_identificateur_infinity;
115   }
116   const alias_ref_identificateur ref_infinity={-1,0,0,string_infinity,0,0};
117   const define_alias_gen(alias_unsigned_inf,_IDNT,0,&ref_infinity);
118   const gen & unsigned_inf = * (gen *) & alias_unsigned_inf;
119 
120   const char string_undef[]="undef";
121   static const alias_identificateur alias_identificateur_undef={0,0,string_undef,0,0};
_IDNT_undef()122   const identificateur & _IDNT_undef(){
123     return * (const identificateur *) &alias_identificateur_undef;
124   }
125   static const alias_ref_identificateur ref_undef={-1,0,0,string_undef,0,0};
126   const define_alias_gen(alias_undef,_IDNT,0,&ref_undef);
127   const gen & undef = * (gen *) & alias_undef;
128 
129 #endif // GIAC_GENERIC_CONSTANTS
130 
131 #if defined GIAC_HAS_STO_38 || defined NSPIRE || defined NSPIRE_NEWLIB || defined KHICAS
132 #if 0
133   static const alias_identificateur alias_identificateur_a38={0,0,"A",0,0};
134   const identificateur & a__IDNT=* (const identificateur *) &alias_identificateur_a38;
135   const alias_ref_identificateur ref_a38={-1,0,0,"A",0,0};
136   const define_alias_gen(alias_a38,_IDNT,0,&ref_a38);
137 //  const gen & a__IDNT_e = * (gen *) & alias_a38;
138 
139   static const alias_identificateur alias_identificateur_b38={0,0,"B",0,0};
140   const identificateur & b__IDNT=* (const identificateur *) &alias_identificateur_b38;
141   const alias_ref_identificateur ref_b38={-1,0,0,"B",0,0};
142   const define_alias_gen(alias_b38,_IDNT,0,&ref_b38);
143 //  const gen & b__IDNT_e = * (gen *) & alias_b38;
144 
145   static const alias_identificateur alias_identificateur_c38={0,0,"C",0,0};
146   const identificateur & c__IDNT=* (const identificateur *) &alias_identificateur_c38;
147   const alias_ref_identificateur ref_c38={-1,0,0,"C",0,0};
148   const define_alias_gen(alias_c38,_IDNT,0,&ref_c38);
149 //  const gen & c__IDNT_e = * (gen *) & alias_c38;
150 
151   static const alias_identificateur alias_identificateur_d38={0,0,"D",0,0};
152   const identificateur & d__IDNT=* (const identificateur *) &alias_identificateur_d38;
153   const alias_ref_identificateur ref_d38={-1,0,0,"D",0,0};
154   const define_alias_gen(alias_d38,_IDNT,0,&ref_d38);
155 //  const gen & d__IDNT_e = * (gen *) & alias_d38;
156 
157   static const alias_identificateur alias_identificateur_e38={0,0,"E",0,0};
158   const identificateur & e__IDNT=* (const identificateur *) &alias_identificateur_e38;
159   const alias_ref_identificateur ref_e38={-1,0,0,"E",0,0};
160   const define_alias_gen(alias_e38,_IDNT,0,&ref_e38);
161 //  const gen & e__IDNT_e = * (gen *) & alias_e38;
162 
163   static const alias_identificateur alias_identificateur_f38={0,0,"F",0,0};
164   const identificateur & f__IDNT=* (const identificateur *) &alias_identificateur_f38;
165   const alias_ref_identificateur ref_f38={-1,0,0,"F",0,0};
166   const define_alias_gen(alias_f38,_IDNT,0,&ref_f38);
167 //  const gen & f__IDNT_e = * (gen *) & alias_f38;
168 
169   static const alias_identificateur alias_identificateur_g38={0,0,"G",0,0};
170   const identificateur & g__IDNT=* (const identificateur *) &alias_identificateur_g38;
171   const alias_ref_identificateur ref_g38={-1,0,0,"G",0,0};
172   const define_alias_gen(alias_g38,_IDNT,0,&ref_g38);
173 //  const gen & g__IDNT_e = * (gen *) & alias_g38;
174 
175   static const alias_identificateur alias_identificateur_h38={0,0,"H",0,0};
176   const identificateur & h__IDNT=* (const identificateur *) &alias_identificateur_h38;
177   const alias_ref_identificateur ref_h38={-1,0,0,"H",0,0};
178   const define_alias_gen(alias_h38,_IDNT,0,&ref_h38);
179 //  const gen & h__IDNT_e = * (gen *) & alias_h38;
180 
181   static const alias_identificateur alias_identificateur_i38={0,0,"I",0,0};
182   const identificateur & i__IDNT=* (const identificateur *) &alias_identificateur_i38;
183   const alias_ref_identificateur ref_i38={-1,0,0,"I",0,0};
184   const define_alias_gen(alias_i38,_IDNT,0,&ref_i38);
185 //  const gen & i__IDNT_e = * (gen *) & alias_i38;
186 
187   static const alias_identificateur alias_identificateur_j38={0,0,"J",0,0};
188   const identificateur & j__IDNT=* (const identificateur *) &alias_identificateur_j38;
189   const alias_ref_identificateur ref_j38={-1,0,0,"J",0,0};
190   const define_alias_gen(alias_j38,_IDNT,0,&ref_j38);
191 //  const gen & j__IDNT_e = * (gen *) & alias_j38;
192 
193   static const alias_identificateur alias_identificateur_k38={0,0,"K",0,0};
194   const identificateur & k__IDNT=* (const identificateur *) &alias_identificateur_k38;
195   const alias_ref_identificateur ref_k38={-1,0,0,"K",0,0};
196   const define_alias_gen(alias_k38,_IDNT,0,&ref_k38);
197 // const gen & k__IDNT_e = * (gen *) & alias_k38;
198 
199   static const alias_identificateur alias_identificateur_l38={0,0,"L",0,0};
200   const identificateur & l__IDNT=* (const identificateur *) &alias_identificateur_l38;
201   const alias_ref_identificateur ref_l38={-1,0,0,"L",0,0};
202   const define_alias_gen(alias_l38,_IDNT,0,&ref_l38);
203 //  const gen & l__IDNT_e = * (gen *) & alias_l38;
204 
205   static const alias_identificateur alias_identificateur_m38={0,0,"M",0,0};
206   const identificateur & m__IDNT=* (const identificateur *) &alias_identificateur_m38;
207   const alias_ref_identificateur ref_m38={-1,0,0,"M",0,0};
208   const define_alias_gen(alias_m38,_IDNT,0,&ref_m38);
209 //  const gen & m__IDNT_e = * (gen *) & alias_m38;
210 
211   static const alias_identificateur alias_identificateur_n38={0,0,"N",0,0};
212   const identificateur & n__IDNT=* (const identificateur *) &alias_identificateur_n38;
213   const alias_ref_identificateur ref_n38={-1,0,0,"N",0,0};
214   const define_alias_gen(alias_n38,_IDNT,0,&ref_n38);
215 //  const gen & n__IDNT_e = * (gen *) & alias_n38;
216 
217   static const alias_identificateur alias_identificateur_o38={0,0,"O",0,0};
218   const identificateur & o__IDNT=* (const identificateur *) &alias_identificateur_o38;
219   const alias_ref_identificateur ref_o38={-1,0,0,"O",0,0};
220   const define_alias_gen(alias_o38,_IDNT,0,&ref_o38);
221 //  const gen & o__IDNT_e = * (gen *) & alias_o38;
222 
223   static const alias_identificateur alias_identificateur_p38={0,0,"P",0,0};
224   const identificateur & p__IDNT=* (const identificateur *) &alias_identificateur_p38;
225   const alias_ref_identificateur ref_p38={-1,0,0,"P",0,0};
226   const define_alias_gen(alias_p38,_IDNT,0,&ref_p38);
227 //  const gen & p__IDNT_e = * (gen *) & alias_p38;
228 
229   static const alias_identificateur alias_identificateur_q38={0,0,"Q",0,0};
230   const identificateur & q__IDNT=* (const identificateur *) &alias_identificateur_q38;
231   const alias_ref_identificateur ref_q38={-1,0,0,"Q",0,0};
232   const define_alias_gen(alias_q38,_IDNT,0,&ref_q38);
233 //  const gen & q__IDNT_e = * (gen *) & alias_q38;
234 
235   static const alias_identificateur alias_identificateur_r38={0,0,"R",0,0};
236   const identificateur & r__IDNT=* (const identificateur *) &alias_identificateur_r38;
237   const alias_ref_identificateur ref_r38={-1,0,0,"R",0,0};
238   const define_alias_gen(alias_r38,_IDNT,0,&ref_r38);
239 //  const gen & r__IDNT_e = * (gen *) & alias_r38;
240 
241   static const alias_identificateur alias_identificateur_s38={0,0,"S",0,0};
242   const identificateur & s__IDNT=* (const identificateur *) &alias_identificateur_s38;
243   const alias_ref_identificateur ref_s38={-1,0,0,"S",0,0};
244   const define_alias_gen(alias_s38,_IDNT,0,&ref_s38);
245 //  const gen & s__IDNT_e = * (gen *) & alias_s38;
246 
247   static const alias_identificateur alias_identificateur_t38={0,0,"T",0,0};
248   const identificateur & t__IDNT=* (const identificateur *) &alias_identificateur_t38;
249   const alias_ref_identificateur ref_t38={-1,0,0,"T",0,0};
250   const define_alias_gen(alias_t38,_IDNT,0,&ref_t38);
251 //  const gen & t__IDNT_e = * (gen *) & alias_t38;
252 
253   static const alias_identificateur alias_identificateur_u38={0,0,"U",0,0};
254   const identificateur & u__IDNT=* (const identificateur *) &alias_identificateur_u38;
255   const alias_ref_identificateur ref_u38={-1,0,0,"U",0,0};
256   const define_alias_gen(alias_u38,_IDNT,0,&ref_u38);
257 //  const gen & u__IDNT_e = * (gen *) & alias_u38;
258 
259   static const alias_identificateur alias_identificateur_v38={0,0,"V",0,0};
260   const identificateur & v__IDNT=* (const identificateur *) &alias_identificateur_v38;
261   const alias_ref_identificateur ref_v38={-1,0,0,"V",0,0};
262   const define_alias_gen(alias_v38,_IDNT,0,&ref_v38);
263 //  const gen & v__IDNT_e = * (gen *) & alias_v38;
264 
265   static const alias_identificateur alias_identificateur_w38={0,0,"W",0,0};
266   const identificateur & w__IDNT=* (const identificateur *) &alias_identificateur_w38;
267   const alias_ref_identificateur ref_w38={-1,0,0,"W",0,0};
268   const define_alias_gen(alias_w38,_IDNT,0,&ref_w38);
269 //  const gen & w__IDNT_e = * (gen *) & alias_w38;
270 
271   static const alias_identificateur alias_identificateur_x38={0,0,"X",0,0};
272   const identificateur & x__IDNT=* (const identificateur *) &alias_identificateur_x38;
273   const alias_ref_identificateur ref_x38={-1,0,0,"X",0,0};
274   const define_alias_gen(alias_x38,_IDNT,0,&ref_x38);
275 //  const gen & x__IDNT_e = * (gen *) & alias_x38;
276 
277   static const alias_identificateur alias_identificateur_xx38={0,0,"x",0,0};
278   const identificateur & xx__IDNT=* (const identificateur *) &alias_identificateur_xx38;
279   const alias_ref_identificateur ref_xx38={-1,0,0,"x",0,0};
280   const define_alias_gen(alias_xx38,_IDNT,0,&ref_xx38);
281 //  const gen & xx__IDNT_e = * (gen *) & alias_xx38;
282 
283   static const alias_identificateur alias_identificateur_y38={0,0,"Y",0,0};
284   const identificateur & y__IDNT=* (const identificateur *) &alias_identificateur_y38;
285   const alias_ref_identificateur ref_y38={-1,0,0,"Y",0,0};
286   const define_alias_gen(alias_y38,_IDNT,0,&ref_y38);
287 //  const gen & y__IDNT_e = * (gen *) & alias_y38;
288 
289   static const alias_identificateur alias_identificateur_z38={0,0,"Z",0,0};
290   const identificateur & z__IDNT=* (const identificateur *) &alias_identificateur_z38;
291   const alias_ref_identificateur ref_z38={-1,0,0,"Z",0,0};
292   const define_alias_gen(alias_z38,_IDNT,0,&ref_z38);
293 //  const gen & z__IDNT_e = * (gen *) & alias_z38;
294 
295 #else
296   static const alias_identificateur alias_identificateur_a38={0,0,"a",0,0};
297   const identificateur & a__IDNT=* (const identificateur *) &alias_identificateur_a38;
298   const alias_ref_identificateur ref_a38={-1,0,0,"a",0,0};
299   const define_alias_gen(alias_a38,_IDNT,0,&ref_a38);
300 //  const gen & a__IDNT_e = * (gen *) & alias_a38;
301 
302   static const alias_identificateur alias_identificateur_b38={0,0,"b",0,0};
303   const identificateur & b__IDNT=* (const identificateur *) &alias_identificateur_b38;
304   const alias_ref_identificateur ref_b38={-1,0,0,"b",0,0};
305   const define_alias_gen(alias_b38,_IDNT,0,&ref_b38);
306 //  const gen & b__IDNT_e = * (gen *) & alias_b38;
307 
308   static const alias_identificateur alias_identificateur_c38={0,0,"c",0,0};
309   const identificateur & c__IDNT=* (const identificateur *) &alias_identificateur_c38;
310   const alias_ref_identificateur ref_c38={-1,0,0,"c",0,0};
311   const define_alias_gen(alias_c38,_IDNT,0,&ref_c38);
312 //  const gen & c__IDNT_e = * (gen *) & alias_c38;
313 
314   static const alias_identificateur alias_identificateur_d38={0,0,"d",0,0};
315   const identificateur & d__IDNT=* (const identificateur *) &alias_identificateur_d38;
316   const alias_ref_identificateur ref_d38={-1,0,0,"d",0,0};
317   const define_alias_gen(alias_d38,_IDNT,0,&ref_d38);
318 //  const gen & d__IDNT_e = * (gen *) & alias_d38;
319 
320   static const alias_identificateur alias_identificateur_e38={0,0,"e",0,0};
321   const identificateur & e__IDNT=* (const identificateur *) &alias_identificateur_e38;
322   const alias_ref_identificateur ref_e38={-1,0,0,"e",0,0};
323   const define_alias_gen(alias_e38,_IDNT,0,&ref_e38);
324 //  const gen & e__IDNT_e = * (gen *) & alias_e38;
325 
326   static const alias_identificateur alias_identificateur_f38={0,0,"f",0,0};
327   const identificateur & f__IDNT=* (const identificateur *) &alias_identificateur_f38;
328   const alias_ref_identificateur ref_f38={-1,0,0,"f",0,0};
329   const define_alias_gen(alias_f38,_IDNT,0,&ref_f38);
330 //  const gen & f__IDNT_e = * (gen *) & alias_f38;
331 
332   static const alias_identificateur alias_identificateur_g38={0,0,"g",0,0};
333   const identificateur & g__IDNT=* (const identificateur *) &alias_identificateur_g38;
334   const alias_ref_identificateur ref_g38={-1,0,0,"g",0,0};
335   const define_alias_gen(alias_g38,_IDNT,0,&ref_g38);
336 //  const gen & g__IDNT_e = * (gen *) & alias_g38;
337 
338   static const alias_identificateur alias_identificateur_h38={0,0,"h",0,0};
339   const identificateur & h__IDNT=* (const identificateur *) &alias_identificateur_h38;
340   const alias_ref_identificateur ref_h38={-1,0,0,"h",0,0};
341   const define_alias_gen(alias_h38,_IDNT,0,&ref_h38);
342 //  const gen & h__IDNT_e = * (gen *) & alias_h38;
343 
344   static const alias_identificateur alias_identificateur_i38={0,0,"i",0,0};
345   const identificateur & i__IDNT=* (const identificateur *) &alias_identificateur_i38;
346   const alias_ref_identificateur ref_i38={-1,0,0,"i",0,0};
347   const define_alias_gen(alias_i38,_IDNT,0,&ref_i38);
348 //  const gen & i__IDNT_e = * (gen *) & alias_i38;
349 
350   static const alias_identificateur alias_identificateur_j38={0,0,"j",0,0};
351   const identificateur & j__IDNT=* (const identificateur *) &alias_identificateur_j38;
352   const alias_ref_identificateur ref_j38={-1,0,0,"j",0,0};
353   const define_alias_gen(alias_j38,_IDNT,0,&ref_j38);
354 //  const gen & j__IDNT_e = * (gen *) & alias_j38;
355 
356   static const alias_identificateur alias_identificateur_k38={0,0,"k",0,0};
357   const identificateur & k__IDNT=* (const identificateur *) &alias_identificateur_k38;
358   const alias_ref_identificateur ref_k38={-1,0,0,"k",0,0};
359   const define_alias_gen(alias_k38,_IDNT,0,&ref_k38);
360 // const gen & k__IDNT_e = * (gen *) & alias_k38;
361 
362   static const alias_identificateur alias_identificateur_l38={0,0,"l",0,0};
363   const identificateur & l__IDNT=* (const identificateur *) &alias_identificateur_l38;
364   const alias_ref_identificateur ref_l38={-1,0,0,"l",0,0};
365   const define_alias_gen(alias_l38,_IDNT,0,&ref_l38);
366 //  const gen & l__IDNT_e = * (gen *) & alias_l38;
367 
368   static const alias_identificateur alias_identificateur_m38={0,0,"m",0,0};
369   const identificateur & m__IDNT=* (const identificateur *) &alias_identificateur_m38;
370   const alias_ref_identificateur ref_m38={-1,0,0,"m",0,0};
371   const define_alias_gen(alias_m38,_IDNT,0,&ref_m38);
372 //  const gen & m__IDNT_e = * (gen *) & alias_m38;
373 
374   static const alias_identificateur alias_identificateur_n38={0,0,"n",0,0};
375   const identificateur & n__IDNT=* (const identificateur *) &alias_identificateur_n38;
376   const alias_ref_identificateur ref_n38={-1,0,0,"n",0,0};
377   const define_alias_gen(alias_n38,_IDNT,0,&ref_n38);
378 //  const gen & n__IDNT_e = * (gen *) & alias_n38;
379 
380   static const alias_identificateur alias_identificateur_o38={0,0,"o",0,0};
381   const identificateur & o__IDNT=* (const identificateur *) &alias_identificateur_o38;
382   const alias_ref_identificateur ref_o38={-1,0,0,"o",0,0};
383   const define_alias_gen(alias_o38,_IDNT,0,&ref_o38);
384 //  const gen & o__IDNT_e = * (gen *) & alias_o38;
385 
386   static const alias_identificateur alias_identificateur_p38={0,0,"p",0,0};
387   const identificateur & p__IDNT=* (const identificateur *) &alias_identificateur_p38;
388   const alias_ref_identificateur ref_p38={-1,0,0,"p",0,0};
389   const define_alias_gen(alias_p38,_IDNT,0,&ref_p38);
390 //  const gen & p__IDNT_e = * (gen *) & alias_p38;
391 
392   static const alias_identificateur alias_identificateur_q38={0,0,"q",0,0};
393   const identificateur & q__IDNT=* (const identificateur *) &alias_identificateur_q38;
394   const alias_ref_identificateur ref_q38={-1,0,0,"q",0,0};
395   const define_alias_gen(alias_q38,_IDNT,0,&ref_q38);
396 //  const gen & q__IDNT_e = * (gen *) & alias_q38;
397 
398   static const alias_identificateur alias_identificateur_r38={0,0,"r",0,0};
399   const identificateur & r__IDNT=* (const identificateur *) &alias_identificateur_r38;
400   const alias_ref_identificateur ref_r38={-1,0,0,"r",0,0};
401   const define_alias_gen(alias_r38,_IDNT,0,&ref_r38);
402 //  const gen & r__IDNT_e = * (gen *) & alias_r38;
403 
404   static const alias_identificateur alias_identificateur_s38={0,0,"s",0,0};
405   const identificateur & s__IDNT=* (const identificateur *) &alias_identificateur_s38;
406   const alias_ref_identificateur ref_s38={-1,0,0,"s",0,0};
407   const define_alias_gen(alias_s38,_IDNT,0,&ref_s38);
408 //  const gen & s__IDNT_e = * (gen *) & alias_s38;
409 
410   static const alias_identificateur alias_identificateur_t38={0,0,"t",0,0};
411   const identificateur & t__IDNT=* (const identificateur *) &alias_identificateur_t38;
412   const alias_ref_identificateur ref_t38={-1,0,0,"t",0,0};
413   const define_alias_gen(alias_t38,_IDNT,0,&ref_t38);
414 //  const gen & t__IDNT_e = * (gen *) & alias_t38;
415 
416   static const alias_identificateur alias_identificateur_u38={0,0,"u",0,0};
417   const identificateur & u__IDNT=* (const identificateur *) &alias_identificateur_u38;
418   const alias_ref_identificateur ref_u38={-1,0,0,"u",0,0};
419   const define_alias_gen(alias_u38,_IDNT,0,&ref_u38);
420 //  const gen & u__IDNT_e = * (gen *) & alias_u38;
421 
422   static const alias_identificateur alias_identificateur_v38={0,0,"v",0,0};
423   const identificateur & v__IDNT=* (const identificateur *) &alias_identificateur_v38;
424   const alias_ref_identificateur ref_v38={-1,0,0,"v",0,0};
425   const define_alias_gen(alias_v38,_IDNT,0,&ref_v38);
426 //  const gen & v__IDNT_e = * (gen *) & alias_v38;
427 
428   static const alias_identificateur alias_identificateur_w38={0,0,"w",0,0};
429   const identificateur & w__IDNT=* (const identificateur *) &alias_identificateur_w38;
430   const alias_ref_identificateur ref_w38={-1,0,0,"w",0,0};
431   const define_alias_gen(alias_w38,_IDNT,0,&ref_w38);
432 //  const gen & w__IDNT_e = * (gen *) & alias_w38;
433 
434   static const alias_identificateur alias_identificateur_x38={0,0,"x",0,0};
435   const identificateur & x__IDNT=* (const identificateur *) &alias_identificateur_x38;
436   const alias_ref_identificateur ref_x38={-1,0,0,"x",0,0};
437   const define_alias_gen(alias_x38,_IDNT,0,&ref_x38);
438 //  const gen & x__IDNT_e = * (gen *) & alias_x38;
439 
440   static const alias_identificateur alias_identificateur_xx38={0,0,"x",0,0};
441   const identificateur & xx__IDNT=* (const identificateur *) &alias_identificateur_xx38;
442   const alias_ref_identificateur ref_xx38={-1,0,0,"x",0,0};
443   const define_alias_gen(alias_xx38,_IDNT,0,&ref_xx38);
444 //  const gen & x__IDNT_e = * (gen *) & alias_xx38;
445 
446   static const alias_identificateur alias_identificateur_y38={0,0,"y",0,0};
447   const identificateur & y__IDNT=* (const identificateur *) &alias_identificateur_y38;
448   const alias_ref_identificateur ref_y38={-1,0,0,"y",0,0};
449   const define_alias_gen(alias_y38,_IDNT,0,&ref_y38);
450 //  const gen & y__IDNT_e = * (gen *) & alias_y38;
451 
452   static const alias_identificateur alias_identificateur_z38={0,0,"z",0,0};
453   const identificateur & z__IDNT=* (const identificateur *) &alias_identificateur_z38;
454   const alias_ref_identificateur ref_z38={-1,0,0,"z",0,0};
455   const define_alias_gen(alias_z38,_IDNT,0,&ref_z38);
456 //  const gen & z__IDNT_e = * (gen *) & alias_z38;
457 #endif
458 
459   static const alias_identificateur alias_identificateur_laplace_var={0,0," s",0,0};
460   const identificateur & laplace_var=* (const identificateur *) &alias_identificateur_laplace_var;
461   const alias_ref_identificateur ref_laplace_var={-1,0,0," s",0,0};
462   const define_alias_gen(alias_laplace_var,_IDNT,0,&ref_laplace_var);
463   const gen & laplace_var_e = * (gen *) & alias_laplace_var;
464 
465   static const alias_identificateur alias_identificateur_theta38={0,0,"θ",0,0};
466   const identificateur & theta__IDNT=* (const identificateur *) &alias_identificateur_theta38;
467   const alias_ref_identificateur ref_theta38={-1,0,0,"θ",0,0};
468   const define_alias_gen(alias_theta38,_IDNT,0,&ref_theta38);
469   const gen & theta__IDNT_e = * (gen *) & alias_theta38;
470 
471   static const alias_identificateur alias_identificateur_CST38={0,0,"CST",0,0};
472   const identificateur & CST__IDNT=* (const identificateur *) &alias_identificateur_CST38;
473   const alias_ref_identificateur ref_CST38={-1,0,0,"CST",0,0};
474   const define_alias_gen(alias_CST38,_IDNT,0,&ref_CST38);
475   const gen & CST__IDNT_e = * (gen *) & alias_CST38;
476 
477   static const alias_identificateur alias_identificateur_at38={0,0,"at",0,0};
478   const identificateur & _IDNT_id_at=* (const identificateur *) &alias_identificateur_at38;
479   const alias_ref_identificateur ref_at38={-1,0,0,"at",0,0};
480   const define_alias_gen(alias_at38,_IDNT,0,&ref_at38);
481   const gen & at__IDNT_e = * (gen *) & alias_at38;
482 
483 #ifdef CAS38_DISABLED
484   define_alias_gen(alias_vx38,_IDNT,0,&ref_x38);
485 #else
486   define_alias_gen(alias_vx38,_IDNT,0,&ref_xx38);
487 #endif
488 
489 #ifdef NSPIRE
490   // gen & vx_var = * (gen *) & alias_vx38;
491   gen vx_var;
492 #else
493   gen vx_var(identificateur("x"));
494 #endif
495 
496   /* model
497   static const alias_identificateur alias_identificateur_zzz38={0,0,"ZZZ",0,0};
498   const identificateur & zzz__IDNT=* (const identificateur *) &alias_identificateur_zzz38;
499   const alias_ref_identificateur ref_zzz38={-1,0,0,"ZZZ",0,0};
500   const define_alias_gen(alias_zzz38,_IDNT,0,&ref_zzz38);
501   const gen & zzz__IDNT_e = * (gen *) & alias_zzz38;
502 
503   */
504 
505 #else // GIAC_HAS_STO_38
506   identificateur a__IDNT("a");
507   gen a__IDNT_e(a__IDNT);
508   identificateur b__IDNT("b");
509   gen b__IDNT_e(b__IDNT);
510   identificateur c__IDNT("c");
511   gen c__IDNT_e(c__IDNT);
512   identificateur d__IDNT("d");
513   gen d__IDNT_e(d__IDNT);
514   identificateur e__IDNT("e");
515   gen e__IDNT_e(e__IDNT);
516   identificateur f__IDNT("f");
517   gen f__IDNT_e(f__IDNT);
518   identificateur g__IDNT("g");
519   gen g__IDNT_e(g__IDNT);
520   identificateur h__IDNT("h");
521   gen h__IDNT_e(h__IDNT);
522   identificateur i__IDNT("i");
523   gen i__IDNT_e(i__IDNT);
524   identificateur j__IDNT("j");
525   gen j__IDNT_e(j__IDNT);
526   identificateur k__IDNT("k");
527   gen k__IDNT_e(k__IDNT);
528   identificateur l__IDNT("l");
529   gen l__IDNT_e(l__IDNT);
530   identificateur m__IDNT("m");
531   gen m__IDNT_e(m__IDNT);
532   identificateur n__IDNT("n");
533   gen n__IDNT_e(n__IDNT);
534   identificateur o__IDNT("o");
535   gen o__IDNT_e(o__IDNT);
536   identificateur p__IDNT("p");
537   gen p__IDNT_e(p__IDNT);
538   identificateur q__IDNT("q");
539   gen q__IDNT_e(q__IDNT);
540   identificateur r__IDNT("r");
541   gen r__IDNT_e(r__IDNT);
542   identificateur s__IDNT("s");
543   gen s__IDNT_e(s__IDNT);
544   identificateur t__IDNT("t");
545   gen t__IDNT_e(t__IDNT);
546   identificateur u__IDNT("u");
547   gen u__IDNT_e(u__IDNT);
548   identificateur v__IDNT("v");
549   gen v__IDNT_e(v__IDNT);
550   identificateur w__IDNT("w");
551   gen w__IDNT_e(w__IDNT);
552   identificateur x__IDNT("x");
553   gen x__IDNT_e(x__IDNT);
554   identificateur y__IDNT("y");
555   gen y__IDNT_e(y__IDNT);
556   identificateur z__IDNT("z");
557   gen z__IDNT_e(z__IDNT);
558   identificateur laplace_var(" s");
559   gen laplace_var_e(laplace_var);
560   identificateur theta__IDNT("θ");
561   gen theta__IDNT_e(theta__IDNT);
562   identificateur CST__IDNT("CST");
563   gen CST__IDNT_e(CST__IDNT);
564   identificateur _IDNT_id_at("id_at");
565   gen vx_var(x__IDNT_e);
566 #endif // GIAC_HAS_STO_38
567 
568   const gen * const tab_one_letter_idnt[]={&a__IDNT_e,&b__IDNT_e,&c__IDNT_e,&d__IDNT_e,&e__IDNT_e,&f__IDNT_e,&g__IDNT_e,&h__IDNT_e,&i__IDNT_e,&j__IDNT_e,&k__IDNT_e,&l__IDNT_e,&m__IDNT_e,&n__IDNT_e,&o__IDNT_e,&p__IDNT_e,&q__IDNT_e,&r__IDNT_e,&s__IDNT_e,&t__IDNT_e,&u__IDNT_e,&v__IDNT_e,&w__IDNT_e,&x__IDNT_e,&y__IDNT_e,&z__IDNT_e};
569 
identificateur()570   identificateur::identificateur(){
571     int_string_shortint_bool * ptr = new int_string_shortint_bool;
572     ptr->i=1;
573     ptr->b=0;
574     ptr->s_dynalloc=true;
575 #if defined GIAC_HAS_STO_38 || defined NSPIRE
576     string tmp=string("_"+print_INT_(std_rand()));
577 #else
578     string tmp=string(" "+print_INT_(std_rand()));
579 #endif
580     int l=int(tmp.size());
581     char * c = new char[l+1];
582     strcpy(c,tmp.c_str());
583     ptr->s=c;
584     ref_count = &ptr->i ;
585     value = NULL;
586     quoted = &ptr->b ;
587     localvalue = 0;
588     id_name = ptr->s ;
589   }
590 
identificateur(const string & s)591   identificateur::identificateur(const string & s){
592     bool b=strchr(s.c_str(),' ')?true:false;
593     int_string_shortint_bool * ptr = new int_string_shortint_bool;
594     ptr->i=1;
595     ptr->b=0;
596     ptr->s_dynalloc=true;
597     char * c = new char[s.size()+(b?3:1)];
598 #if defined NSPIRE || defined FXCG
599     if (b){
600       string s1=('`'+s+'`');
601       ptr->s=strcpy(c,s1.c_str());
602     }
603     else
604       ptr->s=strcpy(c,s.c_str());
605 #else
606     ptr->s=strcpy(c,b?('`'+s+'`').c_str():s.c_str());
607 #endif
608 #if defined GIAC_HAS_STO_38 || defined NSPIRE || defined FXCG
609     for (;*c;++c){
610       if (*c==' ')
611 	*c='_';
612     }
613 #endif
614     ref_count = &ptr->i ;
615     value = NULL;
616     quoted = &ptr->b ;
617     localvalue = 0;
618     id_name = ptr->s ;
619   }
620 
identificateur(const string & s,const gen & e)621   identificateur::identificateur(const string & s,const gen & e){
622     bool b=strchr(s.c_str(),' ')?true:false;
623     int_string_shortint_bool * ptr = new int_string_shortint_bool;
624     ptr->i=1;
625     ptr->b=0;
626     ptr->s_dynalloc=true;
627     char * c = new char[s.size()+(b?3:1)];
628 #if defined NSPIRE || defined FXCG
629     if (b){
630       string s1=('`'+s+'`');
631       ptr->s=strcpy(c,s1.c_str());
632     }
633     else
634       ptr->s=strcpy(c,s.c_str());
635 #else
636     ptr->s=strcpy(c,b?('`'+s+'`').c_str():s.c_str());
637 #endif
638     /* #if defined GIAC_HAS_STO_38 || defined NSPIRE
639     for (;*c;++c){
640       if (*c==' ')
641 	*c='_';
642     }
643     #endif */
644     ref_count = &ptr->i ;
645     quoted = &ptr->b ;
646     localvalue = 0;
647     id_name = ptr->s ;
648     value = new gen(e);
649   }
650 
identificateur(const char * s)651   identificateur::identificateur(const char * s){
652     if (strchr(s,' ')){
653       ref_count=0;
654       string S(s);
655 #if defined GIAC_HAS_STO_38 || defined NSPIRE || defined FXCG
656       for (unsigned i=0;i<S.size();++i){
657 	if (S[i]==' '){
658 	  S[i]='_';
659 	}
660       }
661 #endif
662       *this=identificateur(S);
663       return;
664     }
665     int_string_shortint_bool * ptr = new int_string_shortint_bool;
666     ptr->i=1;
667     ptr->b=0;
668     ptr->s=s;
669     ptr->s_dynalloc=false;
670     ref_count = &ptr->i ;
671     value = NULL;
672     quoted = &ptr->b ;
673     localvalue = 0;
674     id_name = ptr->s ;
675   }
676 
677 #ifdef GIAC_HAS_STO_38
identificateur(const char * s,bool StringIsNowYours)678   identificateur::identificateur(const char * s, bool StringIsNowYours){
679     if (strchr(s,' ')){
680       ref_count=0;
681       string S(s);
682       // #ifdef GIAC_HAS_STO_38
683       for (unsigned i=0;i<S.size();++i){
684 	if (S[i]==' '){
685 	  S[i]='_';
686 	}
687       }
688       // #endif
689       *this=identificateur(S);
690       return;
691     }
692     int_string_shortint_bool * ptr = new int_string_shortint_bool;
693     ptr->i=1;
694     ptr->b=0;
695     ptr->s=s;
696     ptr->s_dynalloc= StringIsNowYours;
697     ref_count = &ptr->i ;
698     value = NULL;
699     quoted = &ptr->b ;
700     localvalue = 0;
701     id_name = ptr->s ;
702   }
703 #endif
704 
identificateur(const char * s,const gen & e)705   identificateur::identificateur(const char * s,const gen & e){
706     if (strchr(s,' ')){
707       ref_count=0;
708       *this=identificateur(string(s),e);
709       return;
710     }
711     int_string_shortint_bool * ptr = new int_string_shortint_bool;
712     ptr->i=1;
713     ptr->b=0;
714     ptr->s=s;
715     ptr->s_dynalloc=false;
716     ref_count = &ptr->i ;
717     quoted = &ptr->b ;
718     localvalue = 0;
719     id_name = ptr->s ;
720     value = new gen(e);
721   }
722 
identificateur(const identificateur & s)723   identificateur::identificateur(const identificateur & s){
724     ref_count=s.ref_count;
725     if (ref_count)
726       ++(*ref_count);
727     value=s.value;
728     quoted=s.quoted;
729     localvalue=s.localvalue;
730     id_name=s.id_name;
731   }
732 
~identificateur()733   identificateur::~identificateur(){
734     if (ref_count){
735       --(*ref_count);
736       if (!(*ref_count)){
737 	int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
738 	if (ptr->s_dynalloc)
739 	  delete [] ptr->s;
740 	delete ptr;
741 	if (value)
742 	  delete value;
743 	if (localvalue)
744 	  delete localvalue;
745       }
746     }
747   }
748 
MakeCopyOfNameIfNotLocal()749   void identificateur::MakeCopyOfNameIfNotLocal() {
750     int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
751     if (ptr->s_dynalloc) return;
752     id_name = ptr->s= strdup(ptr->s);
753     ptr->s_dynalloc= true;
754   }
755 
operator =(const identificateur & s)756   identificateur & identificateur::operator =(const identificateur & s){
757     if (ref_count){
758       --(*ref_count);
759       if (!(*ref_count)){
760 	int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
761 	if (ptr->s_dynalloc)
762 	  delete [] ptr->s;
763 	delete ptr;
764 	if (value)
765 	  delete value;
766 	if (localvalue)
767 	  delete localvalue;
768       }
769     }
770     ref_count=s.ref_count;
771     if (ref_count)
772       ++(*ref_count);
773     value=s.value;
774     quoted=s.quoted;
775     localvalue=s.localvalue;
776     id_name=s.id_name;
777     return *this;
778   }
779 
globalize(const gen & g)780   gen globalize(const gen & g){
781     gen tmp(g);
782     switch (tmp.type){
783     case _IDNT:
784       tmp.subtype=_GLOBAL__EVAL;
785       break;
786     case _VECT:
787       if (lidnt(tmp).empty())
788 	return g;
789       tmp=apply(tmp,globalize);
790       break;
791     case _SYMB:
792       if (tmp._SYMBptr->sommet!=at_program)
793 	tmp=symbolic(tmp._SYMBptr->sommet,globalize(tmp._SYMBptr->feuille));
794       break;
795     }
796     return tmp;
797   }
798 
799   // make g identificateurs evaluated as global
global_eval(const gen & g,int level)800   gen global_eval(const gen & g,int level){
801     if (g.type<_IDNT)
802       return g;
803     bool save_local_eval=local_eval(context0);
804     local_eval(false,context0);
805     gen tmp;
806 #ifndef NO_STDEXCEPT
807     try {
808 #endif
809       tmp=g.eval(level,context0);
810 #ifndef NO_STDEXCEPT
811     }
812     catch (std::runtime_error & e){
813       cerr << e.what() << '\n';
814       // eval_level(level,contextptr);
815     }
816 #endif
817     local_eval(save_local_eval,context0);
818     return globalize(tmp);
819   }
820 
821   bool check_not_assume(const gen & not_evaled,gen & evaled, bool evalf_after,const context * contextptr);
822 
823   // make g identificateurs evaluated as global
global_evalf(const gen & g,int level)824   gen global_evalf(const gen & g,int level){
825     if (g.type<_IDNT)
826       return g;
827     bool save_local_eval=local_eval(context0);
828     local_eval(false,context0);
829     gen tmp;
830 #ifndef NO_STDEXCEPT
831     try {
832 #endif
833       tmp=g.eval(level,context0);
834       if (tmp.type==_IDNT){
835 	gen evaled(tmp._IDNTptr->eval(level,tmp,context0));
836 	if (check_not_assume(tmp,evaled,true,context0))
837 	  tmp=evaled;
838       }
839 #ifndef NO_STDEXCEPT
840     }
841     catch (std::runtime_error & e){
842       cerr << e.what() << '\n';
843       // eval_level(level,contextptr);
844     }
845 #endif
846     local_eval(save_local_eval,context0);
847     return globalize(tmp);
848   }
849 
850   gen _prod(const gen & args,GIAC_CONTEXT);
851 #if 0
852   static inline bool eval_38(int level,const gen & orig,gen & res,const char * s,GIAC_CONTEXT){
853     if (storcl_38 && storcl_38(res,0,s,undef,false,contextptr,NULL)){
854       return true;
855     }
856     return false;
857     size_t ss=strlen(s);
858 #ifdef GIAC_HAS_STO_38
859     if (
860 	(ss>1 && s[0]=='G')
861 #ifndef CAS38_DISABLED
862 	|| (ss==1 && s[0]>='a' && s[0]<='z')
863 #endif
864 	){ // checking for a geometry global variables
865       if (contextptr){
866 	sym_tab::const_iterator it=contextptr->globalcontextptr->tabptr->find(s);
867 	if (it!=contextptr->globalcontextptr->tabptr->end()){
868 	  res=it->second;
869 	  return true;
870 	}
871       }
872       res=orig;
873       return false;
874     }
875 #endif
876     if (calc_mode(contextptr)!=38 || !strcmp(s,string_pi) || !strcmp(s,string_euler_gamma) || !strcmp(s,string_infinity) || !strcmp(s,string_undef)){
877       res=orig;
878       return false;
879     }
880     if (ss<=1){
881       if (s[0]>'Z'){
882 	res=orig;
883 	return false;
884       }
885       res=0.0;
886       return true;
887     }
888     if (ss==2 && s[1]<='9') {
889       res=orig;
890       gen tmp,evaled;
891       switch(s[0]){
892       case 'C': case 'L':
893 	res=gen(vecteur(0),_LIST__VECT);
894 	break;
895       case 'E': case 'H': /* case 'S': */
896 	return false;
897       case 'G': // FIXME: grob
898 	return false;
899       case 'F': case 'R': case 'U': case 'X': case 'Y':
900 	if (calc_mode(contextptr)==38)
901 	  res=gensizeerr(gettext("Function not defined"));
902 	return true;
903       case 'M':
904 	res=makevecteur(makevecteur(0));
905 	break;
906       case 'V':
907 	res=makevecteur(0);
908 	break;
909       case 'Z':
910 	res=0.0;
911 	break;
912       case 'i':
913 	res=(s[1]-'0')*cst_i;
914 	break;
915       case 'e':
916 	res=(s[1]-'0')*std::exp(1.0);
917 	break;
918       default:
919 	tmp=identificateur(string(1,s[0]));
920 	if (tmp._IDNTptr->in_eval(1,tmp,evaled,contextptr))
921 	  res=(s[1]-'0')*evaled;
922 	else
923 	  res=0.0;
924       }
925       return true;
926     }
927     char ch;
928     for (size_t i=0;i<ss;++i){
929       ch=s[i];
930       if ( (ch>'Z' && ch!='i' && ch!='e')|| ch<'0'){
931 	res=orig;
932 	return false;
933       }
934     }
935     // all chars are regular 38 characters, split as a product
936     vecteur args;
937     gen g;
938     for (size_t i=0;i<ss;++i){
939       ch=s[i];
940       if (ch=='C' || (ch>='E' && ch<='H') || ch=='L' || ch=='M' || ch=='R'
941 	  /* || ch=='S' */
942 	  || ch=='U' || ch=='V' || (ch>='X' && ch<='Z')){
943 	string name;
944 	name += ch;
945 	char c=0;
946 	if (i<ss-1)
947 	  c=s[i+1];
948 	if (c>='0' && c<='9'){
949 	  name += c;
950 	  ++i;
951 	}
952 	g=identificateur(name);
953 	g=g.eval(level,contextptr);
954 	args.push_back(g);
955       }
956       else {
957 	string coeff;
958 	for (++i;i<ss;++i){
959 	  if (s[i]>32 && isalpha(s[i])){
960 	    --i;
961 	    break;
962 	  }
963 	  coeff += s[i];
964 	}
965 	if (coeff.empty())
966 	  g=1;
967 	else
968 	  g=atof(coeff.c_str());
969 	if (ch=='i')
970 	  g=g*cst_i;
971 	else {
972 	  if (ch=='e')
973 	    g=std::exp(1.0)*g;
974 	  else {
975 	    coeff="";
976 	    coeff += ch;
977 	    gen tmp=identificateur(coeff),evaled;
978 	    if (tmp._IDNTptr->in_eval(1,tmp,evaled,contextptr))
979 	      g=g*evaled;
980 	    else
981 	      g=0.0;
982 	  }
983 	}
984 	args.push_back(g);
985       }
986     }
987     res=_prod(args,contextptr);
988     return true;
989   }
990 #endif
991 
eval(int level,const gen & orig,const context * contextptr)992   gen identificateur::eval(int level,const gen & orig,const context * contextptr) {
993     if (!ref_count)
994       return orig;
995     gen evaled;
996     // cerr << "idnt::eval " << *this << " " << level << '\n';
997     if (level<=0){
998       if (level==0)
999 	return orig;
1000       // If 38 is there, let it look at the current state and decide if it needs to evaluate the name or if it needs to let the CAS do it
1001       // This will depend on the order of priorities and the status of the requested variable (local/global...)
1002       if (storcl_38 && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr,NULL,false)) return evaled;
1003       if (contextptr){
1004 	sym_tab::const_iterator it=contextptr->tabptr->find(id_name),itend=contextptr->tabptr->end();
1005 	if (it!=itend)
1006 	  return it->second;
1007 	//if (abs_calc_mode(contextptr)==38){
1008 	//  gen evaled;
1009 	//  if (eval_38(level,orig,evaled,id_name,contextptr))
1010 	//    return evaled;
1011 	//}
1012 	return orig;
1013       }
1014       else {
1015 	if (!localvalue || localvalue->empty())
1016 	  return orig;
1017 	iterateur jtend=localvalue->end();
1018 	return (protection_level>(jtend-2)->val)?localvalue->back():orig;
1019       }
1020     }
1021     --level;
1022     if (in_eval(level,orig,evaled,contextptr))
1023       return evaled;
1024     else
1025       return *this;
1026     /*
1027     int save_level=eval_level(contextptr);
1028     eval_level(level,contextptr);
1029     gen res=in_eval(level,contextptr);
1030     eval_level(save_level,contextptr);
1031     return res;
1032     */
1033   }
1034 
1035   // if globalize is true, use global value in eval
do_local_eval(const identificateur & i,int level,bool globalize)1036   gen do_local_eval(const identificateur & i,int level,bool globalize) {
1037     if (!i.localvalue)
1038       return i;
1039     gen res;
1040     iterateur jtend=i.localvalue->end();
1041     if (protection_level>(jtend-2)->val)
1042       res=i.localvalue->back();
1043     else {
1044       for (iterateur jt=i.localvalue->begin();;){
1045 	if (jt==jtend)
1046 	  break;
1047 	--jtend;
1048 	--jtend;
1049 	if (protection_level>jtend->val){
1050 	  ++jtend;
1051 	  ++jtend;
1052 	  break;
1053 	}
1054       }
1055       i.localvalue->erase(jtend,i.localvalue->end());
1056       if (!i.localvalue->empty())
1057 	res=i.localvalue->back();
1058     }
1059     return globalize?global_eval(res,level):res;
1060   }
1061 
printsymtab(sym_tab * ptr)1062   void printsymtab(sym_tab * ptr){
1063     sym_tab::const_iterator it=ptr->begin(),itend=ptr->end();
1064     for (;it!=itend;++it)
1065       CERR << it->first << ":" << it->second << '\n';
1066   }
1067 
in_eval(int level,const gen & orig,gen & evaled,const context * contextptr,bool No38Lookup)1068   bool identificateur::in_eval(int level,const gen & orig,gen & evaled,const context * contextptr, bool No38Lookup) {
1069     // if (!ref_count) return false; // does not work for cst ref identificateur
1070     if (contextptr){ // Look for local variables...
1071       // If 38 is there, let it look at variable priorities, but ONLY looking at local for the moment! We do not want to look as globals as they might need to be quoted...
1072       if (storcl_38!=NULL && !No38Lookup && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr, NULL, true))
1073 	return true;
1074       const context * cur=contextptr;
1075       int pythoncompat=python_compat(contextptr)?2:0;
1076       for (;cur->previous;cur=cur->previous){
1077 	sym_tab::const_iterator it=cur->tabptr->find(id_name);
1078 	if (it!=cur->tabptr->end()){
1079 	  if (!level || !it->second.in_eval(level,evaled,contextptr->globalcontextptr))
1080 	    evaled=it->second;
1081 	  return true;
1082 	}
1083 	if (pythoncompat){
1084 	  --pythoncompat;
1085 	  if (!pythoncompat){
1086 	    while (cur->previous)
1087 	      cur=cur->previous;
1088 	    break;
1089 	  }
1090 	}
1091       }
1092       // now at global level
1093       // check for quoted
1094       if (cur->quoted_global_vars && !cur->quoted_global_vars->empty() && equalposcomp(*cur->quoted_global_vars,orig))
1095 	return false;
1096       // If 38 is there, look again, but now it is allowed to look at local and globals!
1097       if (storcl_38!=NULL && !No38Lookup && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr, NULL, false))
1098 	return true;
1099       // printsymtab(cur->tabptr);
1100       sym_tab::const_iterator it=cur->tabptr->find(id_name);
1101       if (it==cur->tabptr->end()){
1102         //if (No38Lookup) return false;
1103 	//if (storcl_38 && abs_calc_mode(contextptr)==38)
1104 	//  return eval_38(level,orig,evaled,id_name,contextptr);
1105 	return false;
1106       }
1107       else {
1108 	if (!it->second.in_eval(level,evaled,contextptr->globalcontextptr))
1109 	  evaled=it->second;
1110 	return true;
1111       }
1112       //if (!No38Lookup && storcl_38){ //  && abs_calc_mode(contextptr)==38)
1113       //   if (eval_38(level,orig,evaled,id_name,contextptr))
1114       //      return true;
1115       //}
1116     }
1117     if (local_eval(contextptr) && localvalue && !localvalue->empty()){
1118       evaled=do_local_eval(*this,level,true);
1119       return true;
1120     }
1121     if (quoted && *quoted & 1)
1122       return false;
1123     if (current_folder_name.type==_IDNT && current_folder_name._IDNTptr->value && current_folder_name._IDNTptr->value->type==_VECT){
1124       evaled=find_in_folder(*current_folder_name._IDNTptr->value->_VECTptr,orig);
1125       return (evaled!=orig);
1126     }
1127     if (value){
1128       evaled=value->eval(level,contextptr);
1129       return true;
1130     }
1131     // look in current directory for a value
1132     if ( secure_run || (!variables_are_files(contextptr))
1133 #if !defined __MINGW_H && !defined NSPIRE && !defined FXCG
1134 	 || (access((name()+string(cas_suffixe)).c_str(),R_OK))
1135 #endif
1136 	 ){
1137       evaled=orig;
1138       if (!local_eval(contextptr))
1139 	evaled.subtype=_GLOBAL__EVAL;
1140       return true;
1141     }
1142 #if !defined NSPIRE && !defined FXCG && !defined GIAC_HAS_STO_38
1143     // set current value
1144     ifstream inf((name()+string(cas_suffixe)).c_str());
1145     evaled=read1arg_from_stream(inf,contextptr);
1146     if (child_id)
1147       return true;
1148     value = new gen(evaled);
1149     evaled=evaled.eval(level,contextptr);
1150 #endif
1151     return true;
1152   }
1153 
push(int protection,const gen & e)1154   void identificateur::push(int protection,const gen & e){
1155     if (!localvalue)
1156       localvalue=new vecteur;
1157     localvalue->push_back(protection);
1158     localvalue->push_back(e);
1159   }
1160 
print(GIAC_CONTEXT) const1161   const char * identificateur::print(GIAC_CONTEXT) const{
1162     if (!strcmp(id_name,string_pi)){
1163 #ifndef KHICAS
1164       if (abs_calc_mode(contextptr)==38)
1165 #endif
1166 	return "π";
1167       switch (xcas_mode(contextptr)){
1168       case 1:
1169 	return "Pi";
1170       case 2:
1171 	return "PI";
1172       default:
1173 	return string_pi;
1174       }
1175     }
1176     if (
1177 	//calc_mode(contextptr)!=1 &&
1178 	abs_calc_mode(contextptr)==38 &&
1179 	!strcmp(id_name,string_infinity))
1180       return "±∞";
1181     // index != sqrt(-1) wich has different notations
1182     if (xcas_mode(contextptr)==0){
1183       if (strcmp(id_name,"i")==0)
1184 	return "i_i_";
1185     }
1186     else {
1187       if (strcmp(id_name,"I")==0)
1188 	return "i_i_";
1189     }
1190     /*
1191     if (!localvalue->empty())
1192       return string("_") + *name ;
1193     if (value)
1194       return string("~") + *name ;
1195     else
1196     */
1197     return id_name  ;
1198   }
1199 
1200 #ifdef NSPIRE
1201   template<class T>
operator <<(nio::ios_base<T> & os,const identificateur & s)1202   nio::ios_base<T> & operator << (nio::ios_base<T> & os,const identificateur & s) { return os << s.print(context0);}
1203 #else
operator <<(ostream & os,const identificateur & s)1204   ostream & operator << (ostream & os,const identificateur & s) { return os << s.print(context0);}
1205 #endif
1206 
removecomments(const char * ss,char * ss2)1207   int removecomments(const char * ss,char * ss2){
1208     int j=0,k=0;
1209     for (;ss[j];j++){
1210       if (ss[j]=='#'){
1211 	ss2[k]=char(0); // end ss2 string
1212 	break;
1213       }
1214       if (ss[j]>31){ // supress control chars
1215 	ss2[k]=ss[j];
1216 	k++;
1217       }
1218     }
1219     return k;
1220   }
1221 
unassign()1222   void identificateur::unassign(){
1223     if (value){
1224       delete(value);
1225       value = NULL;
1226     }
1227   }
1228 
1229 #ifndef NO_NAMESPACE_GIAC
1230 } // namespace giac
1231 #endif // ndef NO_NAMESPACE_GIAC
1232