File:  [local] / rpl / src / rplexternals.h
Revision 1.85: download - view: text, annotated - select for diffs - revision graph
Mon Jul 17 21:37:41 2017 UTC (6 years, 9 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Patches pour la gestion des bibliothèques externes.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.27
    4:   Copyright (C) 1989-2017 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #ifndef INCLUSION_RPLARGS
   24: #   define INCLUSION_RPLARGS
   25: 
   26: /*
   27: ================================================================================
   28:   INCLUSIONS
   29: ================================================================================
   30: */
   31: 
   32: // Si TYPE_DECLARATION est défini, toutes les structures internes du RPL/2
   33: // sont exposés pour travailler sur des nouveaux types de données.
   34: #   ifndef TYPE_DECLARATION
   35: #       define RPLARGS
   36: #       define struct_processus void
   37: #   endif
   38: 
   39: #   include "rpl.h"
   40: 
   41: /*
   42: ================================================================================
   43:   MACROS SPECIFIQUES
   44: ================================================================================
   45: */
   46: 
   47: #define __RPL__ struct_rpl_arguments *rpl_arguments; \
   48:     rpl_arguments = &__static_rpl_arguments; \
   49: 
   50: #define __CATCH_SYSTEM_ERROR__ \
   51:         do { if (((*rpl_arguments).erreur != 0) && \
   52:                 ((*rpl_arguments).type_erreur == 'S')) \
   53:             return 0; } while(0)
   54: #define leave do { return(0); } while(0)
   55: #define _allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a)
   56: #define _copie_objet(a, b) librpl_copie_objet( \
   57:             (*rpl_arguments).s_etat_processus, a, b)
   58: #define _liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a)
   59: 
   60: #ifdef __RPLC_MAIN
   61:     struct_rpl_arguments __static_rpl_arguments;
   62:     void *__static_library_descriptor;
   63: #   define global
   64: #   define initialize(a, b) a = b
   65: #   define declarePersistantObject(rpl_object) declareObject(rpl_object)
   66: #else
   67:     extern struct_rpl_arguments __static_rpl_arguments;
   68:     extern void *__static_library_descriptor;
   69: #   define global extern
   70: #   define initialize(a, b) a;
   71: #   define declarePersistantObject(rpl_object) extern struct_objet *rpl_object
   72: #endif
   73: 
   74: #define empty int
   75: 
   76: /*
   77: --------------------------------------------------------------------------------
   78:   Gestion des objets
   79: --------------------------------------------------------------------------------
   80: */
   81: 
   82: // new, dup, drop, disp, parse
   83: // __type_new(struct_rpl_arguments *rpl_arguments)
   84: #define declareTypeExtension(fct) \
   85:         int __type_##fct(struct_processus *s_etat_processus, void **arg) { \
   86:             char *rptr, *ptr, *iptr; \
   87:             rptr = (char *) ((*s_etat_processus).definitions_chainees + \
   88:                     (*s_etat_processus).position_courante); \
   89:             ptr = rptr; \
   90:             iptr = (char *) (*s_etat_processus).instruction_courante; \
   91:             if ((ptr != rptr) && (iptr)) goto __parse_error;
   92: #define parseError  { goto __parse_error; } while(0)
   93: #define typeError { return(0); } while(0)
   94: #define typeSystemError { (*s_etat_processus).erreur_systeme = \
   95:         d_es_execution_bibliotheque; return(0); } while(0)
   96: #define typeSuccess { return(1); } while(0)
   97: #define typeFound(a) { return(a); } while(0)
   98: #define endTypeExtension __parse_error: return(0); }
   99: #define sizeOfParse (rptr - ptr)
  100: #define searchType(...) { recherche_type(s_etat_processus); \
  101:             if (((*s_etat_processus).erreur_execution != d_ex) || \
  102:                     ((*s_etat_processus).erreur_systeme != d_es)) \
  103:                 { __VA_ARGS__; return(0); } } while(0)
  104: #define structObject struct_objet
  105: #define initializeObject(a, b)  do { \
  106:             (*a).descripteur_bibliotheque = (*b).descripteur_bibliotheque; \
  107:             (*a).extension_type = (*b).extension_type; } while(0)
  108: #define objectContainer(a) ((*a).objet)
  109: #define ifIsExternal(a, b) if (((*a).type == EXT) && ((*a).extension_type == b))
  110: #define elseIfIsExternal(a, b) } else if (((*a).type == EXT) && \
  111:             ((*a).extension_type == b))
  112: #define subType(a) ((*a).extension_type)
  113: #define integerFormat(a) formateur_nombre(s_etat_processus, a, 'I')
  114: #define procStatus(a) (*a).s_etat_processus
  115: 
  116: /*
  117: --------------------------------------------------------------------------------
  118:   Types
  119: --------------------------------------------------------------------------------
  120: */
  121: 
  122: #define declareObject(rpl_object) struct_objet *rpl_object = NULL
  123: #define declareInteger(integer) integer8 integer
  124: #define declareReal(real) real8 real
  125: #define declareComplex(complex) complex16 complex
  126: #define declareDaisyChain(daisyChain) struct_liste_chainee *daisyChain = NULL
  127: 
  128: #define getDaisyChainFromList(list, daisyChain) \
  129:     __CATCH_SYSTEM_ERROR__; \
  130:     do { \
  131:     typeof(list) __list = list; \
  132:     daisyChain = NULL; \
  133:     ifIsList(__list) { daisyChain = (*__list).objet; } \
  134:     else executionError("Type mistmatch error"); } while(0)
  135: 
  136: #define fetchElementFromDaisyChain(daisyChain) \
  137:     ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \
  138:     if (__daisyChain == NULL) executionError("End of daisy chain"); \
  139:     (__daisyChain == NULL) ? NULL : (*__daisyChain).donnee; })
  140: 
  141: #define replaceElementIntoDaisyChain(daisyChain, element) \
  142:     __CATCH_SYSTEM_ERROR__; \
  143:     do { typeof(daisyChain) __daisyChain = daisyChain; \
  144:     if (__daisyChain == NULL) executionError("Nullified daisy chain"); \
  145:     freeObject((*__daisyChain).donnee); \
  146:     (*__daisyChain).donnee = element; } while(0)
  147: 
  148: #define nextElementOfDaisyChain(daisyChain) \
  149:     ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \
  150:     if (__daisyChain == NULL) executionError("End of daisy chain"); \
  151:     (__daisyChain == NULL) ? NULL : (*__daisyChain).suivant; })
  152: 
  153: #define next    suivant
  154: #define data    donnee
  155:     
  156: #define null NULL
  157: #define nullify(ptr) __CATCH_SYSTEM_ERROR__; do { ptr = NULL; } while(0)
  158: #define nullified(ptr) ((ptr) == NULL)
  159: 
  160: #define postIncr(x) (x++)
  161: #define preIncr(x) (++x)
  162: #define postDecr(x) (x--)
  163: #define preDecr(x) (--x)
  164: 
  165: #define eq ==
  166: #define ne !=
  167: #define ge >=
  168: #define gt >
  169: #define le <=
  170: #define lt <
  171: #define not !
  172: #define and &&
  173: #define or ||
  174: #define false 0
  175: #define true -1
  176: 
  177: #define setFalse(a) a = false
  178: #define setTrue(a) a = true
  179: 
  180: #define logical int
  181: #define string char *
  182: #define integer int
  183: 
  184: #define declareStructure typedef struct {
  185: #define declareUnion typedef union {
  186: #define as(name) } name;
  187: 
  188: #define target(a) (*(a))
  189: #define address(a) (&(a))
  190: 
  191: #define subroutine(name) int name()
  192: #define beginGroup { __CATCH_SYSTEM_ERROR__;
  193: #define endGroup __CATCH_SYSTEM_ERROR__; }
  194: #define beginMacro do beginGroup
  195: #define endMacro endGroup while(0)
  196: #define stopRequest ({ __CATCH_SYSTEM_ERROR__; \
  197:         test_arret((*rpl_arguments).s_etat_processus); })
  198: 
  199: /*
  200: --------------------------------------------------------------------------------
  201:   Signaux
  202: --------------------------------------------------------------------------------*/
  203: 
  204: #define blockSignals \
  205:     { __CATCH_SYSTEM_ERROR__; sigset_t set, oldset; sigfillset(&set); \
  206:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
  207: #define unblockSignals \
  208:     pthread_sigmask(SIG_SETMASK, &oldset, NULL); __CATCH_SYSTEM_ERROR__; }
  209: 
  210: /*
  211: --------------------------------------------------------------------------------
  212:   Constructeurs
  213: --------------------------------------------------------------------------------
  214: */
  215: 
  216: #define DISABLE_SET_BUT_NOT_USED_WARNING(a) if (&a != ((&a) + 1));
  217: 
  218: #define HEADER \
  219:     int             __constante; \
  220:     logical1        __evaluation; \
  221:     logical1        __validation_instruction = d_faux; \
  222:     logical1        __presence_aide = d_faux; \
  223:     logical1        __presence_validation = d_faux; \
  224:     unsigned char   __indice_bit; \
  225:     unsigned char   __indice_bloc; \
  226:     unsigned char   __taille_bloc; \
  227:     unsigned char   __type; \
  228:     t_8_bits        __masque; \
  229:     void *s_etat_processus = (*rpl_arguments).s_etat_processus; \
  230:     DISABLE_SET_BUT_NOT_USED_WARNING(s_etat_processus); \
  231:     { \
  232:         (*rpl_arguments).instruction_valide = 'Y'; \
  233:         (*rpl_arguments).erreur = 0; \
  234:         __constante = 0; \
  235:         __evaluation = d_faux; \
  236:         DISABLE_SET_BUT_NOT_USED_WARNING(__evaluation); \
  237:         DISABLE_SET_BUT_NOT_USED_WARNING(__type); \
  238:         DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bit); \
  239:         DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bloc); \
  240:         DISABLE_SET_BUT_NOT_USED_WARNING(__taille_bloc); \
  241:         DISABLE_SET_BUT_NOT_USED_WARNING(__masque);
  242: 
  243: #define FUNCTION \
  244:     if (__validation_instruction == d_vrai) return 0; \
  245:     if (__presence_aide == d_faux) \
  246:     { \
  247:         systemError("Help string not defined"); \
  248:     } \
  249:     else if (__presence_validation == d_faux) \
  250:     { \
  251:         systemError("Number of arguments not defined"); \
  252:     } \
  253:     __indice_bit = 0; \
  254:     __indice_bloc = 0; \
  255:     __taille_bloc = 0; \
  256:     __type = 0; \
  257:     __masque = 0; \
  258:     {
  259: 
  260: #define END \
  261:         strcpy((char *) __function_name, ""); \
  262:         if (__constante != 0) \
  263:             systemError("Constant definition error"); \
  264:         __CATCH_SYSTEM_ERROR__; \
  265:     } } \
  266:     leave;
  267: 
  268: /*
  269: --------------------------------------------------------------------------------
  270:   Destruction d'un objet
  271: --------------------------------------------------------------------------------
  272: */
  273: 
  274: #define freeObject(rpl_object) \
  275:     __CATCH_SYSTEM_ERROR__; \
  276:     do { \
  277:         if (rpl_object == NULL) \
  278:             systemError("Nullified object"); \
  279:         _liberation(rpl_object); \
  280:         rpl_object = NULL; \
  281:     } while(0)
  282: 
  283: /*
  284: --------------------------------------------------------------------------------
  285:   Copie d'un objet
  286: --------------------------------------------------------------------------------
  287: */
  288: 
  289: #define dupObject(rpl_object) \
  290:     __CATCH_SYSTEM_ERROR__; \
  291:     do { if (_copie_objet(rpl_object, 'P') != rpl_object) \
  292:         systemError("Memory allocation error"); } while(0)
  293: 
  294: /*
  295: --------------------------------------------------------------------------------
  296:   Déclaration des fonctions internes
  297: --------------------------------------------------------------------------------
  298: */
  299: 
  300: #define CONCAT(a, b) __RPL_CONCAT(a, b)
  301: #define __RPL_CONCAT(a, b) a##b
  302: #define FIRST(...) FIRST_HELPER(__VA_ARGS__, throwaway)
  303: #define FIRST_HELPER(first, ...) first
  304: #define REST(...) REST_HELPER(NUM(__VA_ARGS__), __VA_ARGS__)
  305: #define REST_HELPER(qty, ...) REST_HELPER2(qty, __VA_ARGS__)
  306: #define REST_HELPER2(qty, ...) REST_HELPER_##qty(__VA_ARGS__)
  307: #define REST_HELPER_ONE(first)
  308: #define REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__
  309: #define NUM(...) \
  310:         SELECT_10TH(__VA_ARGS__, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
  311:         TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway)
  312: #define SELECT_10TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, ...) a10
  313: 
  314: #define declareInternalFunction(type, ...) \
  315:     type CONCAT(__internal_, FIRST(__VA_ARGS__)) \
  316:             (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__)) { \
  317:     type __internal_return; __internal_return = 0; int __type; \
  318:     DISABLE_SET_BUT_NOT_USED_WARNING(__type);
  319: 
  320: #define endInternalFunction return(__internal_return); }
  321: 
  322: #define useInternalFunction(type, ...) \
  323:     type CONCAT(__internal_, FIRST(__VA_ARGS__)) \
  324:             (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__))
  325: 
  326: #define callInternalFunction(...) \
  327:     CONCAT(__internal_, FIRST(__VA_ARGS__))(rpl_arguments REST(__VA_ARGS__))
  328: 
  329: /*
  330: --------------------------------------------------------------------------------
  331:   Déclaration des fonctions C
  332: --------------------------------------------------------------------------------
  333: */
  334: 
  335: #define declareCFunction(type, name, ...) \
  336:         type name(__VA_ARGS__) { __RPL__ type __c_return;
  337: #define endCFunction return(__c_return); }
  338: 
  339: #define useCFunction(type, name, ...) type name(__VA_ARGS__)
  340: 
  341: /*
  342: --------------------------------------------------------------------------------
  343:   Déclaration des fonctions externes
  344: --------------------------------------------------------------------------------
  345: */
  346: 
  347: #define declareExternalFunction(name) \
  348:     int __external_##name(struct_rpl_arguments *rpl_arguments) { \
  349:     char __function_name[] = "__external_"#name; \
  350:     __static_rpl_arguments = (*rpl_arguments);
  351: 
  352: #define useExternalFunction(function) \
  353:     int __external_##function(struct_rpl_arguments *rpl_arguments)
  354: 
  355: #define libraryName(name) char __library_name[] = #name;
  356: 
  357: #define __onLoading int __runOnLoading(struct_rpl_arguments *rpl_arguments, \
  358:         void *descriptor)
  359: #define __onClosing int __runOnClosing(struct_rpl_arguments *rpl_arguments, \
  360:         void *descriptor)
  361: #define declareSubroutine(when) __##when { \
  362:     char __function_name[] = #when; \
  363:     __static_rpl_arguments = (*rpl_arguments); \
  364:     __static_library_descriptor = descriptor; \
  365:     HEADER \
  366:         declareHelpString(""); \
  367:         numberOfArguments(0); \
  368:     FUNCTION
  369: #define endSubroutine END }
  370: 
  371: #define notice(s, ...) __CATCH_SYSTEM_ERROR__; \
  372:         do { ufprintf(s, __VA_ARGS__); fflush(s); } while(0)
  373: #define logger(...) __CATCH_SYSTEM_ERROR__; \
  374:         do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0) 
  375: 
  376: #define exportExternalFunctions(...) \
  377:     char **___external_symbols(struct_rpl_arguments *rpl_arguments, \
  378:             integer8 *nb_symbols, \
  379:             const char *version) { \
  380:         char arguments[] = #__VA_ARGS__; \
  381:         char **tableau; \
  382:         char *ptr1, *ptr2; \
  383:         int drapeau; \
  384:         unsigned long i; \
  385:         struct_processus *s_etat_processus; \
  386:         s_etat_processus = (*rpl_arguments).s_etat_processus; \
  387:         if (strcmp(version, _d_version_rpl) != 0) \
  388:         { \
  389:             notice(stdout, "Versions mismatch : library %s, expected %s\n", \
  390:                     _d_version_rpl, version); \
  391:             (*nb_symbols) = -1; return(NULL); \
  392:         } \
  393:         (*nb_symbols) = 0; ptr1 = arguments; drapeau = 0; \
  394:         while((*ptr1) != 0) \
  395:         { \
  396:             if (((*ptr1) != ',') && ((*ptr1) != ' ')) drapeau = -1; \
  397:             ptr1++; \
  398:         } \
  399:         if (drapeau == 0) return(NULL); \
  400:         ptr1 = arguments; (*nb_symbols) = 1; \
  401:         while((*ptr1) != 0) if ((*ptr1++) == ',') (*nb_symbols)++; \
  402:         if ((tableau = malloc((*nb_symbols) * sizeof(char *))) == NULL) \
  403:             return(NULL); \
  404:         ptr2 = arguments; i = 0; \
  405:         while(*ptr2 != 0) \
  406:         { \
  407:             while(((*ptr2) == ' ') || ((*ptr2) == ',')) ptr2++; \
  408:             ptr1 = ptr2; \
  409:             while(((*ptr2) != 0) && ((*ptr2) != ',') && ((*ptr2) != ' ')) \
  410:                     ptr2++; \
  411:             if ((tableau[i] = malloc((ptr2 + 2 + \
  412:                     strlen(__library_name) - ptr1) * \
  413:                     sizeof(unsigned char))) == NULL) \
  414:                 return(NULL); \
  415:             sprintf(tableau[i], "%s$", __library_name); \
  416:             strncat(&tableau[i][strlen(tableau[i])], ptr1, ptr2 - ptr1); \
  417:             i++; \
  418:             if ((*ptr2) != 0) \
  419:             { \
  420:                 while((*ptr2) == ' ') ptr2++; \
  421:                 if ((*ptr2) == ',') ptr2++; \
  422:             } \
  423:         } \
  424:         (*nb_symbols) = i; \
  425:         return(tableau); \
  426:     }
  427: 
  428: #define endExternalFunction leave; }
  429: 
  430: #define callExternalFunction(function) do { \
  431:     __CATCH_SYSTEM_ERROR__; \
  432:     __taille_bloc = sizeof(t_8_bits) * 8; \
  433:     __indice_bloc = (35 - 1) / __taille_bloc; \
  434:     __indice_bit = (35 - 1) % __taille_bloc; \
  435:     __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
  436:     __evaluation = ((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) \
  437:             ? d_vrai : d_faux; \
  438:     __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
  439:     (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
  440:     __external_##function(rpl_arguments); \
  441:     if (__evaluation == d_vrai) \
  442:     { \
  443:         __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
  444:         (*rpl_arguments).drapeaux_etat[__indice_bloc] |= __masque; \
  445:     } \
  446:     else \
  447:     { \
  448:         __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
  449:         (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
  450:     } } while(0)
  451: 
  452: /*
  453: --------------------------------------------------------------------------------
  454:   Macros spécifiques à l'en-tête
  455: --------------------------------------------------------------------------------
  456: */
  457: 
  458: #define declareHelpString(h) do { \
  459:     __presence_aide = d_vrai; \
  460:     if ((*rpl_arguments).affichage_arguments == 'Y') \
  461:     { \
  462:         uprintf("%s\n", h); \
  463:         return 0; \
  464:     } } while(0)
  465: 
  466: #define declareSymbolicConstant do { \
  467:     numberOfArguments(0); \
  468:     (*rpl_arguments).constante_symbolique = 'Y'; \
  469:     __constante++; } while(0)
  470: 
  471: #define numberOfArguments(n) do { \
  472:     __presence_validation = d_vrai; \
  473:     if ((*rpl_arguments).test_instruction == 'Y') \
  474:     { \
  475:         if (n < 0) \
  476:             systemError("Number of arguments must be positive or null"); \
  477:         (*rpl_arguments).nombre_arguments = n; \
  478:         __validation_instruction = d_vrai; \
  479:     } \
  480:     else \
  481:     { \
  482:         __taille_bloc = sizeof(t_8_bits) * 8; \
  483:         __indice_bloc = (31 - 1) / __taille_bloc; \
  484:         __indice_bit = (31 - 1) % __taille_bloc; \
  485:         __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
  486:         if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
  487:         { \
  488:             (*rpl_arguments).l_base_pile_last = \
  489:                     sauvegarde_arguments(rpl_arguments, n); \
  490:         } \
  491:     } } while(0)
  492: 
  493: /*
  494: --------------------------------------------------------------------------------
  495:   Gestion des boucles
  496: --------------------------------------------------------------------------------
  497: */
  498: 
  499: #define loop(b, e, s) for(b; e; s) {
  500: #define endLoop __CATCH_SYSTEM_ERROR__; }
  501: 
  502: #define repeatWhile(c) while(c) {
  503: #define endWhile __CATCH_SYSTEM_ERROR__; }
  504: 
  505: #define doUntil do {
  506: #define repeatUntil(c) __CATCH_SYSTEM_ERROR__; } while(!(c));
  507: 
  508: #define select(s) switch(s) {
  509: #define endSelect __CATCH_SYSTEM_ERROR__; }
  510: #define nonExclusiveCase(c) case c: {
  511: #define endNonExclusiveCase __CATCH_SYSTEM_ERROR__; }
  512: #define exclusiveCase(c) case c: {
  513: #define endExclusiveCase break; __CATCH_SYSTEM_ERROR__; }
  514: #define defaultCase default:
  515: #define endDefaultCase break; __CATCH_SYSTEM_ERROR__; }
  516: 
  517: /*
  518: --------------------------------------------------------------------------------
  519:   Gestion des erreurs
  520: --------------------------------------------------------------------------------
  521: */
  522: 
  523: #define returnOnError(...) do { \
  524:     if ((*rpl_arguments).erreur != 0) \
  525:     { \
  526:         __VA_ARGS__; \
  527:         return 0; \
  528:     } } while(0)
  529: 
  530: #define systemError(message) do { \
  531:     (*rpl_arguments).erreur = __LINE__; \
  532:     (*rpl_arguments).type_erreur = 'S'; \
  533:     (*rpl_arguments).message_erreur = (unsigned char *) message; \
  534:     return 0; } while(0)
  535: 
  536: #define executionError(message) do { \
  537:     (*rpl_arguments).erreur = __LINE__; \
  538:     (*rpl_arguments).type_erreur = 'E'; \
  539:     (*rpl_arguments).message_erreur = (unsigned char *) message; } while(0)
  540: 
  541: #define onSystemError(...) do { \
  542:     if (((*rpl_arguments).erreur != 0) && \
  543:             ((*rpl_arguments).type_erreur == 'S')) \
  544:     { \
  545:         blockSignals; \
  546:             kill(getpid(), SIGTERM); \
  547:         unblockSignals; \
  548:         __VA_ARGS__; \
  549:     } } while(0)
  550: 
  551: #define onError(...) \
  552:     __CATCH_SYSTEM_ERROR__; \
  553:     do { if (((*rpl_arguments).type_erreur == 'E') && \
  554:             ((*rpl_arguments).erreur != 0)) { __VA_ARGS__; \
  555:             (*rpl_arguments).erreur = 0; } } while(0)
  556: 
  557: #define onExecution(...) \
  558:     __CATCH_SYSTEM_ERROR__; \
  559:     do { if (((*rpl_arguments).type_erreur == 'E') && \
  560:             ((*rpl_arguments).erreur == 0)) { __VA_ARGS__; } } while(0)
  561: 
  562: /*
  563: --------------------------------------------------------------------------------
  564:   Gestion de la pile opérationnelle
  565: --------------------------------------------------------------------------------
  566: */
  567: 
  568: #define pushOnStack(rpl_object) do { \
  569:     __CATCH_SYSTEM_ERROR__; \
  570:     if (((*rpl_arguments).l_base_pile = \
  571:             empilement_pile_operationnelle(rpl_arguments, rpl_object)) \
  572:                     == NULL) \
  573:         systemError("Memory allocation error"); \
  574:     if ((*rpl_object).nombre_occurrences == 1) rpl_object = NULL; } while(0)
  575: 
  576: #define pullFromStack(rpl_object, ...) do { \
  577:     __CATCH_SYSTEM_ERROR__; \
  578:     (*rpl_arguments).l_base_pile = \
  579:             depilement_pile_operationnelle(rpl_arguments, &rpl_object); \
  580:     if (rpl_object == NULL) \
  581:     { \
  582:         executionError("Too few arguments"); \
  583:     } \
  584:     else \
  585:     { \
  586:         if (strlen(#__VA_ARGS__) == 0) \
  587:         { \
  588:             systemError("Undefined type"); \
  589:         } \
  590:         else \
  591:         { \
  592:             __type = 0; \
  593:             if (strstr(#__VA_ARGS__, "integer") != NULL) \
  594:                 if ((*rpl_object).type == INT) __type = 1; \
  595:             if (strstr(#__VA_ARGS__, "real") != NULL) \
  596:                 if ((*rpl_object).type == REL) __type = 1; \
  597:             if (strstr(#__VA_ARGS__, "complex") != NULL) \
  598:                 if ((*rpl_object).type == CPL) __type = 1; \
  599:             if (strstr(#__VA_ARGS__, "string") != NULL) \
  600:                 if ((*rpl_object).type == CHN) __type = 1; \
  601:             if (strstr(#__VA_ARGS__, "list") != NULL) \
  602:                 if ((*rpl_object).type == LST) __type = 1; \
  603:             if (strstr(#__VA_ARGS__, "external") != NULL) \
  604:                 if ((*rpl_object).type == EXT) { \
  605:                     if ((*rpl_object).descripteur_bibliotheque == \
  606:                             __static_library_descriptor) __type = 1; }\
  607:             if (strstr(#__VA_ARGS__, "unknown") != NULL) \
  608:                 __type = 1; \
  609:             if (__type == 0) \
  610:             { \
  611:                 executionError("Type not allowed"); \
  612:             } \
  613:         } \
  614:     } } while(0)
  615: 
  616: #define objectSubtype(a) (*a).extension_type
  617: 
  618: /*
  619: --------------------------------------------------------------------------------
  620:   Gestion des objets
  621: --------------------------------------------------------------------------------
  622: */
  623: 
  624: #define then {
  625: #define endIf __CATCH_SYSTEM_ERROR__; }
  626: #define elseIf __CATCH_SYSTEM_ERROR__; } else if
  627: #define orElse __CATCH_SYSTEM_ERROR__; } else {
  628: 
  629: //  Constantes symboliques
  630: 
  631: #define createSymbolicConstant(rpl_object, type, value) do { \
  632:     struct_processus *s_etat_processus; \
  633:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
  634:     if ((strcmp(#type, "integer") != 0) && (strcmp(#type, "real") != 0)) \
  635:         systemError("Type not allowed for symbolic constant"); \
  636:     __taille_bloc = sizeof(t_8_bits) * 8; \
  637:     __indice_bloc = (35 - 1) / __taille_bloc; \
  638:     __indice_bit = (35 - 1) % __taille_bloc; \
  639:     __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
  640:     if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
  641:     { \
  642:         createNameObject(rpl_object); \
  643:         __CATCH_SYSTEM_ERROR__; \
  644:         { \
  645:             char *__constant_name; \
  646:             if ((__constant_name = malloc((strlen(__library_name) + \
  647:                     strlen(__function_name) - 9) * sizeof(char))) == NULL) \
  648:                 systemError("Memory allocation error"); \
  649:             sprintf(__constant_name, "%s$%s", __library_name, \
  650:                     &(__function_name[11])); \
  651:             setName(rpl_object, __constant_name); \
  652:             free(__constant_name); \
  653:         } \
  654:     } \
  655:     else \
  656:     { \
  657:         if (strcmp(#type, "integer") == 0) \
  658:         { \
  659:             createIntegerObject(rpl_object); \
  660:             __CATCH_SYSTEM_ERROR__; \
  661:             setInteger(rpl_object, value); \
  662:         } \
  663:         else if (strcmp(#type, "real") == 0) \
  664:         { \
  665:             createRealObject(rpl_object); \
  666:             __CATCH_SYSTEM_ERROR__; \
  667:             setReal(rpl_object, value); \
  668:         } \
  669:     } \
  670:     __CATCH_SYSTEM_ERROR__; \
  671:     __constante--; } while(0)
  672: 
  673: #define createSymbolicComplexConstant(rpl_object, rp, ip) do { \
  674:     struct_processus *s_etat_processus; \
  675:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
  676:     __taille_bloc = sizeof(t_8_bits) * 8; \
  677:     __indice_bloc = (35 - 1) / __taille_bloc; \
  678:     __indice_bit = (35 - 1) % __taille_bloc; \
  679:     __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
  680:     if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
  681:     { \
  682:         createNameObject(rpl_object); \
  683:         __CATCH_SYSTEM_ERROR__; \
  684:         { \
  685:             char *__constant_name; \
  686:             if ((__constant_name = malloc((strlen(__library_name) + \
  687:                     strlen(__function_name) + 2) * sizeof(char))) == NULL) \
  688:                 systemError("Memory allocation error"); \
  689:             sprintf(__constant_name, "%s$%s", __library_name, \
  690:                     __function_name); \
  691:             setName(rpl_object, __constant_name); \
  692:             free(__constant_name); \
  693:         } \
  694:     } \
  695:     else \
  696:     { \
  697:         createComplexObject(rpl_object); \
  698:         __CATCH_SYSTEM_ERROR__; \
  699:         setComplex(rpl_object, rp, im); \
  700:     } \
  701:     __CATCH_SYSTEM_ERROR__; \
  702:     __constante--; } while(0)
  703: 
  704: // Integer
  705: 
  706: #define setInteger(rpl_object, value) do { \
  707:     ifIsInteger(rpl_object) \
  708:     { \
  709:         if ((*rpl_object).nombre_occurrences > 1) \
  710:         { \
  711:             struct_objet *__tmp_rpl_object; \
  712:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  713:                 systemError("Memory allocation error"); \
  714:             _liberation(rpl_object); \
  715:             rpl_object = __tmp_rpl_object; \
  716:         } \
  717:         (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \
  718:     } \
  719:     else executionError("Type mistmatch error"); } while(0)
  720: 
  721: #define isInteger(rpl_object) \
  722:     ((*rpl_object).type == INT)
  723: 
  724: #define ifIsInteger(rpl_object) if (isInteger(rpl_object))
  725: #define elseIfIsInteger(rpl_object) } else ifIsInteger(rpl_object)
  726: 
  727: #define getInteger(rpl_object, value) do { \
  728:     value = 0; \
  729:     ifIsInteger(rpl_object) value = (*((integer8 *) (*rpl_object).objet)); \
  730:     else executionError("Type mismatch error"); } while(0)
  731: 
  732: #define createIntegerObject(rpl_object) do { \
  733:     if (rpl_object != NULL) \
  734:         systemError("Reallocated object"); \
  735:     if ((rpl_object = _allocation(INT)) == NULL) \
  736:         systemError("Memory allocation error"); \
  737:     setInteger(rpl_object, 0); } while(0)
  738: 
  739: // Real
  740: 
  741: #define setReal(rpl_object, value) do { \
  742:     ifIsReal(rpl_object) \
  743:     { \
  744:         if ((*rpl_object).nombre_occurrences > 1) \
  745:         { \
  746:             struct_objet *__tmp_rpl_object; \
  747:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  748:                 systemError("Memory allocation error"); \
  749:             _liberation(rpl_object); \
  750:             rpl_object = __tmp_rpl_object; \
  751:         } \
  752:         (*((real8 *) (*rpl_object).objet)) = (real8) value; \
  753:     } \
  754:     else executionError("Type mistmatch error"); } while(0)
  755: 
  756: #define isReal(rpl_object) \
  757:     ((*rpl_object).type == REL)
  758: 
  759: #define ifIsReal(rpl_object) if (isReal(rpl_object))
  760: #define elseIfIsReal(rpl_object) } else ifIsReal(rpl_object)
  761: 
  762: #define getReal(rpl_object, value) do { \
  763:     value = 0; \
  764:     ifIsReal(rpl_object) value = (*((real8 *) (*rpl_object).objet)); \
  765:     else executionError("Type mismatch error"); } while(0)
  766: 
  767: #define createRealObject(rpl_object) do { \
  768:     if (rpl_object != NULL) \
  769:         systemError("Reallocated object"); \
  770:     if ((rpl_object = _allocation(REL)) == NULL) \
  771:         systemError("Memory allocation error"); \
  772:     setReal(rpl_object, 0); } while(0)
  773: 
  774: // Complex
  775: 
  776: #define setComplex(rpl_object, rp, ip) do { \
  777:     typeof(rp) __rp = rp; \
  778:     typeof(ip) __ip = ip; \
  779:     ifIsComplex(rpl_object) \
  780:     { \
  781:         if ((*rpl_object).nombre_occurrences > 1) \
  782:         { \
  783:             struct_objet *__tmp_rpl_object; \
  784:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  785:                 systemError("Memory allocation error"); \
  786:             _liberation(rpl_object); \
  787:             rpl_object = __tmp_rpl_object; \
  788:         } \
  789:         setRealPartOfComplex(rpl_object, __rp); \
  790:         setImaginaryPartOfComplex(rpl_object, __ip); \
  791:     } \
  792:     else executionError("Type mismatch error"); } while(0)
  793: 
  794: #define setRealPartOfComplex(rpl_object, value) do { \
  795:     if ((*rpl_object).nombre_occurrences > 1) \
  796:     { \
  797:         struct_objet *__tmp_rpl_object; \
  798:         if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  799:             systemError("Memory allocation error"); \
  800:         _liberation(rpl_object); \
  801:         rpl_object = __tmp_rpl_object; \
  802:     } \
  803:     ifIsComplex(rpl_object) (*((complex16 *) (*rpl_object).objet)) \
  804:             .partie_reelle = value; \
  805:     else executionError("Type mismatch error"); } while(0)
  806: 
  807: #define setImaginaryPartOfComplex(rpl_object, value) do { \
  808:     if ((*rpl_object).nombre_occurrences > 1) \
  809:     { \
  810:         struct_objet *__tmp_rpl_object; \
  811:         if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  812:             systemError("Memory allocation error"); \
  813:         _liberation(rpl_object); \
  814:         rpl_object = __tmp_rpl_object; \
  815:     } \
  816:     (*((complex16 *) (*rpl_object).objet)).partie_imaginaire = value; \
  817:     else executionError("Type mismatch error"); } while(0)
  818: 
  819: #define getRealPartOfComplex(rpl_object, value) \
  820:     value = (*((complex16 *) (*rpl_object).objet)).partie_reelle
  821: 
  822: #define getImaginaryPartOfComplex(rpl_object, value) \
  823:     value = (*((complex16 *) (*rpl_object).objet)).partie_imaginaire
  824: 
  825: #define isComplex(rpl_object) \
  826:     ((*rpl_object).type == CPL)
  827: 
  828: #define ifIsComplex(rpl_object) if (isComplex(rpl_object))
  829: #define elseIfIsComplex(rpl_object) } else ifIsComplex(rpl_object)
  830: 
  831: #define getComplex(rpl_object, value) do { \
  832:     value.partie_reelle = 0; \
  833:     value.partie_imaginaire = 0; \
  834:     ifIsComplex(rpl_object) value = (*((complex16 *) (*rpl_object).objet)); \
  835:     else systemError("Not a complex"); } while(0)
  836: 
  837: #define createComplexObject(rpl_object) do { \
  838:     if (rpl_object != NULL) \
  839:         systemError("Reallocated object"); \
  840:     if ((rpl_object = _allocation(CPL)) == NULL) \
  841:         systemError("Memory allocation error"); \
  842:     setComplex(rpl_object, 0, 0); } while(0)
  843: 
  844: // Generalized vectors
  845: 
  846: #define createVectorObject(rpl_object, size, otype, structure, cat) do { \
  847:     integer8 i; \
  848:     struct_processus *s_etat_processus; \
  849:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
  850:     if (rpl_object != NULL) \
  851:         systemError("Reallocated object"); \
  852:     if ((rpl_object = _allocation(cat)) == NULL) \
  853:         systemError("Memory allocation error"); \
  854:     (*((structure *) (*rpl_object).objet)).taille = size; \
  855:     if (((*((structure *) (*rpl_object).objet)).tableau = \
  856:             malloc(size * sizeof(otype))) == NULL) \
  857:         systemError("Memory allocation error"); \
  858:     if (cat != VCX) \
  859:     { \
  860:         if (cat == VIN) \
  861:             (*((structure *) (*rpl_object).objet)).type = 'I'; \
  862:         else \
  863:             (*((structure *) (*rpl_object).objet)).type = 'R'; \
  864:         for(i = 0; i < size; ((otype *) (*((structure *) (*rpl_object).objet)) \
  865:                 .tableau)[i++] = (otype) 0); \
  866:     } \
  867:     else \
  868:     { \
  869:         (*((structure *) (*rpl_object).objet)).type = 'C'; \
  870:         for(i = 0; i < size; i++) \
  871:         { \
  872:             ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \
  873:                     .partie_reelle = 0; \
  874:             ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \
  875:                     .partie_imaginaire = 0; \
  876:         } \
  877:     } } while(0)
  878: 
  879: // Integer vector
  880: 
  881: #define setIntegerIntoVector(rpl_object, value, position) do { \
  882:     typeof(position) __position = position; \
  883:     ifIsIntegerVector(rpl_object) \
  884:     { \
  885:         if ((*rpl_object).nombre_occurrences > 1) \
  886:         { \
  887:             struct_objet *__tmp_rpl_object; \
  888:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  889:                 systemError("Memory allocation error"); \
  890:             _liberation(rpl_object); \
  891:             rpl_object = __tmp_rpl_object; \
  892:         } \
  893:         __position--; \
  894:         if ((__position < 0) || (__position >= (*((struct_vecteur *) \
  895:                 (*rpl_object).objet)).taille)) \
  896:             { executionError("Element out of range"); } \
  897:         else \
  898:             ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \
  899:                     [__position] = (integer8) value; \
  900:     } \
  901:     else executionError("Type mistmatch error"); } while(0)
  902: 
  903: #define isIntegerVector(rpl_object) \
  904:     ((*rpl_object).type == VIN)
  905: 
  906: #define ifIsIntegerVector(rpl_object) if (isIntegerVector(rpl_object))
  907: #define elseIfIsIntegerVector(rpl_object) } else ifIsIntegerVector(rpl_object)
  908: 
  909: #define getIntegerFromVector(rpl_object, value, position) do { \
  910:     typeof(position) __position = position; \
  911:     value = 0; \
  912:     ifIsIntegerVector(rpl_object) \
  913:     { \
  914:         __position--; \
  915:         if ((__position < 0) || (__position >= (*((struct_vecteur *) \
  916:                 (*rpl_object).objet)).taille)) \
  917:             executionError("Element out of range"); \
  918:         else \
  919:             value = ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)) \
  920:                 .tableau)[__position]; \
  921:     } \
  922:     else executionError("Type mismatch error"); } while(0)
  923: 
  924: #define createIntegerVectorObject(rpl_object, size) \
  925:     createVectorObject(rpl_object, size, integer8, struct_vecteur, VIN)
  926: 
  927: // Real vector
  928: 
  929: #define setRealIntoVector(rpl_object, value, position) do { \
  930:     typeof(position) __position = position; \
  931:     ifIsRealVector(rpl_object) \
  932:     { \
  933:         if ((*rpl_object).nombre_occurrences > 1) \
  934:         { \
  935:             struct_objet *__tmp_rpl_object; \
  936:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  937:                 systemError("Memory allocation error"); \
  938:             _liberation(rpl_object); \
  939:             rpl_object = __tmp_rpl_object; \
  940:         } \
  941:         __position--; \
  942:         if ((__position < 0) || (__position >= (*((struct_vecteur *) \
  943:                 (*rpl_object).objet)).taille)) \
  944:             { executionError("Element out of range"); } \
  945:         else \
  946:             ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \
  947:                     [__position] = (real8) value; \
  948:     } \
  949:     else executionError("Type mistmatch error"); } while(0)
  950: 
  951: #define isRealVector(rpl_object) \
  952:     ((*rpl_object).type == VRL)
  953: 
  954: #define ifIsRealVector(rpl_object) if (isRealVector(rpl_object))
  955: #define elseIfIsRealVector(rpl_object) } else ifIsRealVector(rpl_object)
  956: 
  957: #define getRealFromVector(rpl_object, value, position) do { \
  958:     typeof(position) __position = position; \
  959:     value = 0; \
  960:     ifIsRealVector(rpl_object) \
  961:     { \
  962:         __position--; \
  963:         if ((__position < 0) || (__position >= (*((struct_vecteur *) \
  964:                 (*rpl_object).objet)).taille)) \
  965:             executionError("Element out of range"); \
  966:         value = ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)) \
  967:                 .tableau)[__position]; \
  968:     } \
  969:     else executionError("Type mismatch error"); } while(0)
  970: 
  971: #define createRealVectorObject(rpl_object, size) \
  972:     createVectorObject(rpl_object, size, real8, struct_vecteur, VRL)
  973: 
  974: // A FIXER
  975: 
  976: #define createComplexVectorObject
  977: 
  978: #define createIntegerMatrixObject
  979: 
  980: #define createRealMatrixObject
  981: 
  982: #define createComplexMatrixObject
  983: 
  984: // Binary integer
  985: 
  986: #define setBinaryInteger(rpl_object, value) do { \
  987:     ifIsBinaryInteger(rpl_object) \
  988:     { \
  989:         if ((*rpl_object).nombre_occurrences > 1) \
  990:         { \
  991:             struct_objet *__tmp_rpl_object; \
  992:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
  993:                 systemError("Memory allocation error"); \
  994:             _liberation(rpl_object); \
  995:             rpl_object = __tmp_rpl_object; \
  996:         } \
  997:         (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \
  998:     } \
  999:     else executionError("Type mistmatch error"); } while(0)
 1000: 
 1001: #define isBinaryInteger(rpl_object) \
 1002:     ((*rpl_object).type == BIN)
 1003: 
 1004: #define ifIsBinaryInteger(rpl_object) if (isBinaryInteger(rpl_object))
 1005: #define elseIfIsBinaryInteger(rpl_object) } else ifIsBinaryInteger(rpl_object)
 1006: 
 1007: #define getBinaryInteger(rpl_object, value) do { \
 1008:     value = 0; \
 1009:     ifIsBinaryInteger(rpl_object) value = \
 1010:             (*((integer8 *) (*rpl_object).objet)); \
 1011:     else executionError("Type mismatch error"); } while(0)
 1012: 
 1013: #define createBinaryIntegerObject(rpl_object) do { \
 1014:     if (rpl_object != NULL) \
 1015:         systemError("Reallocated object"); \
 1016:     if ((rpl_object = _allocation(BIN)) == NULL) \
 1017:         systemError("Memory allocation error"); \
 1018:     setBinaryInteger(rpl_object, 0); } while(0)
 1019: 
 1020: // Name
 1021: 
 1022: #define isName(rpl_object) \
 1023:     ((*rpl_object).type == NOM)
 1024: 
 1025: #define ifIsName(rpl_object) if (isName(rpl_object))
 1026: #define elseIfIsName(rpl_object)  } else if (isName(rpl_object))
 1027: 
 1028: #define setName(rpl_object, value) do { \
 1029:     struct_processus *s_etat_processus; \
 1030:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1031:     ifIsName(rpl_object) \
 1032:     { \
 1033:         if ((*rpl_object).nombre_occurrences > 1) \
 1034:         { \
 1035:             struct_objet *__tmp_rpl_object; \
 1036:             if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \
 1037:                 systemError("Memory allocation error"); \
 1038:             _liberation(rpl_object); \
 1039:             rpl_object = __tmp_rpl_object; \
 1040:         } \
 1041:         free((*((struct_nom *) (*rpl_object).objet)).nom); \
 1042:         (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \
 1043:         if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \
 1044:                 (strlen(value) + 1) * sizeof(unsigned char))) == NULL) \
 1045:             systemError("Memory allocation error"); \
 1046:         strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, \
 1047:                 (char *) value); \
 1048:     } \
 1049:     else executionError("Type mistmatch error"); } while(0)
 1050: 
 1051: #define setSymbolicName(rpl_object, value) do { \
 1052:     setName(rpl_object, value); \
 1053:     (*((struct_nom *) (*rpl_object).objet)).symbole = d_vrai; } while(0)
 1054: 
 1055: #define createNameObject(rpl_object) do { \
 1056:     struct_processus *s_etat_processus; \
 1057:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1058:     if (rpl_object != NULL) \
 1059:         systemError("Reallocated object"); \
 1060:     if ((rpl_object = _allocation(NOM)) == NULL) \
 1061:         systemError("Memory allocation error"); \
 1062:     (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \
 1063:     if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \
 1064:             sizeof(unsigned char))) == NULL) \
 1065:         systemError("Memory allocation error"); \
 1066:     strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, ""); } while(0)
 1067: 
 1068: // String
 1069: 
 1070: #define isString(rpl_object) \
 1071:     ((*rpl_object).type == CHN)
 1072: 
 1073: #define ifIsString(rpl_object) if (isString(rpl_object))
 1074: #define elseIfIsString(rpl_object) } else if (isString(rpl_object))
 1075: 
 1076: #define setString(rpl_object, string) do { \
 1077:     struct_processus *s_etat_processus; \
 1078:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1079:     ifIsString(rpl_object) \
 1080:     { \
 1081:         if (string == NULL) executionError("Nullified string"); else \
 1082:         { \
 1083:             if ((*rpl_object).nombre_occurrences > 1) \
 1084:             { \
 1085:                 struct_objet *__tmp_rpl_object; \
 1086:                 if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) \
 1087:                         == NULL) \
 1088:                     systemError("Memory allocation error"); \
 1089:                 _liberation(rpl_object); \
 1090:                 rpl_object = __tmp_rpl_object; \
 1091:             } \
 1092:             free((unsigned char *) (*rpl_object).objet); \
 1093:             if (((*rpl_object).objet = malloc((strlen(string) + 1) * \
 1094:                     sizeof(unsigned char))) == NULL) \
 1095:                 systemError("Memory allocation error"); \
 1096:             strcpy((char *) (*rpl_object).objet, string); \
 1097:         } \
 1098:     } \
 1099:     else executionError("Type mistmatch error"); } while(0)
 1100: 
 1101: #define getString(rpl_object, string) do { \
 1102:     string = NULL; \
 1103:     ifIsString(rpl_object) string = (char *) (*rpl_object).objet; \
 1104:     else executionError("Type mismatch error"); } while(0)
 1105: 
 1106: #define createStringObject(rpl_object) do { \
 1107:     struct_processus *s_etat_processus; \
 1108:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1109:     if (rpl_object != NULL) \
 1110:         systemError("Reallocated object"); \
 1111:     if ((rpl_object = _allocation(CHN)) == NULL) \
 1112:         systemError("Memory allocation error"); \
 1113:     if (((*rpl_object).objet = malloc(sizeof(unsigned char))) == NULL) \
 1114:         systemError("Memory allocation error"); \
 1115:     strcpy((char *) (*rpl_object).objet, ""); } while(0)
 1116: 
 1117: // List
 1118: 
 1119: #define isList(rpl_object) \
 1120:     ((*rpl_object).type == LST)
 1121: 
 1122: #define ifIsList(rpl_object) if (isList(rpl_object))
 1123: #define elseIfIsList(rpl_object) else if (isList(rpl_object))
 1124: 
 1125: #define createListObject(rpl_object) do { \
 1126:     if (rpl_object != NULL) \
 1127:         systemError("Reallocated object"); \
 1128:     if ((rpl_object = _allocation(LST)) == NULL) \
 1129:         systemError("Memory allocation error"); \
 1130:     (*rpl_object).objet = NULL; } while(0)
 1131: 
 1132: #define addObjectToList(list, rpl_object) do { \
 1133:     struct_processus *s_etat_processus; \
 1134:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1135:     ifIsList(list) \
 1136:     { \
 1137:         struct_objet *__tmp_rpl_object; \
 1138:         if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \
 1139:             systemError("Memory allocation error"); \
 1140:         _liberation(list); \
 1141:         list = __tmp_rpl_object; \
 1142:         if ((*list).objet == NULL) \
 1143:         { \
 1144:             if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
 1145:                     == NULL) \
 1146:                 systemError("Memory allocation error"); \
 1147:             (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
 1148:             (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \
 1149:         } \
 1150:         else \
 1151:         { \
 1152:             struct_liste_chainee    *l_element_courant; \
 1153:             l_element_courant = (*list).objet; \
 1154:             while((*l_element_courant).suivant != NULL) \
 1155:                 l_element_courant = (*l_element_courant).suivant; \
 1156:             if (((*l_element_courant).suivant = \
 1157:                     malloc(sizeof(struct_liste_chainee))) == NULL) \
 1158:                 systemError("Memory allocation error"); \
 1159:             l_element_courant = (*l_element_courant).suivant; \
 1160:             (*l_element_courant).suivant = NULL; \
 1161:             (*l_element_courant).donnee = rpl_object; \
 1162:         } \
 1163:         rpl_object = NULL; \
 1164:     } \
 1165:     else executionError("Type mistmatch error"); } while(0)
 1166: 
 1167: #define insertObjectIntoList(list, rpl_object) do { \
 1168:     struct_processus *s_etat_processus; \
 1169:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1170:     ifIsList(list) \
 1171:     { \
 1172:         struct_objet *__tmp_rpl_object; \
 1173:         if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \
 1174:             systemError("Memory allocation error"); \
 1175:         _liberation(list); \
 1176:         list = __tmp_rpl_object; \
 1177:         if ((*list).objet == NULL) \
 1178:         { \
 1179:             if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
 1180:                     == NULL) \
 1181:                 systemError("Memory allocation error"); \
 1182:             (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
 1183:             (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \
 1184:         } \
 1185:         else \
 1186:         { \
 1187:             struct_liste_chainee    *l_element_courant; \
 1188:             if ((l_element_courant = \
 1189:                     malloc(sizeof(struct_liste_chainee))) == NULL) \
 1190:                 systemError("Memory allocation error"); \
 1191:             (*l_element_courant).donnee = rpl_object; \
 1192:             (*l_element_courant).suivant = (*list).objet; \
 1193:             (*list).objet = l_element_courant; \
 1194:         } \
 1195:         rpl_object = NULL; \
 1196:     } \
 1197:     else executionError("Type mistmatch error"); } while(0)
 1198: 
 1199: #define removeObjectFromList(list, rpl_object) do { \
 1200:     struct_processus *s_etat_processus; \
 1201:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1202:     ifIsList(list) \
 1203:     { \
 1204:         if ((*list).objet != NULL) \
 1205:         { \
 1206:             struct_liste_chainee    *__current; \
 1207:             struct_liste_chainee    *__previous; \
 1208:             __current = (*list).objet; \
 1209:             __previous = NULL; \
 1210:             if ((*__current).donnee == rpl_object) \
 1211:             { \
 1212:                 (*list).objet = (*__current).suivant; \
 1213:             } \
 1214:             else \
 1215:             { \
 1216:                 while(__current != NULL) \
 1217:                 { \
 1218:                     if ((*__current).donnee == rpl_object) \
 1219:                     { \
 1220:                         (*__previous).suivant = (*__current).suivant; \
 1221:                         break; \
 1222:                     } \
 1223:                     __previous = __current; \
 1224:                     __current = (*__current).suivant; \
 1225:                 } \
 1226:             } \
 1227:             _liberation((*__current).donnee); \
 1228:             free(__current); \
 1229:         } \
 1230:     } \
 1231:     else executionError("Type mistmatch error"); } while(0)
 1232: 
 1233: #define getObjectFromList(list, position, rpl_object)
 1234: 
 1235: #define putObjectIntoList(list, position, rpl_object)
 1236: 
 1237: #define getListFromList(list, position1, position2, rpl_object)
 1238: 
 1239: #define listLength(list, length) do { \
 1240:     if (list == NULL) executionError("Nullified object"); \
 1241:     if ((*list).type != LST) \
 1242:             executionError("Type mistmatch error"); \
 1243:     { \
 1244:         struct_liste_chainee        *l_element_courant; \
 1245:         length = 0; \
 1246:         l_element_courant = (*list).objet; \
 1247:         while(l_element_courant != NULL) \
 1248:         { \
 1249:             l_element_courant = (*l_element_courant).suivant; \
 1250:             length++; \
 1251:         } \
 1252:     } } while(0)
 1253: 
 1254: // NON
 1255: #define createObject(rpl_object) do { \
 1256:     if (rpl_object != NULL) \
 1257:         systemError("Reallocated object"); \
 1258:     if ((rpl_object = _allocation(NON)) == NULL) \
 1259:         systemError("Memory allocation error"); \
 1260:     (*rpl_object).objet = NULL; \
 1261:     } while(0)
 1262: 
 1263: // EXT
 1264: #define createExternalObject(rpl_object, subtype) do { \
 1265:     if (rpl_object != NULL) \
 1266:         systemError("Reallocated object"); \
 1267:     if ((rpl_object = _allocation(EXT)) == NULL) \
 1268:         systemError("Memory allocation error"); \
 1269:     (*rpl_object).objet = NULL; \
 1270:     (*rpl_object).extension_type = subtype; \
 1271:     (*rpl_object).descripteur_bibliotheque = __static_library_descriptor; \
 1272:     } while(0)
 1273: 
 1274: /*
 1275: --------------------------------------------------------------------------------
 1276:   Allocation mémoire
 1277: --------------------------------------------------------------------------------
 1278: */
 1279: 
 1280: #define size(a) sizeof(a)
 1281: 
 1282: #define allocate(a) ({ void *ptr; \
 1283:     struct_processus *s_etat_processus; \
 1284:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1285:     if ((ptr = malloc(a)) == NULL) \
 1286:         { systemError("Memory allocation error"); \
 1287:         __CATCH_SYSTEM_ERROR__; } ptr; }) \
 1288: 
 1289: #define reallocate(a, s) ({ void *ptr; \
 1290:     struct_processus *s_etat_processus; \
 1291:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1292:     if ((ptr = realloc(a, s)) == NULL) \
 1293:         { systemError("Memory allocation error"); \
 1294:         __CATCH_SYSTEM_ERROR__; } ptr; }) \
 1295: 
 1296: #define deallocate(a) do { \
 1297:     struct_processus *s_etat_processus; \
 1298:     s_etat_processus = (*rpl_arguments).s_etat_processus; \
 1299:     free(a); } while(0)
 1300: 
 1301: /*
 1302: --------------------------------------------------------------------------------
 1303:   Récupération des interruptions et des signaux
 1304: --------------------------------------------------------------------------------
 1305: */
 1306: 
 1307: #define pollSignalsAndInterrupts() \
 1308:     __CATCH_SYSTEM_ERROR__; \
 1309:     do { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0)
 1310: 
 1311: /*
 1312: --------------------------------------------------------------------------------
 1313:   Exécution d'une fonction intrinsèque
 1314: --------------------------------------------------------------------------------
 1315: */
 1316: 
 1317: #define intrinsic(function) do { \
 1318:     int __status; \
 1319:     __CATCH_SYSTEM_ERROR__; \
 1320:     __status = wrapper_instruction_intrinseque( \
 1321:             instruction_##function, rpl_arguments); \
 1322:     if (__status == 1) executionError(#function); \
 1323:     if (__status == 2) systemError(#function); \
 1324:     } while(0)
 1325: 
 1326: #endif
 1327: 
 1328: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>