Taumath.cpp.bak 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #include <setjmp.h>
  3. #include "defs.h"
  4. extern "C"{
  5. #include "console.h"
  6. #include "fxlib.h"
  7. #define EXPR_BUF_SIZE 256
  8. extern U ** mem;
  9. extern unsigned int **free_stack;
  10. int
  11. initialize_tuamath()
  12. {
  13. // modified by anderain
  14. free_stack = (unsigned int**) calloc(500,sizeof(unsigned int*));
  15. mem = (U**) calloc(100,sizeof(U*));
  16. stack = (U**) calloc(TOS,sizeof(U*));
  17. symtab = (U*) calloc(NSYM,sizeof(U));
  18. binding = (U**) calloc(NSYM,sizeof(U*));
  19. arglist = (U**) calloc(NSYM,sizeof(U*));
  20. logbuf = (char*) calloc(256,1);
  21. }
  22. const unsigned char *Setup[]={
  23. "logab(a,b)=log(b)/log(a)",
  24. "log10(x)=log(x)/log(10)",
  25. "ln(x)=log(x)",
  26. "cis(x)=cos(x)+i*sin(x)",
  27. "cot(x)=1/tan(x)",
  28. "coth(x)=cosh(x)/sinh(x)",
  29. "arccot(x)=arctan(1/x)",
  30. "arccoth(x)=arctanh(1/x)",
  31. "sec(x)=1/cos(x)",
  32. "sech(x)=1/cosh(x)",
  33. "arcsec(x)=arccos(1/x)",
  34. "arcsech(x)=arccosh(1/x)",
  35. "csc(x)=1/sin(x)",
  36. "csch(x)=1/sinh(x)",
  37. "arccsc(x)=arcsin(1/x)",
  38. "arccsch(x)=arcsinh(1/x)",
  39. "npr(n,r)=(n!)/(n-r)!",
  40. "ncr(n,r)=n!/(r!(n-r)!)",
  41. "xor(x,y)=or(and(x,not(y)),and(not(x),y))",
  42. NULL,
  43. }
  44. int AddIn_main(int isAppli, unsigned short OptionNum)
  45. {
  46. unsigned int key;
  47. unsigned char *expr;
  48. initialize_tuamath();
  49. // initialize failed ?
  50. if (!(free_stack && mem && stack && symtab && binding && arglist && logbuf))
  51. return 0;
  52. int i = 0;
  53. while(Setup[i] != NULL)
  54. {
  55. run((char *)Setup[i++]);
  56. }
  57. Console_Init();
  58. Console_Disp();
  59. while(1)
  60. {
  61. if((expr=Console_GetLine())==NULL) stop("memory error");
  62. run((char *)expr);
  63. Console_NewLine(LINE_TYPE_OUTPUT,1);
  64. Console_Disp();
  65. }
  66. for(;;)GetKey(&key);
  67. return 1;
  68. }
  69. #pragma section _BR_Size
  70. unsigned long BR_Size;
  71. #pragma section
  72. #pragma section _TOP
  73. int InitializeSystem(int isAppli, unsigned short OptionNum)
  74. {
  75. return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
  76. }
  77. #pragma section
  78. }