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