From 58e2d2bfcdb22f9ea363222d3080b7cdde661609 Mon Sep 17 00:00:00 2001 From: Nemhardy Date: Sat, 16 Jul 2016 01:25:49 +0200 Subject: [PATCH] Add a new user-defined commands loading at the program startupfeature --- Taumath.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++-------- config.h | 2 +- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/Taumath.cpp b/Taumath.cpp index 25506d4..6675697 100644 --- a/Taumath.cpp +++ b/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_FUN.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_FUN 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 diff --git a/config.h b/config.h index dc270c6..df2c80e 100644 --- a/config.h +++ b/config.h @@ -6,7 +6,7 @@ extern "C"{ #endif -#define CONFIG_FILE "\\\\fls0\\EIGEN.CONF" +#define CONFIG_FILE "\\\\fls0\\EIGEN.cfg" typedef enum { CHECK_BOX, FUNCTION_CALL,