12 #define EXPR_BUF_SIZE 256
14 #define USER_FUNCTIONS "\\\\fls0\\USER.eig"
15 #define USER_FUNCTIONS_MAX_LENGTH 200
18 extern unsigned int **free_stack
;
23 // modified by anderain
24 free_stack
= (unsigned int**) calloc(500,sizeof(unsigned int*));
25 mem
= (U
**) calloc(100,sizeof(U
*));
26 stack
= (U
**) calloc(TOS
,sizeof(U
*));
27 symtab
= (U
*) calloc(NSYM
,sizeof(U
));
28 binding
= (U
**) calloc(NSYM
,sizeof(U
*));
29 arglist
= (U
**) calloc(NSYM
,sizeof(U
*));
30 logbuf
= (char*) calloc(256,1);
35 Txt_Init(FONT_SYSTEM
);
43 const unsigned char *Setup
[]={
44 "logab(a,b)=log(b)/log(a)",
45 "log10(x)=log(x)/log(10)",
47 "cis(x)=cos(x)+i*sin(x)",
49 "coth(x)=cosh(x)/sinh(x)",
50 "arccot(x)=arctan(1/x)",
51 "arccoth(x)=arctanh(1/x)",
54 "arcsec(x)=arccos(1/x)",
55 "arcsech(x)=arccosh(1/x)",
58 "arccsc(x)=arcsin(1/x)",
59 "arccsch(x)=arcsinh(1/x)",
60 "npr(n,r)=(n!)/(n-r)!",
61 "ncr(n,r)=n!/(r!(n-r)!)",
62 "xor(x,y)=or(and(x,not(y)),and(not(x),y))",
67 int AddIn_main(int isAppli
, unsigned short OptionNum
)
71 unsigned char *user_functions
;
75 unsigned char *line
= (unsigned char *)malloc(USER_FUNCTIONS_MAX_LENGTH
*sizeof(unsigned char));
84 // initialize failed ?
85 if (!(line
&& free_stack
&& mem
&& stack
&& symtab
&& binding
&& arglist
&& logbuf
))
88 while(Setup
[i
] != NULL
) {
89 run((char *)Setup
[i
++]);
94 user_functions
= (unsigned char*)memory_load(USER_FUNCTIONS
);
96 // Just extracting each line of the file containing user functions and running them one by one
98 if(user_functions
!= NULL
) {
104 memset(line
, '\0', USER_FUNCTIONS_MAX_LENGTH
* sizeof(unsigned char));
106 while (i
< strlen((char*)user_functions
) && j
< USER_FUNCTIONS_MAX_LENGTH
107 && user_functions
[i
] != '\n' && user_functions
[i
] != '\r'
108 && user_functions
[i
] != '\0') {
109 line
[j
++] = user_functions
[i
++];
114 // Printing the error message if needed
116 if(Console_GetEditLine()[0] != '\0') {
117 char line_number
[15] = ""; // That should be enough...
119 // Printing the actual error message
120 Console_NewLine(LINE_TYPE_OUTPUT
,1);
122 // More details on where the error is
123 Console_Output("\xE6\x92 USER.eig line : ");
124 sprintf(line_number
, "%d", line_count
);
125 strcat(line_number
, " ");
126 Console_Output((unsigned char*)line_number
);
127 Console_NewLine(LINE_TYPE_INPUT
,1);
131 } while(line
[0] != '\0');
133 free(user_functions
);
135 Console_Output((unsigned char*)" ");
136 Console_NewLine(LINE_TYPE_OUTPUT
,1);
144 if((expr
=Console_GetLine())==NULL
) stop("memory error");
147 Console_NewLine(LINE_TYPE_OUTPUT
,1);
157 #pragma section _BR_Size
158 unsigned long BR_Size
;
162 int InitializeSystem(int isAppli
, unsigned short OptionNum
)
164 return INIT_ADDIN_APPLICATION(isAppli
, OptionNum
);