1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
|
From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Thu, 14 Nov 2024 00:58:31 +0100
Subject: Remove needless allocations. Read input with std::getline() instead
of fgets(1024). Calculate path to ~/.concalcvariables once. Allow all input
files to be non-seekable
---
src/concalc.cpp | 332 +++++++++++++++++---------------------------------------
src/global.h | 24 ++--
2 files changed, 114 insertions(+), 242 deletions(-)
diff --git a/src/concalc.cpp b/src/concalc.cpp
index 3805eb4..be8f9b8 100644
--- a/src/concalc.cpp
+++ b/src/concalc.cpp
@@ -17,6 +17,10 @@ any later version.
#include "global.h"
#include <sys/time.h>
#include <float.h>
+#include <iostream>
+#include <fstream>
+#include <iterator>
+#include <string>
#include <stdlib.h>
#include "concalc.h"
@@ -49,25 +53,23 @@ any later version.
int main(int argc,char**argv)
{
- Variable *vars=new Variable[VARNUM];
+ Variable vars[VARNUM]{};
Number value;
- for(int c=0; c<VARNUM;c++)
- vars[c]=0.0;
- Preferences *pref=new Preferences;
+ Preferences pref_;
+ const auto pref = &pref_;
pref->angle=RAD;
pref->calcType=SCIENTIFIC;
pref->base=DEC;
pref->complex=false;
bool ask=true;
- char*input=NULL;
+ std::string input;
bool script=false;
- Script*s;
ThreadSync scriptData;
scriptData.vars=new Number*[VARNUM];
for(int c=0; c<VARNUM;c++)
{
- scriptData.vars[c]=(Number*)malloc(sizeof(Number));
+ scriptData.vars[c]=new Number;
scriptData.numlen[c]=1;
for(int c1=0; c1<VARDIMENSIONS; c1++)
scriptData.dimension[c][c1]=1;
@@ -75,81 +77,68 @@ int main(int argc,char**argv)
scriptData.vars[c][0].cval=NULL;
}
-
+
#ifndef NO_LONG_DOUBLE
pref->outputLength=pref->precision=LDBL_DIG;
int maxLength=LDBL_DIG;
-#else
+#else
pref->outputLength=pref->precision=DBL_DIG;
int maxLength=DBL_DIG;
#endif
- char*homedir=getenv("HOME");
- char*path=new char[strlen(homedir)+20];
- memcpy(path,homedir,strlen(homedir));
- memcpy(&path[strlen(homedir)],"/.concalcvariables",19);
+ std::string variablesPath=getenv("HOME");
+ variablesPath += "/.concalcvariables";
struct timeval rndTime;
gettimeofday(&rndTime,NULL);
srand(rndTime.tv_usec*rndTime.tv_sec);
-
+
int fileLength;
struct stat fileStat;
char*variablesString;
- char*var;
-
- if(lstat(path,&fileStat) == 0)
- {
- FILE*variablesFile=fopen(path,"r");
+ FILE*variablesFile=fopen(variablesPath.c_str(),"r");
if(variablesFile!=NULL)
{
fileLength=fileStat.st_size;
- variablesString=new char[fileLength+1];
- fread(variablesString,fileLength,1,variablesFile);
-
+ char *var{};
+ size_t varLineCap{};
+ ssize_t varLineLen{};
+
int varStart=0;
int varEnd=0;
int varCount=0;
bool real=true;
-
-
- for(int c=0; c<fileLength && varCount<27; c++)
+
+
+ for(int c=0; (varLineLen = getline(&var, &varLineCap, variablesFile)) != -1 && varCount<27; c++)
{
- if(variablesString[c]=='\n' || c == fileLength-1)
- {
- varEnd=c;
- var=new char[varEnd-varStart+1];
- memcpy(var,&variablesString[varStart],varEnd-varStart);
- var[varEnd-varStart]=(char)0;
+ if(var[varLineLen - 1] == '\n')
+ var[varLineLen - 1] = '\0';
+
scriptData.vars[varCount][0].type=NFLOAT;
if(real)
{
#ifndef NO_LONG_DOUBLE
vars[varCount]=strtold(var,NULL);
-#else
+#else
vars[varCount]=strtod(var,NULL);
#endif
real=false;
}
- else
+ else
{
#ifndef NO_LONG_DOUBLE
scriptData.vars[varCount][0].fval=Complex(vars[varCount],strtold(var,NULL));
-#else
+#else
scriptData.vars[varCount][0].fval=Complex(vars[varCount],strtod(var,NULL));
#endif
varCount++;
real=true;
}
- varStart=varEnd+1;
- delete[] var;
- }
}
fclose(variablesFile);
- delete[] variablesString;
}
- }
for(int c=1; c<argc; c++)
@@ -166,16 +155,12 @@ int main(int argc,char**argv)
pref->angle=GRA;
else {
printf("Invalid argument for -a!\n\nPossible Arguments:\n-a deg\n-a rad\n-a gra\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
c++;
}
else {
printf("Invalid argument for -a!\n\nPossible Arguments:\n-a deg\n-a rad\n-a gra\n\nPlease use man calc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
}
@@ -194,16 +179,12 @@ int main(int argc,char**argv)
}
else {
printf("Invalid argument for -m!\n\nPossible Arguments:\n-m base\n-m std\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
c++;
}
else {
printf("Invalid argument for -m!\n\nPossible Arguments:\n-m base\n-m std\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
}
@@ -221,16 +202,12 @@ int main(int argc,char**argv)
pref->base=DEC;
else {
printf("Invalid argument for -m!\n\nPossible Arguments:\n-m base\n-m std\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
c++;
}
else {
printf("Invalid argument for -b!\n\nPossible Arguments:\n-b dec\n-b hex\n-b bin\n-b oct\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
}
@@ -242,18 +219,14 @@ int main(int argc,char**argv)
if(outLen<2 || outLen>pref->precision)
{
printf("Invalid argument for -o!\n\nThe argument must be a number between 2 and %i.\nFor example: -o 8\n\nPlease use man concalc for further information\n",pref->precision);
- delete pref;
- delete[] vars;
return 0;
}
pref->outputLength=outLen;
-
+
c++;
}
else {
printf("Invalid argument for -o!\n\nThe argument must be a number between 2 and %i.\nFor example: -o 8\n\nPlease use man concalc for further information\n",pref->precision);
- delete pref;
- delete[] vars;
return 0;
}
}
@@ -264,83 +237,48 @@ int main(int argc,char**argv)
else if(strcmp(argv[c],"-h")==0 || strcmp(argv[c],"--help")==0)
{
printf("Usage:\nconcalc \"input\"\nFor example: calc \"2*(3+7/2)\"\n\nOptions:\n-a, --angle (deg, rad, gra)\n-m, --mode (base, std, script)\n-c, --complex\n-b, --base (dec, hex, bin, oct) only in base mode\n-o, --output (2-18)\n-h, --help\n-v, --version\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
- return 0;
+ return 0;
}
else if(strcmp(argv[c],"-v")==0 || strcmp(argv[c],"--version")==0)
{
printf("\n%s\n\n%s",VERSIONSTRING,AUTHORSTRING);
- delete pref;
- delete[] vars;
- return 0;
+ return 0;
}
else {
ask=false;
- if(input==NULL)
- {
- input=(char*)malloc(strlen(argv[c])+1);
- memcpy(input,argv[c],strlen(argv[c])+1);
- }
- else {
- char*temp=input;
- input=(char*)malloc(strlen(argv[c])+strlen(temp)+1);
- memcpy(input,temp,strlen(temp));
- memcpy(&input[strlen(temp)],argv[c],strlen(argv[c])+1);
- }
+ input += argv[c];
}
}
if(pref->calcType == SCIENTIFIC && pref->base!=DEC)
{
printf("Invalid option -b!\nOption -b can only be used when -m is set!\n\nPlease use man concalc for further information\n");
- delete pref;
- delete[] vars;
return 0;
}
if(ask)
{
- input=(char*)malloc(1026);
- scanf("%1024s",input);
+ std::getline(std::cin, input);
}
if(script)
{
- char*path=input;
- struct stat fileinfo;
- FILE*scriptFile;
- if(lstat(path,&fileinfo)!=0)
+ std::string path = std::move(input);
+ std::ifstream ifs{path};
+ if(!ifs)
{
- printf("Opening script file %s failed!\n",path);
- delete[]path;
+ printf("Opening script file %s failed!\n",path.c_str());
return 0;
}
- if(fileinfo.st_size<=0)
+ input={std::istreambuf_iterator<char>{ifs}, {}};
+ if(input.empty())
{
- printf("Invalid file %s !\n",path);
- delete[]path;
+ printf("File %s empty !\n",path.c_str());
return 0;
}
- scriptFile=fopen(path,"r");
- if(scriptFile==NULL)
- {
- printf("Opening script file %s failed!\n",path);
- delete[]path;
- return 0;
- }
- input =(char*)malloc(fileinfo.st_size+2);
- if(fread(input,fileinfo.st_size,1,scriptFile)<=0)
- {
- printf("Can't read file %s !\n",path);
- delete[]path;
- return 0;
- }
- input[fileinfo.st_size]=(char)0;
}
- char*printString=new char[50];
char*res=NULL;
-
+
scriptData.error=false;
-
+
struct termios terminfo,oldTerminfo;
tcgetattr(fileno(stdout),&terminfo);
@@ -354,62 +292,52 @@ int main(int argc,char**argv)
scriptData.usleep=false;
scriptData.bbreak=false;
scriptData.bcontinue=false;
-
+
scriptData.exit=false;
-
+
if(script)
{
-
-
+
+
scriptData.countDifference=0;
- initDebugging(input,&scriptData);
- res=preprocessor(input,pref,true);
-
-
+ initDebugging(input.data(),&scriptData);
+ res=preprocessor(input.data(),pref,true);
+
+
if(res==NULL)
{
fprintf(stderr,"Preprocessor Error\n");
- free(input);
- delete[]printString;
- delete[]vars;
- delete pref;
tcsetattr(fileno(stdout),TCSANOW,&oldTerminfo);
return 0;
}
searchScripts(res,pref,vars,&scriptData);
-
+
scriptData.calcMode=false;
fprintf(stderr,"\nProcessing main file ...\n");
- s=new Script((Script*)NULL,res,pref,vars,&scriptData);
- loadSubScripts(&scriptData,pref,vars,s);
+ Script s((Script*)NULL,res,pref,vars,&scriptData);
+ loadSubScripts(&scriptData,pref,vars,&s);
if(scriptData.error)
{
fprintf(stderr,"Script processing failed\n");
- free(input);
- delete[]printString;
- delete[]vars;
- delete pref;
- delete s;
tcsetattr(fileno(stdout),TCSANOW,&oldTerminfo);
return 0;
}
- value=s->exec();
+ value=s.exec();
}
- else
+ else
{
- res=preprocessor(input,pref,false);
+ res=preprocessor(input.data(),pref,false);
scriptData.calcMode=true;
- s=new Script((Script*)NULL,res,pref,vars,&scriptData);
- value=s->exec();
- delete s;
+ Script s((Script*)NULL,res,pref,vars,&scriptData);
+ value=s.exec();
}
-
-
+
+
if(pref->calcType==SCIENTIFIC)
- {
+ {
switch(value.type)
{
case NFLOAT:
@@ -423,7 +351,7 @@ int main(int argc,char**argv)
printf("%.*Lg+%.*Lgi",pref->outputLength,real(value.fval),pref->outputLength,imag(value.fval));
else printf("%.*Lg%.*Lgi",pref->outputLength,real(value.fval),pref->outputLength,imag(value.fval));
}
-
+
break;
}
case NINT:
@@ -450,7 +378,7 @@ int main(int argc,char**argv)
}
else {
long long ival;
-
+
switch(value.type)
{
case NFLOAT:
@@ -465,8 +393,8 @@ int main(int argc,char**argv)
default:
ival=0;
}
-
-
+
+
switch(pref->base)
{
case DEC:
@@ -475,7 +403,7 @@ int main(int argc,char**argv)
case BIN:
{
long long result=ival;
- char*cRes=new char[65];
+ char cRes[65];
cRes[64]=(char)0;
for(long long c=0; c<64;c++)
{
@@ -498,16 +426,13 @@ int main(int argc,char**argv)
case OCT:
printf("%llo\n",ival);
break;
- }
+ }
}
- char*newVarString="";
-
- char*varString=new char[maxLength+20];
-
scriptData.vars[26][0]=value;
+ variablesFile=fopen(variablesPath.c_str(),"w");
for(int c=0; c<27; c++)
{
if(scriptData.vars[c][0].type==NINT)
@@ -516,38 +441,14 @@ int main(int argc,char**argv)
scriptData.vars[c][0].fval=Complex((long double)scriptData.vars[c][0].bval,0.0);
else if(scriptData.vars[c][0].type!=NFLOAT)
scriptData.vars[c][0].fval=Complex(NAN,0.0);
-
- sprintf(varString,"%.*Lg",maxLength,scriptData.vars[c][0].fval.real());
- newVarString=strins(newVarString,varString,strlen(newVarString));
- newVarString=strins(newVarString,"\n",strlen(newVarString));
-
- sprintf(varString,"%.*Lg",maxLength,scriptData.vars[c][0].fval.imag());
- newVarString=strins(newVarString,varString,strlen(newVarString));
- newVarString=strins(newVarString,"\n",strlen(newVarString));
- }
- chdir(getenv("HOME"));
- FILE*variablesFile=fopen(".concalcvariables","w");
- if(variablesFile!=NULL)
- {
- fwrite(newVarString,strlen(newVarString),1,variablesFile);
- fclose(variablesFile);
- }
- delete[] newVarString;
- tcsetattr(fileno(stdout),TCSANOW,&oldTerminfo);
-
- free(res);
- for(int c=0; c<VARNUM; c++)
- {
- if(scriptData.vars[c]!=NULL)
- free(scriptData.vars[c]);
+ if(variablesFile!=NULL) {
+ fprintf(variablesFile,"%.*Lg\n",maxLength,scriptData.vars[c][0].fval.real());
+ fprintf(variablesFile,"%.*Lg\n",maxLength,scriptData.vars[c][0].fval.imag());
+ }
}
- delete[] scriptData.vars;
- delete pref;
- delete[] vars;
- delete[] path;
- delete[] varString;
- delete[] printString;
+ tcsetattr(fileno(stdout),TCSANOW,&oldTerminfo);
+
return 0;
}
@@ -562,8 +463,7 @@ void initDebugging(char*code,ThreadSync*scriptData)
bool quote=false;
char* line;
int len=strlen(code);
-
- int lineLen;
+
int lineCount=0;
int run=1;
int c;
@@ -574,11 +474,8 @@ void initDebugging(char*code,ThreadSync*scriptData)
if(c>=len)
run=false;
lineCount++;
- line=new char[pos2-pos1+1];
- memcpy(line,&code[pos1],pos2-pos1);
- line[pos2-pos1]=(char)0;
- lineLen=strlen(line);
- for(int c=0; c<lineLen && !(line[c]=='/' && line[c+1]=='/'); c++)
+ std::string line{&code[pos1],size_t(pos2-pos1)};
+ for(int c=0; c<line.size() && !(line[c]=='/' && line[c+1]=='/'); c++)
{
if(line[c]=='\"')
quote=!quote;
@@ -588,7 +485,6 @@ void initDebugging(char*code,ThreadSync*scriptData)
}
}
pos1=pos2+1;
- delete[]line;
}
}
@@ -610,36 +506,21 @@ void searchScripts(char*code,Preferences*pref,Variable*vars,ThreadSync*scriptDat
pos++;
continue;
}
- scriptName=new char[pos2-pos-5];
- strcopy(scriptName,&code[pos+5],pos2-pos-6);
+ std::string scriptName{&code[pos+5],size_t(pos2-pos-5)};
bool newScript=true;
for(int c=0; c<scriptData->subprogramPath.GetLen(); c++)
- if(strcmp(scriptData->subprogramPath[c],scriptName)==0)
+ if(scriptData->subprogramPath[c]==scriptName)
{
newScript=false;
break;
}
if(newScript)
{
- struct stat fileStat;
- char*subFileContent;
-
- if(lstat(scriptName,&fileStat)!=0)
- ;
- else {
- subFile=fopen(scriptName,"r");
- if(subFile==NULL || fileStat.st_size<=0)
- ;
- else
- {
- subFileContent=new char[fileStat.st_size+1];
- subFileContent[fileStat.st_size]=(char)0;
- fread(subFileContent,fileStat.st_size,1,subFile);
- fclose(subFile);
- scriptData->subprogramPath.NewItem(scriptName);
- searchScripts(subFileContent,pref,vars,scriptData);
- delete[]subFileContent;
- }
+ std::ifstream subFile{scriptName};
+ if(subFile)
+ {
+ std::string subFileContent{std::istreambuf_iterator<char>{subFile}, {}};
+ searchScripts(subFileContent.data(),pref,vars,scriptData);
}
}
pos=pos2+1;
@@ -660,21 +541,14 @@ void loadSubScripts(ThreadSync*scriptData,Preferences*pref,Variable*vars,Script*
for(int c=0; c<scriptData->subprogramPath.GetLen(); c++)
{
filePath=scriptData->subprogramPath[c];
- if(lstat(filePath,&fileStat)!=0)
+ std::ifstream subFile{filePath};
+ if(!subFile)
scriptData->subprograms.NewItem((Math*)NULL);
else {
- subFile=fopen(filePath,"r");
- if(subFile==NULL || fileStat.st_size<=0)
- scriptData->subprograms.NewItem((Math*)NULL);
- else
- {
- subFileContent=new char[fileStat.st_size+1];
- subFileContent[fileStat.st_size]=(char)0;
- fread(subFileContent,fileStat.st_size,1,subFile);
- fclose(subFile);
+ std::string subFileContent{std::istreambuf_iterator<char>{subFile}, {}};
scriptData->countDifference+=scriptData->semicolonLines.GetLen();
- initDebugging(subFileContent,scriptData);
- cleanSubFileContent=preprocessor(subFileContent,pref,true);
+ initDebugging(subFileContent.data(),scriptData);
+ cleanSubFileContent=preprocessor(subFileContent.data(),pref,true);
fprintf(stderr,"\nProcessing file ");
fprintf(stderr,"%s", scriptData->subprogramPath[c]);
fprintf(stderr,"\n");
@@ -683,14 +557,12 @@ void loadSubScripts(ThreadSync*scriptData,Preferences*pref,Variable*vars,Script*
fprintf(stderr,"Preprocessor Error\n");
subScript=NULL;
}
- else
+ else
{
subScript=new Script(parent,NULL,pref,vars,scriptData);
subScript->split(cleanSubFileContent,0,strlen(cleanSubFileContent));
}
- free(subFileContent);
scriptData->subprograms.NewItem(subScript);
- }
}
}
@@ -702,8 +574,8 @@ int preferencesPreprocessor(char *code,Preferences*pref)
int pos=0,startPos=0,endPos=0,len;
bool comment=false,quote=false;
char*configString=NULL;
-
-
+
+
while(pos<=(len=strlen(code)))
{
if(quote)
@@ -725,20 +597,20 @@ int preferencesPreprocessor(char *code,Preferences*pref)
startPos=pos;
int configStartPos=startPos;
endPos=pos;
-
+
if(strncmp(&code[startPos],"#config",7)==0)
configStartPos+=7;
else return PPINVALIDCOMMAND;
-
+
while(code[endPos]!='\n' && endPos<=len) endPos++;
-
-
+
+
while((code[configStartPos]==' ' || code[configStartPos]=='\t') && configStartPos<=len) configStartPos++;
-
+
configString=(char*)realloc(configString,endPos-configStartPos+1);
strcopy(configString,&code[configStartPos],endPos-configStartPos);
-
+
if(strncmp(configString,"complexon",9)==0)
pref->complex=true;
@@ -763,19 +635,19 @@ int preferencesPreprocessor(char *code,Preferences*pref)
else return PPINVALIDARGUMENT;
}
else return PPINVALIDPREF;
-
+
memmove(&code[startPos],&code[endPos],len-endPos+1);
-
+
if(endPos==len)
break;
pos=startPos;
}
pos++;
}
-
+
if(strlen(code)<=0)
return PPEMPTY;
-
+
return 0;
}
*/
diff --git a/src/global.h b/src/global.h
index d2ee9ea..169218f 100644
--- a/src/global.h
+++ b/src/global.h
@@ -179,7 +179,7 @@ using namespace std;
#endif
#ifdef M_El
#define EULER M_El
-#else
+#else
#define EULER 2.718281828459045235360287471352662497757
#endif
#define SPI "3.141592653589793238462643383279502884197"
@@ -307,8 +307,8 @@ class Math
double number;
int var;
-
-
+
+
public:
int operation;
Math(Math*par,Preferences*pr,Variable*va)
@@ -330,33 +330,33 @@ class Math
horzObj=NULL;
}
}
-
+
int getOperation()
{
return operation;
}
-
+
virtual double calc() {return 0.0;}
virtual double calcVertObj() {return 0.0;}
virtual double calcHorzObj() {return 0.0;}
-
+
virtual Number exec() {Number r;r.type=NNONE;return r;}
virtual Number execVertObj() {Number r;r.type=NNONE;return r;}
virtual Number execHorzObj() {Number r;r.type=NNONE;return r;}
virtual int split(char*,int,int){return 0;}
virtual int parse(char*,int,int){return 0;}
-
+
};
class Calculate :public Math
{
-
+
virtual int split(char* line,int,int);
public:
-
+
Calculate(Math *par,char* line,int start, int end,Preferences*pr,Variable*va) :Math((Math*)par,pr,va)
{
horzObj=vertObj=NULL;
@@ -398,9 +398,9 @@ class Script :public Math
Number value;
Math *vertObj2,*vertObj3,*vertObj4;
ThreadSync*eventReciver;
-
+
private:
-
+
inline bool resizeVar(int var,int newlen);
public:
@@ -428,7 +428,7 @@ class Script :public Math
}
}
}
-
+
Script(Script*par,char*line,int start,int end,Preferences*pr,Variable*va,ThreadSync*evrec) :Math((Math*)par,pr,va)
{
horzObj=vertObj=vertObj2=vertObj3=vertObj4=NULL;
|