--- rpl/src/rplexternals.h 2017/06/30 13:11:26 1.76 +++ rpl/src/rplexternals.h 2020/01/10 11:15:51 1.97 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.27 - Copyright (C) 1989-2017 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.32 + Copyright (C) 1989-2020 Dr. BERTRAND Joël This file is part of RPL/2. @@ -45,7 +45,7 @@ */ #define __RPL__ struct_rpl_arguments *rpl_arguments; \ - rpl_arguments = &__static_rpl_arguments; + rpl_arguments = &__static_rpl_arguments; \ #define __CATCH_SYSTEM_ERROR__ \ do { if (((*rpl_arguments).erreur != 0) && \ @@ -59,11 +59,13 @@ #ifdef __RPLC_MAIN struct_rpl_arguments __static_rpl_arguments; + void *__static_library_descriptor; # define global # define initialize(a, b) a = b # define declarePersistantObject(rpl_object) declareObject(rpl_object) #else extern struct_rpl_arguments __static_rpl_arguments; + extern void *__static_library_descriptor; # define global extern # define initialize(a, b) a; # define declarePersistantObject(rpl_object) extern struct_objet *rpl_object @@ -89,6 +91,8 @@ if ((ptr != rptr) && (iptr)) goto __parse_error; #define parseError { goto __parse_error; } while(0) #define typeError { return(0); } while(0) +#define typeSystemError { (*s_etat_processus).erreur_systeme = \ + d_es_execution_bibliotheque; return(0); } while(0) #define typeSuccess { return(1); } while(0) #define typeFound(a) { return(a); } while(0) #define endTypeExtension __parse_error: return(0); } @@ -97,6 +101,18 @@ if (((*s_etat_processus).erreur_execution != d_ex) || \ ((*s_etat_processus).erreur_systeme != d_es)) \ { __VA_ARGS__; return(0); } } while(0) +#define structObject struct_objet +#define initializeObject(a, b) do { \ + (*a).descripteur_bibliotheque = (*b).descripteur_bibliotheque; \ + (*a).extension_type = (*b).extension_type; } while(0) +#define objectContainer(type, a) ((type *) ((*a).objet)) +#define objectOf(a) ((*a).objet) +#define ifIsExternal(a, b) if (((*a).type == EXT) && ((*a).extension_type == b)) +#define elseIfIsExternal(a, b) } else if (((*a).type == EXT) && \ + ((*a).extension_type == b)) +#define subType(a) ((*a).extension_type) +#define integerFormat(a) formateur_nombre(s_etat_processus, a, 'I') +#define procStatus(a) (*a).s_etat_processus /* -------------------------------------------------------------------------------- @@ -134,6 +150,10 @@ ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \ if (__daisyChain == NULL) executionError("End of daisy chain"); \ (__daisyChain == NULL) ? NULL : (*__daisyChain).suivant; }) + +#define next suivant +#define data donnee +#define daisyChain struct_liste_chainee #define null NULL #define nullify(ptr) __CATCH_SYSTEM_ERROR__; do { ptr = NULL; } while(0) @@ -167,8 +187,8 @@ #define declareUnion typedef union { #define as(name) } name; -#define target(a) (*a) -#define address(a) (&a) +#define target(a) (*(a)) +#define address(a) (&(a)) #define subroutine(name) int name() #define beginGroup { __CATCH_SYSTEM_ERROR__; @@ -208,6 +228,8 @@ unsigned char __taille_bloc; \ unsigned char __type; \ t_8_bits __masque; \ + void *s_etat_processus = (*rpl_arguments).s_etat_processus; \ + DISABLE_SET_BUT_NOT_USED_WARNING(s_etat_processus); \ { \ (*rpl_arguments).instruction_valide = 'Y'; \ (*rpl_arguments).erreur = 0; \ @@ -334,11 +356,14 @@ #define libraryName(name) char __library_name[] = #name; -#define __onLoading int __runOnLoading(struct_rpl_arguments *rpl_arguments) -#define __onClosing int __runOnClosing(struct_rpl_arguments *rpl_arguments) +#define __onLoading int __runOnLoading(struct_rpl_arguments *rpl_arguments, \ + void *descriptor) +#define __onClosing int __runOnClosing(struct_rpl_arguments *rpl_arguments, \ + void *descriptor) #define declareSubroutine(when) __##when { \ char __function_name[] = #when; \ __static_rpl_arguments = (*rpl_arguments); \ + __static_library_descriptor = descriptor; \ HEADER \ declareHelpString(""); \ numberOfArguments(0); \ @@ -351,7 +376,7 @@ do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0) #define exportExternalFunctions(...) \ - char **__external_symbols(struct_rpl_arguments *rpl_arguments, \ + char **___external_symbols(struct_rpl_arguments *rpl_arguments, \ integer8 *nb_symbols, \ const char *version) { \ char arguments[] = #__VA_ARGS__; \ @@ -577,6 +602,10 @@ if ((*rpl_object).type == CHN) __type = 1; \ if (strstr(#__VA_ARGS__, "list") != NULL) \ if ((*rpl_object).type == LST) __type = 1; \ + if (strstr(#__VA_ARGS__, "external") != NULL) \ + if ((*rpl_object).type == EXT) { \ + if ((*rpl_object).descripteur_bibliotheque == \ + __static_library_descriptor) __type = 1; }\ if (strstr(#__VA_ARGS__, "unknown") != NULL) \ __type = 1; \ if (__type == 0) \ @@ -586,6 +615,8 @@ } \ } } while(0) +#define objectSubtype(a) (*a).extension_type + /* -------------------------------------------------------------------------------- Gestion des objets @@ -952,6 +983,54 @@ #define createComplexMatrixObject +// Array + +#define isArray(rpl_object) \ + ((*rpl_object).type == TBL) + +#define ifIsArray(rpl_object) if (isArray(rpl_object)) +#define elseIfIsArray(rpl_object) } else if (isArray(rpl_object)) + +#define createArray(rpl_object, size) do { \ + int __i; \ + if (rpl_object != NULL) systemError("Reallocated object"); \ + if ((rpl_object = _allocation(TBL)) == NULL) \ + systemError("Memory allocation error"); \ + (*((struct_tableau *) (*rpl_object).objet)).nombre_elements = size; \ + if (((*((struct_tableau *) (*rpl_object).objet)).elements = malloc( \ + size * sizeof(struct_objet *))) == NULL) \ + systemError("Memory allocation error"); \ + for(__i = 0; __i < size; __i++) { \ + nullify((*((struct_tableau *) (*rpl_object).objet)).elements[__i]); \ + createIntegerObject((*((struct_tableau *) (*rpl_object).objet)) \ + .elements[__i]); } \ + } while(0) + +#define setObjectIntoArray(rpl_array, pos, rpl_object) do { \ + typeof(pos) __position = pos; __position--; \ + ifIsArray(rpl_array) { \ + if ((__position < 0) || (__position >= (*((struct_tableau *) \ + (*rpl_array).objet)).nombre_elements)) \ + executionError("Element out of range"); \ + if ((*rpl_array).nombre_occurrences > 1) \ + { \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_array, 'O')) == NULL) \ + systemError("Memory allocation error"); \ + _liberation(rpl_array); \ + rpl_array = __tmp_rpl_object; \ + } \ + _liberation((*((struct_tableau *) (*rpl_array).objet)) \ + .elements[__position]); \ + (*((struct_tableau *) (*rpl_array).objet)).elements[__position] = \ + rpl_object; \ + } \ + else executionError("Type mistmatch error"); \ + nullify(rpl_object); \ + } while(0) + +#define getObjectFromArray() + // Binary integer #define setBinaryInteger(rpl_object, value) do { \ @@ -1042,7 +1121,7 @@ ((*rpl_object).type == CHN) #define ifIsString(rpl_object) if (isString(rpl_object)) -#define elseIfIsString(rpl_object) else if (isString(rpl_object)) +#define elseIfIsString(rpl_object) } else if (isString(rpl_object)) #define setString(rpl_object, string) do { \ struct_processus *s_etat_processus; \ @@ -1074,6 +1153,22 @@ ifIsString(rpl_object) string = (char *) (*rpl_object).objet; \ else executionError("Type mismatch error"); } while(0) +#define unEscString(s) ({ \ + unsigned char *__a; integer8 __l; \ + __a = formateur_flux((*rpl_arguments).s_etat_processus, \ + (unsigned char *) s, &__l); \ + if (nullified(__a)) systemError("Memory allocation error"); \ + (string) __a; \ + }) + +#define escString(rpl_object) ({ \ + unsigned char *__a; integer8 __l; \ + __a = analyse_flux((*rpl_arguments).s_etat_processus, \ + (unsigned char *) s, strlen(s)); \ + if (nullified(__a)) systemError("Memory allocation error"); \ + (string) __a; \ + }) + #define createStringObject(rpl_object) do { \ struct_processus *s_etat_processus; \ s_etat_processus = (*rpl_arguments).s_etat_processus; \ @@ -1222,6 +1317,26 @@ } \ } } while(0) +// NON +#define createObject(rpl_object) do { \ + if (rpl_object != NULL) \ + systemError("Reallocated object"); \ + if ((rpl_object = _allocation(NON)) == NULL) \ + systemError("Memory allocation error"); \ + (*rpl_object).objet = NULL; \ + } while(0) + +// EXT +#define createExternalObject(rpl_object, subtype) do { \ + if (rpl_object != NULL) \ + systemError("Reallocated object"); \ + if ((rpl_object = _allocation(EXT)) == NULL) \ + systemError("Memory allocation error"); \ + (*rpl_object).objet = NULL; \ + (*rpl_object).extension_type = subtype; \ + (*rpl_object).descripteur_bibliotheque = __static_library_descriptor; \ + } while(0) + /* -------------------------------------------------------------------------------- Allocation mémoire @@ -1234,13 +1349,15 @@ struct_processus *s_etat_processus; \ s_etat_processus = (*rpl_arguments).s_etat_processus; \ if ((ptr = malloc(a)) == NULL) \ - systemError("Memory allocation error"); ptr; }) + { systemError("Memory allocation error"); \ + __CATCH_SYSTEM_ERROR__; } ptr; }) \ #define reallocate(a, s) ({ void *ptr; \ struct_processus *s_etat_processus; \ s_etat_processus = (*rpl_arguments).s_etat_processus; \ if ((ptr = realloc(a, s)) == NULL) \ - systemError("Memory allocation error"); ptr; }) + { systemError("Memory allocation error"); \ + __CATCH_SYSTEM_ERROR__; } ptr; }) \ #define deallocate(a) do { \ struct_processus *s_etat_processus; \