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