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