Add a new user-defined commands loading at the program startup feature
This commit is contained in:
parent
43de010caa
commit
3ca1a4df38
79
Taumath.cpp
79
Taumath.cpp
|
@ -7,9 +7,13 @@ extern "C"{
|
|||
#include "fxlib.h"
|
||||
#include "syscalls.h"
|
||||
#include "tex/TeX.h"
|
||||
#include "memory.h"
|
||||
#include "config.h"
|
||||
#define EXPR_BUF_SIZE 256
|
||||
|
||||
#define USER_FUNCTIONS "\\\\fls0\\USER.eig"
|
||||
#define USER_FUNCTIONS_MAX_LENGTH 200
|
||||
|
||||
extern U ** mem;
|
||||
extern unsigned int **free_stack;
|
||||
|
||||
|
@ -29,12 +33,10 @@ initialize_tuamath()
|
|||
void TeX_init(void)
|
||||
{
|
||||
Txt_Init(FONT_SYSTEM);
|
||||
//debug_init();
|
||||
}
|
||||
|
||||
void TeX_quit(void)
|
||||
{
|
||||
//debug_quit();
|
||||
Txt_Quit();
|
||||
}
|
||||
|
||||
|
@ -66,24 +68,77 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
|
|||
{
|
||||
unsigned int key;
|
||||
unsigned char *expr;
|
||||
char fkey = NULL;
|
||||
unsigned char *user_functions;
|
||||
|
||||
int i = 0, j = 0;
|
||||
|
||||
unsigned char *line = (unsigned char *)malloc(USER_FUNCTIONS_MAX_LENGTH*sizeof(unsigned char));
|
||||
|
||||
initialize_tuamath();
|
||||
|
||||
TeX_init();
|
||||
Console_Init();
|
||||
Console_Disp();
|
||||
load_config();
|
||||
|
||||
// initialize failed ?
|
||||
if (!(free_stack && mem && stack && symtab && binding && arglist && logbuf))
|
||||
if (!(line && free_stack && mem && stack && symtab && binding && arglist && logbuf))
|
||||
return 0;
|
||||
|
||||
int i = 0;
|
||||
while(Setup[i] != NULL)
|
||||
{
|
||||
while(Setup[i] != NULL) {
|
||||
run((char *)Setup[i++]);
|
||||
}
|
||||
|
||||
TeX_init();
|
||||
Console_Init();
|
||||
Console_Disp();
|
||||
load_config();
|
||||
i = 0;
|
||||
|
||||
user_functions = (unsigned char*)memory_load(USER_FUNCTIONS);
|
||||
|
||||
// Just extracting each line of the file containing user functions and running them one by one
|
||||
|
||||
if(user_functions != NULL) {
|
||||
int line_count = 0;
|
||||
do {
|
||||
j = 0;
|
||||
line_count++;
|
||||
|
||||
memset(line, '\0', USER_FUNCTIONS_MAX_LENGTH * sizeof(unsigned char));
|
||||
|
||||
while (i < strlen((char*)user_functions) && j < USER_FUNCTIONS_MAX_LENGTH
|
||||
&& user_functions[i] != '\n' && user_functions[i] != '\r'
|
||||
&& user_functions[i] != '\0') {
|
||||
line[j++] = user_functions[i++];
|
||||
}
|
||||
|
||||
run((char *)line);
|
||||
|
||||
// Printing the error message if needed
|
||||
|
||||
if(Console_GetEditLine()[0] != '\0') {
|
||||
char line_number[15] = ""; // That should be enough...
|
||||
|
||||
// Printing the actual error message
|
||||
Console_NewLine(LINE_TYPE_OUTPUT,1);
|
||||
|
||||
// More details on where the error is
|
||||
Console_Output("\xE6\x92 USER.eig line : ");
|
||||
sprintf(line_number, "%d", line_count);
|
||||
strcat(line_number, " ");
|
||||
Console_Output((unsigned char*)line_number);
|
||||
Console_NewLine(LINE_TYPE_INPUT,1);
|
||||
Console_Disp();
|
||||
}
|
||||
i+=2;
|
||||
} while(line[0] != '\0');
|
||||
|
||||
free(user_functions);
|
||||
|
||||
Console_Output((unsigned char*)" ");
|
||||
Console_NewLine(LINE_TYPE_OUTPUT,1);
|
||||
Console_Disp();
|
||||
}
|
||||
|
||||
free(line);
|
||||
|
||||
while(1)
|
||||
{
|
||||
if((expr=Console_GetLine())==NULL) stop("memory error");
|
||||
|
@ -96,7 +151,7 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
|
|||
|
||||
TeX_quit();
|
||||
for(;;)GetKey(&key);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#pragma section _BR_Size
|
||||
|
|
Loading…
Reference in New Issue