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