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