X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=calc.c;h=500be08f98d982ef093a3de71bf7bad2d1b19c52;hb=a67f1cfd7bb89dfd00cdc099651b81456ca4c327;hp=e20b066dcd3b4538204f8feebfe22a9b01e06f88;hpb=de1ca79a91bc02ebf5bc2f404036c8a8e4c5453f;p=calc.git diff --git a/calc.c b/calc.c index e20b066..500be08 100644 --- a/calc.c +++ b/calc.c @@ -174,6 +174,7 @@ int main (int argc, char *argv[]) free (buffer); continue; } else if (strcmp (buffer, ".") == 0) { + free (buffer); break; } @@ -309,7 +310,7 @@ int main (int argc, char *argv[]) // test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | calc.exe -n | grep -q 2 // test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | calc.exe | grep -q 64 // test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | calc.exe | grep -q 2 -// test: echo -e '-cos (1)\n1 + 1\n1 - 1\n1 * 1\n1 / 1\n3%2\n2^2\nsqrt (2)\ncos (0)\nsin (0)\ntan (0)\nacos (0)\nasin (0)\natan (0)\nlog (1)\nexp (1)\nabs (-1)\nceil (1.2)\nfloor (-1.2)\nans\ne\npi\nsto (1)\nrcl (2)\ndisp\nhelp\nquit' | calc.exe -v 3 | grep -q bye +// test: echo -e '-cos (1)\n1 + 1\n1 - 1\n1 * 1\n1 / 1\n3%2\n2^2\nsqrt (2)\ncos (0)\nsin (0)\ntan (0)\nacos (0)\nasin (0)\natan (0)\nlog (1)\nexp (1)\nabs (-1)\nceil (1.2)\nfloor (-1.2)\nans\ne\npi\nsto (1)\nrcl (2)\ndisp\nhelp\nquit' | calc.exe -n -v 3 | grep -q bye // test: echo -e '1 +\n1 -\n1 * 1\n1 /\n3%\n2^\nsqrt ()\ncos ()\nsin ()\ntan ()\nacos ()\nasin ()\natan ()\nlog ()\nexp ()\nabs ()\nceil ()\nfloor ()\n1 + (\n1+2(\n1+2cos\n1+2pi' | calc.exe | grep -c error | xargs test 21 = // test: echo -e '1 + 1\nans' | calc.exe -p 3 | grep -c 2 | xargs test 2 = // test: echo -e 'sin (pi / 2)' | calc.exe -p 4 | grep -q 1 @@ -352,19 +353,19 @@ int main (int argc, char *argv[]) // test: echo -e 'sto (2, 3)\ncond (rcl (2) > 2, log (64), exp (75 / 10))' | calc.exe | grep -q '=> 4\.15888' // test: echo -e 'sto (2, 1)\ncond (rcl (2) > 2, log (64), exp (75 / 10))' | calc.exe | grep -q '=> 1808\.04' // test: echo -e 'sto (2, 1)\ncond (rcl (2) > 2, log (64))' | calc.exe | grep -q '=> 0' -// test: echo -e 'cond (0, 1, 2)' | calc.exe -v 3 | grep -q Cond +// test: echo -e 'cond (0, 1, 2)\nquit' | calc.exe -v 3 | grep -q Cond // test: echo -e 'cond\ncond (\ncond (1 >0,'| calc.exe | grep -c error | xargs test 3 = -// test: echo -e 'sto (1, 4)\ninc (1)\ninc (1)\ndec (1)\ninc (1)\nrcl (1) == 6' | calc.exe -v 3 | grep -q '=> 1' +// test: echo -e 'sto (1, 4)\ninc (1)\ninc (1)\ndec (1)\ninc (1)\nrcl (1) == 6\nquit' | calc.exe -v 3 | grep -q '=> 1' // test: echo -e 'inc\ninc (\ndec\ndec (' | calc.exe | grep -c error | xargs test 4 = // test: echo -e 'inc (11)\ndec (0)' | calc.exe | grep -c invalid | xargs test 2 = // test: echo -e 'while (inc (1) < 100, sto (2, rcl (1) + rcl (2)))' | calc.exe | grep -q '=> 5050' // test: echo -e 'while\nwhile (inc (1) < 3,\nwhile (inc (1) < 100, sto (2, rcl (1) + rcl (2))' | calc.exe | grep -c error | xargs test 3 = -// test: echo -e 'while (0, 1)' | calc.exe -v 3 | grep -q While -// test: echo -e '{sto (1, 1 + 1), rcl (1) * 3}' | calc.exe -v 3 | grep -q 'Code' +// test: echo -e 'while (0, 1)\nquit' | calc.exe -v 3 | grep -q While +// test: echo -e '{sto (1, 1 + 1), rcl (1) * 3}\nquit' | calc.exe -v 3 | grep -q 'Code' // test: echo -e '{sto (1, 1 + 1), rcl (1) * 3}' | calc.exe | grep -q '=> 6' // test: echo -e '{\n{}\n{1, 2\n{sto (1, 1 + 1),\npow(2, {sto (1, 1 + 2), 2}, {rcl(2)})\n2 {sto (1, 1 + 1)}' | calc.exe | grep -c error | xargs test 6 = // test: echo -e '1 }\n1 )\n1 , 2\n ' | calc.exe | grep -c error | xargs test 3 = -// test: echo -e 'print (1)' | calc.exe -v 3 | grep -q Print +// test: echo -e 'print (1)\nquit' | calc.exe -v 3 | grep -q Print // test: echo -e 'si\t\t (pi / 2)' | calc.exe | grep -q '=> 1' // test: echo -e '1 + 1;\nans + 1' | calc.exe | grep -qv 2 // test: echo -e 'mem (3)\nsto (4, pi)' | calc.exe | grep -q "invalid index" @@ -375,10 +376,10 @@ int main (int argc, char *argv[]) // test: echo -e 'inc (2)\ndisp' | calc.exe | grep -q "storage: 0 1 0 0 0 0 0 0 0 0" // test: echo -e 'dec (2)\ndisp' | calc.exe | grep -q "storage: 0 -1 0 0 0 0 0 0 0 0" // test: echo -e 'sto (3, pi)\nclr\ndisp' | calc.exe | grep -q "storage: 0 0 0 0 0 0 0 0 0 0" -// test: echo -e 'mem (3)\nclr' | calc.exe -v 3 | grep -q Clear +// test: echo -e 'mem (3)\nclr\nquit' | calc.exe -v 3 | grep -q Clear // test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\nprog (1, 1, {cos (rcl (1)^2)})\ncall (1, pi/6)\nprog (2, 1, {rcl (1) * 3})\ncall (2, 1, 2)\nls' | calc.exe -// test: echo -e 'prog (1, 2, {rcl (2) - rcl (1)})\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\nls' | calc.exe -v 3 |grep -q Program -// test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\nls' | calc.exe | grep -c error | xargs test 1 = +// test: echo -e 'prog (1, 2, {rcl (2) - rcl (1)})\ncall (1, 2, 3)\nls\nedit (1)\nprog (1, 2, {rcl (2) + rcl (1)})\nedit (1)\ndel (1)\nquit' | calc.exe -v 3 |grep -q bye +// test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\nprog (3, 1, cos(rcl (1) * pi / 3))\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\n\ndel (2)\ncall (2, 1, 4)' | calc.exe | grep -c error | xargs test 4 = // Gauss sequence // test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})};' | calc.exe | grep -q '=> 5050'