Annotation of rpl/src/rpl.c, revision 1.88
1.1 bertrand 1: /*
2: ================================================================================
1.77 bertrand 3: RPL/2 (R) version 4.1.3
1.57 bertrand 4: Copyright (C) 1989-2011 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: #define MAIN_RPL
1.35 bertrand 24: #include "rpl-conv.h"
1.1 bertrand 25:
1.37 bertrand 26:
1.1 bertrand 27: /*
28: ================================================================================
29: Programme principal
30: ================================================================================
31: */
32:
33: int
1.11 bertrand 34: rplinit(int argc, char *argv[], unsigned char ***resultats, char *rpl_home)
1.1 bertrand 35: {
1.35 bertrand 36: # include "copyright-conv.h"
37: # include "licence-conv.h"
1.1 bertrand 38:
39: file *f_source;
40:
41: int erreur_historique;
42: int option_P;
43:
44: logical1 core;
45: logical1 debug;
46: logical1 erreur_fichier;
47: logical1 existence;
48: logical1 mode_interactif;
49: logical1 option_a;
50: logical1 option_A;
51: logical1 option_c;
52: logical1 option_d;
53: logical1 option_D;
54: logical1 option_h;
55: logical1 option_i;
56: logical1 option_l;
57: logical1 option_n;
58: logical1 option_p;
59: logical1 option_s;
60: logical1 option_S;
61: logical1 option_t;
62: logical1 option_v;
63: logical1 ouverture;
64:
65: pthread_mutexattr_t attributs_mutex;
66:
67: ssize_t longueur_ecriture;
68:
69: struct_objet *s_objet;
70:
71: struct_processus *s_etat_processus;
72:
73: struct_table_variables_partagees s_variables_partagees;
74:
75: struct sigaction action;
76: struct sigaction registre;
77:
78: struct timespec attente;
79:
80: unsigned char *arguments;
81: unsigned char drapeau_encart;
82: unsigned char *type_debug;
83: unsigned char *home;
84: unsigned char *langue;
85: unsigned char *message;
86: unsigned char *nom_fichier_temporaire;
87: unsigned char option;
88: unsigned char presence_definition;
89: unsigned char *ptr;
90: unsigned char *tampon;
91:
92: unsigned long i;
93: unsigned long unite_fichier;
94:
95: void *l_element_courant;
96: void *l_element_suivant;
97:
98: volatile int erreur;
99: volatile unsigned char traitement_fichier_temporaire;
100:
1.37 bertrand 101: errno = 0;
1.85 bertrand 102: s_queue_signaux = NULL;
1.82 bertrand 103: pid_processus_pere = getpid();
1.37 bertrand 104:
1.27 bertrand 105: # ifdef DEBUG_MEMOIRE
106: debug_memoire_initialisation();
107: # endif
108:
1.1 bertrand 109: setvbuf(stdout, NULL, _IOLBF, 0);
110: setvbuf(stderr, NULL, _IOLBF, 0);
111:
1.17 bertrand 112: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 113: sem_init(&semaphore_gestionnaires_signaux, 0, 0);
1.17 bertrand 114: # else
1.87 bertrand 115: semaphore_gestionnaires_signaux = sem_init2(0, getpid());
1.84 bertrand 116:
117: if (semaphore_gestionnaires_signaux == SEM_FAILED)
1.17 bertrand 118: {
119: erreur = d_es_allocation_memoire;
120:
121: if ((langue = getenv("LANG")) != NULL)
122: {
123: if (strncmp(langue, "fr", 2) == 0)
124: {
125: uprintf("+++Système : Mémoire insuffisante\n");
126: }
127: else
128: {
129: uprintf("+++System : Not enough memory\n");
130: }
131: }
132: else
133: {
134: uprintf("+++System : Not enough memory\n");
135: }
136:
137: return(EXIT_FAILURE);
138: }
139: # endif
1.1 bertrand 140:
141: if ((s_etat_processus = malloc(sizeof(struct_processus))) == NULL)
142: {
143: erreur = d_es_allocation_memoire;
144:
1.17 bertrand 145: if ((langue = getenv("LANG")) != NULL)
1.1 bertrand 146: {
1.17 bertrand 147: if (strncmp(langue, "fr", 2) == 0)
148: {
149: uprintf("+++Système : Mémoire insuffisante\n");
150: }
151: else
152: {
153: uprintf("+++System : Not enough memory\n");
154: }
1.1 bertrand 155: }
156: else
157: {
1.17 bertrand 158: uprintf("+++System : Not enough memory\n");
1.1 bertrand 159: }
160:
161: return(EXIT_FAILURE);
162: }
163:
1.17 bertrand 164: if ((langue = getenv("LANG")) != NULL)
165: {
166: (*s_etat_processus).langue = (strncmp(langue, "fr", 2) == 0)
167: ? 'F' : 'E';
168: }
169: else
170: {
171: (*s_etat_processus).langue = 'E';
172: }
173:
1.76 bertrand 174: initialisation_contexte_cas(s_etat_processus);
175:
1.1 bertrand 176: (*s_etat_processus).exception = d_ep;
177: (*s_etat_processus).erreur_systeme = d_es;
178: (*s_etat_processus).erreur_execution = d_ex;
1.80 bertrand 179: (*s_etat_processus).compteur_violation_d_acces = 0;
1.1 bertrand 180:
1.11 bertrand 181: (*s_etat_processus).rpl_home = rpl_home;
182:
1.1 bertrand 183: pthread_mutexattr_init(&attributs_mutex);
184: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
185: pthread_mutex_init(&((*s_etat_processus).mutex), &attributs_mutex);
186: pthread_mutexattr_destroy(&attributs_mutex);
187:
1.30 bertrand 188: pthread_mutexattr_init(&attributs_mutex);
189: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
190: pthread_mutex_init(&((*s_etat_processus).mutex_allocation),
191: &attributs_mutex);
192: pthread_mutexattr_destroy(&attributs_mutex);
193:
1.84 bertrand 194: pthread_mutexattr_init(&attributs_mutex);
195: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
196: pthread_mutex_init(&((*s_etat_processus).mutex_fork),
197: &attributs_mutex);
198: pthread_mutexattr_destroy(&attributs_mutex);
199: pthread_mutex_lock(&((*s_etat_processus).mutex_fork));
1.1 bertrand 200:
201: pthread_mutexattr_init(&attributs_mutex);
202: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
203: pthread_mutex_init(&((*s_etat_processus).protection_liste_mutexes),
204: &attributs_mutex);
205: pthread_mutexattr_destroy(&attributs_mutex);
206:
207: (*s_etat_processus).s_liste_variables_partagees = &s_variables_partagees;
208:
209: s_variables_partagees.nombre_variables = 0;
210: s_variables_partagees.nombre_variables_allouees = 0;
211: s_variables_partagees.table = NULL;
212:
213: pthread_mutexattr_init(&attributs_mutex);
214: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
215: pthread_mutex_init(&((*((*s_etat_processus).s_liste_variables_partagees))
216: .mutex), &attributs_mutex);
217: pthread_mutexattr_destroy(&attributs_mutex);
218:
1.40 bertrand 219: (*s_etat_processus).chemin_fichiers_temporaires =
220: recherche_chemin_fichiers_temporaires(s_etat_processus);
221:
1.43 bertrand 222: insertion_thread(s_etat_processus, d_vrai);
1.83 bertrand 223: creation_queue_signaux(s_etat_processus);
1.40 bertrand 224:
1.43 bertrand 225: # ifndef OS2
226: localisation_courante(s_etat_processus);
227: # else
1.42 bertrand 228: if ((*s_etat_processus).erreur_systeme != d_es)
229: {
230: if (((*s_etat_processus).localisation = malloc((strlen(d_locale) + 1) *
231: sizeof(unsigned char))) == NULL)
232: {
233: if ((*s_etat_processus).langue == 'F')
234: {
235: uprintf("+++Système : Mémoire insuffisante\n");
236: }
237: else
238: {
239: uprintf("+++System : Not enough memory\n");
240: }
241:
242: return(EXIT_FAILURE);
243: }
244:
245: strcpy((*s_etat_processus).localisation, d_locale);
246: }
1.40 bertrand 247: # endif
248:
1.17 bertrand 249: (*s_etat_processus).erreur_systeme = d_es;
1.1 bertrand 250:
1.17 bertrand 251: if ((*s_etat_processus).localisation == NULL)
1.1 bertrand 252: {
1.17 bertrand 253: if (((*s_etat_processus).localisation = malloc((strlen(d_locale) + 1) *
254: sizeof(unsigned char))) == NULL)
1.1 bertrand 255: {
1.17 bertrand 256: if ((*s_etat_processus).langue == 'F')
257: {
258: uprintf("+++Système : Mémoire insuffisante\n");
259: }
260: else
261: {
262: uprintf("+++System : Not enough memory\n");
263: }
264:
265: return(EXIT_FAILURE);
1.1 bertrand 266: }
267:
1.17 bertrand 268: strcpy((*s_etat_processus).localisation, d_locale);
1.1 bertrand 269: }
270:
271: printf("+++RPL/2 (R) version %s (%s)\n", d_version_rpl,
272: ((*s_etat_processus).langue == 'F') ? d_date_rpl : d_date_en_rpl);
273:
274: if ((*s_etat_processus).langue == 'F')
275: {
1.57 bertrand 276: printf("+++Copyright (C) 1989 à 2010, 2011 BERTRAND Joël\n");
1.1 bertrand 277: }
278: else
279: {
1.57 bertrand 280: printf("+++Copyright (C) 1989 to 2010, 2011 BERTRAND Joel\n");
1.1 bertrand 281: }
282:
283: if (getenv("HOME") != NULL)
284: {
285: home = getenv("HOME");
286: }
287: else if ((getenv("USER") != NULL) && (getpwnam(getenv("USER")) != NULL))
288: {
289: home = getpwnam(getenv("USER"))->pw_dir;
290: }
291: else if ((getenv("LOGNAME") != NULL) && (getpwnam(getenv("LOGNAME"))
292: != NULL))
293: {
294: home = getpwnam(getenv("LOGNAME"))->pw_dir;
295: }
296: else if ((getuid() != ((uid_t) -1)) && (getpwuid(getuid()) != NULL))
297: {
298: home = getpwuid(getuid())->pw_dir;
299: }
300: else
301: {
302: home = "";
303: }
304:
305: // Initialisation d'une pile de signal pour récupérer les
306: // débordement de pile
307:
1.39 bertrand 308: # if !defined(Cygwin) && !defined(OpenBSD)
1.1 bertrand 309: if (((*s_etat_processus).pile_signal.ss_sp =
310: malloc((*s_etat_processus).pile_signal.ss_size =
311: SIGSTKSZ)) == NULL)
312: {
313: erreur = d_es_allocation_memoire;
314:
315: if ((*s_etat_processus).langue == 'F')
316: {
317: printf("+++Système : Mémoire insuffisante\n");
318: }
319: else
320: {
321: printf("+++System : Not enough memory\n");
322: }
323:
324: return(EXIT_FAILURE);
325: }
326:
327: (*s_etat_processus).pile_signal.ss_flags = 0;
328:
329: if (sigaltstack(&((*s_etat_processus).pile_signal), NULL) != 0)
330: {
331: erreur = d_es_signal;
332:
333: if ((*s_etat_processus).langue == 'F')
334: {
335: printf("+++Système : Initialisation de la pile spécifique de signal"
336: " impossible\n");
337: }
338: else
339: {
340: printf("+++System : Initialization of signal stack failed\n");
341: }
342:
343: return(EXIT_FAILURE);
344: }
1.9 bertrand 345: # endif
1.1 bertrand 346:
1.40 bertrand 347: action.sa_handler = interruption1;
1.83 bertrand 348: action.sa_flags = SA_ONSTACK;
1.1 bertrand 349:
350: if (sigaction(SIGINT, &action, NULL) != 0)
351: {
352: erreur = d_es_signal;
353:
354: if ((*s_etat_processus).langue == 'F')
355: {
356: printf("+++Système : Initialisation des signaux POSIX "
357: "impossible\n");
358: }
359: else
360: {
361: printf("+++System : Initialization of POSIX signals failed\n");
362: }
363:
364: return(EXIT_FAILURE);
365: }
366:
1.81 bertrand 367: signal_test = SIGTEST;
368: kill(getpid(), SIGINT);
369:
370: if (signal_test != SIGINT)
371: {
372: erreur = d_es_signal;
373:
374: if ((*s_etat_processus).langue == 'F')
375: {
376: printf("+++Système : Initialisation des signaux POSIX "
377: "impossible\n");
378: }
379: else
380: {
381: printf("+++System : Initialization of POSIX signals failed\n");
382: }
383:
384: return(EXIT_FAILURE);
385: }
386:
1.54 bertrand 387: if (sigaction(SIGTERM, &action, NULL) != 0)
388: {
389: erreur = d_es_signal;
390:
391: if ((*s_etat_processus).langue == 'F')
392: {
393: printf("+++Système : Initialisation des signaux POSIX "
394: "impossible\n");
395: }
396: else
397: {
398: printf("+++System : Initialization of POSIX signals failed\n");
399: }
400:
401: return(EXIT_FAILURE);
402: }
403:
1.81 bertrand 404: signal_test = SIGTEST;
405: kill(getpid(), SIGTERM);
406:
407: if (signal_test != SIGTERM)
408: {
409: erreur = d_es_signal;
410:
411: if ((*s_etat_processus).langue == 'F')
412: {
413: printf("+++Système : Initialisation des signaux POSIX "
414: "impossible\n");
415: }
416: else
417: {
418: printf("+++System : Initialization of POSIX signals failed\n");
419: }
420:
421: return(EXIT_FAILURE);
422: }
423:
1.40 bertrand 424: action.sa_handler = interruption2;
1.83 bertrand 425: action.sa_flags = SA_NODEFER | SA_ONSTACK;
1.1 bertrand 426:
427: if (sigaction(SIGTSTP, &action, NULL) != 0)
428: {
429: if ((*s_etat_processus).langue == 'F')
430: {
431: printf("+++Système : Initialisation des signaux POSIX "
432: "impossible\n");
433: }
434: else
435: {
436: printf("+++System : Initialization of POSIX signals failed\n");
437: }
438:
439: return(EXIT_FAILURE);
440: }
441:
1.81 bertrand 442: signal_test = SIGTEST;
443: kill(getpid(), SIGTSTP);
444:
445: if (signal_test != SIGTSTP)
446: {
447: erreur = d_es_signal;
448:
449: if ((*s_etat_processus).langue == 'F')
450: {
451: printf("+++Système : Initialisation des signaux POSIX "
452: "impossible\n");
453: }
454: else
455: {
456: printf("+++System : Initialization of POSIX signals failed\n");
457: }
458:
459: return(EXIT_FAILURE);
460: }
461:
1.40 bertrand 462: action.sa_handler = interruption5;
1.83 bertrand 463: action.sa_flags = SA_NODEFER | SA_ONSTACK;
1.1 bertrand 464:
465: if (sigaction(SIGPIPE, &action, NULL) != 0)
466: {
467: erreur = d_es_signal;
468:
469: if ((*s_etat_processus).langue == 'F')
470: {
471: printf("+++Système : Initialisation des signaux POSIX "
472: "impossible\n");
473: }
474: else
475: {
476: printf("+++System : Initialization of POSIX signals failed\n");
477: }
478:
479: return(EXIT_FAILURE);
480: }
481:
1.81 bertrand 482: signal_test = SIGTEST;
483: kill(getpid(), SIGPIPE);
484:
485: if (signal_test != SIGPIPE)
486: {
487: erreur = d_es_signal;
488:
489: if ((*s_etat_processus).langue == 'F')
490: {
491: printf("+++Système : Initialisation des signaux POSIX "
492: "impossible\n");
493: }
494: else
495: {
496: printf("+++System : Initialization of POSIX signals failed\n");
497: }
498:
499: return(EXIT_FAILURE);
500: }
501:
1.40 bertrand 502: action.sa_handler = interruption1;
1.83 bertrand 503: action.sa_flags = SA_NODEFER | SA_ONSTACK;
1.1 bertrand 504:
505: if (sigaction(SIGALRM, &action, NULL) != 0)
506: {
507: erreur = d_es_signal;
508:
509: if ((*s_etat_processus).langue == 'F')
510: {
511: printf("+++Système : Initialisation des signaux POSIX "
512: "impossible\n");
513: }
514: else
515: {
516: printf("+++System : Initialization of POSIX signals failed\n");
517: }
518:
519: return(EXIT_FAILURE);
520: }
521:
1.81 bertrand 522: signal_test = SIGTEST;
523: kill(getpid(), SIGALRM);
524:
525: if (signal_test != SIGALRM)
526: {
527: erreur = d_es_signal;
528:
529: if ((*s_etat_processus).langue == 'F')
530: {
531: printf("+++Système : Initialisation des signaux POSIX "
532: "impossible\n");
533: }
534: else
535: {
536: printf("+++System : Initialization of POSIX signals failed\n");
537: }
538:
539: return(EXIT_FAILURE);
540: }
541:
1.82 bertrand 542: signal_test = SIGTEST + 1;
1.1 bertrand 543:
1.13 bertrand 544: erreur = d_absence_erreur;
1.1 bertrand 545: core = d_faux;
546: mode_interactif = d_faux;
547: (*s_etat_processus).nom_fichier_source = NULL;
548: (*s_etat_processus).definitions_chainees = NULL;
549: (*s_etat_processus).type_debug = 0;
550: traitement_fichier_temporaire = 'N';
551: option = ' ';
552: drapeau_encart = 'Y';
553: debug = d_faux;
554: arguments = NULL;
555:
556: (*s_etat_processus).s_fichiers = NULL;
557: (*s_etat_processus).s_sockets = NULL;
558: (*s_etat_processus).s_connecteurs_sql = NULL;
559:
560: setlogmask(LOG_MASK(LOG_NOTICE));
561: openlog(argv[0], LOG_ODELAY | LOG_PID, LOG_USER);
562:
563: if (argc == 1)
564: {
1.13 bertrand 565: erreur = d_erreur;
1.1 bertrand 566: informations(s_etat_processus);
567: }
568: else
569: {
570: presence_definition = 'N';
571: (*s_etat_processus).debug = d_faux;
572: (*s_etat_processus).lancement_interactif = d_faux;
573:
574: option_a = d_faux;
575: option_A = d_faux;
576: option_c = d_faux;
577: option_d = d_faux;
578: option_D = d_faux;
579: option_h = d_faux;
580: option_i = d_faux;
581: option_l = d_faux;
582: option_n = d_faux;
583: option_p = d_faux;
584: option_P = 0;
585: option_s = d_faux;
586: option_S = d_faux;
587: option_t = d_faux;
588: option_v = d_faux;
589:
1.86 bertrand 590: // Lorsque le programme est appelé depuis un shebang, argv[0] contient
591: // le chemin du programme et argv[1] tous les arguments.
592: // argv[2] contient quant à lui le nom du script RPL/2.
593: //
594: // Exemple :
595: // argv[0] : /usr/local/bin/rpl
596: // argv[1] : -csdp -t 800
597: // argv[2] : ./on_exit.rpl
598:
1.1 bertrand 599: while((--argc) > 0)
600: {
601: if ((*(++argv))[0] == '-')
602: {
603: while((option = *(++argv[0])) != '\0')
604: {
605: switch(option)
606: {
607: case 'a' :
608: {
609: if (option_a == d_vrai)
610: {
611: if ((*s_etat_processus).langue == 'F')
612: {
613: printf("+++Erreur : option -a présente "
614: "plus d'une fois\n");
615: }
616: else
617: {
618: printf("+++Error : more than one -a "
619: "on command line");
620: }
621:
622: return(EXIT_FAILURE);
623: }
624:
625: option_a = d_vrai;
626: break;
627: }
628:
629: case 'A' :
630: {
631: if (option_A == d_vrai)
632: {
633: if ((*s_etat_processus).langue == 'F')
634: {
635: printf("+++Erreur : option -A présente "
636: "plus d'une fois\n");
637: }
638: else
639: {
640: printf("+++Error : more than one -A "
641: "on command line");
642: }
643:
644: return(EXIT_FAILURE);
645: }
646:
647: option_A = d_vrai;
648:
649: while(*(++argv[0]) == ' ');
650: argv[0]--;
651:
652: if ((*(++argv[0])) != '\0')
653: {
654: if ((arguments = malloc((strlen(argv[0]) + 7) *
655: sizeof(unsigned char))) == NULL)
656: {
657: if ((*s_etat_processus).langue == 'F')
658: {
659: printf("+++Système : Mémoire "
660: "insuffisante\n");
661: }
662: else
663: {
664: printf("+++System : Not enough "
665: "memory\n");
666: }
667:
668: return(EXIT_FAILURE);
669: }
670:
671: ptr = arguments;
672: (*ptr) = d_code_fin_chaine;
673: strcat(ptr, "<< ");
674: ptr += 3;
675:
676: while(*(argv[0]) != '\0')
677: {
678: *(ptr++) = *(argv[0]++);
679: }
680:
681: (*ptr) = '\0';
682:
683: strcat(arguments, " >>");
684: argv[0]--;
685: }
686: else if ((--argc) > 0)
687: {
688: argv++;
689:
690: if ((arguments = malloc((strlen(argv[0]) + 7) *
691: sizeof(unsigned char))) == NULL)
692: {
693: if ((*s_etat_processus).langue == 'F')
694: {
695: printf("+++Système : Mémoire "
696: "insuffisante\n");
697: }
698: else
699: {
700: printf("+++System : Not enough "
701: "memory\n");
702: }
703:
704: return(EXIT_FAILURE);
705: }
706:
707: ptr = arguments;
708: (*ptr) = d_code_fin_chaine;
709: strcat(ptr, "<< ");
710: ptr += 3;
711:
712: while(*(argv[0]) != '\0')
713: {
714: *(ptr++) = *(argv[0]++);
715: }
716:
717: (*ptr) = '\0';
718:
719: strcat(arguments, " >>");
720: argv[0]--;
721: }
722: else
723: {
724: if ((*s_etat_processus).langue == 'F')
725: {
726: printf("+++Erreur : Aucune donnée "
727: "spécifié après l'option -A\n");
728: }
729: else
730: {
731: printf("+++Error : Data required after "
732: "-A option\n");
733: }
734:
735: return(EXIT_FAILURE);
736: }
737:
738: break;
739: }
740:
741: case 'c' :
742: {
743: if (option_c == d_vrai)
744: {
745: if ((*s_etat_processus).langue == 'F')
746: {
747: printf("+++Erreur : option -c présente "
748: "plus d'une fois\n");
749: }
750: else
751: {
752: printf("+++Error : more than one -c "
753: "on command line");
754: }
755:
756: return(EXIT_FAILURE);
757: }
758:
759: option_c = d_vrai;
760: core = d_vrai;
761: break;
762: }
763:
764: case 'd' :
765: {
766: if (option_d == d_vrai)
767: {
768: if ((*s_etat_processus).langue == 'F')
769: {
770: printf("+++Erreur : option -d présente "
771: "plus d'une fois\n");
772: }
773: else
774: {
775: printf("+++Error : more than one -d "
776: "on command line");
777: }
778:
779: return(EXIT_FAILURE);
780: }
781:
782: option_d = d_vrai;
783: debug = d_vrai;
784: break;
785: }
786:
787: case 'D' :
788: {
789: if (option_D == d_vrai)
790: {
791: if ((*s_etat_processus).langue == 'F')
792: {
793: printf("+++Erreur : option -D présente "
794: "plus d'une fois\n");
795: }
796: else
797: {
798: printf("+++Error : more than one -D "
799: "on command line");
800: }
801:
802: return(EXIT_FAILURE);
803: }
804:
805: option_D = d_vrai;
806: break;
807: }
808:
809: case 'h' :
810: {
811: if (option_h == d_vrai)
812: {
813: if ((*s_etat_processus).langue == 'F')
814: {
815: printf("+++Erreur : option -h présente "
816: "plus d'une fois\n");
817: }
818: else
819: {
820: printf("+++Error : more than one -h "
821: "on command line");
822: }
823:
824: return(EXIT_FAILURE);
825: }
826:
827: option_h = d_vrai;
828: informations(s_etat_processus);
829: break;
830: }
831:
832: case 'i' :
833: {
834: if (option_i == d_vrai)
835: {
836: if ((*s_etat_processus).langue == 'F')
837: {
838: printf("+++Erreur : option -i présente "
839: "plus d'une fois\n");
840: }
841: else
842: {
843: printf("+++Error : more than one -i "
844: "on command line");
845: }
846:
847: return(EXIT_FAILURE);
848: }
849: else if (option_S == d_vrai)
850: {
851: if ((*s_etat_processus).langue == 'F')
852: {
853: printf("+++Erreur : options -i et -S "
854: "incompatibles\n");
855: }
856: else
857: {
858: printf("+++Error : incompatible options -i "
859: "and -S\n");
860: }
861:
862: return(EXIT_FAILURE);
863: }
864: else if (option_p == d_vrai)
865: {
866: if ((*s_etat_processus).langue == 'F')
867: {
868: printf("+++Erreur : options -i et -p "
869: "incompatibles\n");
870: }
871: else
872: {
873: printf("+++Error : incompatible options -i "
874: "and -p\n");
875: }
876:
877: return(EXIT_FAILURE);
878: }
879:
880: option_i = d_vrai;
881: mode_interactif = d_vrai;
882: presence_definition = 'O';
883: break;
884: }
885:
886: case 'l' :
887: {
888: if (option_l == d_vrai)
889: {
890: if ((*s_etat_processus).langue == 'F')
891: {
892: printf("+++Erreur : option -l présente "
893: "plus d'une fois\n");
894: }
895: else
896: {
897: printf("+++Error : more than one -l "
898: "on command line");
899: }
900:
901: return(EXIT_FAILURE);
902: }
903:
904: option_l = d_vrai;
905:
906: if ((*s_etat_processus).langue == 'F')
907: {
908: printf("%s\n\n", CeCILL_fr);
909: }
910: else
911: {
912: printf("%s\n\n", CeCILL_en);
913: }
914:
915: break;
916: }
917:
918: case 'n' :
919: {
920: if (option_n == d_vrai)
921: {
922: if ((*s_etat_processus).langue == 'F')
923: {
924: printf("+++Erreur : option -n présente "
925: "plus d'une fois\n");
926: }
927: else
928: {
929: printf("+++Error : more than one -n "
930: "on command line");
931: }
932:
933: return(EXIT_FAILURE);
934: }
935:
936: option_n = d_vrai;
937:
938: break;
939: }
940:
941: case 'p' :
942: {
943: if (option_p == d_vrai)
944: {
945: if ((*s_etat_processus).langue == 'F')
946: {
947: printf("+++Erreur : option -p présente "
948: "plus d'une fois\n");
949: }
950: else
951: {
952: printf("+++Error : more than one -p "
953: "on command line");
954: }
955:
956: return(EXIT_FAILURE);
957: }
958: else if (option_i == d_vrai)
959: {
960: if ((*s_etat_processus).langue == 'F')
961: {
962: printf("+++Erreur : options -i et -p "
963: "incompatibles\n");
964: }
965: else
966: {
967: printf("+++Error : incompatible options -i "
968: "and -p\n");
969: }
970:
971: return(EXIT_FAILURE);
972: }
973:
974: option_p = d_vrai;
975:
976: break;
977: }
978:
979: case 'P' :
980: {
981: if (option_P > 2)
982: {
983: if ((*s_etat_processus).langue == 'F')
984: {
985: printf("+++Erreur : option -P présente "
986: "plus de deux fois\n");
987: }
988: else
989: {
990: printf("+++Error : more than two -P "
991: "on command line");
992: }
993:
994: return(EXIT_FAILURE);
995: }
996:
997: option_P++;
998:
999: break;
1000: }
1001:
1002: case 's' :
1003: {
1004: if (option_s == d_vrai)
1005: {
1006: if ((*s_etat_processus).langue == 'F')
1007: {
1008: printf("+++Erreur : option -s présente "
1009: "plus d'une fois\n");
1010: }
1011: else
1012: {
1013: printf("+++Error : more than one -s "
1014: "on command line");
1015: }
1016:
1017: return(EXIT_FAILURE);
1018: }
1019:
1020: option_s = d_vrai;
1021: drapeau_encart = 'N';
1022: break;
1023: }
1024:
1025: case 'S' :
1026: {
1027: if (option_S == d_vrai)
1028: {
1029: if ((*s_etat_processus).langue == 'F')
1030: {
1031: printf("+++Erreur : option -S présente "
1032: "plus d'une fois\n");
1033: }
1034: else
1035: {
1036: printf("+++Error : more than one -S "
1037: "on command line");
1038: }
1039:
1040: return(EXIT_FAILURE);
1041: }
1042: else if (option_i == d_vrai)
1043: {
1044: if ((*s_etat_processus).langue == 'F')
1045: {
1046: printf("+++Erreur : options -i et -S "
1047: "incompatibles\n");
1048: }
1049: else
1050: {
1051: printf("+++Error : incompatible options -S "
1052: "and -i\n");
1053: }
1054:
1055: return(EXIT_FAILURE);
1056: }
1057:
1058: option_S = d_vrai;
1059:
1060: while(*(++argv[0]) == ' ');
1061: argv[0]--;
1062:
1063: if ((*(++argv[0])) != '\0')
1064: {
1065: if (((*s_etat_processus).definitions_chainees =
1066: malloc((strlen(argv[0]) + 1) *
1067: sizeof(unsigned char))) == NULL)
1068: {
1069: if ((*s_etat_processus).langue == 'F')
1070: {
1071: printf("+++Système : Mémoire "
1072: "insuffisante\n");
1073: }
1074: else
1075: {
1076: printf("+++System : Not enough "
1077: "memory\n");
1078: }
1079:
1080: return(EXIT_FAILURE);
1081: }
1082:
1083: ptr = (*s_etat_processus).definitions_chainees;
1084:
1085: while(*(argv[0]) != '\0')
1086: {
1087: *(ptr++) = *(argv[0]++);
1088: }
1089:
1090: (*ptr) = '\0';
1091:
1092: argv[0]--;
1093: presence_definition = 'O';
1094: }
1095: else if ((--argc) > 0)
1096: {
1097: argv++;
1098:
1099: if (((*s_etat_processus).definitions_chainees =
1100: malloc((strlen(argv[0]) + 1) *
1101: sizeof(unsigned char))) == NULL)
1102: {
1103: if ((*s_etat_processus).langue == 'F')
1104: {
1105: printf("+++Système : Mémoire "
1106: "insuffisante\n");
1107: }
1108: else
1109: {
1110: printf("+++System : Not enough "
1111: "memory\n");
1112: }
1113:
1114: return(EXIT_FAILURE);
1115: }
1116:
1117: ptr = (*s_etat_processus).definitions_chainees;
1118:
1119: while(*(argv[0]) != '\0')
1120: {
1121: *(ptr++) = *(argv[0]++);
1122: }
1123:
1124: (*ptr) = '\0';
1125:
1126: argv[0]--;
1127: presence_definition = 'O';
1128: }
1129: else
1130: {
1131: if ((*s_etat_processus).langue == 'F')
1132: {
1133: printf("+++Erreur : Aucun script "
1134: "spécifié après l'option -S\n");
1135: }
1136: else
1137: {
1138: printf("+++Error : Script required after "
1139: "-S option\n");
1140: }
1141:
1142: return(EXIT_FAILURE);
1143: }
1144:
1145: if (((*s_etat_processus).definitions_chainees =
1146: compactage((*s_etat_processus)
1147: .definitions_chainees)) == NULL)
1148: {
1149: if ((*s_etat_processus).langue == 'F')
1150: {
1151: printf("+++Système : Mémoire "
1152: "insuffisante\n");
1153: }
1154: else
1155: {
1156: printf("+++System : Not enough "
1157: "memory\n");
1158: }
1159:
1160: return(EXIT_FAILURE);
1161: }
1162:
1163: (*s_etat_processus).longueur_definitions_chainees =
1164: strlen((*s_etat_processus)
1165: .definitions_chainees);
1166:
1167: break;
1168: }
1169:
1170: case 't' :
1171: {
1172: if (option_t == d_vrai)
1173: {
1174: if ((*s_etat_processus).langue == 'F')
1175: {
1176: printf("+++Erreur : option -t présente "
1177: "plus d'une fois\n");
1178: }
1179: else
1180: {
1181: printf("+++Error : more than one -t "
1182: "on command line");
1183: }
1184:
1185: return(EXIT_FAILURE);
1186: }
1187:
1188: option_t = d_vrai;
1189: (*s_etat_processus).debug = d_vrai;
1190:
1191: while(*(++argv[0]) == ' ');
1192: argv[0]--;
1193:
1194: if ((*(++argv[0])) != '\0')
1195: {
1196: if ((type_debug = malloc((strlen(argv[0]) + 1) *
1197: sizeof(unsigned char))) == NULL)
1198: {
1199: if ((*s_etat_processus).langue == 'F')
1200: {
1201: printf("+++Système : Mémoire "
1202: "insuffisante\n");
1203: }
1204: else
1205: {
1206: printf("+++System : Not enough "
1207: "memory\n");
1208: }
1209:
1210: return(EXIT_FAILURE);
1211: }
1212:
1213: ptr = type_debug;
1214:
1215: while((*(argv[0]) != '\0') &&
1216: (*(argv[0]) != ' '))
1217: {
1218: *(ptr++) = *(argv[0]++);
1219: }
1220:
1221: (*ptr) = '\0';
1222:
1223: argv[0]--;
1224: }
1225: else if ((--argc) > 0)
1226: {
1227: argv++;
1228:
1229: if ((type_debug =
1230: malloc((strlen(argv[0]) + 1) *
1231: sizeof(unsigned char))) == NULL)
1232: {
1233: if ((*s_etat_processus).langue == 'F')
1234: {
1235: printf("+++Système : Mémoire "
1236: "insuffisante\n");
1237: }
1238: else
1239: {
1240: printf("+++System : Not enough "
1241: "memory\n");
1242: }
1243:
1244: return(EXIT_FAILURE);
1245: }
1246:
1247: ptr = type_debug;
1248:
1249: while(*(argv[0]) != '\0')
1250: {
1251: *(ptr++) = *(argv[0]++);
1252: }
1253:
1254: (*ptr) = '\0';
1255:
1256: argv[0]--;
1257: }
1258: else
1259: {
1260: if ((*s_etat_processus).langue == 'F')
1261: {
1262: printf("+++Erreur : Aucun niveau "
1263: "de débogage spécifié après "
1264: "l'option -t\n");
1265: }
1266: else
1267: {
1268: printf("+++Error : Debug level not "
1269: "specified after -t option\n");
1270: }
1271:
1272: return(EXIT_FAILURE);
1273: }
1274:
1275: ptr = type_debug;
1276:
1277: while(*ptr != '\0')
1278: {
1279: switch(*ptr)
1280: {
1281: case '0':
1282: case '1':
1283: case '2':
1284: case '3':
1285: case '4':
1286: case '5':
1287: case '6':
1288: case '7':
1289: case '8':
1290: case '9':
1291: case 'A':
1292: case 'B':
1293: case 'C':
1294: case 'D':
1295: case 'E':
1296: case 'F':
1297: {
1298: break;
1299: }
1300:
1301: default:
1302: {
1303: if ((*s_etat_processus).langue == 'F')
1304: {
1305: printf("+++Erreur : Niveau "
1306: "de débogage non "
1307: "hexadécimal\n");
1308: }
1309: else
1310: {
1311: printf("+++Error : Debug level must"
1312: " be hexadecimal "
1313: "integer\n");
1314: }
1315:
1316: return(EXIT_FAILURE);
1317: }
1318: }
1319:
1320: ptr++;
1321: }
1322:
1323: if (sscanf(type_debug, "%llX",
1324: &((*s_etat_processus).type_debug)) != 1)
1325: {
1326: if ((*s_etat_processus).langue == 'F')
1327: {
1328: printf("+++Erreur : Niveau "
1329: "de débogage non entier\n");
1330: }
1331: else
1332: {
1333: printf("+++Error : Debug level must"
1334: " be integer\n");
1335: }
1336:
1337: return(EXIT_FAILURE);
1338: }
1339:
1.17 bertrand 1340: free(type_debug);
1.1 bertrand 1341: break;
1342: }
1343:
1344: case 'v' :
1345: {
1346: if (option_v == d_vrai)
1347: {
1348: if ((*s_etat_processus).langue == 'F')
1349: {
1350: printf("+++Erreur : option -v présente "
1351: "plus d'une fois\n");
1352: }
1353: else
1354: {
1355: printf("+++Error : more than one -v "
1356: "on command line");
1357: }
1358:
1359: return(EXIT_FAILURE);
1360: }
1361:
1362: option_v = d_vrai;
1363: printf("\n");
1364:
1365: if ((*s_etat_processus).langue == 'F')
1366: {
1367: printf(" Reverse Polish Lisp/2 version %s "
1368: "pour systèmes "
1369: "POSIX\n", d_version_rpl);
1370: printf(" Langage procédural de très haut "
1371: "niveau, semi-compilé, "
1372: "extensible,\n");
1373: printf(" destiné principalement aux "
1374: "calculs scientifiques et "
1375: "symboliques\n");
1376: printf("%s\n", copyright);
1377: }
1378: else
1379: {
1380: printf(" Reverse Polish Lisp/2 version %s "
1381: "for POSIX operating systems\n",
1382: d_version_rpl);
1383: printf(" Half-compiled, high-level "
1384: "procedural language,\n");
1385: printf(" mainly aiming at scientific "
1386: "calculations\n");
1387: printf("%s\n", copyright_anglais);
1388: }
1389:
1390: printf("\n");
1391: break;
1392: }
1393:
1.86 bertrand 1394: case '-':
1395: case ' ':
1396: {
1397: break;
1398: }
1399:
1.1 bertrand 1400: default :
1401: {
1402: if ((*s_etat_processus).langue == 'F')
1403: {
1.3 bertrand 1404: printf("+++Information : Option -%c inconnue\n",
1.1 bertrand 1405: option);
1406: }
1407: else
1408: {
1.3 bertrand 1409: printf("+++Warning : -%c option unknown\n",
1.1 bertrand 1410: option);
1411: }
1412:
1413: informations(s_etat_processus);
1414: break;
1415: }
1416: }
1417: }
1418: }
1419: else
1420: {
1421: if (presence_definition == 'O')
1422: {
1423: argc = 0;
1424:
1425: if ((*s_etat_processus).langue == 'F')
1426: {
1427: printf("+++Erreur : Plusieurs définitions\n");
1428: }
1429: else
1430: {
1431: printf("+++Error : More than one definition\n");
1432: }
1433:
1.13 bertrand 1434: erreur = d_erreur;
1.1 bertrand 1435: }
1436: else
1437: {
1438: (*s_etat_processus).nom_fichier_source = argv[0];
1439: presence_definition = 'O';
1440: }
1441: }
1442: }
1443:
1444: if (debug == d_faux)
1445: {
1.82 bertrand 1446: action.sa_handler = interruption3;
1.83 bertrand 1447: action.sa_flags = SA_NODEFER | SA_ONSTACK;
1.82 bertrand 1448:
1.1 bertrand 1449: if (sigaction(SIGSEGV, &action, NULL) != 0)
1450: {
1451: if ((*s_etat_processus).langue == 'F')
1452: {
1453: printf("+++Système : Initialisation des signaux POSIX "
1454: "impossible\n");
1455: }
1456: else
1457: {
1458: printf("+++System : Initialization of POSIX signals "
1459: "failed\n");
1460: }
1461:
1462: return(EXIT_FAILURE);
1463: }
1464:
1465: if (sigaction(SIGBUS, &action, NULL) != 0)
1466: {
1467: if ((*s_etat_processus).langue == 'F')
1468: {
1469: printf("+++Système : Initialisation des signaux POSIX "
1470: "impossible\n");
1471: }
1472: else
1473: {
1474: printf("+++System : Initialization of POSIX signals "
1475: "failed\n");
1476: }
1477:
1478: return(EXIT_FAILURE);
1479: }
1480: }
1481:
1482: if (option_n == d_vrai)
1483: {
1.83 bertrand 1484: action.sa_handler = interruption4;
1485: action.sa_flags = SA_ONSTACK;
1.1 bertrand 1486:
1487: if (sigaction(SIGHUP, &action, NULL) != 0)
1488: {
1489: if ((*s_etat_processus).langue == 'F')
1490: {
1491: printf("+++Système : Initialisation des signaux POSIX "
1492: "impossible\n");
1493: }
1494: else
1495: {
1496: printf("+++System : Initialization of POSIX signals "
1497: "failed\n");
1498: }
1499:
1500: return(EXIT_FAILURE);
1501: }
1502: }
1503:
1504: if (mode_interactif == d_vrai)
1505: {
1506: printf("\n");
1507:
1508: if ((*s_etat_processus).langue == 'F')
1509: {
1510: printf("+++Ce logiciel est un logiciel libre"
1511: " sans aucune garantie de "
1512: "fonctionnement.\n");
1513: printf("+++Pour plus de détails, utilisez la "
1514: "commande 'warranty'.\n");
1515: }
1516: else
1517: {
1518: printf("+++This is a free software with "
1519: "absolutely no warranty.\n");
1520: printf("+++For details, type 'warranty'.\n");
1521: }
1522:
1523: printf("\n");
1524:
1525: traitement_fichier_temporaire = 'Y';
1526:
1527: if ((nom_fichier_temporaire =
1528: creation_nom_fichier(s_etat_processus, (*s_etat_processus)
1529: .chemin_fichiers_temporaires)) == NULL)
1530: {
1531: if ((*s_etat_processus).langue == 'F')
1532: {
1533: printf("+++Système : Fichier indisponible\n");
1534: }
1535: else
1536: {
1537: printf("+++System : File unavailable\n");
1538: }
1539:
1540: return(EXIT_FAILURE);
1541: }
1542:
1543: if ((f_source = fopen(nom_fichier_temporaire, "w"))
1544: == NULL)
1545: {
1546: if ((*s_etat_processus).langue == 'F')
1547: {
1548: printf("+++Système : Fichier introuvable\n");
1549: }
1550: else
1551: {
1552: printf("+++System : File not found\n");
1553: }
1554:
1555: return(EXIT_FAILURE);
1556: }
1557:
1558: if (fprintf(f_source, "MODE_INTERACTIF\n") < 0)
1559: {
1560: if ((*s_etat_processus).langue == 'F')
1561: {
1562: printf("+++Système : Erreur d'écriture dans un fichier\n");
1563: }
1564: else
1565: {
1566: printf("+++System : Cannot write in file\n");
1567: }
1568:
1569: return(EXIT_FAILURE);
1570: }
1571:
1572: if (fprintf(f_source,
1573: "<< DO HALT UNTIL FALSE END >>\n") < 0)
1574: {
1575: if ((*s_etat_processus).langue == 'F')
1576: {
1577: printf("+++Système : Erreur d'écriture dans un fichier\n");
1578: }
1579: else
1580: {
1581: printf("+++System : Cannot write in file\n");
1582: }
1583:
1584: return(EXIT_FAILURE);
1585: }
1586:
1587: if (fclose(f_source) != 0)
1588: {
1589: if ((*s_etat_processus).langue == 'F')
1590: {
1591: printf("+++Système : Fichier indisponible\n");
1592: }
1593: else
1594: {
1595: printf("+++System : File unavailable\n");
1596: }
1597:
1598: return(EXIT_FAILURE);
1599: }
1600:
1601: (*s_etat_processus).lancement_interactif = d_vrai;
1602: (*s_etat_processus).nom_fichier_source =
1603: nom_fichier_temporaire;
1604:
1605: presence_definition = 'O';
1606: }
1607: else
1608: {
1609: nom_fichier_temporaire = NULL;
1610: }
1611:
1612: if ((*s_etat_processus).nom_fichier_source == NULL)
1613: {
1614: erreur_fichier = d_erreur;
1615: }
1616: else
1617: {
1618: erreur_fichier = caracteristiques_fichier(s_etat_processus,
1619: (*s_etat_processus).nom_fichier_source,
1620: &existence, &ouverture, &unite_fichier);
1621: }
1622:
1623: if (((existence == d_faux) || (erreur_fichier != d_absence_erreur)) &&
1624: (option_S == d_faux))
1625: {
1626: if (presence_definition == 'O')
1627: {
1628: if ((*s_etat_processus).langue == 'F')
1629: {
1630: printf("+++Erreur : Fichier %s inexistant\n",
1631: (*s_etat_processus).nom_fichier_source);
1632: }
1633: else
1634: {
1635: printf("+++Error : File %s not found\n",
1636: (*s_etat_processus).nom_fichier_source);
1637: }
1638:
1.13 bertrand 1639: erreur = d_erreur;
1.1 bertrand 1640: }
1641: else
1642: {
1643: if ((*s_etat_processus).langue == 'F')
1644: {
1645: printf("+++Erreur : Absence de définition à exécuter\n");
1646: }
1647: else
1648: {
1649: printf("+++Error : Any executable definition\n");
1650: }
1651: }
1.3 bertrand 1652:
1653: return(EXIT_FAILURE);
1.1 bertrand 1654: }
1655:
1656: if ((*s_etat_processus).chemin_fichiers_temporaires == NULL)
1657: {
1658: if ((*s_etat_processus).langue == 'F')
1659: {
1660: printf("+++Système : Chemin des fichiers temporaires nul\n");
1661: }
1662: else
1663: {
1664: printf("+++System : Null temporary files path\n");
1665: }
1666:
1667: return(EXIT_FAILURE);
1668: }
1669:
1670: if ((*s_etat_processus).debug == d_vrai)
1671: {
1672: if ((*s_etat_processus).langue == 'F')
1673: {
1674: printf("[%d] Chemin des fichiers temporaires %s\n\n",
1675: (int) getpid(),
1676: (*s_etat_processus).chemin_fichiers_temporaires);
1677: }
1678: else
1679: {
1680: printf("[%d] Temporary files path %s\n\n",
1681: (int) getpid(),
1682: (*s_etat_processus).chemin_fichiers_temporaires);
1683: }
1684: }
1685:
1.13 bertrand 1686: if ((erreur == d_absence_erreur) && (presence_definition == 'O'))
1.1 bertrand 1687: {
1688: (*s_etat_processus).profilage = (option_P != 0) ? d_vrai : d_faux;
1689: (*s_etat_processus).niveau_profilage = option_P;
1690: (*s_etat_processus).pile_profilage = NULL;
1691: (*s_etat_processus).pile_profilage_fonctions = NULL;
1692: gettimeofday(&((*s_etat_processus).horodatage_profilage), NULL);
1693:
1694: (*s_etat_processus).liste_mutexes = NULL;
1695:
1696: (*s_etat_processus).test_instruction = 'N';
1697: (*s_etat_processus).nombre_arguments = 0;
1698: (*s_etat_processus).affichage_arguments = 'N';
1.6 bertrand 1699: (*s_etat_processus).autorisation_conversion_chaine = 'Y';
1.1 bertrand 1700: (*s_etat_processus).autorisation_evaluation_nom = 'Y';
1.62 bertrand 1701:
1702: if (mode_interactif == d_vrai)
1703: {
1704: (*s_etat_processus).autorisation_nom_implicite = 'Y';
1705: }
1706: else
1707: {
1708: (*s_etat_processus).autorisation_nom_implicite = 'N';
1709: }
1710:
1.1 bertrand 1711: (*s_etat_processus).autorisation_empilement_programme = 'N';
1712: (*s_etat_processus).requete_arret = 'N';
1.4 bertrand 1713: (*s_etat_processus).evaluation_forcee = 'N';
1.51 bertrand 1714: (*s_etat_processus).recherche_type = 'N';
1.1 bertrand 1715:
1716: (*s_etat_processus).constante_symbolique = 'N';
1717: (*s_etat_processus).traitement_symbolique = 'N';
1718:
1719: (*s_etat_processus).expression_courante = NULL;
1720: (*s_etat_processus).objet_courant = NULL;
1721: (*s_etat_processus).evaluation_expression_compilee = 'N';
1722:
1723: (*s_etat_processus).l_base_pile = NULL;
1724: (*s_etat_processus).l_base_pile_last = NULL;
1725:
1.64 bertrand 1726: (*s_etat_processus).s_arbre_variables = NULL;
1.65 bertrand 1727: (*s_etat_processus).l_liste_variables_par_niveau = NULL;
1.1 bertrand 1728: (*s_etat_processus).gel_liste_variables = d_faux;
1.64 bertrand 1729: (*s_etat_processus).pointeur_variable_courante = NULL;
1.1 bertrand 1730: (*s_etat_processus).s_liste_variables_statiques = NULL;
1731: (*s_etat_processus).nombre_variables_statiques = 0;
1732: (*s_etat_processus).nombre_variables_statiques_allouees = 0;
1733: (*s_etat_processus).niveau_courant = 0;
1734: (*s_etat_processus).niveau_initial = 0;
1735: (*s_etat_processus).creation_variables_statiques = d_faux;
1736: (*s_etat_processus).creation_variables_partagees = d_faux;
1737: (*s_etat_processus).position_variable_statique_courante = 0;
1738:
1739: (*s_etat_processus).s_bibliotheques = NULL;
1740: (*s_etat_processus).s_instructions_externes = NULL;
1741: (*s_etat_processus).nombre_instructions_externes = 0;
1742:
1743: (*s_etat_processus).systeme_axes = 0;
1744:
1745: (*s_etat_processus).x_min = -10.;
1746: (*s_etat_processus).x_max = 10.;
1747: (*s_etat_processus).y_min = -10.;
1748: (*s_etat_processus).y_max = 10.;
1749: (*s_etat_processus).z_min = -10.;
1750: (*s_etat_processus).z_max = 10.;
1751:
1752: (*s_etat_processus).x2_min = -10.;
1753: (*s_etat_processus).x2_max = 10.;
1754: (*s_etat_processus).y2_min = -10.;
1755: (*s_etat_processus).y2_max = 10.;
1756: (*s_etat_processus).z2_min = -10.;
1757: (*s_etat_processus).z2_max = 10.;
1758:
1759: (*s_etat_processus).resolution = .01;
1760:
1761: (*s_etat_processus).souris_active = d_faux;
1762:
1763: (*s_etat_processus).echelle_automatique_x = d_faux;
1764: (*s_etat_processus).echelle_automatique_y = d_faux;
1765: (*s_etat_processus).echelle_automatique_z = d_faux;
1766:
1767: (*s_etat_processus).echelle_automatique_x2 = d_faux;
1768: (*s_etat_processus).echelle_automatique_y2 = d_faux;
1769: (*s_etat_processus).echelle_automatique_z2 = d_faux;
1770:
1771: (*s_etat_processus).echelle_log_x = d_faux;
1772: (*s_etat_processus).echelle_log_y = d_faux;
1773: (*s_etat_processus).echelle_log_z = d_faux;
1774:
1775: (*s_etat_processus).echelle_log_x2 = d_faux;
1776: (*s_etat_processus).echelle_log_y2 = d_faux;
1777: (*s_etat_processus).echelle_log_z2 = d_faux;
1778:
1779: (*s_etat_processus).point_de_vue_theta = 4 * atan((real8) 1) / 6;
1780: (*s_etat_processus).point_de_vue_phi = 4 * atan((real8) 1) / 3;
1781: (*s_etat_processus).echelle_3D = 1;
1782:
1783: strcpy((*s_etat_processus).type_trace_eq, "FONCTION");
1784: strcpy((*s_etat_processus).type_trace_sigma, "POINTS");
1785: (*s_etat_processus).fichiers_graphiques = NULL;
1786: (*s_etat_processus).nom_fichier_impression = NULL;
1787: strcpy((*s_etat_processus).format_papier, "a4paper");
1788: (*s_etat_processus).entree_standard = NULL;
1789: (*s_etat_processus).s_marques = NULL;
1790: (*s_etat_processus).requete_nouveau_plan = d_vrai;
1791: (*s_etat_processus).mise_a_jour_trace_requise = d_faux;
1792:
1793: (*s_etat_processus).l_base_pile = NULL;
1794: (*s_etat_processus).hauteur_pile_operationnelle = 0;
1795: (*s_etat_processus).l_base_pile_contextes = NULL;
1796: (*s_etat_processus).l_base_pile_taille_contextes = NULL;
1797:
1798: (*s_etat_processus).position_courante = 0;
1799:
1800: (*s_etat_processus).l_base_pile_systeme = NULL;
1801: (*s_etat_processus).hauteur_pile_systeme = 0;
1802:
1803: (*s_etat_processus).l_base_pile_processus = NULL;
1804: (*s_etat_processus).presence_pipes = d_faux;
1805: (*s_etat_processus).pipe_donnees = 0;
1806: (*s_etat_processus).pipe_acquittement = 0;
1807: (*s_etat_processus).pipe_injections = 0;
1808: (*s_etat_processus).pipe_nombre_injections = 0;
1809: (*s_etat_processus).nombre_objets_injectes = 0;
1810: (*s_etat_processus).nombre_objets_envoyes_non_lus = 0;
1811: (*s_etat_processus).pourcentage_maximal_cpu = 100;
1812: (*s_etat_processus).temps_maximal_cpu = 0;
1813: (*s_etat_processus).thread_fusible = 0;
1814: (*s_etat_processus).presence_fusible = d_faux;
1815:
1816: (*s_etat_processus).niveau_recursivite = 0;
1817: (*s_etat_processus).generateur_aleatoire = NULL;
1818: (*s_etat_processus).type_generateur_aleatoire = NULL;
1819:
1820: (*s_etat_processus).colonne_statistique_1 = 1;
1821: (*s_etat_processus).colonne_statistique_2 = 2;
1822:
1823: (*s_etat_processus).debug_programme = d_faux;
1824: (*s_etat_processus).execution_pas_suivant = d_faux;
1825: (*s_etat_processus).traitement_instruction_halt = d_faux;
1826:
1827: (*s_etat_processus).derniere_exception = d_ep;
1828: (*s_etat_processus).derniere_erreur_systeme = d_es;
1829: (*s_etat_processus).derniere_erreur_execution = d_ex;
1830: (*s_etat_processus).derniere_erreur_evaluation = d_ex;
1831: (*s_etat_processus).derniere_erreur_fonction_externe = 0;
1832:
1833: (*s_etat_processus).erreur_processus_fils = d_faux;
1834: (*s_etat_processus).erreur_systeme_processus_fils = d_es;
1835: (*s_etat_processus).erreur_execution_processus_fils = d_ex;
1836: (*s_etat_processus).pid_erreur_processus_fils = 0;
1837: (*s_etat_processus).exception_processus_fils = d_ep;
1838: (*s_etat_processus).core = core;
1839: (*s_etat_processus).invalidation_message_erreur = d_faux;
1840: (*s_etat_processus).s_objet_errone = NULL;
1841: (*s_etat_processus).s_objet_erreur = NULL;
1842:
1843: (*s_etat_processus).retour_routine_evaluation = 'N';
1844:
1845: (*s_etat_processus).traitement_interruption = 'N';
1846: (*s_etat_processus).traitement_interruptible = 'Y';
1847: (*s_etat_processus).nombre_interruptions_en_queue = 0;
1848: (*s_etat_processus).nombre_interruptions_non_affectees = 0;
1849:
1850: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
1851: {
1852: (*s_etat_processus).masque_interruptions[i] = 'N';
1853: (*s_etat_processus).queue_interruptions[i] = 0;
1854: (*s_etat_processus).corps_interruptions[i] = NULL;
1855: (*s_etat_processus).pile_origine_interruptions[i] = NULL;
1856: }
1857:
1.20 bertrand 1858: (*s_etat_processus).at_exit = NULL;
1.34 bertrand 1859: (*s_etat_processus).at_poke = NULL;
1860: (*s_etat_processus).traitement_at_poke = 'N';
1.19 bertrand 1861:
1.1 bertrand 1862: (*s_etat_processus).pointeurs_caracteres = NULL;
1863: (*s_etat_processus).arbre_instructions = NULL;
1864:
1865: (*s_etat_processus).tid_processus_pere = pthread_self();
1866: (*s_etat_processus).pid_processus_pere = getpid();
1867: (*s_etat_processus).processus_detache = d_vrai;
1868: (*s_etat_processus).var_volatile_processus_pere = -1;
1.45 bertrand 1869: (*s_etat_processus).var_volatile_processus_racine = -1;
1.1 bertrand 1870: (*s_etat_processus).var_volatile_traitement_retarde_stop = 0;
1871: (*s_etat_processus).var_volatile_alarme = 0;
1872: (*s_etat_processus).var_volatile_requete_arret = 0;
1873: (*s_etat_processus).var_volatile_requete_arret2 = 0;
1874: (*s_etat_processus).var_volatile_traitement_retarde_stop = 0;
1875: (*s_etat_processus).var_volatile_traitement_sigint = 0;
1876: (*s_etat_processus).var_volatile_recursivite = 0;
1877: (*s_etat_processus).var_volatile_exception_gsl = 0;
1.22 bertrand 1878: (*s_etat_processus).arret_depuis_abort = 0;
1.83 bertrand 1879: (*s_etat_processus).pointeur_signal_lecture = 0;
1880: (*s_etat_processus).pointeur_signal_ecriture = 0;
1.1 bertrand 1881:
1882: initialisation_allocateur(s_etat_processus);
1883: initialisation_drapeaux(s_etat_processus);
1.65 bertrand 1884: initialisation_variables(s_etat_processus);
1885: initialisation_instructions(s_etat_processus);
1.1 bertrand 1886:
1887: if ((*s_etat_processus).erreur_systeme != d_es)
1888: {
1889: if ((*s_etat_processus).langue == 'F')
1890: {
1891: printf("+++Système : Mémoire insuffisante\n");
1892: }
1893: else
1894: {
1895: printf("+++System : Not enough memory\n");
1896: }
1897:
1898: return(EXIT_FAILURE);
1899: }
1900:
1901: if (((*s_etat_processus).instruction_derniere_erreur =
1.32 bertrand 1902: malloc(sizeof(unsigned char))) == NULL)
1.1 bertrand 1903: {
1904: erreur = d_es_allocation_memoire;
1905:
1906: if ((*s_etat_processus).langue == 'F')
1907: {
1908: printf("+++Système : Mémoire insuffisante\n");
1909: }
1910: else
1911: {
1912: printf("+++System : Not enough memory\n");
1913: }
1914:
1915: return(EXIT_FAILURE);
1916: }
1917:
1918: strcpy((*s_etat_processus).instruction_derniere_erreur, "");
1919: (*s_etat_processus).niveau_derniere_erreur = 0;
1920:
1921: if (traitement_fichier_temporaire == 'Y')
1922: {
1923: (*s_etat_processus).mode_interactif = 'Y';
1924: }
1925: else
1926: {
1927: (*s_etat_processus).mode_interactif = 'N';
1928: }
1929:
1930: if (((*s_etat_processus).instruction_courante = (unsigned char *)
1931: malloc(sizeof(unsigned char))) == NULL)
1932: {
1933: erreur = d_es_allocation_memoire;
1934:
1935: if ((*s_etat_processus).langue == 'F')
1936: {
1937: printf("+++Système : Mémoire insuffisante\n");
1938: }
1939: else
1940: {
1941: printf("+++System : Not enough memory\n");
1942: }
1943:
1944: return(EXIT_FAILURE);
1945: }
1946:
1947: (*s_etat_processus).instruction_courante[0] = d_code_fin_chaine;
1948:
1949: empilement_pile_systeme(s_etat_processus);
1950:
1951: free((*s_etat_processus).instruction_courante);
1952:
1.41 bertrand 1953: if ((*s_etat_processus).erreur_systeme != d_es)
1.1 bertrand 1954: {
1955: erreur = d_es_allocation_memoire;
1956: }
1957: else
1958: {
1959: (*((*s_etat_processus).l_base_pile_systeme))
1960: .retour_definition = 'Y';
1961:
1962: (*s_etat_processus).indep = (struct_objet *) malloc(
1963: sizeof(struct_objet));
1964: (*s_etat_processus).depend = (struct_objet *) malloc(
1965: sizeof(struct_objet));
1966: (*s_etat_processus).parametres_courbes_de_niveau =
1967: (struct_objet *) malloc(sizeof(struct_objet));
1968:
1969: if (((*s_etat_processus).indep != NULL) &&
1970: ((*s_etat_processus).depend != NULL) &&
1971: ((*s_etat_processus).parametres_courbes_de_niveau
1972: != NULL))
1973: {
1974: (*((*s_etat_processus).indep)).type = NOM;
1975: (*((*s_etat_processus).depend)).type = NOM;
1976: (*((*s_etat_processus).
1977: parametres_courbes_de_niveau)).type = LST;
1978:
1979: initialisation_objet((*s_etat_processus).indep);
1980: initialisation_objet((*s_etat_processus).depend);
1981: initialisation_objet((*s_etat_processus)
1982: .parametres_courbes_de_niveau);
1983:
1984: (*((*s_etat_processus).indep)).objet = (struct_nom *)
1985: malloc(sizeof(struct_nom));
1986: (*((*s_etat_processus).depend)).objet = (struct_nom *)
1987: malloc(sizeof(struct_nom));
1988: (*((*s_etat_processus).parametres_courbes_de_niveau))
1989: .objet = (struct_liste_chainee *)
1990: malloc(sizeof(struct_liste_chainee));
1991:
1992: if (((*((*s_etat_processus).depend)).objet == NULL) ||
1993: ((*((*s_etat_processus).depend)).objet == NULL) ||
1994: ((*((*s_etat_processus).
1995: parametres_courbes_de_niveau)).objet == NULL))
1996: {
1997: erreur = d_es_allocation_memoire;
1998:
1999: if ((*s_etat_processus).langue == 'F')
2000: {
2001: printf("+++Système : Mémoire insuffisante\n");
2002: }
2003: else
2004: {
2005: printf("+++System : Not enough memory\n");
2006: }
2007:
2008: return(EXIT_FAILURE);
2009: }
2010:
2011: (*((struct_nom *) (*((*s_etat_processus).indep)).objet))
2012: .nom = malloc(2 * sizeof(unsigned char));
2013: (*((struct_nom *) (*((*s_etat_processus).depend)).objet))
2014: .nom = malloc(2 * sizeof(unsigned char));
2015:
2016: if (((*((struct_nom *) (*((*s_etat_processus).indep))
2017: .objet)).nom == NULL) || ((*((struct_nom *)
2018: (*((*s_etat_processus).depend)).objet)).nom ==
2019: NULL))
2020: {
2021: erreur = d_es_allocation_memoire;
2022:
2023: if ((*s_etat_processus).langue == 'F')
2024: {
2025: printf("+++Système : Mémoire insuffisante\n");
2026: }
2027: else
2028: {
2029: printf("+++System : Not enough memory\n");
2030: }
2031:
2032: return(EXIT_FAILURE);
2033: }
2034:
2035: strcpy((*((struct_nom *) (*((*s_etat_processus).indep))
2036: .objet)).nom, "X");
2037: strcpy((*((struct_nom *) (*((*s_etat_processus).depend))
2038: .objet)).nom, "Y");
2039:
2040: (*((struct_nom *) (*((*s_etat_processus).indep))
2041: .objet)).symbole = d_vrai;
2042: (*((struct_nom *) (*((*s_etat_processus).depend))
2043: .objet)).symbole = d_vrai;
2044:
2045: (*((struct_liste_chainee *) (*((*s_etat_processus)
2046: .parametres_courbes_de_niveau)).objet)).suivant
2047: = NULL;
2048:
2049: (*((struct_liste_chainee *) (*((*s_etat_processus)
2050: .parametres_courbes_de_niveau)).objet)).donnee
2051: = malloc(sizeof(struct_objet));
2052:
2053: (*s_etat_processus).legende =
2054: malloc(sizeof(unsigned char));
2055: (*s_etat_processus).label_x =
2056: malloc(sizeof(unsigned char));
2057: (*s_etat_processus).label_y =
2058: malloc(sizeof(unsigned char));
2059: (*s_etat_processus).label_z =
2060: malloc(sizeof(unsigned char));
2061: (*s_etat_processus).titre =
2062: malloc(sizeof(unsigned char));
2063:
2064: if (((*s_etat_processus).label_x == NULL) ||
2065: ((*s_etat_processus).label_y == NULL) ||
2066: ((*s_etat_processus).label_z == NULL) ||
2067: ((*s_etat_processus).titre == NULL) ||
2068: ((*s_etat_processus).legende == NULL) ||
2069: ((*((struct_liste_chainee *) (*((*s_etat_processus)
2070: .parametres_courbes_de_niveau)).objet)).donnee
2071: == NULL))
2072: {
2073: erreur = d_es_allocation_memoire;
2074:
2075: if ((*s_etat_processus).langue == 'F')
2076: {
2077: printf("+++Système : Mémoire insuffisante\n");
2078: }
2079: else
2080: {
2081: printf("+++System : Not enough memory\n");
2082: }
2083:
2084: return(EXIT_FAILURE);
2085: }
2086:
2087: (*(*((struct_liste_chainee *) (*((*s_etat_processus)
2088: .parametres_courbes_de_niveau)).objet)).donnee)
2089: .type = CHN;
2090:
2091: initialisation_objet((*((struct_liste_chainee *)
2092: (*((*s_etat_processus)
2093: .parametres_courbes_de_niveau))
2094: .objet)).donnee);
2095:
2096: if (((*(*((struct_liste_chainee *) (*((*s_etat_processus)
2097: .parametres_courbes_de_niveau)).objet)).donnee)
2098: .objet = malloc(10 * sizeof(unsigned char)))
2099: == NULL)
2100: {
2101: erreur = d_es_allocation_memoire;
2102:
2103: if ((*s_etat_processus).langue == 'F')
2104: {
2105: printf("+++Système : Mémoire insuffisante\n");
2106: }
2107: else
2108: {
2109: printf("+++System : Not enough memory\n");
2110: }
2111:
2112: return(EXIT_FAILURE);
2113: }
2114:
2115: strcpy((unsigned char *) (*(*((struct_liste_chainee *)
2116: (*((*s_etat_processus)
2117: .parametres_courbes_de_niveau))
2118: .objet)).donnee).objet, "AUTOMATIC");
2119:
2120: (*s_etat_processus).label_x[0] = d_code_fin_chaine;
2121: (*s_etat_processus).label_y[0] = d_code_fin_chaine;
2122: (*s_etat_processus).label_z[0] = d_code_fin_chaine;
2123: (*s_etat_processus).titre[0] = d_code_fin_chaine;
2124: (*s_etat_processus).legende[0] = d_code_fin_chaine;
2125:
2126: (*s_etat_processus).nom_fichier_gnuplot = NULL;
2127: (*s_etat_processus).type_fichier_gnuplot = NULL;
2128:
2129: (*s_etat_processus).x_tics = 0;
2130: (*s_etat_processus).y_tics = 0;
2131: (*s_etat_processus).z_tics = 0;
2132:
2133: (*s_etat_processus).x_lines = d_vrai;
2134: (*s_etat_processus).y_lines = d_vrai;
2135: (*s_etat_processus).z_lines = d_vrai;
2136:
2137: (*s_etat_processus).mx_tics = -1;
2138: (*s_etat_processus).my_tics = -1;
2139: (*s_etat_processus).mz_tics = -1;
2140:
2141: (*s_etat_processus).mx_lines = d_faux;
2142: (*s_etat_processus).my_lines = d_faux;
2143: (*s_etat_processus).mz_lines = d_faux;
2144:
2145: (*s_etat_processus).x2_tics = -1;
2146: (*s_etat_processus).y2_tics = -1;
2147: (*s_etat_processus).z2_tics = -1;
2148:
2149: (*s_etat_processus).x2_lines = d_faux;
2150: (*s_etat_processus).y2_lines = d_faux;
2151: (*s_etat_processus).z2_lines = d_faux;
2152:
2153: (*s_etat_processus).mx2_tics = -1;
2154: (*s_etat_processus).my2_tics = -1;
2155: (*s_etat_processus).mz2_tics = -1;
2156:
2157: (*s_etat_processus).mx2_lines = d_faux;
2158: (*s_etat_processus).my2_lines = d_faux;
2159: (*s_etat_processus).mz2_lines = d_faux;
2160:
2161: if ((*s_etat_processus).erreur_systeme != d_es)
2162: {
2163: if ((*s_etat_processus).langue == 'F')
2164: {
2165: printf("+++Système : Mémoire insuffisante\n");
2166: }
2167: else
2168: {
2169: printf("+++System : Not enough memory\n");
2170: }
2171:
2172: return(EXIT_FAILURE);
2173: }
2174:
2175: (*s_etat_processus).mode_evaluation_expression = 'N';
2176: (*s_etat_processus).mode_execution_programme = 'Y';
2177:
2178: if ((*s_etat_processus).definitions_chainees == NULL)
2179: {
2180: if ((erreur = chainage(s_etat_processus)) !=
2181: d_absence_erreur)
2182: {
2183: if ((*s_etat_processus).langue == 'F')
2184: {
2185: printf("+++Fatal :"
2186: " Chaînage des définitions"
2187: " impossible\n");
2188: }
2189: else
2190: {
2191: printf("+++Fatal : Error in "
2192: "compilation\n");
2193: }
2194:
2195: if (traitement_fichier_temporaire == 'Y')
2196: {
2197: if (destruction_fichier(
2198: nom_fichier_temporaire)
2199: == d_erreur)
2200: {
2201: return(EXIT_FAILURE);
2202: }
2203:
2204: free(nom_fichier_temporaire);
2205: }
2206:
2207: return(EXIT_FAILURE);
2208: }
2209: }
2210:
2211: if ((erreur = compilation(s_etat_processus)) !=
2212: d_absence_erreur)
2213: {
2214: if (traitement_fichier_temporaire == 'Y')
2215: {
2216: if (destruction_fichier(nom_fichier_temporaire)
2217: == d_erreur)
2218: {
2219: return(EXIT_FAILURE);
2220: }
2221:
2222: free(nom_fichier_temporaire);
2223: }
2224:
2225: printf("%s [%d]\n", message =
2226: messages(s_etat_processus), (int) getpid());
2227: free(message);
2228:
2229: if (test_cfsf(s_etat_processus, 51) == d_faux)
2230: {
2231: printf("%s", ds_beep);
2232: }
2233:
2234: if ((*s_etat_processus).core == d_vrai)
2235: {
2236: printf("\n");
2237:
2238: if ((*s_etat_processus).langue == 'F')
2239: {
2240: printf("+++Information : Génération du fichier "
2241: "rpl-core [%d]\n", (int) getpid());
2242: }
2243: else
2244: {
2245: printf("+++Information : Writing rpl-core "
2246: "file [%d]\n", (int) getpid());
2247: }
2248:
2249: rplcore(s_etat_processus);
2250:
2251: if ((*s_etat_processus).langue == 'F')
2252: {
2253: printf("+++Information : Processus tracé "
2254: "[%d]\n", (int) getpid());
2255: }
2256: else
2257: {
2258: printf("+++Information : Done [%d]\n",
2259: (int) getpid());
2260: }
2261:
2262: printf("\n");
2263: }
2264:
2265: return(EXIT_FAILURE);
2266: }
2267:
2268: (*s_etat_processus).position_courante = 0;
2269: (*s_etat_processus).traitement_cycle_exit = 'N';
2270:
1.64 bertrand 2271: if ((*s_etat_processus).s_arbre_variables == NULL)
1.1 bertrand 2272: {
2273: if ((*s_etat_processus).langue == 'F')
2274: {
2275: printf("+++Fatal : Aucun point d'entrée\n");
2276: }
2277: else
2278: {
2279: printf("+++Fatal : Any entry point\n");
2280: }
2281:
2282: if (test_cfsf(s_etat_processus, 51) == d_faux)
2283: {
2284: printf("%s", ds_beep);
2285: }
2286:
2287: return(EXIT_FAILURE);
2288: }
2289:
2290: if (recherche_instruction_suivante(s_etat_processus)
2291: == d_erreur)
2292: {
2293: if ((*s_etat_processus).langue == 'F')
2294: {
2295: printf("+++Fatal : Aucun point d'entrée\n");
2296: }
2297: else
2298: {
2299: printf("+++Fatal : Any entry point\n");
2300: }
2301:
2302: if (test_cfsf(s_etat_processus, 51) == d_faux)
2303: {
2304: printf("%s", ds_beep);
2305: }
2306:
2307: return(EXIT_FAILURE);
2308: }
2309:
2310: if (recherche_variable(s_etat_processus,
2311: (*s_etat_processus)
2312: .instruction_courante) == d_faux)
2313: {
2314: if ((*s_etat_processus).langue == 'F')
2315: {
2316: printf("+++Fatal : Aucun point d'entrée\n");
2317: }
2318: else
2319: {
2320: printf("+++Fatal : Any entry point\n");
2321: }
2322:
2323: if (test_cfsf(s_etat_processus, 51) == d_faux)
2324: {
2325: printf("%s", ds_beep);
2326: }
2327:
2328: return(EXIT_FAILURE);
2329: }
2330:
1.64 bertrand 2331: if ((*(*s_etat_processus).pointeur_variable_courante)
2332: .niveau != 0)
1.1 bertrand 2333: {
2334: if ((*s_etat_processus).langue == 'F')
2335: {
2336: printf("+++Fatal : Aucun point d'entrée\n");
2337: }
2338: else
2339: {
2340: printf("+++Fatal : Any entry point\n");
2341: }
2342:
2343: if (test_cfsf(s_etat_processus, 51) == d_faux)
2344: {
2345: printf("%s", ds_beep);
2346: }
2347:
2348: return(EXIT_FAILURE);
2349: }
2350:
2351: free((*s_etat_processus).instruction_courante);
2352: (*s_etat_processus).position_courante = 0;
2353:
2354: if (((*s_etat_processus).nom_fichier_historique =
2355: malloc((strlen(home) +
2356: strlen(ds_fichier_historique) + 2) *
2357: sizeof(unsigned char))) == NULL)
2358: {
2359: erreur = d_es_allocation_memoire;
2360:
2361: if ((*s_etat_processus).langue == 'F')
2362: {
2363: printf("+++Système : Mémoire insuffisante\n");
2364: }
2365: else
2366: {
2367: printf("+++System : Not enough memory\n");
2368: }
2369:
2370: return(EXIT_FAILURE);
2371: }
2372:
2373: sprintf((*s_etat_processus).nom_fichier_historique, "%s/%s",
2374: home, ds_fichier_historique);
2375:
2376: using_history();
2377: erreur_historique = read_history(
2378: (*s_etat_processus).nom_fichier_historique);
2379:
2380: gsl_set_error_handler(&traitement_exceptions_gsl);
2381:
2382: if (drapeau_encart == 'Y')
2383: {
2384: (*s_etat_processus).erreur_systeme = d_es;
2385: encart(s_etat_processus,
2386: (unsigned long) (5 * 1000000));
2387:
2388: if ((*s_etat_processus).erreur_systeme != d_es)
2389: {
2390: if ((message = messages(s_etat_processus))
2391: == NULL)
2392: {
2393: erreur = d_es_allocation_memoire;
2394:
2395: if ((*s_etat_processus).langue == 'F')
2396: {
2397: printf("+++Système : Mémoire "
2398: "insuffisante\n");
2399: }
2400: else
2401: {
2402: printf("+++System : Not enough "
2403: "memory\n");
2404: }
2405:
2406: return(EXIT_FAILURE);
2407: }
2408:
2409: printf("%s [%d]\n", message, (int) getpid());
2410: free(message);
2411:
2412: return(EXIT_FAILURE);
2413: }
2414: }
2415:
2416: fflush(stdout);
2417:
2418: if (arguments != NULL)
2419: {
2420: tampon = (*s_etat_processus).definitions_chainees;
2421: (*s_etat_processus).definitions_chainees =
2422: arguments;
2423:
2424: if (analyse_syntaxique(s_etat_processus) ==
2425: d_erreur)
2426: {
2427: if ((*s_etat_processus).erreur_systeme != d_es)
2428: {
2429: erreur = d_es_allocation_memoire;
2430:
2431: if ((*s_etat_processus).langue == 'F')
2432: {
2433: printf("+++Système : Mémoire "
2434: "insuffisante\n");
2435: }
2436: else
2437: {
2438: printf("+++System : Not enough "
2439: "memory\n");
2440: }
2441:
2442: return(EXIT_FAILURE);
2443: }
2444: else
2445: {
2446: if ((*s_etat_processus).langue == 'F')
2447: {
2448: printf("+++Erreur : Erreur de "
2449: "syntaxe\n");
2450: }
2451: else
2452: {
2453: printf("+++Error : Syntax error\n");
2454: }
2455:
2456: return(EXIT_FAILURE);
2457: }
2458: }
2459:
2460: (*s_etat_processus).instruction_courante
2461: = arguments;
2462: (*s_etat_processus).definitions_chainees = tampon;
2463: (*s_etat_processus).position_courante = 0;
2464:
2465: recherche_type(s_etat_processus);
2466:
2467: if ((*s_etat_processus).erreur_systeme != d_es)
2468: {
2469: if ((message = messages(s_etat_processus))
2470: == NULL)
2471: {
2472: erreur = d_es_allocation_memoire;
2473:
2474: if ((*s_etat_processus).langue == 'F')
2475: {
2476: printf("+++Système : Mémoire "
2477: "insuffisante\n");
2478: }
2479: else
2480: {
2481: printf("+++System : Not enough "
2482: "memory\n");
2483: }
2484:
2485: return(EXIT_FAILURE);
2486: }
2487:
2488: printf("%s [%d]\n", message, (int) getpid());
2489: free(message);
2490:
2491: return(EXIT_FAILURE);
2492: }
2493:
2494: if ((*s_etat_processus).erreur_execution != d_ex)
2495: {
2496: if ((message = messages(s_etat_processus))
2497: == NULL)
2498: {
2499: erreur = d_es_allocation_memoire;
2500:
2501: if ((*s_etat_processus).langue == 'F')
2502: {
2503: printf("+++Erreur : Mémoire "
2504: "insuffisante\n");
2505: }
2506: else
2507: {
2508: printf("+++Error : Not enough "
2509: "memory\n");
2510: }
2511:
2512: return(EXIT_FAILURE);
2513: }
2514:
2515: printf("%s [%d]\n", message, (int) getpid());
2516: free(message);
2517:
2518: return(EXIT_FAILURE);
2519: }
2520:
2521: if (depilement(s_etat_processus,
2522: &((*s_etat_processus).l_base_pile),
2523: &s_objet) == d_erreur)
2524: {
2525: if ((message = messages(s_etat_processus))
2526: == NULL)
2527: {
2528: erreur = d_es_allocation_memoire;
2529:
2530: if ((*s_etat_processus).langue == 'F')
2531: {
2532: printf("+++Erreur : Mémoire "
2533: "insuffisante\n");
2534: }
2535: else
2536: {
2537: printf("+++Error : Not enough "
2538: "memory\n");
2539: }
2540:
2541: return(EXIT_FAILURE);
2542: }
2543:
2544: printf("%s [%d]\n", message, (int) getpid());
2545: free(message);
2546:
2547: return(EXIT_FAILURE);
2548: }
2549:
2550: if (evaluation(s_etat_processus, s_objet, 'E')
2551: == d_erreur)
2552: {
2553: if ((*s_etat_processus).erreur_systeme != d_es)
2554: {
2555: if ((message = messages(s_etat_processus))
2556: == NULL)
2557: {
2558: erreur = d_es_allocation_memoire;
2559:
2560: if ((*s_etat_processus).langue == 'F')
2561: {
2562: printf("+++Système : Mémoire "
2563: "insuffisante\n");
2564: }
2565: else
2566: {
2567: printf("+++System : Not enough "
2568: "memory\n");
2569: }
2570:
2571: return(EXIT_FAILURE);
2572: }
2573:
2574: printf("%s [%d]\n", message,
2575: (int) getpid());
2576: free(message);
2577:
2578: return(EXIT_FAILURE);
2579: }
2580:
2581: if ((*s_etat_processus).erreur_execution
2582: != d_ex)
2583: {
2584: if ((message = messages(s_etat_processus))
2585: == NULL)
2586: {
2587: erreur = d_es_allocation_memoire;
2588:
2589: if ((*s_etat_processus).langue == 'F')
2590: {
2591: printf("+++Erreur : Mémoire "
2592: "insuffisante\n");
2593: }
2594: else
2595: {
2596: printf("+++Error : Not enough "
2597: "memory\n");
2598: }
2599:
2600: return(EXIT_FAILURE);
2601: }
2602:
2603: printf("%s [%d]\n", message,
2604: (int) getpid());
2605: free(message);
2606:
2607: return(EXIT_FAILURE);
2608: }
2609: }
2610:
2611: (*s_etat_processus).instruction_courante = NULL;
2612: liberation(s_etat_processus, s_objet);
2613:
2614: free(arguments);
2615: }
2616:
1.13 bertrand 2617: if (option_a == d_vrai)
1.1 bertrand 2618: {
1.13 bertrand 2619: fprintf(stdout, "%s\n", (*s_etat_processus)
2620: .definitions_chainees);
1.1 bertrand 2621: }
1.13 bertrand 2622: else
2623: {
2624: if (option_D == d_vrai)
2625: {
2626: lancement_daemon(s_etat_processus);
2627: }
1.1 bertrand 2628:
1.83 bertrand 2629: // A FIXER
2630: // création signaux
1.13 bertrand 2631: if (option_p == d_faux)
1.1 bertrand 2632: {
1.13 bertrand 2633: if (setjmp(contexte_initial) == 0)
2634: {
2635: erreur = sequenceur(s_etat_processus);
1.80 bertrand 2636:
2637: if (erreur == d_absence_erreur)
2638: {
2639: if (((*s_etat_processus).var_volatile_alarme
2640: == 0) && ((*s_etat_processus)
2641: .arret_depuis_abort == 0) &&
2642: ((*s_etat_processus).at_exit
2643: != NULL))
2644: {
2645: erreur = evaluation(s_etat_processus,
2646: (*s_etat_processus).at_exit,
2647: 'E');
2648: }
2649: }
1.13 bertrand 2650: }
1.1 bertrand 2651: }
1.13 bertrand 2652: else
1.1 bertrand 2653: {
1.13 bertrand 2654: if (setjmp(contexte_initial) == 0)
2655: {
2656: erreur = sequenceur_optimise(s_etat_processus);
1.19 bertrand 2657:
1.80 bertrand 2658: if (erreur == d_absence_erreur)
2659: {
2660: if (((*s_etat_processus).var_volatile_alarme
2661: == 0) && ((*s_etat_processus)
2662: .arret_depuis_abort == 0) &&
2663: ((*s_etat_processus).at_exit
2664: != NULL))
2665: {
2666: erreur = evaluation(s_etat_processus,
2667: (*s_etat_processus).at_exit,
2668: 'E');
2669: }
2670: }
1.21 bertrand 2671: }
1.19 bertrand 2672: }
1.83 bertrand 2673: // A FIXER
2674: // destruction signaux
1.34 bertrand 2675: }
1.19 bertrand 2676:
1.34 bertrand 2677: liberation(s_etat_processus, (*s_etat_processus).at_exit);
2678: liberation(s_etat_processus, (*s_etat_processus).at_poke);
1.1 bertrand 2679:
2680: if ((*s_etat_processus).generateur_aleatoire != NULL)
2681: {
2682: liberation_generateur_aleatoire(s_etat_processus);
2683: }
2684:
2685: l_element_courant = (*s_etat_processus).liste_mutexes;
2686: while(l_element_courant != NULL)
2687: {
2688: pthread_mutex_trylock(&((*((struct_mutex *)
2689: (*(*((struct_liste_chainee *)
2690: l_element_courant)).donnee).objet)).mutex));
2691: pthread_mutex_unlock(&((*((struct_mutex *)
2692: (*(*((struct_liste_chainee *)
2693: l_element_courant)).donnee).objet)).mutex));
2694: pthread_mutex_destroy(&((*((struct_mutex *)
2695: (*(*((struct_liste_chainee *)
2696: l_element_courant)).donnee).objet)).mutex));
2697:
2698: liberation(s_etat_processus,
2699: (*((struct_liste_chainee *)
2700: l_element_courant)).donnee);
2701: l_element_suivant = (*((struct_liste_chainee *)
2702: l_element_courant)).suivant;
2703: free((struct_liste_chainee *) l_element_courant);
2704: l_element_courant = l_element_suivant;
2705: }
2706:
2707: /*
2708: * Arrêt des processus fils
2709: */
2710:
2711: if ((*s_etat_processus).presence_fusible == d_vrai)
2712: {
2713: pthread_cancel((*s_etat_processus).thread_fusible);
2714: }
2715:
2716: pthread_mutex_lock(&((*s_etat_processus).mutex));
2717:
2718: l_element_courant = (void *) (*s_etat_processus)
2719: .l_base_pile_processus;
2720:
2721: while(l_element_courant != NULL)
2722: {
2723: if ((*s_etat_processus).debug == d_vrai)
2724: {
2725: if (((*s_etat_processus).type_debug &
2726: d_debug_processus) != 0)
2727: {
2728: if ((*(*((struct_processus_fils *)
2729: (*(*((struct_liste_chainee *)
2730: l_element_courant)).donnee)
2731: .objet)).thread)
2732: .processus_detache == d_vrai)
2733: {
2734: if ((*s_etat_processus).langue == 'F')
2735: {
2736: printf("[%d] Signalement pour arrêt du "
2737: "processus %d\n",
2738: (int) getpid(), (int)
2739: (*(*((struct_processus_fils *)
2740: (*(*((struct_liste_chainee *)
2741: l_element_courant)).donnee)
2742: .objet)).thread).pid);
2743: }
2744: else
2745: {
2746: printf("[%d] Send stop signal to "
2747: "process %d\n",
2748: (int) getpid(), (int)
2749: (*(*((struct_processus_fils *)
2750: (*(*((struct_liste_chainee *)
2751: l_element_courant)).donnee)
2752: .objet)).thread).pid);
2753: }
2754: }
2755: else
2756: {
2757: if ((*s_etat_processus).langue == 'F')
2758: {
2759: printf("[%d] Signalement pour arrêt du "
2760: "thread %llu\n", (int) getpid(),
2761: (unsigned long long)
2762: (*(*((struct_processus_fils *)
2763: (*(*((struct_liste_chainee *)
2764: l_element_courant)).donnee)
2765: .objet)).thread).tid);
2766: }
2767: else
2768: {
2769: printf("[%d] Send stop signal to "
2770: "thread %llu\n",
2771: (int) getpid(),
2772: (unsigned long long)
2773: (*(*((struct_processus_fils *)
2774: (*(*((struct_liste_chainee *)
2775: l_element_courant)).donnee)
2776: .objet)).thread).tid);
2777: }
2778: }
2779: }
2780: }
2781:
2782: if ((*(*((struct_processus_fils *)
2783: (*(*((struct_liste_chainee *)
2784: l_element_courant)).donnee).objet))
2785: .thread).processus_detache == d_vrai)
2786: {
2787: if ((*s_etat_processus).var_volatile_alarme != 0)
2788: {
1.83 bertrand 2789: envoi_signal_processus(
2790: (*(*((struct_processus_fils *)
1.1 bertrand 2791: (*(*((struct_liste_chainee *)
2792: l_element_courant)).donnee).objet))
1.83 bertrand 2793: .thread).pid, rpl_sigurg);
1.1 bertrand 2794: }
2795: else
2796: {
1.22 bertrand 2797: if ((*s_etat_processus).arret_depuis_abort
2798: == -1)
2799: {
1.83 bertrand 2800: envoi_signal_processus(
2801: (*(*((struct_processus_fils *)
1.22 bertrand 2802: (*(*((struct_liste_chainee *)
2803: l_element_courant)).donnee).objet))
1.83 bertrand 2804: .thread).pid, rpl_sigabort);
1.22 bertrand 2805: }
2806: else
2807: {
1.83 bertrand 2808: envoi_signal_processus(
2809: (*(*((struct_processus_fils *)
1.22 bertrand 2810: (*(*((struct_liste_chainee *)
2811: l_element_courant)).donnee).objet))
1.83 bertrand 2812: .thread).pid, rpl_sigstop);
1.22 bertrand 2813: }
1.1 bertrand 2814: }
2815: }
2816: else
2817: {
2818: pthread_mutex_lock(&((*(*((struct_processus_fils *)
2819: (*(*((struct_liste_chainee *)
2820: l_element_courant)).donnee).objet)).thread)
2821: .mutex));
2822:
2823: if ((*(*((struct_processus_fils *)
2824: (*(*((struct_liste_chainee *)
2825: l_element_courant)).donnee).objet)).thread)
2826: .thread_actif == d_vrai)
2827: {
2828: if ((*s_etat_processus).var_volatile_alarme
2829: != 0)
2830: {
1.83 bertrand 2831: envoi_signal_thread(
2832: (*(*((struct_processus_fils *)
1.1 bertrand 2833: (*(*((struct_liste_chainee *)
2834: l_element_courant)).donnee).objet))
1.83 bertrand 2835: .thread).tid, rpl_sigurg);
1.1 bertrand 2836: }
2837: else
2838: {
1.22 bertrand 2839: if ((*s_etat_processus).arret_depuis_abort
2840: == -1)
2841: {
1.83 bertrand 2842: envoi_signal_thread(
1.22 bertrand 2843: (*(*((struct_processus_fils *)
2844: (*(*((struct_liste_chainee *)
2845: l_element_courant)).donnee)
2846: .objet)).thread).tid,
1.83 bertrand 2847: rpl_sigabort);
1.22 bertrand 2848: }
2849: else
2850: {
1.83 bertrand 2851: envoi_signal_thread(
1.22 bertrand 2852: (*(*((struct_processus_fils *)
2853: (*(*((struct_liste_chainee *)
2854: l_element_courant)).donnee)
2855: .objet)).thread).tid,
1.83 bertrand 2856: rpl_sigstop);
1.22 bertrand 2857: }
1.1 bertrand 2858: }
2859: }
2860:
2861: pthread_mutex_unlock(
2862: &((*(*((struct_processus_fils *)
2863: (*(*((struct_liste_chainee *)
2864: l_element_courant)).donnee).objet)).thread)
2865: .mutex));
2866: }
2867:
2868: l_element_courant = (*((struct_liste_chainee *)
2869: l_element_courant)).suivant;
2870: }
2871:
2872: /*
2873: * Attente de la fin de tous les processus fils
2874: */
2875:
2876: for(i = 0; i < d_NOMBRE_INTERRUPTIONS;
2877: (*s_etat_processus).masque_interruptions[i++]
2878: = 'I');
2879:
2880: attente.tv_sec = 0;
2881: attente.tv_nsec = GRANULARITE_us * 1000;
2882:
2883: while((*s_etat_processus).l_base_pile_processus != NULL)
2884: {
2885: l_element_courant = (void *)
2886: (*s_etat_processus).l_base_pile_processus;
2887:
2888: for(i = 0; i < (unsigned long)
2889: (*(*((struct_processus_fils *)
2890: (*(*((struct_liste_chainee *)
2891: l_element_courant)).donnee).objet)).thread)
2892: .nombre_objets_dans_pipe; i++)
2893: {
2894: if ((s_objet = lecture_pipe(
2895: s_etat_processus,
2896: (*(*((struct_processus_fils *)
2897: (*(*((struct_liste_chainee *)
2898: l_element_courant)).donnee).objet)).thread)
2899: .pipe_objets[0])) != NULL)
2900: {
2901: liberation(s_etat_processus, s_objet);
2902:
2903: (*(*((struct_processus_fils *)
2904: (*(*((struct_liste_chainee *)
2905: l_element_courant)).donnee).objet))
2906: .thread).nombre_objets_dans_pipe--;
2907:
2908: action.sa_handler = SIG_IGN;
2909: action.sa_flags = SA_ONSTACK;
2910:
2911: if (sigaction(SIGPIPE, &action, ®istre)
2912: != 0)
2913: {
2914: pthread_mutex_unlock(
2915: &((*s_etat_processus).mutex));
2916: return(EXIT_FAILURE);
2917: }
2918:
2919: while((longueur_ecriture =
2920: write_atomic(s_etat_processus,
2921: (*(*((struct_processus_fils *)
2922: (*(*((struct_liste_chainee *)
2923: l_element_courant)).donnee).objet))
2924: .thread).pipe_nombre_injections[1], "+",
2925: sizeof(unsigned char))) !=
2926: sizeof(unsigned char))
2927: {
2928: if (longueur_ecriture == -1)
2929: {
2930: // Le processus n'existe plus.
2931: break;
2932: }
2933: }
2934:
2935: if (sigaction(SIGPIPE, ®istre, NULL)
2936: != 0)
2937: {
2938: pthread_mutex_unlock(
2939: &((*s_etat_processus).mutex));
2940: return(EXIT_FAILURE);
2941: }
2942: }
2943: }
2944:
2945: pthread_mutex_unlock(&((*s_etat_processus).mutex));
1.23 bertrand 2946:
2947: if ((*s_etat_processus)
2948: .nombre_interruptions_non_affectees != 0)
2949: {
2950: affectation_interruptions_logicielles(
2951: s_etat_processus);
2952: }
2953:
1.1 bertrand 2954: nanosleep(&attente, NULL);
1.85 bertrand 2955: scrutation_interruptions(s_etat_processus);
1.1 bertrand 2956: pthread_mutex_lock(&((*s_etat_processus).mutex));
2957: }
2958:
2959: pthread_mutex_unlock(&((*s_etat_processus).mutex));
2960:
2961: erreur_historique = write_history(
2962: (*s_etat_processus).nom_fichier_historique);
2963: clear_history();
2964:
2965: if (erreur_historique != 0)
2966: {
2967: if ((*s_etat_processus).langue == 'F')
2968: {
2969: printf("+++Erreur : L'historique ne peut être "
2970: "écrit\n");
2971: }
2972: else
2973: {
2974: printf("+++Error : History cannot be "
2975: "written\n");
2976: }
2977:
2978: if (test_cfsf(s_etat_processus, 51) == d_faux)
2979: {
2980: printf("%s", ds_beep);
2981: }
2982: }
2983:
2984: free((*s_etat_processus).nom_fichier_historique);
2985:
2986: if (((*s_etat_processus).core == d_vrai) &&
2987: (erreur == d_erreur) &&
2988: ((*s_etat_processus).var_volatile_traitement_sigint
2989: == 0))
2990: {
2991: printf("\n");
2992:
2993: if ((*s_etat_processus).langue == 'F')
2994: {
2995: printf("+++Information : Génération du fichier "
2996: "rpl-core [%d]\n", (int) getpid());
2997: }
2998: else
2999: {
3000: printf("+++Information : Writing rpl-core "
3001: "file [%d]\n", (int) getpid());
3002: }
3003:
3004: rplcore(s_etat_processus);
3005:
3006: if ((*s_etat_processus).langue == 'F')
3007: {
3008: printf("+++Information : Processus tracé [%d]\n",
3009: (int) getpid());
3010: }
3011: else
3012: {
3013: printf("+++Information : Done [%d]\n",
3014: (int) getpid());
3015: }
3016:
3017: printf("\n");
3018: }
3019:
3020: free((*s_etat_processus).definitions_chainees);
3021:
3022: /*
3023: * Libération de l'arbre des instructions
3024: */
3025:
3026: liberation_arbre_instructions(s_etat_processus,
3027: (*s_etat_processus).arbre_instructions);
3028: free((*s_etat_processus).pointeurs_caracteres);
3029:
3030: if ((*s_etat_processus).entree_standard != NULL)
3031: {
3032: pclose((*s_etat_processus).entree_standard);
3033: (*s_etat_processus).entree_standard = NULL;
3034: }
3035:
3036: if ((*s_etat_processus).nom_fichier_impression != NULL)
3037: {
3038: if (test_cfsf(s_etat_processus, 51) == d_faux)
3039: {
3040: printf("%s", ds_beep);
3041: }
3042:
3043: if ((*s_etat_processus).langue == 'F')
3044: {
3045: printf("+++Attention : Queue d'impression "
3046: "non vide !\n");
3047: }
3048: else
3049: {
3050: printf("+++Warning : Non empty printing "
3051: "spool queue !\n");
3052: }
3053:
3054: instruction_erase(s_etat_processus);
3055: }
3056:
3057: if ((*s_etat_processus).fichiers_graphiques != NULL)
3058: {
3059: instruction_cllcd(s_etat_processus);
3060: }
3061:
3062: liberation(s_etat_processus, (*s_etat_processus).indep);
3063: liberation(s_etat_processus, (*s_etat_processus).depend);
3064:
3065: free((*s_etat_processus).label_x);
3066: free((*s_etat_processus).label_y);
3067: free((*s_etat_processus).label_z);
3068: free((*s_etat_processus).titre);
3069: free((*s_etat_processus).legende);
3070:
3071: liberation(s_etat_processus, (*s_etat_processus)
3072: .parametres_courbes_de_niveau);
3073:
3074: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
3075: {
3076: liberation(s_etat_processus,
3077: (*s_etat_processus).corps_interruptions[i]);
3078:
3079: l_element_courant = (*s_etat_processus)
3080: .pile_origine_interruptions[i];
3081:
3082: while(l_element_courant != NULL)
3083: {
3084: l_element_suivant = (*((struct_liste_chainee *)
3085: l_element_courant)).suivant;
3086:
3087: liberation(s_etat_processus,
3088: (*((struct_liste_chainee *)
3089: l_element_courant)).donnee);
3090: free(l_element_courant);
3091:
3092: l_element_courant = l_element_suivant;
3093: }
3094: }
3095:
3096: if ((*s_etat_processus).instruction_derniere_erreur
3097: != NULL)
3098: {
3099: free((*s_etat_processus).instruction_derniere_erreur);
3100: (*s_etat_processus).instruction_derniere_erreur = NULL;
3101: }
3102:
3103: /*
3104: * Le pointeur s_etat_processus.nom_fichier_source est
3105: * alloué par le système. Il ne faut donc pas
3106: * le libérer...
3107: */
3108:
1.66 bertrand 3109: liberation_arbre_variables(s_etat_processus,
3110: (*s_etat_processus).s_arbre_variables, d_vrai);
3111: free((*s_etat_processus).pointeurs_caracteres_variables);
1.1 bertrand 3112:
3113: for(i = 0; i < (*s_etat_processus)
3114: .nombre_variables_statiques; i++)
3115: {
3116: liberation(s_etat_processus, (*s_etat_processus)
3117: .s_liste_variables_statiques[i].objet);
3118: free((*s_etat_processus)
3119: .s_liste_variables_statiques[i].nom);
3120: }
3121:
3122: free((*s_etat_processus).s_liste_variables_statiques);
3123:
3124: for(i = 0; i < (*((*s_etat_processus)
3125: .s_liste_variables_partagees)).nombre_variables;
3126: i++)
3127: {
3128: liberation(s_etat_processus, (*((*s_etat_processus)
3129: .s_liste_variables_partagees)).table[i].objet);
3130: free((*((*s_etat_processus)
3131: .s_liste_variables_partagees)).table[i].nom);
3132: }
3133:
3134: free((struct_variable_partagee *)
3135: (*((*s_etat_processus).s_liste_variables_partagees))
3136: .table);
3137:
3138: /*
3139: * Si resultats est non nul, rplinit a été appelé
3140: * depuis rpl() [librpl] et non main().
3141: * On copie alors le contenu de la * pile dans un
3142: * tableau **resultats dont le pointeur de base a
3143: * été alloué dans rpl().
3144: */
3145:
3146: if (resultats != NULL)
3147: {
3148: if ((*resultats) != NULL)
3149: {
3150: free((*resultats));
3151:
3152: if (((*resultats) = malloc(((*s_etat_processus)
3153: .hauteur_pile_operationnelle + 1)
3154: * sizeof(unsigned char **))) != NULL)
3155: {
3156: (*resultats)[(*s_etat_processus)
3157: .hauteur_pile_operationnelle] = NULL;
3158: l_element_courant = (void *) (*s_etat_processus)
3159: .l_base_pile;
3160:
3161: for(i = 0; i < (*s_etat_processus)
3162: .hauteur_pile_operationnelle; i++)
3163: {
3164: if (l_element_courant != NULL)
3165: {
3166: (*resultats)[i] =
3167: formateur(s_etat_processus,
3168: 0, (*((struct_liste_chainee *)
3169: l_element_courant)).donnee);
3170:
3171: if ((*resultats)[i] == NULL)
3172: {
3173: i = (*s_etat_processus).
3174: hauteur_pile_operationnelle;
3175: }
3176: else
3177: {
3178: l_element_suivant =
3179: (*((struct_liste_chainee *)
3180: l_element_courant)).suivant;
3181: }
3182: }
3183: }
3184: }
3185: else
3186: {
3187: (*resultats) = NULL;
3188: erreur = d_es_allocation_memoire;
3189: }
3190: }
3191: }
3192:
3193: l_element_courant = (void *) (*s_etat_processus)
3194: .l_base_pile;
3195: while(l_element_courant != NULL)
3196: {
3197: l_element_suivant = (*((struct_liste_chainee *)
3198: l_element_courant)).suivant;
3199:
3200: liberation(s_etat_processus,
3201: (*((struct_liste_chainee *)
3202: l_element_courant)).donnee);
3203: free((struct_liste_chainee *) l_element_courant);
3204:
3205: l_element_courant = l_element_suivant;
3206: }
3207:
3208: l_element_courant = (void *) (*s_etat_processus)
3209: .l_base_pile_contextes;
3210: while(l_element_courant != NULL)
3211: {
3212: l_element_suivant = (*((struct_liste_chainee *)
3213: l_element_courant)).suivant;
3214:
3215: liberation(s_etat_processus,
3216: (*((struct_liste_chainee *)
3217: l_element_courant)).donnee);
3218: free((struct_liste_chainee *) l_element_courant);
3219:
3220: l_element_courant = l_element_suivant;
3221: }
3222:
3223: l_element_courant = (void *) (*s_etat_processus)
3224: .l_base_pile_taille_contextes;
3225: while(l_element_courant != NULL)
3226: {
3227: l_element_suivant = (*((struct_liste_chainee *)
3228: l_element_courant)).suivant;
3229:
3230: liberation(s_etat_processus,
3231: (*((struct_liste_chainee *)
3232: l_element_courant)).donnee);
3233: free((struct_liste_chainee *) l_element_courant);
3234:
3235: l_element_courant = l_element_suivant;
3236: }
3237:
3238: for(i = 0; i < (*s_etat_processus)
3239: .nombre_instructions_externes; i++)
3240: {
3241: free((*s_etat_processus).s_instructions_externes[i]
3242: .nom);
3243: free((*s_etat_processus).s_instructions_externes[i]
3244: .nom_bibliotheque);
3245: }
3246:
3247: if ((*s_etat_processus).nombre_instructions_externes != 0)
3248: {
3249: free((*s_etat_processus).s_instructions_externes);
3250: }
3251:
3252: l_element_courant = (void *) (*s_etat_processus)
3253: .s_bibliotheques;
3254:
3255: while(l_element_courant != NULL)
3256: {
3257: l_element_suivant = (*((struct_liste_chainee *)
3258: l_element_courant)).suivant;
3259:
3260: free((*((struct_bibliotheque *)
3261: (*((struct_liste_chainee *)
3262: l_element_courant)).donnee)).nom);
3263: dlclose((*((struct_bibliotheque *)
3264: (*((struct_liste_chainee *)
3265: l_element_courant)).donnee)).descripteur);
3266: free((*((struct_liste_chainee *) l_element_courant))
3267: .donnee);
3268: free(l_element_courant);
3269:
3270: l_element_courant = l_element_suivant;
3271: }
3272:
3273: l_element_courant = (void *) (*s_etat_processus)
3274: .l_base_pile_last;
3275: while(l_element_courant != NULL)
3276: {
3277: l_element_suivant = (*((struct_liste_chainee *)
3278: l_element_courant)).suivant;
3279:
3280: liberation(s_etat_processus,
3281: (*((struct_liste_chainee *)
3282: l_element_courant)).donnee);
3283: free((struct_liste_chainee *) l_element_courant);
3284:
3285: l_element_courant = l_element_suivant;
3286: }
3287:
3288: l_element_courant = (void *) (*s_etat_processus)
3289: .l_base_pile_systeme;
3290: while(l_element_courant != NULL)
3291: {
3292: l_element_suivant = (*((struct_liste_pile_systeme *)
3293: l_element_courant)).suivant;
3294:
3295: liberation(s_etat_processus,
3296: (*((struct_liste_pile_systeme *)
3297: l_element_courant)).indice_boucle);
3298: liberation(s_etat_processus,
3299: (*((struct_liste_pile_systeme *)
3300: l_element_courant)).limite_indice_boucle);
3301: liberation(s_etat_processus,
3302: (*((struct_liste_pile_systeme *)
3303: l_element_courant)).objet_de_test);
3304:
3305: if ((*((struct_liste_pile_systeme *)
3306: l_element_courant)).nom_variable != NULL)
3307: {
3308: free((*((struct_liste_pile_systeme *)
3309: l_element_courant)).nom_variable);
3310: }
3311:
3312: free((struct_liste_pile_systeme *)
3313: l_element_courant);
3314:
3315: l_element_courant = l_element_suivant;
3316: }
3317:
3318: l_element_courant = (void *)
3319: (*s_etat_processus).s_fichiers;
3320: while(l_element_courant != NULL)
3321: {
3322: l_element_suivant = (*((struct_liste_chainee *)
3323: l_element_courant)).suivant;
3324:
3325: fclose((*((struct_descripteur_fichier *)
3326: (*((struct_liste_chainee *)
3327: l_element_courant)).donnee))
1.12 bertrand 3328: .descripteur_c);
3329:
3330: if ((*((struct_descripteur_fichier *)
3331: (*((struct_liste_chainee *)
3332: l_element_courant)).donnee)).type != 'C')
3333: {
3334: sqlite3_close((*((struct_descripteur_fichier *)
3335: (*((struct_liste_chainee *)
3336: l_element_courant)).donnee))
3337: .descripteur_sqlite);
3338: }
1.1 bertrand 3339:
3340: if ((*((struct_descripteur_fichier *)
3341: (*((struct_liste_chainee *)
3342: l_element_courant)).donnee))
3343: .effacement == 'Y')
3344: {
3345: unlink((*((struct_descripteur_fichier *)
3346: (*((struct_liste_chainee *)
3347: l_element_courant)).donnee))
3348: .nom);
3349: }
3350:
3351: free((*((struct_descripteur_fichier *)
3352: (*((struct_liste_chainee *)
3353: l_element_courant)).donnee)).nom);
3354: free((struct_descripteur_fichier *)
3355: (*((struct_liste_chainee *)
3356: l_element_courant)).donnee);
3357: free(l_element_courant);
3358:
3359: l_element_courant = l_element_suivant;
3360: }
3361:
3362: l_element_courant = (void *)
3363: (*s_etat_processus).s_sockets;
3364: while(l_element_courant != NULL)
3365: {
3366: l_element_suivant = (*((struct_liste_chainee *)
3367: l_element_courant)).suivant;
3368:
3369: if ((*((struct_socket *)
3370: (*(*((struct_liste_chainee *)
3371: l_element_courant)).donnee).objet))
3372: .socket_connectee == d_vrai)
3373: {
3374: shutdown((*((struct_socket *)
3375: (*(*((struct_liste_chainee *)
3376: l_element_courant)).donnee).objet))
3377: .socket, SHUT_RDWR);
3378: }
3379:
3380: close((*((struct_socket *)
3381: (*(*((struct_liste_chainee *)
3382: l_element_courant)).donnee).objet)).socket);
3383:
3384: if ((*((struct_socket *) (*(*((struct_liste_chainee *)
3385: l_element_courant)).donnee).objet)).effacement
3386: == 'Y')
3387: {
3388: unlink((*((struct_socket *)
3389: (*(*((struct_liste_chainee *)
3390: l_element_courant)).donnee).objet))
3391: .adresse);
3392: }
3393:
3394: liberation(s_etat_processus,
3395: (*((struct_liste_chainee *)
3396: l_element_courant)).donnee);
3397: free(l_element_courant);
3398:
3399: l_element_courant = l_element_suivant;
3400: }
3401:
3402: l_element_courant = (void *)
3403: (*s_etat_processus).s_connecteurs_sql;
3404: while(l_element_courant != NULL)
3405: {
3406: l_element_suivant = (*((struct_liste_chainee *)
3407: l_element_courant)).suivant;
3408:
3409: sqlclose((*((struct_liste_chainee *)
3410: l_element_courant)).donnee);
3411: liberation(s_etat_processus,
3412: (*((struct_liste_chainee *)
3413: l_element_courant)).donnee);
3414: free(l_element_courant);
3415:
3416: l_element_courant = l_element_suivant;
3417: }
3418:
3419: l_element_courant = (*s_etat_processus).s_marques;
3420: while(l_element_courant != NULL)
3421: {
3422: free((*((struct_marque *) l_element_courant)).label);
3423: free((*((struct_marque *) l_element_courant)).position);
3424: l_element_suivant = (*((struct_marque *)
3425: l_element_courant)).suivant;
3426: free(l_element_courant);
3427: l_element_courant = l_element_suivant;
3428: }
3429: }
3430: else
3431: {
3432: erreur = d_es_allocation_memoire;
3433:
3434: if (test_cfsf(s_etat_processus, 51) == d_faux)
3435: {
3436: printf("%s", ds_beep);
3437: }
3438:
3439: if ((*s_etat_processus).langue == 'F')
3440: {
3441: printf("+++Système : Mémoire insuffisante\n");
3442: }
3443: else
3444: {
3445: printf("+++System : Not enough memory\n");
3446: }
3447: }
3448: }
3449:
3450: liberation_allocateur(s_etat_processus);
3451: }
3452:
3453: if (traitement_fichier_temporaire == 'Y')
3454: {
3455: if (destruction_fichier(nom_fichier_temporaire) == d_erreur)
3456: {
3457: return(EXIT_FAILURE);
3458: }
3459:
3460: free(nom_fichier_temporaire);
3461: }
3462:
3463: if ((*s_etat_processus).profilage == d_vrai)
3464: {
3465: ecriture_profil(s_etat_processus);
3466: liberation_profil(s_etat_processus);
3467: }
3468: }
3469:
3470: closelog();
3471:
3472: pthread_mutex_destroy(&((*s_etat_processus).protection_liste_mutexes));
3473: pthread_mutex_destroy(&((*((*s_etat_processus).s_liste_variables_partagees))
3474: .mutex));
3475:
3476: retrait_thread(s_etat_processus);
3477:
3478: pthread_mutex_destroy(&((*s_etat_processus).mutex));
1.30 bertrand 3479: pthread_mutex_destroy(&((*s_etat_processus).mutex_allocation));
1.29 bertrand 3480:
1.84 bertrand 3481: pthread_mutex_unlock(&((*s_etat_processus).mutex_fork));
3482: pthread_mutex_destroy(&((*s_etat_processus).mutex_fork));
1.1 bertrand 3483:
3484: free((*s_etat_processus).localisation);
3485:
1.84 bertrand 3486: pthread_mutex_destroy(&mutex_liste_threads);
3487: pthread_mutex_destroy(&mutex_gestionnaires_signaux_atomique);
3488:
1.17 bertrand 3489: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 3490: sem_post(&semaphore_gestionnaires_signaux);
3491: sem_destroy(&semaphore_gestionnaires_signaux);
1.17 bertrand 3492: # else
3493: sem_post(semaphore_gestionnaires_signaux);
1.87 bertrand 3494: sem_destroy2(semaphore_gestionnaires_signaux, getpid());
1.17 bertrand 3495: # endif
1.1 bertrand 3496:
1.83 bertrand 3497: destruction_queue_signaux(s_etat_processus);
1.76 bertrand 3498: liberation_contexte_cas(s_etat_processus);
3499:
1.40 bertrand 3500: free((*s_etat_processus).chemin_fichiers_temporaires);
1.24 bertrand 3501: free(s_etat_processus);
3502:
1.8 bertrand 3503: # ifdef DEBUG_MEMOIRE
1.24 bertrand 3504: debug_memoire_verification();
3505: analyse_post_mortem();
1.8 bertrand 3506: # endif
3507:
1.13 bertrand 3508: return((erreur == d_absence_erreur) ? EXIT_SUCCESS : EXIT_FAILURE);
1.1 bertrand 3509: }
3510:
3511:
3512: void
3513: informations(struct_processus *s_etat_processus)
3514: {
3515: printf("\n");
3516:
3517: if ((*s_etat_processus).langue == 'F')
3518: {
3519: printf(" rpl [-options] [programme]\n");
1.13 bertrand 3520: printf(" -a : analyse du code\n");
1.1 bertrand 3521: printf(" -A : paramètres passés au programme principal\n");
3522: printf(" -c : génération de fichier de débogage (rpl-core)\n");
3523: printf(" -d : option de déverminage interne\n");
3524: printf(" -D : lancement d'un daemon\n");
3525: printf(" -h : aide sur la ligne de commande\n");
3526: printf(" -i : fonctionnement interactif\n");
3527: printf(" -l : licence d'utilisation\n");
3528: printf(" -n : ignorance du signal HUP\n");
3529: printf(" -p : précompilation du script avant exécution\n");
3530: printf(" -P : profilage\n");
3531: printf(" -s : empêchement de l'ouverture de l'écran initial\n");
3532: printf(" -S : exécution du script passé en ligne de commande\n");
3533: printf(" -t : trace\n");
3534: printf(" -v : version\n");
3535: }
3536: else
3537: {
3538: printf(" rpl [-options] [program]\n");
1.13 bertrand 3539: printf(" -a : analyzes program\n");
1.1 bertrand 3540: printf(" -A : sends parameters to main program\n");
3541: printf(" -c : allows creation of a rpl-core file, providing a way"
3542: "\n"
3543: " to debug a program\n");
3544: printf(" -d : internal debug process\n");
3545: printf(" -D : starts in daemon mode\n");
3546: printf(" -h : shows a summary of available options\n");
3547: printf(" -i : runs the RPL/2 sequencer in interactive mode\n");
3548: printf(" -l : prints the user licence of the software\n");
3549: printf(" -n : ignores HUP signal\n");
3550: printf(" -p : precompiles script\n");
3551: printf(" -P : computes profile data\n");
3552: printf(" -s : disables splash screen\n");
3553: printf(" -S : executes script written in command line\n");
3554: printf(" -t : enables tracing mode\n");
3555: printf(" -v : prints the version number\n");
3556: }
3557:
3558: printf("\n");
3559:
3560: return;
3561: }
3562:
3563: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>