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 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
|
// crm_math_exec.c - Controllable Regex Mutilator, version v1.0
// Copyright 2001-2006 William S. Yerazunis, all rights reserved.
//
// This software is licensed to the public under the Free Software
// Foundation's GNU GPL, version 2. You may obtain a copy of the
// GPL by visiting the Free Software Foundations web site at
// www.fsf.org, and a copy is included in this distribution.
//
// Other licenses may be negotiated; contact the
// author for details.
//
// include some standard files
#include "crm114_sysincludes.h"
// include any local crm114 configuration file
#include "crm114_config.h"
// include the crm114 data structures file
#include "crm114_structs.h"
// and include the routine declarations file
#include "crm114.h"
// the command line argc, argv
extern int prog_argc;
extern char **prog_argv;
// the auxilliary input buffer (for WINDOW input)
extern char *newinputbuf;
// the globals used when we need a big buffer - allocated once, used
// wherever needed. These are sized to the same size as the data window.
extern char *inbuf;
extern char *outbuf;
extern char *tempbuf;
static int math_formatter ( double value, char *format, char *buf);
//
// strmath - evaluate a string for the mathematical result
//
long strmath (char *buf, long inlen, long maxlen, long *retstat)
{
long status;
if (inlen < 0)
{
fatalerror ("Bug in caller to strmath() - it makes no sense to",
" have a negative length string! \n");
return (0);
};
// Check for first-character control of Algebraic v. RPN
if (buf[0] == 'A')
{
status = stralmath (&buf[1], inlen-1, maxlen, retstat);
memmove (buf, &buf[1], inlen-1);
buf[inlen] = '\0';
return (status);
}
if (buf[0] == 'R')
{
status = strpnmath (&buf[1], inlen-1, maxlen, retstat);
memmove (buf, &buf[1], inlen-1);
buf[inlen] = '\0';
return (status);
}
// No first-character control, so use q_expansion_mode to control.
if (q_expansion_mode == 0 || q_expansion_mode == 2)
{
return (stralmath (buf, inlen, maxlen, retstat));
}
else
{
return (strpnmath (buf, inlen, maxlen, retstat));
}
}
// strpnmath - do a basic math evaluation of very simple expressions.
//
// This does math, in RPN, on a string, and returns a string value.
//
long strpnmath (char *buf, long inlen, long maxlen, long *retstat)
{
double stack [DEFAULT_MATHSTK_LIMIT]; // the evaluation stack
double sd; // how many 10^n's we've seen since a decimal
long od; // output decimal flag
long ip, op; // in string pointer, out string pointer
long sp; // stack pointer - points to next (vacant) space
long sinc; // stack incrment enable - do we start a new number
long errstat; // error status
char outformat[64]; // output format
long outstringlen;
// start off by initializing things
ip = 0; // in pointer is zero
op = 0; // output pointer is zero
sp = 0; // still at the top of the stack
od = 0; // no decimals seen yet, so no flag to output in decimal
sinc = 0; // no autopush.
outformat[0] = '\0';
// now our number-inputting hacks
stack[sp] = 0.0 ;
sd = 1.0;
// all initialized... let's begin.
if (internal_trace)
fprintf (stderr, "Math on '%s' len %ld retstat %lx \n",
buf, inlen, (long) retstat);
for (ip = 0; ip < inlen; ip++)
{
if (internal_trace)
fprintf (stderr, "ip = %ld, sp = %ld, stack[sp] = %f, ch='%c'\n",
ip, sp, stack[sp], buf[ip]);
if (sp < 0)
{
errstat = nonfatalerror ("Stack Underflow in math evaluation",
"");
return (0);
};
if (sp >= DEFAULT_MATHSTK_LIMIT)
{
errstat=nonfatalerror ("Stack Overflow in math evaluation.\n "
"CRM114 Barbie says 'This math is too hard'.",
buf);
return (0);
};
switch (buf[ip])
{
//
// a digit,or maybe a number - big change - we now use strtod
//
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
{
char *frejected;
// handle the case of a minus sign that isn't a unary -.
if (buf[ip] == '-' && !( isdigit (buf[ip+1])))
{
if (sp > 0)
{
sp--;
stack[sp] = stack[sp] - stack[sp+1];
sinc = 1;
}
break;
};
// use atof to convert the string we're looking at.
sp++;
stack[sp] = strtod ( &buf[ip], &frejected);
if (user_trace)
fprintf (stderr, "got number: %e\n", stack[sp]);
//
// Now, move [ip] over to accomodate characters used.
// (the -1 is because there's an auto-increment in the big
// FOR-loop)
ip = ((unsigned long) frejected) - ((unsigned long) buf ) - 1;
}
break;
//
// and some basic math ops...
//
case '+':
{
if (sp > 0)
{
sp--;
stack[sp] = stack[sp] + stack[sp+1];
sinc = 1;
}
};
break;
case '*':
{
if (sp > 0)
{
sp--;
stack[sp] = stack[sp] * stack[sp+1];
sinc = 1;
}
};
break;
case '/':
{
if (sp > 0)
{
sp--;
if(stack[sp+1] != 0.0)
{
stack[sp] = stack[sp] / stack[sp+1];
sinc = 1;
}
else
{
if (retstat) *retstat = -1;
nonfatalerror ("Attempt to divide by zero in this:",
buf);
}
}
};
break;
case '%':
{
if (sp > 0)
{
sp--;
stack[sp] = ((long long) stack[sp]) % ((long long)stack[sp+1]);
sinc = 1;
}
};
break;
case '=':
{
if (sp > 0)
{
sp--;
if (stack[sp] == stack[sp+1])
{
if (retstat) *retstat = 0;
stack[sp] = 1;
}
else
{
if (retstat) *retstat = 1;
stack[sp] = 0;
};
sinc = 1;
}
};
break;
case '>':
{
if (sp > 0)
{
sp--;
if (stack[sp] > stack[sp+1])
{
if (retstat) *retstat = 0;
stack[sp] = 1;
}
else
{
if (retstat) *retstat = 1;
stack[sp] = 0;
};
sinc = 1;
}
};
break;
case '<':
{
if (sp > 0)
{
sp--;
if (stack[sp] < stack[sp+1])
{
if (retstat) *retstat = 0;
stack[sp] = 1;
}
else
{
if (retstat) *retstat = 1;
stack[sp] = 0;
};
sinc = 1;
}
};
break;
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
case 'x':
case 'X':
// User-specified formatting; use the user's
// top-of-stack value as a format.
//
{
if (sp > 0)
{
char tempstring [2048];
// Special case - if the format is an integer, add a ".0"
// to the format string so we get integer output.
if ( ((long)stack[sp+1]) / 1 == stack[sp+1])
{
sprintf(outformat,"%%%g.0%c",stack[sp+1], buf[ip]);
}
else
{
sprintf(outformat,"%%%g%c", stack[sp+1], buf[ip]);
};
sp--;
if (internal_trace)
fprintf (stderr, "Format string -->%s<-- \n", outformat);
stack[sp+1] = 0;
sprintf (tempstring, outformat, stack[sp]);
if (internal_trace)
fprintf (stderr, "Intermediate result string -->%s<-- \n",
tempstring);
// Note that X formatting (hexadecimal) does NOT do the
// back conversion; the only effect is to store the
// format string for later.
if (buf[ip] != 'x' &&
buf[ip] != 'X')
stack[sp] = strtod (tempstring, NULL);
}
};
break;
case ' ':
case '\n':
case '\t':
//
// a space is just an end-of-number - push the number we're
// seeing.
{
sinc = 1;
};
break;
case '(':
case ')':
// why are you using parenthesis in RPN code??
{
nonfatalerror ("It's just silly to use parenthesis in RPN!",
" Perhaps you should check your setups?");
sinc = 1;
};
break;
default:
{
char bogus[4];
bogus[0] = buf[ip];
bogus[1] = '\000';
nonfatalerror (" Sorry, but I can't do RPN math on the un-mathy "
"character found: ", bogus);
sinc = 1;
};
break;
};
};
if (internal_trace)
{
fprintf (stderr,
"Final qexpand state: ip = %ld, sp = %ld, stack[sp] = %f, ch='%c'\n",
ip, sp, stack[sp], buf[ip]);
if (retstat)
fprintf (stderr, "retstat = %ld\n", *retstat);
};
// now the top of stack contains the result of the calculation.
// fprintf it into the output buffer, and we're done.
outstringlen = math_formatter ( stack[sp], outformat, buf) ;
return (outstringlen);
}
/////////////////////////////////////////////////////////////////
//
// Here's where we format a floating point number so it's "purty".
// Note that if "format" is NULL, or a null string, we do smart
// formatting on the number itself.
//
//
int math_formatter ( double value, char *format, char *buf)
{
// If the user supplied a format, use that.
//
if (format && format[0] != '\0')
{
//
// special case - if the user supplied an x or X-format, that's
// preconversion to integer; use that strlen() does not count
// the null termination.
if (format[strlen(format)-1] == 'x'
|| format[strlen(format)-1] == 'X')
{
long long equiv ;
// fprintf (stderr, "BLARG\n");
equiv = value * 1;
//fprintf (stderr, "Equiv: %llx\n", equiv);
sprintf (buf, format, equiv);
return (strlen (buf));
};
//
// Nothing so special; use the user format as it is.
sprintf (buf, format, value);
return (strlen (buf));
};
// Nope - we didn't get a preferred formatting, so here's the
// adaptive smart code.
//
// print out 0 as 0
//
if (value == 0.0 )
{
sprintf (buf, "0");
goto formatdone;
}
//
// use E notation if bigger than 1 trillion
//
if (value > 1000000000000.0 || value < -1000000000000.0 )
{
sprintf (buf, "%.5E", value);
goto formatdone;
}
//
// use E notation if smaller than .01
//
if ( value < 0.01 && value > -0.01 )
{
sprintf (buf, "%.5E", value);
goto formatdone;
}
//
// if an integer value, print with 0 precision
//
if (((long)(value*2.0) / 2) == value)
{
sprintf (buf, "%.0f", value);
goto formatdone;
}
//
// if none of the above, print with five digits precision
//
sprintf (buf, "%.5f", value);
//
//
// one way or another, once we're here, we've sprinted it.
formatdone:
return (strlen (buf));
}
//
// stralnmath - evaluate a mathematical expression in algebraic
// (that is, infix parenthesized) notation.
//
// The algorithm is this:
// see an open parenthesis - push an empty level
// see a close parethesis - try to "reduce", then pop over the empty
// see an operator - push it onto opstack, sp++
// see a number - push it, then try to "reduce" if there's a valid op.
//
// reduce:
// while sp > 0
// if opstack[sp-1] valid
// sp--
// execute opstack[sp] on [sp], [sp+1]
// replace sp with result
//
// Note that the empty levels (opstack[sp] == '\000') that are
// produced by open and close parens are how we prevent runaway
// reduce operations on the stack.
//
long stralmath (char *buf, long inlen, long maxlen, long *retstat)
{
double valstack [DEFAULT_MATHSTK_LIMIT]; // the evaluation value stack
char opstack [DEFAULT_MATHSTK_LIMIT]; // the evaluation operator stack
double sd; // how many 10^n's we've seen since a decimal
long od; // output decimal flag
long ip, op; // in string pointer, out string pointer
long sp; // stack pointer - points to next (vacant) space
long sinc; // stack incrmenter - do we push on next digit in?
long errstat; // error status
char outformat[64]; // output format (if needed)
// start off by initializing things
ip = 0; // in pointer is zero
op = 0; // output pointer is zero
sp = 0; // still at the top of the stack
od = 0; // no decimals seen yet, so no flag to output in decimal
sinc = 0; // no autopush.
outformat [0] = '\0';
// now our number-inputting hacks
valstack[sp] = 0.0 ;
opstack[sp] = '\000';
sd = 1.0;
// all initialized... let's begin.
if (internal_trace)
fprintf (stderr, "Math on '%s' len %ld *retstat %lx \n",
buf, inlen, (long) retstat);
for (ip = 0; ip < inlen; ip++)
{
if (internal_trace)
fprintf (stderr, "ip = %ld, sp = %ld, valstack[sp] = %f,"
"opstack = '%c', h='%c'\n",
ip, sp, valstack[sp], opstack[sp], buf[ip]);
if (sp < 0)
{
errstat = nonfatalerror ("Stack Underflow in math evaluation",
"");
return (0);
};
if (sp >= DEFAULT_MATHSTK_LIMIT)
{
errstat = nonfatalerror ("Stack Overflow in math evaluation. ",
"CRM114 Barbie says 'This math is too hard'.");
return (0);
};
switch (buf[ip])
{
//
// a digit,or maybe a number - big change - we now use strtod
//
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
{
char *frejected;
if (user_trace)
fprintf (stderr, " found a poss number starting with %c, ",
buf[ip]);
// handle the case of a minus sign that isn't a unary -.
if (buf[ip] == '-'
&& !( isdigit (buf[ip+1])))
{
if (sp > 0 && opstack[sp-1] != '\000')
{
long state;
if (user_trace)
fprintf (stderr, "nope, dyadic minus. \n");
if (sp > 0) sp--;
state = stralmath_reduce (valstack, opstack,
&sp, outformat);
if (state != -1 && retstat) *retstat = state;
}
opstack[sp] = buf[ip];
if (opstack[sp] == ' ') opstack[sp] = '\000';
}
else
{
// use atof to convert the string we're looking at.
sp++;
opstack[sp] = '\000';
valstack[sp] = strtod ( &buf[ip], &frejected);
if (user_trace)
fprintf (stderr, " got number: %e\n", valstack[sp]);
//
// Now, move [ip] over to accomodate characters used.
// (the -1 is because there's an auto-increment in the big
// FOR-loop)
ip = ((unsigned long) frejected) - ((unsigned long) buf ) - 1;
sinc = 0;
}
}
break;
//
// and now the parenthesis ops
//
// open paren- we start a new stack level
case '(':
{
if (user_trace)
fprintf (stderr, " got open parenthesis\n");
sd = 1.0;
sp++;
valstack[sp] = 0.0;
opstack[sp] = '\000';
};
break;
//
// close paren- we finish evaluation down to the open,
// then supply the result to the next lower level.
case ')':
{
long state;
if (user_trace)
fprintf (stderr, " got close parenthesis\n");
if (sp > 0) sp--;
state = stralmath_reduce (valstack, opstack, &sp, outformat);
if (state != -1 && retstat) *retstat = state;
if (sp > 0) sp--;
// and get rid of that extra level we inserted before.
valstack[sp] = valstack[sp+1];
};
break;
//
// The se dyadic operators just put themselves on the
// stack uunless there's a prior dyadic operator, that
// operator runs first.
//
// case '-': (this is handled up above, as part of unary '-'
case '+':
case '*':
case '/':
case '%':
case '=':
case '>':
case '<':
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
case 'x':
case 'X':
{
if (user_trace)
fprintf (stderr, " got dyadic operator %c\n", buf[ip]);
if (sp > 0 && opstack[sp-1] != '\000')
{
long state;
if (sp > 0) sp--;
state = stralmath_reduce (valstack, opstack, &sp, outformat);
if (state != -1 && retstat) *retstat = state;
};
sd = 1.0;
sinc = 1;
opstack[sp] = buf[ip];
if (opstack[sp] == ' ') opstack[sp] = '\000';
};
break;
case ' ':
case '\n':
case '\t':
break;
default:
{
char bogus[4];
bogus[0] = buf[ip];
bogus[1] = '\000';
nonfatalerror (" Sorry, but I can't do math on the un-mathy "
"character found: ", bogus);
};
break;
};
};
// Now do final executes....
if (sp > 0)
{
long state;
if (sp > 0 && opstack [sp-1] != '\000') sp--;
state = stralmath_reduce (valstack, opstack, &sp, outformat);
if (state != -1 && retstat) *retstat = state;
};
if (internal_trace)
{
fprintf (stderr,
"Final qexpand state: ip = %ld, sp = %ld, valstack[sp] = %f, ch='%c'\n",
ip, sp, valstack[sp], buf[ip]);
if (retstat)
fprintf (stderr, "retstat = %ld\n", *retstat);
};
// now the top of stack contains the result of the calculation.
// fprintf it into the output buffer, and we're done.
return (math_formatter (valstack[sp], outformat, buf));
}
//////////////////////////////////////////////////////////////////////
//
// stralmath_reduce - actually do the math for algebraic arithmetic.
// retval is 0 for "successful EQ's", and 1 for unsuccessful,
// and -1 for "no change".
//
long stralmath_reduce (double *valstack, char *opstack, long *sp, char *outformat)
{
long retval;
retval = -1;
if (internal_trace)
fprintf (stderr, " start: *sp = %3ld, "
"vs[*sp] = %6.3f, vs[*sp+1] = %6.3f, "
"op[*sp] = '%c'\n",
*sp, valstack[*sp], valstack[*sp+1], opstack[*sp]);
while (*sp >= 0 && opstack[*sp] != '\000')
{
if (internal_trace)
fprintf (stderr, "running: *sp = %3ld, "
"vs[*sp] = %6.3f, vs[*sp+1] = %6.3f, "
"op[*sp] = '%c'\n",
*sp, valstack[*sp], valstack[*sp+1], opstack[*sp]);
switch (opstack[*sp])
{
case '+':
valstack[*sp] = valstack[*sp] + valstack[*sp+1];
opstack[*sp] = '\000';
break;
case '-':
valstack[*sp] = valstack[*sp] - valstack[*sp+1];
opstack[*sp] = '\000';
break;
case '*':
valstack[*sp] = valstack[*sp] * valstack[*sp+1];
opstack[*sp] = '\000';
break;
case '/':
if (valstack[*sp+1] == 0.0)
{
opstack[*sp+1] = '\000';
nonfatalerror ("Attempt to divide by zero.","");
return (-1);
};
valstack[*sp] = valstack[*sp] / valstack[*sp+1];
opstack[*sp] = '\000';
break;
case '%':
valstack[*sp] = ((long long)valstack[*sp]) % ((long long) valstack[*sp+1]);
opstack[*sp] = '\000';
break;
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G':
case 'x':
case 'X':
// User-specified formatting; use the user's
// top-of-stack value as a format.
//
// Note the funny business in the cases where a .0
// format is needed, because .0 won't print directly
// when we build the format with a %g .
{
char tempstring [2048];
if ( ((long)valstack[*sp+1]) / 1 == valstack[*sp+1])
{
sprintf (outformat, "%%%g.0%c", valstack[*sp+1], opstack[*sp]);
}
else
{
sprintf (outformat, "%%%g%c", valstack[*sp+1], opstack[*sp]);
};
if (internal_trace)
fprintf (stderr, "Format string -->%s<-- \n", outformat);
// A little more funny business needed for hexadecimal print
// out, because X format can't take IEEE floating point
// as inputs.
if (opstack[*sp] != 'x' &&
opstack[*sp] != 'X')
{
// fprintf (stderr, "NORMAL ");
sprintf (tempstring, outformat, valstack[*sp]);
valstack[*sp] = strtod (tempstring, NULL);
}
else
{
// Note that we actually don't use the results of octal
// conversion; the only effect is to set the final format
// string.
long long equiv;
// fprintf (stderr, "BLORT ");
equiv = valstack[*sp] + 0;
// fprintf (stderr, "equiv -->%10lld<-- \n", equiv);
sprintf (tempstring, outformat, equiv);
}
if (internal_trace)
fprintf (stderr, "Intermediate result string -->%s<-- \n",
tempstring);
opstack [*sp] = '\000';
};
break;
//case 'e': // old code here for E - never used...
//case 'E':
//
// valstack[*sp] = valstack[*sp] * pow (10.0, valstack[*sp+1]);
//opstack[*sp] = '\000';
//break;
case '=':
if (valstack[*sp] == valstack[*sp+1])
{
valstack[*sp] = 1 ;
}
else
{
valstack[*sp] = 0;
}
opstack[*sp] = '\000';
retval = 1 - valstack[*sp];
break;
case '>':
if (valstack[*sp] > valstack[*sp+1])
{
valstack[*sp] = 1 ;
}
else
{
valstack[*sp] = 0;
}
opstack[*sp] = '\000';
retval = 1 - valstack[*sp];
break;
case '<':
if (valstack[*sp] < valstack[*sp+1])
{
valstack[*sp] = 1 ;
}
else
{
valstack[*sp] = 0;
}
opstack[*sp] = '\000';
retval = 1 - valstack[*sp];
break;
default:
break;
};
if (*sp > 0 && opstack[(*sp)-1] != '\000') *sp = *sp - 1;
};
if (internal_trace)
fprintf (stderr, " finish: *sp = %3ld, "
"vs[*sp] = %6.3f, vs[*sp+1] = %6.3f, "
"op[*sp] = '%c'\n",
*sp, valstack[*sp], valstack[*sp+1], opstack[*sp]);
return (retval);
}
|