File:  [local] / rpl / src / rplexternals.h
Revision 1.83: download - view: text, annotated - select for diffs - revision graph
Mon Jul 10 14:47:59 2017 UTC (6 years, 9 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Patches pour motif.

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

CVSweb interface <joel.bertrand@systella.fr>