1 /*----------------------------------------------------------------------------
2                   script.cc (main routine of script execution)
3                        This file is a part of topaz systems
4                   Copyright: Hisao Kawaura, All rights reserved
5                                    1997 - 98
6 
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 ----------------------------------------------------------------------------*/
23 
24 #include  <stdio.h>
25 #include  <math.h>
26 #include  <stdlib.h>
27 #include  <string>
28 #include  <ctype.h>
29 #include  <string.h>
30 #include  <unistd.h>
31 #include  <time.h>
32 
33 #include "script.h"
34 #include "system.h"
35 #include "tokenbuff.h"
36 #include "graph.h"
37 #include "buffarray.h"
38 #include "cui.h"
39 #include "browse.h"
40 #include "objectlist.h"
41 #include "pipecall.h"
42 #include "minmax.h"
43 #include "gamma.h"
44 #include "filepoint.h"
45 #include "convtxt.h"
46 #include "msgbuff.h"
47 #include "topazvalues.h"
48 #include "regexpress.h"
49 
50 extern bool dinvq(double in, double *out);
51 extern WINDOW *menuwin, *msgwin, *sepwin ,*titlewin;
52 extern FileHandleArray *fhvuff;
53 extern void cuimenu();
54 extern void showsepwin();
55 extern void message(const char *msg);
56 extern msgbuff* msgb;
57 extern int emessage(int lineno, char *mes, const char *com, char *scrname);
58 
59 #define GRAPHOBJ_INVALID  0
60 #define GRAPHOBJ_SCALAR   1
61 #define GRAPHOBJ_ARRAY    2
62 
script(graph * g)63 script::script(graph *g)
64 {
65   scriptname = new std::string("");
66   stack   = new vstackarray(0);
67   polish  = new vstackarray(0);
68   v       = new stackarray(0);
69   buff    = new stackarray(0);
70   vbuff   = new VariantBuff;
71   gra = g;
72   prevscr = 0;
73 
74   int i;
75   for (i = 0; i < STRSTATUS_BUFF_LEN; i++)
76     strstatusbuff[i] = 0;
77 
78   for (i = 0; i < BRACESTATUS_BUFF_LEN; i++)
79     bracestatusbuff[i] = 0;
80 
81 }
82 
script(graph * g,script * scr)83 script::script(graph *g, script *scr)
84 {
85   prevscr = scr;
86   scriptname = new std::string("");
87   stack   = new vstackarray(0);
88   polish  = new vstackarray(0);
89   v       = new stackarray(0);
90   buff    = new stackarray(0);
91   vbuff   = prevscr->vbuff;
92   gra = g;
93 
94   int i;
95   for (i = 0; i < STRSTATUS_BUFF_LEN; i++)
96     strstatusbuff[i] = 0;
97 
98   for (i = 0; i < BRACESTATUS_BUFF_LEN; i++)
99     bracestatusbuff[i] = 0;
100 
101 }
102 
~script()103 script::~script()
104 {
105   delete scriptname;
106   delete stack;
107   delete polish;
108   delete v;
109   delete buff;
110 
111   if (prevscr == 0)
112     delete vbuff;
113 }
114 
115 
116 
GetValue(tokenbuff * token,std::string * outstring)117 bool script::GetValue(tokenbuff *token, std::string *outstring)
118 {
119   std::string tempvalue, tempstring, tempstring1;
120 
121   if (token->strstatus == STR_UQUOTE)
122     {
123       switch(token->status)
124 	{
125 	case NUM:
126 	  if (execchildprocess(&(*token->value)[0], outstring) == EXIT_SUCCESS)
127 	  {
128 	    token->strstatus = STR_NORMAL;
129 	    return true;
130 	  }
131 	  else
132 	    return false;
133 	  break;
134 	}
135     }
136   else
137     return GetImplicitValue(token, outstring);
138   return true;
139 }
140 
GetImplicitValue(tokenbuff * token,std::string * outstring)141 bool script::GetImplicitValue(tokenbuff *token,  std::string *outstring)
142 {
143   std::string tempvalue, tempstring, tempstring1;
144   tokenbuff temptoken;
145   std::string out;
146   int id;
147 
148   switch(token->status)
149     {
150     case NUM:
151       *outstring = (*token->value)[0];
152       return true;
153       break;
154     case VARIANT:
155       if (vbuff->GetScalar(token->label, &tempvalue) == true)
156 	{
157 	  *outstring = tempvalue;
158 	  return true;
159 	}
160       else
161 	return errormessage(token->lineno, "not defined", token->label->c_str());
162       break;
163     case ARRAYVARIANT:
164       tempstring = std::string("@");
165       tempstring1 = std::string((const char *)(token->label->c_str() + 1));
166       tempstring += tempstring1;
167       if (vbuff->Get(&tempstring, atoi((*token->value)[0].c_str()), &tempvalue) == true)
168 	{
169 	  *outstring = tempvalue;
170 	  return true;
171 	}
172       else
173 	{
174 	  tempstring = *token->label + std::string("[") + (*token->value)[0] + std::string("]");
175 	  return errormessage(token->lineno, "not defined", tempstring.c_str());
176 	}
177       break;
178     case OBJ_MEMBER:
179        if (gra->topobject(token->label, &out, &id) == true)
180 	{
181 	  if (out == std::string("$graph") && id == -1)
182 	    {
183 	      if (gra->shrinkobject(token->label, &out) == true)
184 		{
185 		  if (gra->get(&out,  &temptoken))
186 		  {
187 		    *outstring = (*temptoken.value)[0];
188 		    return true;
189 		  }
190 		  else
191 		    return errormessage(token->lineno, "not defined", token->label->c_str());
192 		}
193 	      else
194 		return errormessage(token->lineno, "not defined", token->label->c_str());
195 	    }
196 	  else
197 	    return errormessage(token->lineno, "not defined", token->label->c_str());
198 	}
199       else
200 	return errormessage(token->lineno, "not defined", token->label->c_str());
201       break;
202     default:
203       return false;
204     }
205   return true;
206 }
207 
errormessage(int lineno,char * mes,const char * com)208 int script::errormessage(int lineno, char *mes, const char *com)
209 {
210   return emessage(lineno, mes, com, (char *)scriptname->c_str());
211 }
212 
213 
214 
215 //*****************************************
216 //************* objpointer ****************
217 //*****************************************
o_objpointer(script * scr,int st,int lineno)218 int o_objpointer(script *scr, int st, int lineno)
219 {
220   stackarray *v = scr->v;
221   std::string str1;
222   char stemp[1024];
223   std::string out;
224   int id;
225   int graphobjtype;
226   buffarray tempbuffarray;
227   tokenbuff temptoken;
228   int itemp;
229 
230   if (st != OBJ_POINTER)
231     return scr->errormessage(lineno, "invalid operator", "->");
232 
233   if (v->getarraylength() > 1 )
234     {
235       // object member
236       if ((*v)[v->getarraylength() - 2].status == OBJ_MEMBER
237 	  &&
238 	  ((*v)[v->getarraylength() - 1].status == OBJ_ARRAYMEMBER
239 	   || (*v)[v->getarraylength() - 1].status == OBJ_MEMBER))
240 	{
241 	  (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
242 
243 	  if ((*v)[v->getarraylength() - 1].status == OBJ_MEMBER)
244 	    {
245 	      *(*v)[v->getarraylength() - 2].label += std::string("->") + *(*v)[v->getarraylength() - 1].label;
246 	      (*v)[v->getarraylength() - 2].status = OBJ_MEMBER;
247 	      v->pop();
248 	    }
249 	  else if ((*v)[v->getarraylength() - 1].status == OBJ_ARRAYMEMBER)
250 	    {
251 	      *(*v)[v->getarraylength() - 2].label += std::string("->")
252 		+ *(*v)[v->getarraylength() - 1].label
253 		+ std::string("[")
254 		+(*(*v)[v->getarraylength() - 1].value)[0]
255 		+ std::string("]");
256 	      (*v)[v->getarraylength() - 2].status = OBJ_MEMBER;
257 	      v->pop();
258 	    }
259 	  else
260 	    return scr->errormessage(lineno, "invalid operator", "->");
261 	}
262       else if (v->getarraylength() > 2)
263 	{
264 	  // object method
265 	  if ((*v)[v->getarraylength() - 3].status == OBJ_MEMBER
266 	      && (*v)[v->getarraylength() - 1].status == OBJ_METHOD)
267 	    {
268 	      *(*v)[v->getarraylength() - 3].label += std::string("->") + *(*v)[v->getarraylength() - 1].label;
269 
270 	      //must execute method here!!
271 	      if ((*v)[v->getarraylength() - 2].status == NUM
272 		  || (*v)[v->getarraylength() - 2].status == VARIANT
273 		  || (*v)[v->getarraylength() - 2].status == ARRAYVARIANT
274 		  || (*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
275 		{
276 		  if (scr->gra->topobject((*v)[v->getarraylength() - 3].label, &out, &id) == true)
277 		    {
278 		      if (out == std::string("$graph"))
279 			graphobjtype = GRAPHOBJ_SCALAR;
280 		      else if (out == std::string("@graph"))
281 			graphobjtype = GRAPHOBJ_ARRAY;
282 		      else
283 			graphobjtype = GRAPHOBJ_INVALID;
284 
285 		      if (graphobjtype != GRAPHOBJ_INVALID && id == -1)
286 			{
287 			  if (scr->gra->shrinkobject((*v)[v->getarraylength() - 3].label, &out) == true)
288 			    {
289 			      if (scr->GetValue(&(*v)[v->getarraylength() - 2], &str1))
290 				{
291 				  tempbuffarray.setarray(0);
292 				  tempbuffarray.add(str1.c_str());
293 
294 				  temptoken.value->setbuff(0);
295 				  if (scr->gra->exec(&out, &tempbuffarray, &temptoken))
296 				    {
297 				      (*v)[v->getarraylength() - 3] = temptoken;
298 				      *(*v)[v->getarraylength() - 3].label = std::string("");
299 
300 				      if (temptoken.value->getarraylength() == 0)
301 					v->pop();
302 				      else if (temptoken.value->getarraylength() == 1 && graphobjtype == GRAPHOBJ_SCALAR)
303 					(*v)[v->getarraylength() - 3].status = NUM;
304 				      else if (temptoken.value->getarraylength() > 1 && graphobjtype == GRAPHOBJ_ARRAY)
305 					(*v)[v->getarraylength() - 3].status = IMPLICITARRAY;
306 				      else
307 					return scr->errormessage(lineno, "invalid return", out.c_str());
308 				    }
309 				  else
310 				    return scr->errormessage(lineno, "execution error", out.c_str());
311 				}
312 			      else
313 				return scr->errormessage(lineno, "invalid arguments", out.c_str());
314 			    }
315 			  else
316 			    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
317 			}
318 		      else
319 			return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
320 		    }
321 		  else
322 		    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
323 		}
324 	      else if ((*v)[v->getarraylength() - 2].status == IMPLICITARRAY)
325 		{
326 		  if (scr->gra->topobject((*v)[v->getarraylength() - 3].label, &out, &id) == true)
327 		    {
328 		      if (out == std::string("$graph"))
329 			graphobjtype = GRAPHOBJ_SCALAR;
330 		      else if (out == std::string("@graph"))
331 			graphobjtype = GRAPHOBJ_ARRAY;
332 		      else
333 			graphobjtype = GRAPHOBJ_INVALID;
334 
335 		      if (graphobjtype != GRAPHOBJ_INVALID && id == -1)
336 			{
337 			  if (scr->gra->shrinkobject((*v)[v->getarraylength() - 3].label, &out) == true)
338 			    {
339 			      temptoken.value->setbuff(0);
340 			      if (scr->gra->exec(&out, (*v)[v->getarraylength() - 2].value, &temptoken))
341 				{
342 				  (*v)[v->getarraylength() - 3] = temptoken;
343 				  *(*v)[v->getarraylength() - 3].label = std::string("");
344 
345 				  if (temptoken.value->getarraylength() == 0)
346 				    v->pop();
347 				  else if (temptoken.value->getarraylength() == 1 && graphobjtype == GRAPHOBJ_SCALAR)
348 				    (*v)[v->getarraylength() - 3].status = NUM;
349 				  else if (temptoken.value->getarraylength() > 1 && graphobjtype == GRAPHOBJ_ARRAY)
350 				    (*v)[v->getarraylength() - 3].status = IMPLICITARRAY;
351 				  else
352 				    return scr->errormessage(lineno, "invalid return", out.c_str());
353 				}
354 			      else
355 				return scr->errormessage(lineno, "execution error", out.c_str());
356 			    }
357 			  else
358 			    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
359 			}
360 		      else
361 			return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
362 		    }
363 		  else
364 		    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
365 		}
366 	      else if ((*v)[v->getarraylength() - 2].status == ARRAY)
367 		{
368 		  if (scr->gra->topobject((*v)[v->getarraylength() - 3].label, &out, &id) == true)
369 		    {
370 		      if (out == std::string("$graph"))
371 			graphobjtype = GRAPHOBJ_SCALAR;
372 		      else if (out == std::string("@graph"))
373 			graphobjtype = GRAPHOBJ_ARRAY;
374 		      else
375 			graphobjtype = GRAPHOBJ_INVALID;
376 
377 		      if (graphobjtype != GRAPHOBJ_INVALID && id == -1)
378 			{
379 			  if (scr->gra->shrinkobject((*v)[v->getarraylength() - 3].label, &out) == true)
380 			    {
381 			      tempbuffarray.setarray(0);
382 			      for (itemp = 0;
383 				   itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 2].label);
384 				   itemp++)
385 				{
386 				  scr->vbuff->Get((*v)[v->getarraylength() - 2].label, itemp, &str1);
387 				  tempbuffarray.add(str1.c_str());
388 				}
389 			      temptoken.value->setbuff(0);
390 			      if (scr->gra->exec(&out, &tempbuffarray, &temptoken))
391 				{
392 				  (*v)[v->getarraylength() - 3] = temptoken;
393 				  *(*v)[v->getarraylength() - 3].label = std::string("");
394 
395 				  if (temptoken.value->getarraylength() == 0)
396 				    v->pop();
397 				  else if (temptoken.value->getarraylength() == 1 && graphobjtype == GRAPHOBJ_SCALAR)
398 				    (*v)[v->getarraylength() - 3].status = NUM;
399 				  else if (temptoken.value->getarraylength() > 1 && graphobjtype == GRAPHOBJ_ARRAY)
400 				    (*v)[v->getarraylength() - 3].status = IMPLICITARRAY;
401 				  else
402 				    return scr->errormessage(lineno, "invalid return", out.c_str());
403 				}
404 			      else
405 				return scr->errormessage(lineno, "execution error", out.c_str());
406 			    }
407 			  else
408 			    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
409 			}
410 		      else
411 			return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
412 		    }
413 		  else
414 		    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
415 		}
416 	      else
417 		return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
418 	      v->pop();
419 	      v->pop();
420 	    }
421 	  else
422 	    return scr->errormessage(lineno, "invalid object", (*v)[v->getarraylength() - 3].label->c_str());
423 	}
424       else
425 	return scr->errormessage(lineno, "invalid object", "");
426     }
427   else
428     return scr->errormessage(lineno, "invalid object", "");
429 
430   return true;
431 }
432 
433 //*****************************************
434 //************* set ***********************
435 //*****************************************
o_set(script * scr,int st,int lineno)436 int o_set(script *scr, int st, int lineno)
437 {
438   stackarray *v = scr->v;
439   std::string str1, str2, str3, str4, tempstring, tempstring1;
440   bool b1;
441   char stemp[1024];
442   FILE *h;
443   std::string out;
444   int id, itemp;
445 
446   if (st != SET)
447     return scr->errormessage(lineno, "invalid operator", "=");
448 
449   if (v->getarraylength() > 1 )
450     {
451       if ((*v)[v->getarraylength() - 2].status == VARIANT)
452 	{
453 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
454 	  if (b1)
455 	    {
456 	      if (!scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label, &str1))
457 		return false;
458 	      (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
459 	      *(*v)[v->getarraylength() - 2].label = std::string("");
460 	      (*v)[v->getarraylength() - 2].status = NUM;
461 	      v->pop();
462 	    }
463 	  else
464 	    {
465 	      if ((*v)[v->getarraylength() - 1].status == ARRAY)
466 		{
467 		  sprintf(stemp, "%d", scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label));
468 		  str4 = std::string(stemp);
469 		  scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label
470 				   , &str4);
471 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
472 		  *(*v)[v->getarraylength() - 2].label = std::string("");
473 		  (*v)[v->getarraylength() - 2].status = NUM;
474 		  v->pop();
475 		}
476 	      else if ((*v)[v->getarraylength() - 1].status == IMPLICITARRAY)
477 		{
478 		  sprintf(stemp, "%d", (*v)[v->getarraylength() - 2].value->getarraylength());
479 		  str4 = std::string(stemp);
480 		  scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label
481 				   , &str4);
482 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
483 		  *(*v)[v->getarraylength() - 2].label = std::string("");
484 		  (*v)[v->getarraylength() - 2].status = NUM;
485 		  v->pop();
486 		}
487 	      //read a line from file
488 	      else if ((*v)[v->getarraylength() - 1].status == READPIPE)
489 		{
490 		  if (fhvuff->get((*v)[v->getarraylength() - 1].label, &h, &itemp, &str3))
491 		    {
492 		      if (ReadLine(h, &str2))
493 			{
494 			  if (!scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label, &str2))
495 			    return false;
496 			  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
497 			}
498 		      else
499 			(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
500 
501 
502 		      *(*v)[v->getarraylength() - 2].label = std::string("");
503 		      (*v)[v->getarraylength() - 2].status = NUM;
504 		      v->pop();
505 		    }
506 		  else
507 		    return scr->errormessage(lineno, "could not get file handle", "=");
508 		}
509 	      else
510 		return scr->errormessage(lineno, "invalid operator", "=");
511 	    }
512 	}
513       else if ((*v)[v->getarraylength() - 2].status == ARRAY)
514 	{
515 	  if ((*v)[v->getarraylength() - 1].status == NUM)
516 	    {
517 	      scr->vbuff->SetArray((*v)[v->getarraylength() - 2].label
518 			      , atoi((*(*v)[v->getarraylength() - 1].value)[0].c_str()));
519 
520 	      (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
521 	      *(*v)[v->getarraylength() - 2].label = std::string("");
522 	      (*v)[v->getarraylength() - 2].status = NUM;
523 	      v->pop();
524 	    }
525 	  else if ((*v)[v->getarraylength() - 1].status == IMPLICITARRAY)
526 	    {
527 	      if (scr->vbuff->SetArray((*v)[v->getarraylength() - 2].label
528 				  , (*v)[v->getarraylength() - 1].value->getarraylength()) == true)
529 		{
530 		  for (itemp = 0; itemp < (*v)[v->getarraylength() - 1].value->getarraylength(); itemp++)
531 		    {
532 		      str1 = (*v)[v->getarraylength() - 1].value->getdata(itemp);
533 		      scr->vbuff->Set((*v)[v->getarraylength() - 2].label,
534 				 itemp,
535 				 &str1);
536 		    }
537 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
538 		  *(*v)[v->getarraylength() - 2].label = std::string("");
539 		  (*v)[v->getarraylength() - 2].status = NUM;
540 		  v->pop();
541 		}
542 	      else
543 		return scr->errormessage(lineno, "could not allocate memory", "=");
544 	    }
545 	  else if ((*v)[v->getarraylength() - 1].status == ARRAY)
546 	    {
547 	      if (scr->vbuff->SetArray((*v)[v->getarraylength() - 2].label
548 				  , scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label)) == true)
549 		{
550 		  for (itemp = 0; itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label); itemp++)
551 		    {
552 		      scr->vbuff->Get((*v)[v->getarraylength() - 1].label, itemp, &str1);
553 		      scr->vbuff->Set((*v)[v->getarraylength() - 2].label, itemp, &str1);
554 		    }
555 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
556 		  *(*v)[v->getarraylength() - 2].label = std::string("");
557 		  (*v)[v->getarraylength() - 2].status = NUM;
558 		  v->pop();
559 		}
560 	      else
561 		return scr->errormessage(lineno, "could not allocate memory", "=");
562 	    }
563 	  //read all lines from file
564 	  else if ((*v)[v->getarraylength() - 1].status == READPIPE)
565 	    {
566 	      if (fhvuff->get((*v)[v->getarraylength() - 1].label, &h, &itemp, &str3))
567 		{
568 		  if (ReadAllLines(h, (*v)[v->getarraylength() - 1].value))
569 		    {
570 		      if (scr->vbuff->SetArray((*v)[v->getarraylength() - 2].label
571 					  , (*v)[v->getarraylength() - 1].value->getarraylength()) == true)
572 			{
573 			  for (itemp = 0; itemp < (*v)[v->getarraylength() - 1].value->getarraylength(); itemp++)
574 			    {
575 			      str1 = (*v)[v->getarraylength() - 1].value->getdata(itemp);
576 			      scr->vbuff->Set((*v)[v->getarraylength() - 2].label,
577 					 itemp,
578 					 &str1);
579 			    }
580 			  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
581 			  *(*v)[v->getarraylength() - 2].label = std::string("");
582 			  (*v)[v->getarraylength() - 2].status = NUM;
583 			  v->pop();
584 			}
585 		      else
586 			return scr->errormessage(lineno, "could not allocate memory", "=");
587 		    }
588 		  else
589 		    return scr->errormessage(lineno, "could not read lines", "=");
590 		}
591 	      else
592 		return scr->errormessage(lineno, "could not get file handle", "=");
593 	    }
594 	  else
595 	    return scr->errormessage(lineno, "invalid operator", "=");
596 	}
597       else if ((*v)[v->getarraylength() - 2].status == ARRAYVARIANT)
598 	{
599 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
600 	  if (b1)
601 	    {
602 	      tempstring = std::string("@");
603 	      tempstring1 = std::string((const char *)((*v)[v->getarraylength() - 2].label->c_str()) + 1);
604 	      tempstring += tempstring1;
605 
606 	      if (scr->vbuff->Set(&tempstring
607 			     , atoi((*(*v)[v->getarraylength() - 2].value)[0].c_str())
608 			     , &str1))
609 		{
610 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
611 		  *(*v)[v->getarraylength() - 2].label = std::string("");
612 		  (*v)[v->getarraylength() - 2].status = NUM;
613 		  v->pop();
614 		}
615 	      else
616 		return scr->errormessage(lineno, "could not allocate memory", "=");
617 	    }
618 	  else
619 	    return scr->errormessage(lineno, "invalid arguments", "=");
620 	}
621       else if ((*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
622 	{
623 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
624 	  if (b1)
625 	    {
626 	      if (scr->gra->topobject((*v)[v->getarraylength() - 2].label, &out, &id) == true)
627 		{
628 		  if (out == std::string("$graph") && id == -1)
629 		    {
630 		      if (scr->gra->shrinkobject((*v)[v->getarraylength() - 2].label, &out) == true)
631 			{
632 			  if (!scr->gra->set(&out, &str1))
633 			    return scr->errormessage(lineno, "invalid object", "=");
634 
635 			  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
636 			  *(*v)[v->getarraylength() - 2].label = std::string("");
637 			  (*v)[v->getarraylength() - 2].status = NUM;
638 			}
639 		      else
640 			return scr->errormessage(lineno, "invalid object", "=");
641 		    }
642 		  else
643 		    return scr->errormessage(lineno, "invalid object", "=");
644 		}
645 	      else
646 		return scr->errormessage(lineno, "invalid object", "=");
647 
648 	      v->pop(); v->pop();
649 	    }
650 	  else
651 	    return scr->errormessage(lineno, "invalid arguments", "=");
652 	}
653       else
654 	return scr->errormessage(lineno, "invalid arguments", "=");
655     }
656   else
657     return scr->errormessage(lineno, "invalid arguments", "=");
658 
659   return true;
660 }
661 
662 //*****************************************
663 //************* to_operand ****************
664 //*****************************************
o_to_operand(script * scr,int st,int lineno)665 int o_to_operand(script *scr, int st, int lineno)
666 {
667   stackarray *v = scr->v;
668   std::string tempstring;
669 
670   if (st != TO_OPERAND)
671     return scr->errormessage(lineno, "invalid operator", "");
672 
673   if (v->getarraylength() > 0)
674     {
675       tempstring = std::string("$");
676       tempstring += (*(*v)[v->getarraylength() - 1].value)[0];
677       (*v)[v->getarraylength() - 1].priority      = PRI_OPERAND;
678       (*v)[v->getarraylength() - 1].status        = VARIANT;
679       (*v)[v->getarraylength() - 1].value->add("");
680       *(*v)[v->getarraylength() - 1].label         = tempstring;
681     }
682   else
683     return scr->errormessage(lineno, "invalid array", "");
684 
685   return true;
686 }
687 
688 //*****************************************
689 //************* to_array ****************
690 //*****************************************
o_to_array(script * scr,int st,int lineno)691 int o_to_array(script *scr, int st, int lineno)
692 {
693   stackarray *v = scr->v;
694   std::string tempstring;
695 
696   if (st != TO_ARRAY)
697     return scr->errormessage(lineno, "invalid operator", "");
698 
699   if (v->getarraylength() > 0)
700     {
701       tempstring = std::string("@");
702       tempstring += (*(*v)[v->getarraylength() - 1].value)[0];
703       (*v)[v->getarraylength() - 1].priority      = PRI_OPERAND;
704       (*v)[v->getarraylength() - 1].status        = ARRAY;
705       (*v)[v->getarraylength() - 1].value->add("");
706       *(*v)[v->getarraylength() - 1].label         = tempstring;
707     }
708   else
709     return scr->errormessage(lineno, "invalid array", "");
710 
711   return true;
712 }
713 
714 //*****************************************
715 //***************** + *********************
716 //*****************************************
o_plus(script * scr,int st,int lineno)717 int o_plus(script *scr, int st, int lineno)
718 {
719   stackarray *v = scr->v;
720   std::string str1, str2;
721   bool b1, b2;
722   double ftemp;
723   char stemp[1024];
724 
725   if (st != PLUS)
726     return scr->errormessage(lineno, "invalid operator", "+");
727 
728   if (v->getarraylength() > 1 )
729     {
730       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
731       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
732       if (b1 && b2)
733 	{
734 	  ftemp = atof(str1.c_str()) + atof(str2.c_str());
735 	  sprintf(stemp, "%.15g", ftemp);
736 	  (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
737 	  *(*v)[v->getarraylength() - 2].label = std::string("");
738 	  (*v)[v->getarraylength() - 2].status = NUM;
739 	  v->pop();
740 	}
741       else
742 	return scr->errormessage(lineno, "invalid operator", "+");
743     }
744   else
745     return scr->errormessage(lineno, "invalid operator", "+");
746 
747   return true;
748 }
749 
750 //*****************************************
751 //***************** pre + *****************
752 //*****************************************
o_preplus(script * scr,int st,int lineno)753 int o_preplus(script *scr, int st, int lineno)
754 {
755   stackarray *v = scr->v;
756   std::string str1;
757   bool b1;
758   double ftemp;
759   char stemp[1024];
760 
761   if (st != PREPLUS)
762     return scr->errormessage(lineno, "invalid operator", "+");
763 
764   if (v->getarraylength() > 0)
765     {
766       b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
767       if (b1)
768 	{
769 	  ftemp = atof(str1.c_str());
770 	  sprintf(stemp, "%.15g", ftemp);
771 	  (*(*v)[v->getarraylength() - 1].value)[0] = std::string(stemp);
772 	  *(*v)[v->getarraylength() - 1].label = std::string("");
773 	  (*v)[v->getarraylength() - 1].status = NUM;
774 	}
775       else
776 	return scr->errormessage(lineno, "invalid sign", "+");
777     }
778   else
779     return scr->errormessage(lineno, "invalid sign", "+");
780 
781   return true;
782 }
783 
784 //*****************************************
785 //***************** . *********************
786 //*****************************************
o_strplus(script * scr,int st,int lineno)787 int o_strplus(script *scr, int st, int lineno)
788 {
789   stackarray *v = scr->v;
790   std::string str1, str2, str3, str4, str5;
791   bool b1, b2, b3;
792   int itemp;
793   tokenbuff arrayinstringseparator;
794 
795   // arrayseparator in string $
796   arrayinstringseparator.priority = PRI_OPERAND;
797   arrayinstringseparator.status = VARIANT;
798   *arrayinstringseparator.label = std::string("$\"");
799   arrayinstringseparator.value->add("");
800 
801   if (v->getarraylength() > 1)
802     {
803       if (st == STR_PLUS)
804 	{
805 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
806 	  b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
807 	}
808       else
809 	{
810 	  b1 = scr->GetImplicitValue(&(*v)[v->getarraylength() - 2], &str1);
811 	  b2 = scr->GetImplicitValue(&(*v)[v->getarraylength() - 1], &str2);
812 	}
813 
814       if (b1 && b2)
815 	{
816 	  (*(*v)[v->getarraylength() - 2].value)[0] = str1 + str2;
817 	  *(*v)[v->getarraylength() - 2].label = std::string("");
818 	  (*v)[v->getarraylength() - 2].status = NUM;
819 	  v->pop();
820 	}
821       else if (!b1 && b2)
822 	{
823 	  if ((*v)[v->getarraylength() - 2].status == ARRAY)
824 	    {
825 	      b3 = scr->GetValue(&arrayinstringseparator, &str3);
826 	      if (b3)
827 		{
828 		  str4 = std::string("");
829 		  for (itemp = 0; itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 2].label) - 1; itemp++)
830 		    {
831 		      scr->vbuff->Get((*v)[v->getarraylength() - 2].label, itemp, &str5);
832 		      str4 += str5 + str3;
833 		    }
834 		  scr->vbuff->Get((*v)[v->getarraylength() - 2].label,
835 			     scr->vbuff->ArrayLength((*v)[v->getarraylength() - 2].label) - 1, &str5);
836 		  str4 += str5;
837 
838 		  (*(*v)[v->getarraylength() - 2].value)[0] = str4 + str2;
839 		  *(*v)[v->getarraylength() - 2].label = std::string("");
840 		  (*v)[v->getarraylength() - 2].status = NUM;
841 			      v->pop();
842 		}
843 	      else
844 		return scr->errormessage(lineno, "invalid operator", ".");
845 	    }
846 	  else
847 	    return scr->errormessage(lineno, "invalid operator", ".");
848 	}
849       else if (b1 && !b2)
850 	{
851 	  if ((*v)[v->getarraylength() - 1].status == ARRAY)
852 	    {
853 	      b3 = scr->GetValue(&arrayinstringseparator, &str3);
854 	      if (b3)
855 		{
856 		  str4 = std::string("");
857 		  for (itemp = 0; itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label) - 1; itemp++)
858 		    {
859 		      scr->vbuff->Get((*v)[v->getarraylength() - 1].label, itemp, &str5);
860 		      str4 += str5 + str3;
861 		    }
862 		  scr->vbuff->Get((*v)[v->getarraylength() - 1].label,
863 				  scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label) - 1, &str5);
864 		  str4 += str5;
865 
866 		  (*(*v)[v->getarraylength() - 2].value)[0] = str1 + str4;
867 		  *(*v)[v->getarraylength() - 2].label = std::string("");
868 		  (*v)[v->getarraylength() - 2].status = NUM;
869 		  v->pop();
870 		}
871 	      else
872 		return scr->errormessage(lineno, "invalid operator", ".");
873 	    }
874 	  else
875 	    return scr->errormessage(lineno, "invalid operator", ".");
876 	}
877       else
878 	return scr->errormessage(lineno, "invalid operator", ".");
879     }
880   else
881     return scr->errormessage(lineno, "invalid operator", ".");
882 
883   return true;
884 }
885 
886 //*****************************************
887 //***************** - *********************
888 //*****************************************
o_minus(script * scr,int st,int lineno)889 int o_minus(script *scr, int st, int lineno)
890 {
891   stackarray *v = scr->v;
892   std::string str1, str2;
893   bool b1, b2;
894   double ftemp;
895   char stemp[1024];
896 
897   if (st != MINUS)
898     return scr->errormessage(lineno, "invalid operator", "-");
899 
900   if (v->getarraylength() > 1)
901     {
902       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
903       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
904       if (b1 && b2)
905 	{
906 	  ftemp = atof(str1.c_str()) - atof(str2.c_str());
907 
908 	  sprintf(stemp, "%.15g", ftemp);
909 	  (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
910 	  *(*v)[v->getarraylength() - 2].label = std::string("");
911 	  (*v)[v->getarraylength() - 2].status = NUM;
912 	  v->pop();
913 	}
914       else
915 	return scr->errormessage(lineno, "invalid operator", "-");
916     }
917   else
918     return scr->errormessage(lineno, "invalid operator", "-");
919 
920   return true;
921 }
922 
923 //*****************************************
924 //***************** pre - *****************
925 //*****************************************
o_preminus(script * scr,int st,int lineno)926 int o_preminus(script *scr, int st, int lineno)
927 {
928   stackarray *v = scr->v;
929   std::string str1;
930   bool b1;
931   double ftemp;
932   char stemp[1024];
933 
934   if (st != PREMINUS)
935     return scr->errormessage(lineno, "invalid operator", "-");
936 
937   if (v->getarraylength() > 0)
938     {
939       b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
940       if (b1)
941 	{
942 	  ftemp = -atof(str1.c_str());
943 	  sprintf(stemp, "%.15g", ftemp);
944 	  (*(*v)[v->getarraylength() - 1].value)[0] = std::string(stemp);
945 	  *(*v)[v->getarraylength() - 1].label = std::string("");
946 	  (*v)[v->getarraylength() - 1].status = NUM;
947 	}
948       else
949 	return scr->errormessage(lineno, "invalid sign", "-");
950     }
951   else
952     return scr->errormessage(lineno, "invalid sign", "-");
953 
954   return true;
955 }
956 
957 //*****************************************
958 //***************** / *********************
959 //*****************************************
o_divide(script * scr,int st,int lineno)960 int o_divide(script *scr, int st, int lineno)
961 {
962   stackarray *v = scr->v;
963   std::string str1, str2;
964   bool b1, b2;
965   double ftemp;
966   char stemp[1024];
967 
968   if (st != DIVIDE)
969     return scr->errormessage(lineno, "invalid operator", "/");
970 
971   if (v->getarraylength() > 1)
972     {
973       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
974       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
975       if (b1 && b2)
976 	{
977 	  if (atof(str2.c_str()) != 0)
978 	    {
979 	      ftemp = atof(str1.c_str()) / atof(str2.c_str());
980 
981 	      sprintf(stemp, "%.15g", ftemp);
982 	      (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
983 	      *(*v)[v->getarraylength() - 2].label = std::string("");
984 			  (*v)[v->getarraylength() - 2].status = NUM;
985 			  v->pop();
986 	    }
987 	  else
988 	    return scr->errormessage(lineno, "zero division", "/");
989 	}
990       else
991 	return scr->errormessage(lineno, "invalid operator", "/");
992     }
993   else
994     return scr->errormessage(lineno, "invalid operator", "/");
995 
996   return true;
997 }
998 
999 //*****************************************
1000 //***************** % *********************
1001 //*****************************************
o_intdivide(script * scr,int st,int lineno)1002 int o_intdivide(script *scr, int st, int lineno)
1003 {
1004   stackarray *v = scr->v;
1005   std::string str1, str2;
1006   bool b1, b2;
1007   double ftemp;
1008   char stemp[1024];
1009 
1010   if (st != INTDIVIDE)
1011     return scr->errormessage(lineno, "invalid operator", "%");
1012 
1013   if (v->getarraylength() > 1)
1014     {
1015       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1016       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1017       if (b1 && b2)
1018 	{
1019 	  if ((int)atof(str2.c_str()) != 0)
1020 	    {
1021 	      ftemp = (double)((int)atof(str1.c_str()) % (int)atof(str2.c_str()));
1022 
1023 	      sprintf(stemp, "%.15g", ftemp);
1024 	      (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
1025 	      *(*v)[v->getarraylength() - 2].label = std::string("");
1026 	      (*v)[v->getarraylength() - 2].status = NUM;
1027 	      v->pop();
1028 	    }
1029 	  else
1030 	    return scr->errormessage(lineno, "zero division", "%");
1031 	}
1032       else
1033 	return scr->errormessage(lineno, "invalid operator", "%");
1034     }
1035   else
1036     return scr->errormessage(lineno, "invalid operator", "%");
1037 
1038   return true;
1039 }
1040 
1041 //*****************************************
1042 //***************** * *********************
1043 //*****************************************
o_times(script * scr,int st,int lineno)1044 int o_times(script *scr, int st, int lineno)
1045 {
1046   stackarray *v = scr->v;
1047   std::string str1, str2;
1048   bool b1, b2;
1049   double ftemp;
1050   char stemp[1024];
1051 
1052   if (st != TIMES)
1053     return scr->errormessage(lineno, "invalid operator", "*");
1054 
1055   if (v->getarraylength() > 1)
1056     {
1057       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1058       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1059       if (b1 && b2)
1060 	{
1061 	  ftemp = atof(str1.c_str()) * atof(str2.c_str());
1062 
1063 	  sprintf(stemp, "%.15g", ftemp);
1064 	  (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
1065 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1066 	  (*v)[v->getarraylength() - 2].status = NUM;
1067 	  v->pop();
1068 	}
1069       else
1070 	return scr->errormessage(lineno, "invalid operator", "*");
1071     }
1072   else
1073     return scr->errormessage(lineno, "invalid operator", "*");
1074 
1075   return true;
1076 }
1077 
1078 //*****************************************
1079 //***************** , *********************
1080 //*****************************************
o_comma(script * scr,int st,int lineno)1081 int o_comma(script *scr, int st, int lineno)
1082 {
1083   stackarray *v = scr->v;
1084   std::string str1, str2;
1085   bool b1, b2;
1086   int itemp;
1087 
1088   if (st != COMMA)
1089     return scr->errormessage(lineno, "invalid operator", ",");
1090 
1091   if (v->getarraylength() > 1)
1092     {
1093       if ((*v)[v->getarraylength() - 2].status == ARRAY)
1094 	{
1095 	  if (scr->vbuff->search((*v)[v->getarraylength() - 2].label, &itemp))
1096 	    {
1097 	      (*v)[v->getarraylength() - 2].value->setbuff(0);
1098 	      for (itemp = 0; itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 2].label); itemp++)
1099 		{
1100 		  scr->vbuff->Get((*v)[v->getarraylength() - 2].label, itemp, &str1);
1101 		  (*v)[v->getarraylength() - 2].value->add(str1.c_str());
1102 		}
1103 	      *(*v)[v->getarraylength() - 2].label = std::string("");
1104 	      (*v)[v->getarraylength() - 2].status = IMPLICITARRAY;
1105 	    }
1106 	  else
1107 	    return scr->errormessage(lineno, "can not fine variable", (*v)[v->getarraylength() - 2].label->c_str());
1108 	}
1109 
1110       if ((*v)[v->getarraylength() - 1].status == ARRAY)
1111 	{
1112 	  if (scr->vbuff->search((*v)[v->getarraylength() - 1].label, &itemp))
1113 	    {
1114 	      (*v)[v->getarraylength() - 1].value->setbuff(0);
1115 	      for (itemp = 0; itemp < scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label); itemp++)
1116 		{
1117 		  scr->vbuff->Get((*v)[v->getarraylength() - 1].label, itemp, &str1);
1118 		  (*v)[v->getarraylength() - 1].value->add(str1.c_str());
1119 		}
1120 	      *(*v)[v->getarraylength() - 1].label = std::string("");
1121 	      (*v)[v->getarraylength() - 1].status = IMPLICITARRAY;
1122 	    }
1123 	  else
1124 	    return scr->errormessage(lineno, "can not find variable", (*v)[v->getarraylength() - 1].label->c_str());
1125 	}
1126 
1127 
1128       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1129       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1130 
1131       if (b1 == true && b2 == true)
1132 	{
1133 	  (*v)[v->getarraylength() - 2].value->setarray(0);
1134 	  (*v)[v->getarraylength() - 2].value->add(str1.c_str());
1135 	  (*v)[v->getarraylength() - 2].value->add(str2.c_str());
1136 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1137 	  (*v)[v->getarraylength() - 2].status = IMPLICITARRAY;
1138 		      v->pop();
1139 	}
1140       else if (b1 == false && b2 == true && (*v)[v->getarraylength() - 2].status == IMPLICITARRAY)
1141 	{
1142 	  (*v)[v->getarraylength() - 2].value->add(str2.c_str());
1143 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1144 	  (*v)[v->getarraylength() - 2].status = IMPLICITARRAY;
1145 
1146 	  v->pop();
1147 	}
1148       else if (b1 == true && b2 == false && (*v)[v->getarraylength() - 1].status == IMPLICITARRAY)
1149 	{
1150 	  (*v)[v->getarraylength() - 2].value->setarray(0);
1151 	  (*v)[v->getarraylength() - 2].value->add(str1.c_str());
1152 
1153 	  for (itemp = 0; itemp < (*v)[v->getarraylength() - 1].value->getarraylength(); itemp++)
1154 	    (*v)[v->getarraylength() - 2].value->add((*(*v)[v->getarraylength() - 1].value)[itemp].c_str());
1155 
1156 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1157 	  (*v)[v->getarraylength() - 2].status = IMPLICITARRAY;
1158 
1159 	  v->pop();
1160 	}
1161       else if (b1 == false && b2 == false
1162 	       && (*v)[v->getarraylength() - 2].status == IMPLICITARRAY
1163 	       && (*v)[v->getarraylength() - 1].status == IMPLICITARRAY)
1164 	{
1165 	  for (itemp = 0; itemp < (*v)[v->getarraylength() - 1].value->getarraylength(); itemp++)
1166 	    (*v)[v->getarraylength() - 2].value->add((*(*v)[v->getarraylength() - 1].value)[itemp].c_str());
1167 
1168 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1169 	  (*v)[v->getarraylength() - 2].status = IMPLICITARRAY;
1170 
1171 	  v->pop();
1172 	}
1173       else
1174 	return scr->errormessage(lineno, "invalid operator", ",");
1175     }
1176   else
1177     return scr->errormessage(lineno, "invalid operator", ",");
1178 
1179   return true;
1180 }
1181 
1182 //*****************************************
1183 //***************** exp *******************
1184 //*****************************************
o_exp(script * scr,int st,int lineno)1185 int o_exp(script *scr, int st, int lineno)
1186 {
1187   stackarray *v = scr->v;
1188   std::string str1, str2;
1189   bool b1, b2;
1190   double ftemp;
1191   char stemp[1024];
1192 
1193   if (st != EXP)
1194     return scr->errormessage(lineno, "invalid operator", "** / ^");
1195 
1196   if (v->getarraylength() > 1)
1197     {
1198       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1199       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1200       if (b1 && b2)
1201 	{
1202 	  ftemp = pow(atof(str1.c_str()), atof(str2.c_str()));
1203 
1204 	  sprintf(stemp, "%.15g", ftemp);
1205 	  (*(*v)[v->getarraylength() - 2].value)[0] = std::string(stemp);
1206 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1207 	  (*v)[v->getarraylength() - 2].status = NUM;
1208 	  v->pop();
1209 	}
1210       else
1211 	return scr->errormessage(lineno, "invalid operator", "** / ^");
1212     }
1213   else
1214     return scr->errormessage(lineno, "invalid operator", "** / ^");
1215 
1216   return true;
1217 }
1218 
1219 //*****************************************
1220 //***************** >= *******************
1221 //*****************************************
o_larger_equal_than(script * scr,int st,int lineno)1222 int o_larger_equal_than(script *scr, int st, int lineno)
1223 {
1224   stackarray *v = scr->v;
1225   std::string str1, str2;
1226   bool b1, b2;
1227 
1228   if (st != LARGER_EQUAL_THAN)
1229     return scr->errormessage(lineno, "invalid operator", ">= / =>");
1230 
1231   if (v->getarraylength() > 1)
1232     {
1233       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1234       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1235       if (b1 && b2)
1236 	{
1237 	  if (atof(str1.c_str()) >= atof(str2.c_str()))
1238 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1239 	  else
1240 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1241 
1242 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1243 	  (*v)[v->getarraylength() - 2].status = NUM;
1244 	  v->pop();
1245 	}
1246       else
1247 	return scr->errormessage(lineno, "invalid operator", ">= / =>");
1248     }
1249   else
1250     return scr->errormessage(lineno, "invalid operator", ">= / =>");
1251 
1252   return true;
1253 }
1254 
1255 //*****************************************
1256 //***************** > *********************
1257 //*****************************************
o_larger_than(script * scr,int st,int lineno)1258 int o_larger_than(script *scr, int st, int lineno)
1259 {
1260   stackarray *v = scr->v;
1261   std::string str1, str2;
1262   bool b1, b2;
1263 
1264   if (st != LARGER_THAN)
1265     return scr->errormessage(lineno, "invalid operator", ">");
1266 
1267   if (v->getarraylength() > 1)
1268     {
1269       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1270       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1271       if (b1 && b2)
1272 	{
1273 	  if (atof(str1.c_str()) > atof(str2.c_str()))
1274 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1275 	  else
1276 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1277 
1278 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1279 	  (*v)[v->getarraylength() - 2].status = NUM;
1280 	  v->pop();
1281 	}
1282       else
1283 	return scr->errormessage(lineno, "invalid operator", ">");
1284     }
1285   else
1286     return scr->errormessage(lineno, "invalid operator", ">");
1287 
1288   return true;
1289 }
1290 
1291 //*****************************************
1292 //***************** <= ********************
1293 //*****************************************
o_smaller_equal_than(script * scr,int st,int lineno)1294 int o_smaller_equal_than(script *scr, int st, int lineno)
1295 {
1296   stackarray *v = scr->v;
1297   std::string str1, str2;
1298   bool b1, b2;
1299 
1300   if (st != SMALLER_EQUAL_THAN)
1301     return scr->errormessage(lineno, "invalid operator", "<= / =<");
1302 
1303   if (v->getarraylength() > 1)
1304     {
1305       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1306       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1307       if (b1 && b2)
1308 	{
1309 	  if (atof(str1.c_str()) <= atof(str2.c_str()))
1310 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1311 	  else
1312 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1313 
1314 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1315 	  (*v)[v->getarraylength() - 2].status = NUM;
1316 	  v->pop();
1317 	}
1318       else
1319 	return scr->errormessage(lineno, "invalid operator", "<= / =<");
1320     }
1321   else
1322     return scr->errormessage(lineno, "invalid operator", "<= / =<");
1323 
1324   return true;
1325 }
1326 
1327 //*****************************************
1328 //***************** < *********************
1329 //*****************************************
o_smaller_than(script * scr,int st,int lineno)1330 int o_smaller_than(script *scr, int st, int lineno)
1331 {
1332   stackarray *v = scr->v;
1333   std::string str1, str2;
1334   bool b1, b2;
1335 
1336   if (st != SMALLER_THAN)
1337     return scr->errormessage(lineno, "invalid operator", "<");
1338 
1339   if (v->getarraylength() > 1)
1340     {
1341       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1342       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1343       if (b1 && b2)
1344 	{
1345 	  if (atof(str1.c_str()) < atof(str2.c_str()))
1346 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1347 	  else
1348 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1349 
1350 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1351 	  (*v)[v->getarraylength() - 2].status = NUM;
1352 	  v->pop();
1353 	}
1354       else
1355 	return scr->errormessage(lineno, "invalid operator", "<");
1356     }
1357   else
1358     return scr->errormessage(lineno, "invalid operator", "<");
1359 
1360   return true;
1361 }
1362 
1363 //*****************************************
1364 //*********** string operation ************
1365 //*****************************************
o_strop(script * scr,int status,int lineno)1366 int o_strop(script *scr, int status, int lineno)
1367 {
1368   stackarray *v = scr->v;
1369   std::string str1, str2, str3, str4;
1370   bool b1, b2;
1371 
1372   if (v->getarraylength() > 1)
1373     {
1374       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1375       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1376       if (b1 && b2)
1377 	{
1378 	  if (status == STR_EQUAL)
1379 	    {
1380 	      if (strcmp(str1.c_str(), str2.c_str()) == 0)
1381 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1382 	      else
1383 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1384 	    }
1385 	  else if (status == STR_NOTEQUAL)
1386 	    {
1387 	      if (strcmp(str1.c_str(), str2.c_str()) == 0)
1388 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1389 	      else
1390 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1391 	    }
1392 	  else if (status == STR_LESSTHAN)
1393 	    {
1394 	      if (strcmp(str1.c_str(), str2.c_str()) < 0)
1395 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1396 	      else
1397 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1398 	    }
1399 	  else if (status == STR_GREATERTHAN)
1400 	    {
1401 	      if (strcmp(str1.c_str(), str2.c_str()) > 0)
1402 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1403 	      else
1404 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1405 	    }
1406 	  else if (status == STR_LESSEQUALTHAN)
1407 	    {
1408 	      if (strcmp(str1.c_str(), str2.c_str()) <= 0)
1409 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1410 	      else
1411 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1412 	    }
1413 	  else if (status == STR_GREATEREQUALTHAN)
1414 	    {
1415 	      if (strcmp(str1.c_str(), str2.c_str()) >= 0)
1416 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1417 	      else
1418 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1419 	    }
1420 	  else if (status == MATCH)
1421 	    {
1422 
1423 	      if (groupmatch(str1.c_str(), str2.c_str(), scr->vbuff))
1424 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1425 	      else
1426 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1427 	    }
1428 	  else if (status == NOTMATCH)
1429 	    {
1430 	      if (groupmatch(str1.c_str(), str2.c_str(), scr->vbuff))
1431 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1432 	      else
1433 		(*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1434 	    }
1435 
1436 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1437 	  (*v)[v->getarraylength() - 2].status = NUM;
1438 	  v->pop();
1439 	}
1440       else
1441 	return scr->errormessage(lineno, "invalid operator", "string operation");
1442     }
1443   else
1444     return scr->errormessage(lineno, "invalid operator", "string operation");
1445 
1446   return true;
1447 }
1448 
1449 //*****************************************
1450 //***************** inc *******************
1451 //*****************************************
o_inc(script * scr,int status,int lineno)1452 int o_inc(script *scr, int status, int lineno)
1453 {
1454   stackarray *v = scr->v;
1455   std::string tempstring, tempstring1, str1, str2, str3, str4;
1456   bool b1;
1457   tokenbuff temptoken;
1458   int itemp;
1459   char stemp[1024];
1460 
1461   if (v->getarraylength() > 0)
1462     {
1463       temptoken = (*v)[v->getarraylength() - 1];
1464       str3 = *temptoken.label;
1465       itemp = temptoken.status;
1466       if (temptoken.status == ARRAYVARIANT)
1467 	str4 = (*temptoken.value)[0];
1468 
1469       b1 = scr->GetValue(&temptoken, &str1);
1470       if (b1)
1471 	{
1472 	  //pre increment/decrement
1473 	  if (status == BEFORE_INC
1474 	      || status == BEFORE_DEC)
1475 	    {
1476 	      if (status == BEFORE_INC)
1477 		sprintf(stemp, "%.15g", (atof(str1.c_str()) + 1.0));
1478 	      else if (status == BEFORE_DEC)
1479 		sprintf(stemp, "%.15g", (atof(str1.c_str()) - 1.0));
1480 
1481 	      str2 = std::string(stemp);
1482 
1483 	      if (itemp == VARIANT)
1484 		{
1485 		  if (!scr->vbuff->SetScalar(&str3, &str2))
1486 				return false;
1487 		}
1488 	      else if (itemp == ARRAYVARIANT)
1489 		{
1490 		  tempstring = std::string("@");
1491 		  tempstring1 = std::string((const char *)(str3.c_str() + 1));
1492 		  tempstring += tempstring1;
1493 
1494 		  if (!scr->vbuff->Set(&tempstring
1495 				  ,atoi(str4.c_str())
1496 					      ,&str2))
1497 		    return false;
1498 		}
1499 	      else
1500 		return scr->errormessage(lineno, "invalid operator", "++ / --");
1501 	    }
1502 	  //end of pre increment/decrement
1503 
1504 
1505 	  //getvalue
1506 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
1507 	  (*(*v)[v->getarraylength() - 1].value)[0] = str1;
1508 	  *(*v)[v->getarraylength() - 1].label = std::string("");
1509 	  (*v)[v->getarraylength() - 1].status = NUM;
1510 
1511 
1512 	  //post increment/decrement
1513 	  if (status == AFTER_INC
1514 	      || status == AFTER_DEC)
1515 	    {
1516 	      if (status == AFTER_INC)
1517 		sprintf(stemp, "%.15g", (atof(str1.c_str()) + 1.0));
1518 	      else if (status == AFTER_DEC)
1519 		sprintf(stemp, "%.15g", (atof(str1.c_str()) - 1.0));
1520 
1521 	      str2 = std::string(stemp);
1522 
1523 	      if (itemp == VARIANT)
1524 		{
1525 		  if (!scr->vbuff->SetScalar(&str3, &str2))
1526 		    return false;
1527 		}
1528 	      else if (itemp == ARRAYVARIANT)
1529 		{
1530 		  tempstring = std::string("@");
1531 		  tempstring1 = std::string((const char *)(str3.c_str() + 1));
1532 		  tempstring += tempstring1;
1533 
1534 		  if (!scr->vbuff->Set(&tempstring
1535 				  ,atoi(str4.c_str())
1536 				  ,&str2))
1537 		    return false;
1538 		}
1539 	      else
1540 		return scr->errormessage(lineno, "invalid operator", "++ / --");
1541 	    }
1542 	  //end of post increment/decrement
1543 
1544 	}
1545       else
1546 	return scr->errormessage(lineno, "invalid operator", "++ / --");
1547     }
1548   else
1549     return scr->errormessage(lineno, "invalid operator", "++ / --");
1550 
1551   return true;
1552 }
1553 
1554 //*****************************************
1555 //***************** or/and ****************
1556 //*****************************************
o_or_and(script * scr,int status,int lineno)1557 int o_or_and(script *scr, int status, int lineno)
1558 {
1559   stackarray *v = scr->v;
1560   std::string str1, str2;
1561   bool b1, b2;
1562 
1563   if (v->getarraylength() > 1)
1564     {
1565       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1566       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1567       if (b1 && b2)
1568 	{
1569 	  if (status == OR)
1570 	    {
1571 	      if (atof(str1.c_str()) < atof(str2.c_str()))
1572 		(*(*v)[v->getarraylength() - 2].value)[0] = str2;
1573 	      else
1574 		(*(*v)[v->getarraylength() - 2].value)[0] = str1;
1575 	    }
1576 	  else if (status == AND)
1577 	    {
1578 	      if (atof(str1.c_str()) < atof(str2.c_str()))
1579 		(*(*v)[v->getarraylength() - 2].value)[0] = str1;
1580 	      else
1581 		(*(*v)[v->getarraylength() - 2].value)[0] = str2;
1582 			}
1583 
1584 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1585 	  (*v)[v->getarraylength() - 2].status = NUM;
1586 	  v->pop();
1587 
1588 	}
1589       else
1590 	return scr->errormessage(lineno, "invalid operator", "|| / &&");
1591     }
1592   else
1593     return scr->errormessage(lineno, "invalid operator", "|| / &&");
1594 
1595   return true;
1596 }
1597 
1598 //*****************************************
1599 //***************** == ********************
1600 //*****************************************
o_equal(script * scr,int st,int lineno)1601 int o_equal(script *scr, int st, int lineno)
1602 {
1603   stackarray *v = scr->v;
1604   std::string str1, str2;
1605   bool b1, b2;
1606 
1607   if (st != EQUAL)
1608     return scr->errormessage(lineno, "invalid operator", "==");
1609 
1610   if (v->getarraylength() > 1)
1611     {
1612       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1613       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1614       if (b1 && b2)
1615 	{
1616 	  if (atof(str1.c_str()) == atof(str2.c_str()))
1617 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1618 	  else
1619 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1620 
1621 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1622 	  (*v)[v->getarraylength() - 2].status = NUM;
1623 	  v->pop();
1624 	}
1625       else
1626 	return scr->errormessage(lineno, "invalid operator", "==");
1627     }
1628   else
1629     return scr->errormessage(lineno, "invalid operator", "==");
1630 
1631   return true;
1632 }
1633 
1634 //*****************************************
1635 //***************** != ********************
1636 //*****************************************
o_not_equal(script * scr,int st,int lineno)1637 int o_not_equal(script *scr, int st, int lineno)
1638 {
1639   stackarray *v = scr->v;
1640   std::string str1, str2;
1641   bool b1, b2;
1642 
1643   if (st != NOTEQUAL)
1644     return scr->errormessage(lineno, "invalid operator", "!=");
1645 
1646   if (v->getarraylength() > 1)
1647     {
1648       b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1649       b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1650       if (b1 && b2)
1651 	{
1652 	  if (atof(str1.c_str()) != atof(str2.c_str()))
1653 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1654 	  else
1655 	    (*(*v)[v->getarraylength() - 2].value)[0] = std::string("0");
1656 
1657 	  *(*v)[v->getarraylength() - 2].label = std::string("");
1658 	  (*v)[v->getarraylength() - 2].status = NUM;
1659 	  v->pop();
1660 	}
1661       else
1662 	return scr->errormessage(lineno, "invalid operator", "!=");
1663     }
1664   else
1665     return scr->errormessage(lineno, "invalid operator", "!=");
1666 
1667   return true;
1668 }
1669 
1670 //*****************************************
1671 //***************** ! *********************
1672 //*****************************************
o_not(script * scr,int st,int lineno)1673 int o_not(script *scr, int st, int lineno)
1674 {
1675   stackarray *v = scr->v;
1676   std::string str1;
1677   bool b1;
1678 
1679   if (st != NOT)
1680     return scr->errormessage(lineno, "invalid operator", "!");
1681 
1682   if (v->getarraylength() > 0)
1683     {
1684       b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
1685       if (b1)
1686 	{
1687 	  if ((int)atof(str1.c_str()) == 1)
1688 	    (*(*v)[v->getarraylength() - 1].value)[0] = std::string("0");
1689 	  else if ((int)atof(str1.c_str()) == 0)
1690 	    (*(*v)[v->getarraylength() - 1].value)[0] = std::string("1");
1691 	  else
1692 	    return false;
1693 
1694 	  *(*v)[v->getarraylength() - 1].label = std::string("");
1695 	  (*v)[v->getarraylength() - 1].status = NUM;
1696 	}
1697       else
1698 	return scr->errormessage(lineno, "invalid operator", "!");
1699     }
1700   else
1701     return scr->errormessage(lineno, "invalid operator", "!");
1702 
1703   return true;
1704 }
1705 
1706 //*****************************************
1707 //***************** ,= ********************
1708 //*****************************************
o_comma_equal(script * scr,int st,int lineno)1709 int o_comma_equal(script *scr, int st, int lineno)
1710 {
1711   stackarray *v = scr->v;
1712   std::string str1;
1713   bool b1;
1714   int itemp;
1715 
1716   if (st != COMMAEQUAL)
1717     return scr->errormessage(lineno, "invalid operator", ",=");
1718 
1719   if (v->getarraylength() > 1)
1720     {
1721       if ((*v)[v->getarraylength() - 2].status == ARRAY)
1722 	{
1723 
1724 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str1);
1725 	  if (b1)
1726 	    {
1727 	      if (scr->vbuff->Add((*v)[v->getarraylength() - 2].label, &str1))
1728 		{
1729 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1730 		  *(*v)[v->getarraylength() - 2].label = std::string("");
1731 		  (*v)[v->getarraylength() - 2].status = NUM;
1732 		  v->pop();
1733 		}
1734 	      else
1735 		return false;
1736 	    }
1737 	  else
1738 	    {
1739 	      if ((*v)[v->getarraylength() - 1].status == ARRAY)
1740 		{
1741 		  itemp = scr->vbuff->ArrayLength((*v)[v->getarraylength() - 1].label);
1742 		  for (int i = 0; i < itemp; i++)
1743 		    {
1744 		      scr->vbuff->Get((*v)[v->getarraylength() - 1].label, i, &str1);
1745 		      scr->vbuff->Add((*v)[v->getarraylength() - 2].label, &str1);
1746 		    }
1747 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1748 		  *(*v)[v->getarraylength() - 2].label = std::string("");
1749 		  (*v)[v->getarraylength() - 2].status = NUM;
1750 		  v->pop();
1751 		}
1752 	      else if ((*v)[v->getarraylength() - 1].status == IMPLICITARRAY)
1753 		{
1754 		  for (itemp = 0; itemp < (*v)[v->getarraylength() - 1].value->getarraylength(); itemp++)
1755 		    {
1756 		      str1 = (*v)[v->getarraylength() - 1].value->getdata(itemp);
1757 		      scr->vbuff->Add((*v)[v->getarraylength() - 2].label, &str1);
1758 		    }
1759 		  (*(*v)[v->getarraylength() - 2].value)[0] = std::string("1");
1760 		  *(*v)[v->getarraylength() - 2].label = std::string("");
1761 		  (*v)[v->getarraylength() - 2].status = NUM;
1762 		  v->pop();
1763 		}
1764 	      else
1765 		return scr->errormessage(lineno, "invalid operator", ",=");
1766 	    }
1767 	}
1768       else
1769 	return scr->errormessage(lineno, "invalid operator", ",=");
1770     }
1771   else
1772     return scr->errormessage(lineno, "invalid operator", ",=");
1773 
1774   return true;
1775 }
1776 
1777 //*****************************************
1778 //***************** op = ******************
1779 //*****************************************
o_op_equal(script * scr,int status,int lineno)1780 int o_op_equal(script *scr, int status, int lineno)
1781 {
1782   stackarray *v = scr->v;
1783   std::string str1, str2, str3;
1784   bool b1, b2;
1785   char stemp[1024];
1786   double ftemp = 0.0;
1787   std::string out;
1788   int id;
1789 
1790   if (v->getarraylength() > 1 )
1791     {
1792       if ((*v)[v->getarraylength() - 2].status == VARIANT
1793 	  || (*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
1794 	{
1795 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1796 	  b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1797 	  if (b1 && b2)
1798 	    {
1799 	      switch(status)
1800 		{
1801 		case PLUSEQUAL:
1802 		  ftemp = atof(str1.c_str()) + atof(str2.c_str());
1803 		  break;
1804 		case MINUSEQUAL:
1805 		  ftemp = atof(str1.c_str()) - atof(str2.c_str());
1806 		  break;
1807 		case TIMESEQUAL:
1808 		  ftemp = atof(str1.c_str()) * atof(str2.c_str());
1809 		  break;
1810 		case DIVIDEEQUAL:
1811 		  if (atof(str2.c_str()) != 0.0)
1812 		    ftemp = atof(str1.c_str()) / atof(str2.c_str());
1813 		  else
1814 		    return scr->errormessage(lineno, "zero division", "/=");
1815 		  break;
1816 		case INTDIVIDEEQUAL:
1817 		  if ((int)atof(str2.c_str()) != 0)
1818 		    ftemp = (double)((int)atof(str1.c_str()) % (int)atof(str2.c_str()));
1819 		  else
1820 		    return scr->errormessage(lineno, "zero division", "%=");
1821 		  break;
1822 		case EXPEQUAL:
1823 		  ftemp = pow(atof(str1.c_str()), atof(str2.c_str()));
1824 		  break;
1825 		}
1826 
1827 	      sprintf(stemp, "%.15g", ftemp);
1828 	      if ((*v)[v->getarraylength() - 2].status == VARIANT)
1829 		{
1830 		  str3 = std::string(stemp);
1831 		  if (!scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label, &str3))
1832 		    return false;
1833 		}
1834 	      else if ((*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
1835 		{
1836 		  if (scr->gra->topobject((*v)[v->getarraylength() - 2].label, &out, &id) == true)
1837 		    {
1838 		      if (out == std::string("$graph") && id == -1)
1839 			{
1840 			  if (scr->gra->shrinkobject((*v)[v->getarraylength() - 2].label, &out) == true)
1841 			    {
1842 			      str3 = std::string(stemp);
1843 			      if (!scr->gra->set(&out, &str3))
1844 				return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1845 			    }
1846 			  else
1847 			    return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1848 			}
1849 		      else
1850 			return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1851 		    }
1852 		  else
1853 				return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1854 		}
1855 	      v->pop(); v->pop();
1856 	    }
1857 	  else
1858 	    return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1859 
1860 	}
1861       else
1862 	return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1863     }
1864   else
1865     return scr->errormessage(lineno, "invalid operator", "+= / -= / *= / . . .");
1866 
1867   return true;
1868 }
1869 
1870 //*****************************************
1871 //***************** .= ********************
1872 //*****************************************
o_strplus_equal(script * scr,int status,int lineno)1873 int o_strplus_equal(script *scr, int status, int lineno)
1874 {
1875   stackarray *v = scr->v;
1876   std::string str1, str2, str3;
1877   bool b1, b2;
1878   std::string out;
1879   int id;
1880 
1881   if (v->getarraylength() > 1 )
1882     {
1883       if ((*v)[v->getarraylength() - 2].status == VARIANT
1884 	  || (*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
1885 	{
1886 	  b1 = scr->GetValue(&(*v)[v->getarraylength() - 2], &str1);
1887 	  b2 = scr->GetValue(&(*v)[v->getarraylength() - 1], &str2);
1888 	  if (b1 && b2)
1889 	    {
1890 	      switch(status)
1891 		{
1892 		case STRPLUSEQUAL:
1893 		  str3 = str1 + str2;
1894 		  break;
1895 		}
1896 
1897 	      if ((*v)[v->getarraylength() - 2].status == VARIANT)
1898 		{
1899 		  if (!scr->vbuff->SetScalar((*v)[v->getarraylength() - 2].label, &str3))
1900 		    return false;
1901 		}
1902 	      else if ((*v)[v->getarraylength() - 2].status == OBJ_MEMBER)
1903 		{
1904 		  if (scr->gra->topobject((*v)[v->getarraylength() - 2].label, &out, &id) == true)
1905 		    {
1906 		      if (out == std::string("$graph") && id == -1)
1907 			{
1908 			  if (scr->gra->shrinkobject((*v)[v->getarraylength() - 2].label, &out) == true)
1909 			    {
1910 			      if (!scr->gra->set(&out, &str3))
1911 				return scr->errormessage(lineno, "invalid operator", ".=");
1912 			    }
1913 			  else
1914 			    return scr->errormessage(lineno, "invalid operator", ".=");
1915 			}
1916 		      else
1917 			return scr->errormessage(lineno, "invalid operator", ".=");
1918 		    }
1919 		  else
1920 		    return scr->errormessage(lineno, "invalid operator", ".=");
1921 		}
1922 
1923 	      v->pop(); v->pop();
1924 	    }
1925 	  else
1926 	    return scr->errormessage(lineno, "invalid operator", ".=");
1927 	}
1928       else
1929 	return scr->errormessage(lineno, "invalid operator", ".=");
1930     }
1931   else
1932     return scr->errormessage(lineno, "invalid operator", ".=");
1933 
1934   return true;
1935 }
1936 
1937 
1938 
1939 typedef struct funcsmap
1940 {
1941   int op;
1942   int (*func)(script *scr, int status, int lineno);
1943 }OPMAP;
1944 
1945 OPMAP opmap[] = {
1946   {OBJ_POINTER, o_objpointer},
1947   {SET, o_set},
1948   {TO_OPERAND, o_to_operand},
1949   {TO_ARRAY, o_to_array},
1950   {BEFORE_INC, o_inc},
1951   {AFTER_INC, o_inc},
1952   {BEFORE_DEC, o_inc},
1953   {AFTER_DEC, o_inc},
1954   {PLUS, o_plus},
1955   {PREPLUS, o_preplus},
1956   {STR_PLUS, o_strplus},
1957   {IMPLICITSTRPLUS, o_strplus},
1958   {MINUS, o_minus},
1959   {PREMINUS, o_preminus},
1960   {DIVIDE, o_divide},
1961   {INTDIVIDE, o_intdivide},
1962   {TIMES, o_times},
1963   {COMMA, o_comma},
1964   {EXP, o_exp},
1965   {LARGER_EQUAL_THAN, o_larger_equal_than},
1966   {LARGER_THAN, o_larger_than},
1967   {SMALLER_EQUAL_THAN, o_smaller_equal_than},
1968   {SMALLER_THAN, o_smaller_than},
1969   {STR_EQUAL, o_strop},
1970   {STR_NOTEQUAL, o_strop},
1971   {STR_LESSTHAN, o_strop},
1972   {STR_GREATERTHAN, o_strop},
1973   {STR_LESSEQUALTHAN, o_strop},
1974   {STR_GREATEREQUALTHAN, o_strop},
1975   {MATCH, o_strop},
1976   {NOTMATCH, o_strop},
1977   {OR, o_or_and},
1978   {AND, o_or_and},
1979   {EQUAL, o_equal},
1980   {NOTEQUAL, o_not_equal},
1981   {NOT, o_not},
1982   {COMMAEQUAL, o_comma_equal},
1983   {PLUSEQUAL, o_op_equal},
1984   {MINUSEQUAL, o_op_equal},
1985   {TIMESEQUAL, o_op_equal},
1986   {DIVIDEEQUAL, o_op_equal},
1987   {INTDIVIDEEQUAL, o_op_equal},
1988   {EXPEQUAL, o_op_equal},
1989   {STRPLUSEQUAL, o_strplus_equal},
1990   {0, 0}
1991 };
1992 
1993 
calc()1994 int script::calc ()
1995 {
1996   int itemp;
1997   std::string tempstring, tempstring1, str1, str2, str3, str4, str5, str6;//, chompstr, flushstr;
1998   int parsepoint;
1999   tokenbuff temptoken;
2000   std::string out;
2001   buffarray tempbuffarray;
2002   int lineno;
2003   int status;
2004 
2005   OPMAP *om;
2006   int itemno;
2007   int (*execfunc)(script *scr, int st, int linenumber);
2008 
2009   /*
2010   // chompstr
2011   str1 = std::string("$/");
2012   vbuff->GetScalar(&str1, &chompstr);
2013 
2014   // flushstr
2015   str1 = std::string("$|");
2016   vbuff->GetScalar(&str1, &flushstr);
2017   */
2018 
2019   for (parsepoint = 0; parsepoint < polish->getarraylength(); parsepoint++)
2020     {
2021       lineno = (*polish)[parsepoint].lineno;
2022       status = (*polish)[parsepoint].status;
2023 
2024       //  NUM
2025       if (status    == NUM
2026 	  || status == VARIANT
2027 	  || status == OBJ_MEMBER
2028 	  || status == OBJ_METHOD
2029 	  || status == ARRAYVARIANT
2030 	  || status == READPIPE
2031 	  || status == ARRAY )
2032 	{
2033 	  v->push1(&(*polish)[parsepoint]);
2034 	}
2035       // FUNC
2036       else if (status == FUNC)
2037 	{
2038 	  itemp = funcs(parsepoint);
2039 	  if (itemp != true)
2040 	    return itemp;
2041 	}
2042       //  TOARRAY
2043       else if (status == TOARRAY)
2044         {
2045 	  if (v->getarraylength() > 0)
2046 	    {
2047 	      if (GetValue(&(*v)[v->getarraylength() - 1], &str1) == true)
2048 		{
2049 		  (*(*v)[v->getarraylength() - 1].value)[0] = str1;
2050 		  *(*v)[v->getarraylength() - 1].label = *(*polish)[parsepoint].label;
2051 		  (*v)[v->getarraylength() - 1].status = ARRAYVARIANT;
2052 		}
2053 	      else
2054 		return errormessage(lineno, "invalid arguments", "toarray");
2055 	    }
2056 	  else
2057 	    return errormessage(lineno, "invalid arguments", "toarray");
2058         }
2059       //  OBJ_TOARRAY
2060       else if (status == OBJ_TOARRAY)
2061         {
2062 	  if (v->getarraylength() > 0)
2063 	    {
2064 	      if (GetValue(&(*v)[v->getarraylength() - 1], &str1) == true)
2065 		{
2066 		  (*(*v)[v->getarraylength() - 1].value)[0] = str1;
2067 		  *(*v)[v->getarraylength() - 1].label = *(*polish)[parsepoint].label;
2068 		  (*v)[v->getarraylength() - 1].status = OBJ_ARRAYMEMBER;
2069 		}
2070 	      else
2071 		return errormessage(lineno, "invalid arguments", "");
2072 	    }
2073 	  else
2074 	    return errormessage(lineno, "invalid arguments", "");
2075         }
2076       else
2077 	{
2078 	  om = opmap;
2079 	  for (; om->op; om++)
2080 	    {
2081 	    }
2082 	  itemno = om - opmap;
2083 	  for (int i = 0; i < itemno; i++)
2084 	    {
2085 	      if (status == opmap[i].op)
2086 		{
2087 		  execfunc = opmap[i].func;
2088 		  if (execfunc(this, status, lineno) == false)
2089 		    return false;
2090 		}
2091 	    }
2092 	}
2093     }
2094 
2095   return true;
2096 }
2097 
2098 
2099 
2100 
2101 
2102 
2103 
2104 
2105 
2106 
2107 
2108