![]() ![]() | ![]() |
1.1 bertrand 1: /*
2: ================================================================================
1.73 ! bertrand 3: RPL/2 (R) version 4.1.20
1.72 bertrand 4: Copyright (C) 1989-2015 Dr. BERTRAND Joël
1.1 bertrand 5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
1.16 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Routine de formation des données pour l'affichage
29: ================================================================================
30: Entrées : structure sur l'état du processus et objet à afficher
31: --------------------------------------------------------------------------------
32: Sorties : chaine de caractères
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: unsigned char *
39: formateur(struct_processus *s_etat_processus, long offset_initial,
40: struct_objet *s_objet)
41: {
42: int parentheses_groupe_gauche;
43: int parentheses_groupe_droit;
44:
45: logical1 registre45;
46:
47: logical4 autorisation_parenthese;
48: logical4 presence_signe;
49:
1.58 bertrand 50: logical8 masque_binaire;
1.41 bertrand 51:
1.1 bertrand 52: struct_liste_chainee *l_atome;
53: struct_liste_chainee *l_element_courant;
54: struct_liste_chainee *l_liste1;
55: struct_liste_chainee *l_liste2;
56:
57: struct_objet *s_sous_objet;
58: struct_objet *s_sous_objet_1;
59: struct_objet *s_sous_objet_2;
60: struct_objet *s_sous_objet_3;
61:
62: unsigned char base[1 + 1];
63: unsigned char *chaine;
64: unsigned char *chaine_fonction;
65: unsigned char *chaine_formatee;
66: unsigned char *chaine_tampon;
67: unsigned char *chaine_sauvegarde;
68: unsigned char *format;
69: unsigned char *format_majuscule;
70: unsigned char *ptre;
71: unsigned char *ptrl;
72: unsigned char *registre;
73: unsigned char tampon[1024 + 1];
74:
1.58 bertrand 75: integer8 i;
76: integer8 j;
77: integer8 k;
78: integer8 longueur_chaine;
79: integer8 longueur_courante;
80: integer8 longueur_decimale_courante;
81: integer8 *longueurs_maximales;
82: integer8 nombre_arguments;
83: integer8 nombre_arguments_fonction;
84: integer8 nombre_colonnes;
85: integer8 nombre_elements;
86: integer8 nombre_lignes;
87: integer8 offset;
1.1 bertrand 88:
89: chaine = NULL;
90: chaine_formatee = NULL;
91: chaine_sauvegarde = NULL;
92:
93: strcpy(base, " ");
94:
95: masque_binaire = 0;
96:
97: if ((*s_objet).type == ADR)
98: {
99:
100: /*
101: --------------------------------------------------------------------------------
102: Adresse
103: --------------------------------------------------------------------------------
104: */
105:
1.63 bertrand 106: if (alsprintf(&chaine, "@ %016llX", (*((unsigned long long *)
1.3 bertrand 107: ((*s_objet).objet)))) < 0)
1.1 bertrand 108: {
109: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
110: return(NULL);
111: }
112: }
113: else if ((*s_objet).type == SLB)
114: {
115:
116: /*
117: --------------------------------------------------------------------------------
118: Bibliothèque partagée
119: --------------------------------------------------------------------------------
120: */
121:
1.69 bertrand 122: # pragma GCC diagnostic push
123: # pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
124:
1.61 bertrand 125: if (alsprintf(&chaine, "Library $ %016llX [%s]",
1.63 bertrand 126: (unsigned long long) (*((struct_bibliotheque *)
1.3 bertrand 127: (*s_objet).objet)).descripteur, (*((struct_bibliotheque *)
128: (*s_objet).objet)).nom) < 0)
1.1 bertrand 129: {
130: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
131: return(NULL);
132: }
1.69 bertrand 133:
134: # pragma GCC diagnostic pop
135:
1.1 bertrand 136: }
137: else if ((*s_objet).type == SPH)
138: {
139:
140: /*
141: --------------------------------------------------------------------------------
142: Sémaphore
143: --------------------------------------------------------------------------------
144: */
145:
1.69 bertrand 146: # pragma GCC diagnostic push
147: # pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
148:
1.63 bertrand 149: if (alsprintf(&chaine, "Semaphore $ %016llX '%s'", (unsigned long long)
1.3 bertrand 150: &((*((struct_semaphore *) (*s_objet).objet)).semaphore),
151: (*((struct_semaphore *) (*s_objet).objet)).nom) < 0)
1.1 bertrand 152: {
153: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
154: return(NULL);
155: }
1.69 bertrand 156:
157: # pragma GCC diagnostic pop
158:
1.1 bertrand 159: }
160: else if ((*s_objet).type == SQL)
161: {
162:
163: /*
164: --------------------------------------------------------------------------------
165: Connecteur SQL
166: --------------------------------------------------------------------------------
167: */
168:
169: if (strcmp((*((struct_connecteur_sql *) (*s_objet).objet)).type,
170: "MYSQL") == 0)
171: {
172: # ifdef MYSQL_SUPPORT
1.61 bertrand 173: if (alsprintf(&chaine, "Sql $ %016llX (%s)",
1.63 bertrand 174: (unsigned long long) (*((struct_connecteur_sql *)
1.1 bertrand 175: (*s_objet).objet)).descripteur.mysql,
1.3 bertrand 176: (*((struct_connecteur_sql *) (*s_objet).objet)).type) < 0)
177: {
178: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
179: return(NULL);
180: }
1.1 bertrand 181: # else
182: if ((*s_etat_processus).langue == 'F')
183: {
184: printf("+++Attention : Support de MySQL "
185: "non compilé !\n");
186: }
187: else
188: {
189: printf("+++Warning : MySQL support "
190: "not available !\n");
191: }
192:
193: fflush(stdout);
194: # endif
195: }
196: else if (strcmp((*((struct_connecteur_sql *) (*s_objet).objet)).type,
197: "POSTGRESQL") == 0)
198: {
199: # ifdef POSTGRESQL_SUPPORT
1.61 bertrand 200: if (alsprintf(&chaine, "Sql $ %016llX (%s)",
1.63 bertrand 201: (unsigned long long) (*((struct_connecteur_sql *)
1.9 bertrand 202: (*s_objet).objet)).descripteur.postgresql,
1.3 bertrand 203: (*((struct_connecteur_sql *) (*s_objet).objet)).type) < 0)
204: {
205: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
206: return(NULL);
207: }
1.1 bertrand 208: # else
209: if ((*s_etat_processus).langue == 'F')
210: {
211: printf("+++Attention : Support de PostgreSQL "
212: "non compilé !\n");
213: }
214: else
215: {
216: printf("+++Warning : PostgreSQL support "
217: "not available !\n");
218: }
219:
220: fflush(stdout);
221: # endif
222: }
223: else
224: {
225: BUG(1, printf("SQL type '%s' not allowed!",
226: (*((struct_connecteur_sql *) (*s_objet).objet))
227: .type));
228: }
229: }
230: else if ((*s_objet).type == PRC)
231: {
232:
233: /*
234: --------------------------------------------------------------------------------
235: Processus
236: --------------------------------------------------------------------------------
237: */
238:
239: if ((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
240: .processus_detache == d_vrai)
241: {
1.63 bertrand 242: if (alsprintf(&chaine, "Process $ %016llX", (unsigned long long)
1.1 bertrand 243: (*(*((struct_processus_fils *) (*s_objet).objet)).thread)
1.3 bertrand 244: .pid) < 0)
1.1 bertrand 245: {
246: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
247: return(NULL);
248: }
249: }
250: else
251: {
1.61 bertrand 252: if (alsprintf(&chaine, "Light weight process $ %016llX/%016llX",
1.63 bertrand 253: (unsigned long long) (*(*((struct_processus_fils *)
1.1 bertrand 254: (*s_objet).objet)).thread).pid,
1.63 bertrand 255: (unsigned long long) (*(*((struct_processus_fils *)
1.3 bertrand 256: (*s_objet).objet)).thread).tid) < 0)
1.1 bertrand 257: {
258: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
259: return(NULL);
260: }
261: }
262: }
263: else if ((*s_objet).type == FCH)
264: {
265:
266: /*
267: --------------------------------------------------------------------------------
268: Fichier
269: --------------------------------------------------------------------------------
270: */
271:
1.63 bertrand 272: if (alsprintf(&chaine, "File $ %016llX", (unsigned long long)
1.3 bertrand 273: (*((struct_fichier *) ((*s_objet).objet))).descripteur) < 0)
1.1 bertrand 274: {
275: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
276: return(NULL);
277: }
278:
279: registre45 = test_cfsf(s_etat_processus, 45);
280: cf(s_etat_processus, 45);
281:
282: if ((format = formateur(s_etat_processus, 0, (*((struct_fichier *)
283: ((*s_objet).objet))).format)) == NULL)
284: {
285: return(NULL);
286: }
287:
288: if (registre45 == d_vrai)
289: {
290: sf(s_etat_processus, 45);
291: }
292: else
293: {
294: cf(s_etat_processus, 45);
295: }
296:
297: if ((format_majuscule = conversion_majuscule(format)) == NULL)
298: {
299: return(NULL);
300: }
301:
302: free(format);
303:
304: registre = chaine;
305:
306: if ((chaine = malloc((strlen(registre) + 1 +
307: strlen(format_majuscule) + 1) * sizeof(unsigned char)))
308: == NULL)
309: {
310: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
311: return(NULL);
312: }
313:
314: sprintf(chaine, "%s %s", registre, format_majuscule);
315: free(registre);
316:
317: tampon[0] = d_code_fin_chaine;
318:
319: if ((*((struct_fichier *) ((*s_objet).objet))).acces == 'S')
320: {
321: strcat(tampon, "SEQUENTIAL, ");
322: }
323: else if ((*((struct_fichier *) ((*s_objet).objet))).acces == 'D')
324: {
325: strcat(tampon, "DIRECT, ");
326: }
327: else
328: {
329: strcat(tampon, "KEYED, ");
330: }
331:
332: if ((*((struct_fichier *) ((*s_objet).objet))).binaire == 'N')
333: {
334: strcat(tampon, "FORMATTED, ");
335: }
336: else if ((*((struct_fichier *) ((*s_objet).objet))).binaire == 'Y')
337: {
338: strcat(tampon, "UNFORMATTED, ");
339: }
340: else
341: {
342: strcat(tampon, "FLOW, ");
343: }
344:
345: if ((*((struct_fichier *) ((*s_objet).objet))).ouverture == 'N')
346: {
347: strcat(tampon, "NEW, ");
348: }
349: else if ((*((struct_fichier *) ((*s_objet).objet))).ouverture == 'O')
350: {
351: strcat(tampon, "OLD, ");
352: }
353: else if ((*((struct_fichier *) ((*s_objet).objet))).ouverture == 'R')
354: {
355: strcat(tampon, "REPLACE, ");
356: }
357: else if ((*((struct_fichier *) ((*s_objet).objet))).ouverture == 'U')
358: {
359: strcat(tampon, "UNKNOWN, ");
360: }
361: else
362: {
363: strcat(tampon, "SCRATCH, ");
364: }
365:
366: if ((*((struct_fichier *) ((*s_objet).objet))).protection == 'R')
367: {
368: strcat(tampon, "READONLY");
369: }
370: else if ((*((struct_fichier *) ((*s_objet).objet))).protection == 'W')
371: {
372: strcat(tampon, "WRITEONLY");
373: }
374: else
375: {
376: strcat(tampon, "READWRITE");
377: }
378:
379: registre = chaine;
380:
381: if ((chaine = malloc((strlen(chaine) + 6 + strlen(tampon) +
382: strlen((*((struct_fichier *) ((*s_objet).objet))).nom) + 1) *
383: sizeof(unsigned char))) == NULL)
384: {
385: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
386: return(NULL);
387: }
388:
389: sprintf(chaine, "%s [%s <%s>]", registre, (*((struct_fichier *)
390: ((*s_objet).objet))).nom, tampon);
391: free(registre);
392:
393: free(format_majuscule);
394: }
395: else if ((*s_objet).type == SCK)
396: {
397:
398: /*
399: --------------------------------------------------------------------------------
400: Socket
401: --------------------------------------------------------------------------------
402: */
403:
1.63 bertrand 404: if (alsprintf(&chaine, "Socket $ %016llX", (unsigned long long)
1.59 bertrand 405: (*((struct_socket *) ((*s_objet).objet))).socket) < 0)
1.1 bertrand 406: {
407: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
408: return(NULL);
409: }
410:
411: registre45 = test_cfsf(s_etat_processus, 45);
412: cf(s_etat_processus, 45);
413:
414: if ((format = formateur(s_etat_processus, 0, (*((struct_socket *)
415: ((*s_objet).objet))).format)) == NULL)
416: {
417: return(NULL);
418: }
419:
420: if (registre45 == d_vrai)
421: {
422: sf(s_etat_processus, 45);
423: }
424: else
425: {
426: cf(s_etat_processus, 45);
427: }
428:
429: if ((format_majuscule = conversion_majuscule(format)) == NULL)
430: {
431: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
432: return(NULL);
433: }
434:
435: free(format);
436:
437: registre = chaine;
438:
439: if ((chaine = malloc((strlen(registre) + 1 +
440: strlen(format_majuscule) + 1) * sizeof(unsigned char)))
441: == NULL)
442: {
443: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
444: return(NULL);
445: }
446:
447: sprintf(chaine, "%s %s", registre, format_majuscule);
448: free(registre);
449:
450: tampon[0] = d_code_fin_chaine;
451:
452: strcat(tampon, (*((struct_socket *) ((*s_objet).objet))).type);
453: strcat(tampon, ", ");
454:
455: if ((*((struct_socket *) ((*s_objet).objet))).domaine == PF_UNIX)
456: {
457: strcat(tampon, "UNIX, ");
458: }
459: else if ((*((struct_socket *) ((*s_objet).objet))).domaine == PF_INET)
460: {
461: strcat(tampon, "IPV4, ");
462: }
463: else if ((*((struct_socket *) ((*s_objet).objet))).domaine == PF_INET6)
464: {
465: strcat(tampon, "IPV6, ");
466: }
467:
468: if ((*((struct_socket *) ((*s_objet).objet))).localisation == 'L')
469: {
470: strcat(tampon, "LOCAL, ");
471: }
472: else
473: {
474: strcat(tampon, "FOREIGN, ");
475: }
476:
477: if ((*((struct_socket *) ((*s_objet).objet))).binaire == 'N')
478: {
479: strcat(tampon, "FORMATTED, ");
480: }
481: else if ((*((struct_socket *) ((*s_objet).objet))).binaire == 'Y')
482: {
483: strcat(tampon, "UNFORMATTED, ");
484: }
485: else
486: {
487: strcat(tampon, "FLOW, ");
488: }
489:
490: if ((*((struct_socket *) ((*s_objet).objet))).protection == 'R')
491: {
492: strcat(tampon, "READONLY");
493: }
494: else if ((*((struct_fichier *) ((*s_objet).objet))).protection == 'W')
495: {
496: strcat(tampon, "WRITEONLY");
497: }
498: else
499: {
500: strcat(tampon, "READWRITE");
501: }
502:
503: registre = chaine;
504:
505: if ((*((struct_socket *) ((*s_objet).objet))).localisation == 'L')
506: { // Socket locale
507: if ((strcmp((*((struct_socket *) ((*s_objet).objet))).type,
508: "STREAM") == 0) || (strcmp((*((struct_socket *)
509: ((*s_objet).objet))).type, "SEQUENTIAL DATAGRAM") == 0))
510: {
511: if (strcmp((*((struct_socket *) ((*s_objet).objet)))
512: .adresse_distante, "") == 0)
513: { // Socket connectée en écoute
514: if ((chaine = malloc((strlen(registre) + 16 +
515: strlen(tampon) + strlen((*((struct_socket *)
516: ((*s_objet).objet))).adresse) +
517: + 1) * sizeof(unsigned char))) == NULL)
518: {
519: (*s_etat_processus).erreur_systeme =
520: d_es_allocation_memoire;
521: return(NULL);
522: }
523:
524: sprintf(chaine, "%s [%s LISTENING <%s>]", registre,
525: (*((struct_socket *) ((*s_objet).objet))).adresse,
526: tampon);
527: }
528: else
529: { // Socket connecté
530: if ((chaine = malloc((strlen(registre) + 12 +
531: strlen(tampon) + strlen((*((struct_socket *)
532: ((*s_objet).objet))).adresse) +
533: strlen((*((struct_socket *) ((*s_objet).objet)))
534: .adresse_distante)
535: + 1) * sizeof(unsigned char))) == NULL)
536: {
537: (*s_etat_processus).erreur_systeme =
538: d_es_allocation_memoire;
539: return(NULL);
540: }
541:
542: sprintf(chaine, "%s [%s FROM %s <%s>]", registre,
543: (*((struct_socket *) ((*s_objet).objet))).adresse,
544: (*((struct_socket *) ((*s_objet).objet)))
545: .adresse_distante, tampon);
546: }
547: }
548: else // Socket non connectée
549: {
550: if ((chaine = malloc((strlen(registre) + 6 +
551: strlen(tampon) + strlen((*((struct_socket *)
552: ((*s_objet).objet))).adresse) +
553: + 1) * sizeof(unsigned char))) == NULL)
554: {
555: (*s_etat_processus).erreur_systeme =
556: d_es_allocation_memoire;
557: return(NULL);
558: }
559:
560: sprintf(chaine, "%s [%s <%s>]", registre,
561: (*((struct_socket *) ((*s_objet).objet))).adresse,
562: tampon);
563: }
564: }
565: else
566: { // Socket distante
567: if ((strcmp((*((struct_socket *) ((*s_objet).objet))).type,
568: "STREAM") == 0) || (strcmp((*((struct_socket *)
569: ((*s_objet).objet))).type, "SEQUENTIAL DATAGRAM") == 0))
570: {
571: if ((chaine = malloc((strlen(registre) + 9 +
572: strlen((*((struct_socket *) ((*s_objet).objet)))
573: .adresse) + strlen(tampon)
574: + 1) * sizeof(unsigned char))) == NULL)
575: {
576: (*s_etat_processus).erreur_systeme =
577: d_es_allocation_memoire;
578: return(NULL);
579: }
580:
581: sprintf(chaine, "%s [TO %s <%s>]", registre,
582: (*((struct_socket *) ((*s_objet).objet)))
583: .adresse, tampon);
584: }
585: else
586: {
587: if (strcmp((*((struct_socket *) ((*s_objet).objet)))
588: .adresse_distante, "") == 0)
589: {
590: if ((chaine = malloc((strlen(registre) + 5 +
591: strlen(tampon) + 1) * sizeof(unsigned char)))
592: == NULL)
593: {
594: (*s_etat_processus).erreur_systeme =
595: d_es_allocation_memoire;
596: return(NULL);
597: }
598:
599: sprintf(chaine, "%s [<%s>]", registre, tampon);
600: }
601: else
602: {
603: if ((chaine = malloc((strlen(registre) + 9 +
604: strlen((*((struct_socket *) ((*s_objet).objet)))
605: .adresse_distante) + strlen(tampon)
606: + 1) * sizeof(unsigned char))) == NULL)
607: {
608: (*s_etat_processus).erreur_systeme =
609: d_es_allocation_memoire;
610: return(NULL);
611: }
612:
613: sprintf(chaine, "%s [TO %s <%s>]", registre,
614: (*((struct_socket *) ((*s_objet).objet)))
615: .adresse_distante, tampon);
616: }
617: }
618: }
619:
620: free(registre);
621: free(format_majuscule);
622: }
623: else if ((*s_objet).type == ALG)
624: {
625:
626: /*
627: --------------------------------------------------------------------------------
628: Expression algébrique
629: --------------------------------------------------------------------------------
630: */
631:
632: l_element_courant = (struct_liste_chainee *) (*s_objet).objet;
633:
634: while(l_element_courant != NULL)
635: {
636: if ((*(*l_element_courant).donnee).type == FCT)
637: {
638: if ((strcmp((*((struct_fonction *) (*(*l_element_courant)
639: .donnee).objet)).nom_fonction, "<<") != 0) &&
640: (strcmp((*((struct_fonction *) (*(*l_element_courant)
641: .donnee).objet)).nom_fonction, ">>") != 0))
642: {
643: if ((strcmp((*((struct_fonction *) (*(*l_element_courant)
644: .donnee).objet)).nom_fonction, "+") == 0) ||
645: (strcmp((*((struct_fonction *)
646: (*(*l_element_courant).donnee).objet))
647: .nom_fonction, "-") == 0) || (strcmp(
648: (*((struct_fonction *) (*(*l_element_courant)
649: .donnee).objet)).nom_fonction, "*") == 0) ||
650: (strcmp((*((struct_fonction *)
651: (*(*l_element_courant).donnee).objet)).nom_fonction,
652: "/") == 0) || (strcmp((*((struct_fonction *)
653: (*(*l_element_courant).donnee).objet)).nom_fonction,
654: "^") == 0) || (strcmp((*((struct_fonction *)
655: (*(*l_element_courant).donnee).objet)).nom_fonction,
656: "<") == 0) || (strcmp((*((struct_fonction *)
657: (*(*l_element_courant).donnee).objet)).nom_fonction,
658: ">") == 0) || (strcmp((*((struct_fonction *)
659: (*(*l_element_courant).donnee).objet)).nom_fonction,
660: "==") == 0) || (strcmp((*((struct_fonction *)
661: (*(*l_element_courant).donnee).objet)).nom_fonction,
662: "<>") == 0) || (strcmp((*((struct_fonction *)
663: (*(*l_element_courant).donnee).objet)).nom_fonction,
664: "<=") == 0) || (strcmp((*((struct_fonction *)
665: (*(*l_element_courant).donnee).objet)).nom_fonction,
666: "=<") == 0) || (strcmp((*((struct_fonction *)
667: (*(*l_element_courant).donnee).objet)).nom_fonction,
668: ">=") == 0) || (strcmp((*((struct_fonction *)
669: (*(*l_element_courant).donnee).objet)).nom_fonction,
670: "=>") == 0))
671: {
672: if (depilement(s_etat_processus, &((*s_etat_processus)
673: .l_base_pile), &s_sous_objet_2) == d_erreur)
674: {
675: return(NULL);
676: }
677:
678: chaine_sauvegarde = (*s_etat_processus)
679: .instruction_courante;
680:
681: if (((*s_etat_processus).instruction_courante =
682: (unsigned char *) malloc((strlen(
683: (unsigned char *) (*s_sous_objet_2).objet) + 2
684: + 1) * sizeof(unsigned char))) == NULL)
685: {
686: (*s_etat_processus).instruction_courante =
687: chaine_sauvegarde;
688: (*s_etat_processus).erreur_systeme =
689: d_es_allocation_memoire;
690: return(NULL);
691: }
692:
693: sprintf((*s_etat_processus).instruction_courante,
694: "'%s'", (unsigned char *)
695: (*s_sous_objet_2).objet);
696:
697: presence_signe = (((*s_etat_processus)
698: .instruction_courante[1] == '+')
699: || ((*s_etat_processus).instruction_courante[1]
700: == '-')) ? d_vrai : d_faux;
701:
1.71 bertrand 702: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 703: recherche_type(s_etat_processus);
704:
705: if ((*s_etat_processus).erreur_execution != d_ex)
706: {
707: // Aucune erreur d'exécution ne peut être
708: // retournée, car l'argument est cohérent.
709:
710: return(NULL);
711: }
712:
713: if (depilement(s_etat_processus, &((*s_etat_processus)
714: .l_base_pile), &s_sous_objet_3) == d_erreur)
715: {
716: return(NULL);
717: }
718:
719: free((*s_etat_processus).instruction_courante);
720:
721: (*s_etat_processus).instruction_courante =
722: chaine_sauvegarde;
723:
724: autorisation_parenthese = d_faux;
725:
726: if ((*s_sous_objet_3).type == ALG)
727: {
728: l_atome = (struct_liste_chainee *)
729: (*s_sous_objet_3).objet;
730: chaine_fonction = "";
731: nombre_arguments_fonction = 0;
732:
733: while(l_atome != NULL)
734: {
735: if ((*(*l_atome).donnee).type == FCT)
736: {
737: if (strcmp((*((struct_fonction *)
738: (*(*l_atome).donnee).objet))
739: .nom_fonction, ">>") != 0)
740: {
741: chaine_fonction = (*((struct_fonction *)
742: (*(*l_atome).donnee).objet))
743: .nom_fonction;
744: nombre_arguments_fonction =
745: (*((struct_fonction *)
746: (*(*l_atome).donnee).objet))
747: .nombre_arguments;
748: }
749: }
750:
751: l_atome = (*l_atome).suivant;
752: }
753:
754: if (strcmp((*((struct_fonction *)
755: (*(*l_element_courant).donnee).objet))
756: .nom_fonction, "+") == 0)
757: {
758: if ((strcmp(chaine_fonction, "AND") == 0) ||
759: (strcmp(chaine_fonction, "XOR") == 0) ||
1.72 bertrand 760: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 761: (strcmp(chaine_fonction, "OR") == 0))
762: {
763: autorisation_parenthese = d_vrai;
764: }
765: }
766: else if (strcmp((*((struct_fonction *)
767: (*(*l_element_courant).donnee).objet))
768: .nom_fonction, "-") == 0)
769: {
770: if (nombre_arguments_fonction != 0)
771: {
772: autorisation_parenthese = d_faux;
773: }
774: else
775: {
776: autorisation_parenthese = d_vrai;
777: }
778: }
779: else if (strcmp((*((struct_fonction *)
780: (*(*l_element_courant).donnee).objet))
781: .nom_fonction, "*") == 0)
782: {
783: if ((strcmp(chaine_fonction, "+") == 0) ||
784: (strcmp(chaine_fonction, "-") == 0) ||
785: (strcmp(chaine_fonction, "AND") == 0) ||
786: (strcmp(chaine_fonction, "XOR") == 0) ||
1.72 bertrand 787: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 788: (strcmp(chaine_fonction, "OR") == 0))
789: {
790: autorisation_parenthese = d_vrai;
791: }
792: }
793: else if (strcmp((*((struct_fonction *)
794: (*(*l_element_courant).donnee).objet))
795: .nom_fonction, "/") == 0)
796: {
797: if (nombre_arguments_fonction != 0)
798: {
799: autorisation_parenthese = d_faux;
800: }
801: else
802: {
803: autorisation_parenthese = d_vrai;
804: }
805: }
806: else if ((strcmp((*((struct_fonction *)
807: (*(*l_element_courant).donnee).objet))
808: .nom_fonction, "^") == 0))
809: {
810: if (nombre_arguments_fonction != 0)
811: {
812: autorisation_parenthese = d_faux;
813: }
814: else
815: {
816: autorisation_parenthese = d_vrai;
817: }
818: }
819: }
820:
821: if ((autorisation_parenthese == d_vrai) ||
822: (presence_signe == d_vrai))
823: {
824: chaine_sauvegarde = (unsigned char *)
825: (*s_sous_objet_2).objet;
826:
1.58 bertrand 827: if (((*s_sous_objet_2).objet =
1.1 bertrand 828: malloc((strlen(chaine_sauvegarde) + 2 + 1)
829: * sizeof(unsigned char))) == NULL)
830: {
831: (*s_etat_processus).erreur_systeme =
832: d_es_allocation_memoire;
833: return(NULL);
834: }
835:
836: sprintf((unsigned char *) (*s_sous_objet_2).objet,
837: "(%s)", chaine_sauvegarde);
838: free(chaine_sauvegarde);
839: }
840:
841: liberation(s_etat_processus, s_sous_objet_3);
842:
843: if (depilement(s_etat_processus, &((*s_etat_processus)
844: .l_base_pile), &s_sous_objet_1) == d_erreur)
845: {
846: return(NULL);
847: }
848:
849: chaine_sauvegarde = (*s_etat_processus)
850: .instruction_courante;
851:
852: if (((*s_etat_processus).instruction_courante =
853: (unsigned char *) malloc((strlen(
854: (unsigned char *) (*s_sous_objet_1).objet) + 2
855: + 1) * sizeof(unsigned char))) == NULL)
856: {
857: (*s_etat_processus).instruction_courante =
858: chaine_sauvegarde;
859: (*s_etat_processus).erreur_systeme =
860: d_es_allocation_memoire;
861: return(NULL);
862: }
863:
864: sprintf((*s_etat_processus).instruction_courante,
865: "'%s'", (unsigned char *)
866: (*s_sous_objet_1).objet);
867:
1.71 bertrand 868: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 869: recherche_type(s_etat_processus);
870:
871: if ((*s_etat_processus).erreur_execution != d_ex)
872: {
873: // Aucune erreur d'exécution ne peut être
874: // retournée, car l'argument est cohérent.
875:
876: return(NULL);
877: }
878:
879: if (depilement(s_etat_processus, &((*s_etat_processus)
880: .l_base_pile), &s_sous_objet_3) == d_erreur)
881: {
882: return(NULL);
883: }
884:
885: free((*s_etat_processus).instruction_courante);
886:
887: (*s_etat_processus).instruction_courante =
888: chaine_sauvegarde;
889:
890: autorisation_parenthese = d_faux;
891:
892: if ((*s_sous_objet_3).type == ALG)
893: {
894: l_atome = (struct_liste_chainee *)
895: (*s_sous_objet_3).objet;
896: chaine_fonction = "";
897:
898: while(l_atome != NULL)
899: {
900: if ((*(*l_atome).donnee).type == FCT)
901: {
902: if (strcmp((*((struct_fonction *)
903: (*(*l_atome).donnee).objet))
904: .nom_fonction, ">>") != 0)
905: {
906: chaine_fonction = (*((struct_fonction *)
907: (*(*l_atome).donnee).objet))
908: .nom_fonction;
909: }
910: }
911:
912: l_atome = (*l_atome).suivant;
913: }
914:
915: if ((strcmp((*((struct_fonction *)
916: (*(*l_element_courant).donnee).objet))
917: .nom_fonction, "+") == 0) ||
918: (strcmp((*((struct_fonction *)
919: (*(*l_element_courant).donnee).objet))
920: .nom_fonction, "-") == 0))
921: {
922: if ((strcmp(chaine_fonction, "AND") == 0) ||
923: (strcmp(chaine_fonction, "XOR") == 0) ||
1.72 bertrand 924: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 925: (strcmp(chaine_fonction, "OR") == 0))
926: {
927: autorisation_parenthese = d_vrai;
928: }
929: }
930: else if ((strcmp((*((struct_fonction *)
931: (*(*l_element_courant).donnee).objet))
932: .nom_fonction, "*") == 0) ||
933: (strcmp((*((struct_fonction *)
934: (*(*l_element_courant).donnee).objet))
935: .nom_fonction, "/") == 0))
936: {
937: if ((strcmp(chaine_fonction, "+") == 0) ||
938: (strcmp(chaine_fonction, "-") == 0) ||
939: (strcmp(chaine_fonction, "AND") == 0) ||
940: (strcmp(chaine_fonction, "XOR") == 0) ||
1.72 bertrand 941: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 942: (strcmp(chaine_fonction, "OR") == 0))
943: {
944: autorisation_parenthese = d_vrai;
945: }
946: }
947: else if ((strcmp((*((struct_fonction *)
948: (*(*l_element_courant).donnee).objet))
949: .nom_fonction, "^") == 0))
950: {
951: autorisation_parenthese = d_vrai;
952: }
953: }
954:
955: if (autorisation_parenthese == d_vrai)
956: {
957: chaine_sauvegarde = (unsigned char *)
958: (*s_sous_objet_1).objet;
959:
1.58 bertrand 960: if (((*s_sous_objet_1).objet =
1.1 bertrand 961: malloc((strlen(chaine_sauvegarde) + 2 + 1)
962: * sizeof(unsigned char))) == NULL)
963: {
964: (*s_etat_processus).erreur_systeme =
965: d_es_allocation_memoire;
966: return(NULL);
967: }
968:
969: sprintf((unsigned char *) (*s_sous_objet_1).objet,
970: "(%s)", chaine_sauvegarde);
971: free(chaine_sauvegarde);
972: }
973:
974: liberation(s_etat_processus, s_sous_objet_3);
975:
976: if ((s_sous_objet = allocation(s_etat_processus, CHN))
977: == NULL)
978: {
979: (*s_etat_processus).erreur_systeme =
980: d_es_allocation_memoire;
981: return(NULL);
982: }
983:
1.58 bertrand 984: if (((*s_sous_objet).objet = malloc((strlen(
1.1 bertrand 985: (unsigned char *) (*s_sous_objet_1).objet) +
986: strlen((*((struct_fonction *)
987: (*(*l_element_courant).donnee).objet))
988: .nom_fonction) + strlen((unsigned char *)
989: (*s_sous_objet_2).objet) + 1) *
990: sizeof(unsigned char))) == NULL)
991: {
992: (*s_etat_processus).erreur_systeme =
993: d_es_allocation_memoire;
994: return(NULL);
995: }
996:
997: sprintf((unsigned char *) (*s_sous_objet).objet,
998: "%s%s%s", (unsigned char *)
999: (*s_sous_objet_1)
1000: .objet, (*((struct_fonction *)
1001: (*(*l_element_courant).donnee).objet))
1002: .nom_fonction, (unsigned char *)
1003: (*s_sous_objet_2).objet);
1004:
1005: liberation(s_etat_processus, s_sous_objet_1);
1006: liberation(s_etat_processus, s_sous_objet_2);
1007:
1008: if (empilement(s_etat_processus, &((*s_etat_processus)
1009: .l_base_pile), s_sous_objet) == d_erreur)
1010: {
1011: return(NULL);
1012: }
1013: }
1014: else if (strcmp((*((struct_fonction *)
1015: (*(*l_element_courant).donnee).objet)).nom_fonction,
1016: "=") == 0)
1017: {
1018: if (depilement(s_etat_processus, &((*s_etat_processus)
1019: .l_base_pile), &s_sous_objet_2) == d_erreur)
1020: {
1021: return(NULL);
1022: }
1023:
1024: if (depilement(s_etat_processus, &((*s_etat_processus)
1025: .l_base_pile), &s_sous_objet_1) == d_erreur)
1026: {
1027: return(NULL);
1028: }
1029:
1030: if ((s_sous_objet = allocation(s_etat_processus, CHN))
1031: == NULL)
1032: {
1033: (*s_etat_processus).erreur_systeme =
1034: d_es_allocation_memoire;
1035: return(NULL);
1036: }
1037:
1038: autorisation_parenthese = d_vrai;
1039: l_atome = l_element_courant;
1040:
1041: if (l_atome != NULL)
1042: {
1043: if ((*l_atome).suivant != NULL)
1044: {
1045: l_atome = (*l_atome).suivant;
1046:
1047: if ((*(*l_atome).donnee).type == FCT)
1048: {
1049: if (strcmp((*((struct_fonction *)
1050: (*(*l_atome).donnee).objet))
1051: .nom_fonction, ">>") == 0)
1052: {
1053: if ((*l_atome).suivant == NULL)
1054: {
1055: autorisation_parenthese = d_faux;
1056: }
1057: }
1058: }
1059: }
1060: }
1061:
1062: if (autorisation_parenthese == d_vrai)
1063: {
1064: if (((*s_sous_objet).objet =
1.58 bertrand 1065: malloc((strlen(
1.1 bertrand 1066: (unsigned char *) (*s_sous_objet_1).objet) +
1067: strlen((*((struct_fonction *)
1068: (*(*l_element_courant).donnee).objet))
1069: .nom_fonction) + strlen((unsigned char *)
1070: (*s_sous_objet_2).objet) + 2 + 1) *
1071: sizeof(unsigned char))) == NULL)
1072: {
1073: (*s_etat_processus).erreur_systeme =
1074: d_es_allocation_memoire;
1075: return(NULL);
1076: }
1077:
1078: sprintf((unsigned char *) (*s_sous_objet).objet,
1079: "(%s%s%s)", (unsigned char *)
1080: (*s_sous_objet_1)
1081: .objet, (*((struct_fonction *)
1082: (*(*l_element_courant).donnee).objet))
1083: .nom_fonction, (unsigned char *)
1084: (*s_sous_objet_2).objet);
1085: }
1086: else
1087: {
1088: if (((*s_sous_objet).objet =
1.58 bertrand 1089: malloc((strlen(
1.1 bertrand 1090: (unsigned char *) (*s_sous_objet_1).objet) +
1091: strlen((*((struct_fonction *)
1092: (*(*l_element_courant).donnee).objet))
1093: .nom_fonction) + strlen((unsigned char *)
1094: (*s_sous_objet_2).objet) + 1) *
1095: sizeof(unsigned char))) == NULL)
1096: {
1097: (*s_etat_processus).erreur_systeme =
1098: d_es_allocation_memoire;
1099: return(NULL);
1100: }
1101:
1102: sprintf((unsigned char *) (*s_sous_objet).objet,
1103: "%s%s%s", (unsigned char *)
1104: (*s_sous_objet_1)
1105: .objet, (*((struct_fonction *)
1106: (*(*l_element_courant).donnee).objet))
1107: .nom_fonction, (unsigned char *)
1108: (*s_sous_objet_2).objet);
1109: }
1110:
1111: liberation(s_etat_processus, s_sous_objet_1);
1112: liberation(s_etat_processus, s_sous_objet_2);
1113:
1114: if (empilement(s_etat_processus, &((*s_etat_processus)
1115: .l_base_pile), s_sous_objet) == d_erreur)
1116: {
1117: return(NULL);
1118: }
1119: }
1120: else if (strcmp((*((struct_fonction *)
1121: (*(*l_element_courant).donnee).objet)).nom_fonction,
1122: "NOT") == 0)
1123: {
1124: if (depilement(s_etat_processus, &((*s_etat_processus)
1125: .l_base_pile), &s_sous_objet_1) == d_erreur)
1126: {
1127: return(NULL);
1128: }
1129:
1130: if ((s_sous_objet = allocation(s_etat_processus, CHN))
1131: == NULL)
1132: {
1133: (*s_etat_processus).erreur_systeme =
1134: d_es_allocation_memoire;
1135: return(NULL);
1136: }
1137:
1138: if (((*s_sous_objet).objet = (unsigned char *) malloc(
1139: (strlen((unsigned char *) (*s_sous_objet_1)
1140: .objet) + 5 + 1) * sizeof(unsigned char))) ==
1141: NULL)
1142: {
1143: (*s_etat_processus).erreur_systeme =
1144: d_es_allocation_memoire;
1145: return(NULL);
1146: }
1147:
1148: sprintf((unsigned char *) (*s_sous_objet).objet,
1149: "%s(%s)", (*((struct_fonction *)
1150: (*(*l_element_courant).donnee).objet))
1151: .nom_fonction, (unsigned char *)
1152: (*s_sous_objet_1).objet );
1153:
1154: liberation(s_etat_processus, s_sous_objet_1);
1155:
1156: if (empilement(s_etat_processus, &((*s_etat_processus)
1157: .l_base_pile), s_sous_objet) == d_erreur)
1158: {
1159: return(NULL);
1160: }
1161: }
1162: else if ((strcmp((*((struct_fonction *)
1163: (*(*l_element_courant).donnee).objet)).nom_fonction,
1164: "OR") == 0) || (strcmp((*((struct_fonction *)
1165: (*(*l_element_courant).donnee).objet)).nom_fonction,
1166: "XOR") == 0) || (strcmp((*((struct_fonction *)
1167: (*(*l_element_courant).donnee).objet)).nom_fonction,
1.72 bertrand 1168: "EQV") == 0) || (strcmp((*((struct_fonction *)
1169: (*(*l_element_courant).donnee).objet)).nom_fonction,
1.1 bertrand 1170: "AND") == 0))
1171: {
1172: if (depilement(s_etat_processus, &((*s_etat_processus)
1173: .l_base_pile), &s_sous_objet_2) == d_erreur)
1174: {
1175: return(NULL);
1176: }
1177:
1178: if (depilement(s_etat_processus, &((*s_etat_processus)
1179: .l_base_pile), &s_sous_objet_1) == d_erreur)
1180: {
1181: return(NULL);
1182: }
1183:
1184: if ((s_sous_objet = allocation(s_etat_processus, CHN))
1185: == NULL)
1186: {
1187: (*s_etat_processus).erreur_systeme =
1188: d_es_allocation_memoire;
1189: return(NULL);
1190: }
1191:
1192: parentheses_groupe_gauche = 0;
1193: parentheses_groupe_droit = 0;
1194:
1195: chaine_sauvegarde = (*s_etat_processus)
1196: .instruction_courante;
1197:
1198: if (((*s_etat_processus).instruction_courante =
1199: (unsigned char *) malloc((strlen(
1200: (unsigned char *) (*s_sous_objet_1).objet) + 2
1201: + 1) * sizeof(unsigned char))) == NULL)
1202: {
1203: (*s_etat_processus).instruction_courante =
1204: chaine_sauvegarde;
1205: (*s_etat_processus).erreur_systeme =
1206: d_es_allocation_memoire;
1207: return(NULL);
1208: }
1209:
1210: sprintf((*s_etat_processus).instruction_courante,
1211: "'%s'", (unsigned char *)
1212: (*s_sous_objet_1).objet);
1213:
1.71 bertrand 1214: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 1215: recherche_type(s_etat_processus);
1216:
1217: if ((*s_etat_processus).erreur_execution != d_ex)
1218: {
1219: // Aucune erreur d'exécution ne peut être
1220: // retournée, car l'argument est cohérent.
1221:
1222: return(NULL);
1223: }
1224:
1225: if (depilement(s_etat_processus, &((*s_etat_processus)
1226: .l_base_pile), &s_sous_objet_3) == d_erreur)
1227: {
1228: return(NULL);
1229: }
1230:
1231: free((*s_etat_processus).instruction_courante);
1232:
1233: (*s_etat_processus).instruction_courante =
1234: chaine_sauvegarde;
1235:
1236: if ((*s_sous_objet_3).type == ALG)
1237: {
1238: l_atome = (struct_liste_chainee *)
1239: (*s_sous_objet_3).objet;
1240: chaine_fonction = "";
1241:
1242: while(l_atome != NULL)
1243: {
1244: if ((*(*l_atome).donnee).type == FCT)
1245: {
1246: if (strcmp((*((struct_fonction *)
1247: (*(*l_atome).donnee).objet))
1248: .nom_fonction, ">>") != 0)
1249: {
1250: chaine_fonction = (*((struct_fonction *)
1251: (*(*l_atome).donnee).objet))
1252: .nom_fonction;
1253: }
1254: }
1255:
1256: l_atome = (*l_atome).suivant;
1257: }
1258:
1259: if (((strcmp(chaine_fonction, "OR") == 0) ||
1.72 bertrand 1260: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 1261: (strcmp(chaine_fonction, "XOR") == 0)) &&
1262: (strcmp((*((struct_fonction *)
1263: (*(*l_element_courant).donnee).objet))
1264: .nom_fonction, "AND") == 0))
1265: {
1266: parentheses_groupe_gauche = 2;
1267: }
1268: }
1269:
1270: liberation(s_etat_processus, s_sous_objet_3);
1271:
1272: chaine_sauvegarde = (*s_etat_processus)
1273: .instruction_courante;
1274:
1275: if (((*s_etat_processus).instruction_courante =
1276: (unsigned char *) malloc((strlen(
1277: (unsigned char *) (*s_sous_objet_2).objet) + 2
1278: + 1) * sizeof(unsigned char))) == NULL)
1279: {
1280: (*s_etat_processus).instruction_courante =
1281: chaine_sauvegarde;
1282: (*s_etat_processus).erreur_systeme =
1283: d_es_allocation_memoire;
1284: return(NULL);
1285: }
1286:
1287: sprintf((*s_etat_processus).instruction_courante,
1288: "'%s'", (unsigned char *)
1289: (*s_sous_objet_2).objet);
1290:
1.71 bertrand 1291: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 1292: recherche_type(s_etat_processus);
1293:
1294: if ((*s_etat_processus).erreur_execution != d_ex)
1295: {
1296: // Aucune erreur d'exécution ne peut être
1297: // retournée, car l'argument est cohérent.
1298:
1299: return(NULL);
1300: }
1301:
1302: if (depilement(s_etat_processus, &((*s_etat_processus)
1303: .l_base_pile), &s_sous_objet_3) == d_erreur)
1304: {
1305: return(NULL);
1306: }
1307:
1308: free((*s_etat_processus).instruction_courante);
1309:
1310: (*s_etat_processus).instruction_courante =
1311: chaine_sauvegarde;
1312:
1313: if ((*s_sous_objet_3).type == ALG)
1314: {
1315: l_atome = (struct_liste_chainee *)
1316: (*s_sous_objet_3).objet;
1317: chaine_fonction = "";
1318:
1319: while(l_atome != NULL)
1320: {
1321: if ((*(*l_atome).donnee).type == FCT)
1322: {
1323: if (strcmp((*((struct_fonction *)
1324: (*(*l_atome).donnee).objet))
1325: .nom_fonction, ">>") != 0)
1326: {
1327: chaine_fonction = (*((struct_fonction *)
1328: (*(*l_atome).donnee).objet))
1329: .nom_fonction;
1330: }
1331: }
1332:
1333: l_atome = (*l_atome).suivant;
1334: }
1335:
1336: if (((strcmp(chaine_fonction, "OR") == 0) ||
1.72 bertrand 1337: (strcmp(chaine_fonction, "EQV") == 0) ||
1.1 bertrand 1338: (strcmp(chaine_fonction, "XOR") == 0)) &&
1339: (strcmp((*((struct_fonction *)
1340: (*(*l_element_courant).donnee).objet))
1341: .nom_fonction, "AND") == 0))
1342: {
1343: parentheses_groupe_droit = 2;
1344: }
1345: }
1346:
1347: liberation(s_etat_processus, s_sous_objet_3);
1348:
1.58 bertrand 1349: if (((*s_sous_objet).objet = malloc((strlen(
1.1 bertrand 1350: (unsigned char *) (*s_sous_objet_1).objet) +
1351: strlen((*((struct_fonction *)
1352: (*(*l_element_courant).donnee).objet))
1353: .nom_fonction) + strlen((unsigned char *)
1354: (*s_sous_objet_2).objet) + 2 + 1 +
1.58 bertrand 1355: ((size_t) parentheses_groupe_gauche) +
1356: ((size_t) parentheses_groupe_droit)) *
1.1 bertrand 1357: sizeof(unsigned char))) == NULL)
1358: {
1359: (*s_etat_processus).erreur_systeme =
1360: d_es_allocation_memoire;
1361: return(NULL);
1362: }
1363:
1364: sprintf((unsigned char *) (*s_sous_objet).objet,
1365: (parentheses_groupe_gauche == 0)
1366: ? ((parentheses_groupe_droit == 0)
1367: ? "%s %s %s"
1368: : "%s %s (%s)")
1369: : ((parentheses_groupe_droit == 0)
1370: ? "(%s) %s %s"
1371: : "(%s) %s (%s)"),
1372: (unsigned char *) (*s_sous_objet_1)
1373: .objet, (*((struct_fonction *)
1374: (*(*l_element_courant).donnee).objet))
1375: .nom_fonction, (unsigned char *)
1376: (*s_sous_objet_2).objet);
1377:
1378: liberation(s_etat_processus, s_sous_objet_1);
1379: liberation(s_etat_processus, s_sous_objet_2);
1380:
1381: if (empilement(s_etat_processus, &((*s_etat_processus)
1382: .l_base_pile), s_sous_objet) == d_erreur)
1383: {
1384: (*s_etat_processus).erreur_systeme =
1385: d_es_allocation_memoire;
1386: return(NULL);
1387: }
1388: }
1389: else
1390: {
1391: nombre_arguments = (*((struct_fonction *)
1392: (*(*l_element_courant).donnee).objet))
1393: .nombre_arguments;
1394:
1395: if ((chaine = (unsigned char *)
1396: malloc(sizeof(unsigned char))) == NULL)
1397: {
1398: (*s_etat_processus).erreur_systeme =
1399: d_es_allocation_memoire;
1400: return(NULL);
1401: }
1402:
1403: chaine[0] = d_code_fin_chaine;
1404:
1405: for(i = 0; i < nombre_arguments; i++)
1406: {
1407: if ((nombre_arguments - i) > 1)
1408: {
1409: l_liste1 = (*s_etat_processus).l_base_pile;
1410:
1411: for(j = 2; j < (nombre_arguments - i); j++)
1412: {
1413: l_liste1 = (*l_liste1).suivant;
1414: }
1415:
1416: l_liste2 = (*l_liste1).suivant;
1417: (*l_liste1).suivant = (*l_liste2).suivant;
1418: (*l_liste2).suivant = (*s_etat_processus)
1419: .l_base_pile;
1420: (*s_etat_processus).l_base_pile = l_liste2;
1421: }
1422:
1423: if (depilement(s_etat_processus,
1424: &((*s_etat_processus).l_base_pile),
1425: &s_sous_objet) == d_erreur)
1426: {
1427: return(NULL);
1428: }
1429:
1430: chaine_sauvegarde = chaine;
1431:
1432: if (strlen(chaine_sauvegarde) == 0)
1433: {
1434: if ((chaine = (unsigned char *) malloc((strlen(
1435: (unsigned char *) (*s_sous_objet).objet)
1436: + 1) * sizeof(unsigned char))) == NULL)
1437: {
1438: (*s_etat_processus).erreur_systeme =
1439: d_es_allocation_memoire;
1440: return(NULL);
1441: }
1442:
1443: sprintf(chaine, "%s", (unsigned char *)
1444: (*s_sous_objet).objet);
1445: }
1446: else
1447: {
1448: if ((chaine = (unsigned char *) malloc((strlen(
1449: chaine_sauvegarde) + 1 + strlen(
1450: (unsigned char *) (*s_sous_objet).objet)
1451: + 1) * sizeof(unsigned char))) == NULL)
1452: {
1453: (*s_etat_processus).erreur_systeme =
1454: d_es_allocation_memoire;
1455: return(NULL);
1456: }
1457:
1458: sprintf(chaine, "%s,%s", chaine_sauvegarde,
1459: (unsigned char *) (*s_sous_objet)
1460: .objet);
1461: }
1462:
1463: free(chaine_sauvegarde);
1464: liberation(s_etat_processus, s_sous_objet);
1465: }
1466:
1467: chaine_sauvegarde = chaine;
1468:
1469: if ((chaine = (unsigned char *) malloc((strlen(
1470: (*((struct_fonction *) (*(*l_element_courant)
1471: .donnee).objet)).nom_fonction) + 2 +
1472: strlen(chaine_sauvegarde) + 1) *
1473: sizeof(unsigned char))) == NULL)
1474: {
1475: (*s_etat_processus).erreur_systeme =
1476: d_es_allocation_memoire;
1477: return(NULL);
1478: }
1479:
1480: sprintf(chaine, "%s(%s)", (*((struct_fonction *)
1481: (*(*l_element_courant).donnee).objet))
1482: .nom_fonction, chaine_sauvegarde);
1483: free(chaine_sauvegarde);
1484:
1485: if ((s_sous_objet = allocation(s_etat_processus, CHN))
1486: == NULL)
1487: {
1488: (*s_etat_processus).erreur_systeme =
1489: d_es_allocation_memoire;
1490: return(NULL);
1491: }
1492:
1.58 bertrand 1493: (*s_sous_objet).objet = chaine;
1.1 bertrand 1494:
1495: if (empilement(s_etat_processus, &((*s_etat_processus)
1496: .l_base_pile), s_sous_objet) == d_erreur)
1497: {
1498: return(NULL);
1499: }
1500: }
1501: }
1502: }
1503: else
1504: {
1505: if ((s_sous_objet = allocation(s_etat_processus, CHN))
1506: == NULL)
1507: {
1508: (*s_etat_processus).erreur_systeme =
1509: d_es_allocation_memoire;
1510: return(NULL);
1511: }
1512:
1.58 bertrand 1513: if (((*s_sous_objet).objet = formateur(
1.1 bertrand 1514: s_etat_processus, 0, (*l_element_courant).donnee))
1515: == NULL)
1516: {
1517: (*s_etat_processus).erreur_systeme =
1518: d_es_allocation_memoire;
1519: return(NULL);
1520: }
1521:
1522: if (((*(*l_element_courant).donnee).type == ALG)
1523: || (((*(*l_element_courant).donnee).type == NOM)
1524: && ((*((struct_nom *) (*(*l_element_courant)
1525: .donnee).objet)).symbole == d_vrai)))
1526: {
1527: chaine_sauvegarde = (unsigned char *) (*s_sous_objet).objet;
1528:
1529: if (((*s_sous_objet).objet = malloc((strlen(
1530: chaine_sauvegarde) - 1) *
1531: sizeof(unsigned char))) == NULL)
1532: {
1533: (*s_etat_processus).erreur_systeme =
1534: d_es_allocation_memoire;
1535: return(NULL);
1536: }
1537:
1538: ptrl = chaine_sauvegarde;
1539: ptre = (unsigned char *) (*s_sous_objet).objet;
1540:
1.58 bertrand 1541: for(ptrl++, i = ((integer8) strlen(chaine_sauvegarde)) - 2;
1542: i > 0; i--, *ptre++ = *ptrl++);
1.1 bertrand 1543:
1544: (*ptre) = d_code_fin_chaine;
1545:
1546: free(chaine_sauvegarde);
1547: }
1548: else if ((*(*l_element_courant).donnee).type == CHN)
1549: {
1550: chaine_sauvegarde = (unsigned char *) (*s_sous_objet).objet;
1551:
1552: if (((*s_sous_objet).objet = malloc((strlen(
1553: chaine_sauvegarde) + 3) *
1554: sizeof(unsigned char))) == NULL)
1555: {
1556: (*s_etat_processus).erreur_systeme =
1557: d_es_allocation_memoire;
1558: return(NULL);
1559: }
1560:
1561: sprintf((unsigned char *) (*s_sous_objet).objet,
1562: "\"%s\"", chaine_sauvegarde);
1563:
1564: free(chaine_sauvegarde);
1565: }
1566:
1567: if (empilement(s_etat_processus, &((*s_etat_processus)
1568: .l_base_pile), s_sous_objet) == d_erreur)
1569: {
1570: return(NULL);
1571: }
1572: }
1573:
1574: l_element_courant = (*l_element_courant).suivant;
1575: }
1576:
1577: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1578: &s_sous_objet) == d_erreur)
1579: {
1580: return(NULL);
1581: }
1582:
1583: if ((chaine = (unsigned char *) malloc((strlen((unsigned char *)
1584: (*s_sous_objet).objet) + 2 + 1) * sizeof(unsigned char)))
1585: == NULL)
1586: {
1587: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1588: return(NULL);
1589: }
1590:
1591: sprintf(chaine, "'%s'", (unsigned char *) (*s_sous_objet).objet);
1592: liberation(s_etat_processus, s_sous_objet);
1593: }
1594: else if ((*s_objet).type == BIN)
1595: {
1596:
1597: /*
1598: --------------------------------------------------------------------------------
1599: Entier binaire en base 2, 8, 10 ou 16
1600: --------------------------------------------------------------------------------
1601: */
1602:
1603: masque_binaire = masque_entiers_binaires(s_etat_processus);
1604:
1605: if ((test_cfsf(s_etat_processus, 43) == d_faux) &&
1606: (test_cfsf(s_etat_processus, 44) == d_faux))
1607: {
1608:
1609: /*
1610: -- Base décimale ---------------------------------------------------------------
1611: */
1612:
1.63 bertrand 1613: sprintf(tampon, "%llu", (*((unsigned long long *)
1.1 bertrand 1614: ((*s_objet).objet))) & masque_binaire);
1615: strcpy(base, "d");
1616: }
1617: else if ((test_cfsf(s_etat_processus, 43) == d_vrai) &&
1618: (test_cfsf(s_etat_processus, 44) == d_faux))
1619: {
1620:
1621: /*
1622: -- Base octale -----------------------------------------------------------------
1623: */
1624:
1.63 bertrand 1625: sprintf(tampon, "%llo", (*((unsigned long long *)
1.1 bertrand 1626: ((*s_objet).objet))) & masque_binaire);
1627: strcpy(base, "o");
1628: }
1629: else if (test_cfsf(s_etat_processus, 44) == d_vrai)
1630: {
1631:
1632: /*
1633: -- Bases hexadécimale et binaire -----------------------------------------------
1634: */
1635:
1.63 bertrand 1636: sprintf(tampon, "%llX", (*((unsigned long long *)
1.1 bertrand 1637: ((*s_objet).objet))) & masque_binaire);
1638:
1639: if (test_cfsf(s_etat_processus, 43) == d_vrai)
1640: {
1641: strcpy(base, "h");
1642: }
1643: else
1644: {
1645: chaine = (unsigned char *) malloc((strlen(tampon) + 1)
1646: * sizeof(unsigned char));
1647:
1648: if (chaine == NULL)
1649: {
1650: (*s_etat_processus).erreur_systeme =
1651: d_es_allocation_memoire;
1652: return(NULL);
1653: }
1654:
1655: strcpy(chaine, tampon);
1656: tampon[0] = 0;
1657:
1.58 bertrand 1658: for(i = 0; i < (integer8) strlen(chaine); i++)
1.1 bertrand 1659: {
1660: switch(chaine[i])
1661: {
1662: case '0' :
1663: {
1664: strcat(tampon, (i != 0) ? "0000" : "0");
1665: break;
1666: }
1667: case '1' :
1668: {
1669: strcat(tampon, (i != 0) ? "0001" : "1");
1670: break;
1671: }
1672: case '2' :
1673: {
1674: strcat(tampon, (i != 0) ? "0010" : "10");
1675: break;
1676: }
1677: case '3' :
1678: {
1679: strcat(tampon, (i != 0) ? "0011" : "11");
1680: break;
1681: }
1682: case '4' :
1683: {
1684: strcat(tampon, (i != 0) ? "0100" : "100");
1685: break;
1686: }
1687: case '5' :
1688: {
1689: strcat(tampon, (i != 0) ? "0101" : "101");
1690: break;
1691: }
1692: case '6' :
1693: {
1694: strcat(tampon, (i != 0) ? "0110" : "110");
1695: break;
1696: }
1697: case '7' :
1698: {
1699: strcat(tampon, (i != 0) ? "0111" : "111");
1700: break;
1701: }
1702: case '8' :
1703: {
1704: strcat(tampon, "1000");
1705: break;
1706: }
1707: case '9' :
1708: {
1709: strcat(tampon, "1001");
1710: break;
1711: }
1712: case 'A' :
1713: {
1714: strcat(tampon, "1010");
1715: break;
1716: }
1717: case 'B' :
1718: {
1719: strcat(tampon, "1011");
1720: break;
1721: }
1722: case 'C' :
1723: {
1724: strcat(tampon, "1100");
1725: break;
1726: }
1727: case 'D' :
1728: {
1729: strcat(tampon, "1101");
1730: break;
1731: }
1732: case 'E' :
1733: {
1734: strcat(tampon, "1110");
1735: break;
1736: }
1737: case 'F' :
1738: {
1739: strcat(tampon, "1111");
1740: break;
1741: }
1742: }
1743: }
1744:
1745: free(chaine);
1746: strcpy(base, "b");
1747: }
1748: }
1749:
1750: chaine = (unsigned char *) malloc((strlen(tampon) + 4)
1751: * sizeof(unsigned char));
1752:
1753: if (chaine == NULL)
1754: {
1755: (*s_etat_processus).erreur_systeme =
1756: d_es_allocation_memoire;
1757: return(NULL);
1758: }
1759:
1760: strcpy(chaine, "# ");
1761:
1762: strcat(chaine, tampon);
1763: strcat(chaine, base);
1764: }
1765: else if ((*s_objet).type == CHN)
1766: {
1767:
1768: /*
1769: --------------------------------------------------------------------------------
1770: Chaîne de caractères
1771: --------------------------------------------------------------------------------
1772: */
1773:
1.23 bertrand 1774: if (((*s_etat_processus).autorisation_conversion_chaine == 'Y') &&
1775: (test_cfsf(s_etat_processus, 34) == d_vrai))
1.5 bertrand 1776: {
1.41 bertrand 1777: if ((chaine = formateur_flux(s_etat_processus,
1778: (unsigned char *) (*s_objet).objet, &longueur_chaine))
1779: == NULL)
1.5 bertrand 1780: {
1.41 bertrand 1781: return(NULL);
1.5 bertrand 1782: }
1.41 bertrand 1783: }
1784: else
1785: {
1786: if ((chaine = malloc((strlen((unsigned char *)
1787: ((*s_objet).objet)) + 1) * sizeof(unsigned char))) == NULL)
1.5 bertrand 1788: {
1789: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1790: return(NULL);
1791: }
1.41 bertrand 1792:
1.5 bertrand 1793: strcpy(chaine, (unsigned char *) ((*s_objet).objet));
1794: }
1.1 bertrand 1795: }
1796: else if ((*s_objet).type == CPL)
1797: {
1798:
1799: /*
1800: --------------------------------------------------------------------------------
1801: Complexe
1802: --------------------------------------------------------------------------------
1803: */
1804:
1.58 bertrand 1805: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 1806: ((struct_complexe16 *) ((*s_objet).objet)), 'C');
1807:
1808: if (chaine_formatee == NULL)
1809: {
1810: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1811: return(NULL);
1812: }
1813:
1814: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
1815: + 1) * sizeof(unsigned char));
1816:
1817: if (chaine == NULL)
1818: {
1819: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1820: return(NULL);
1821: }
1822:
1823: strcpy(chaine, chaine_formatee);
1824: free(chaine_formatee);
1825: }
1826: else if ((*s_objet).type == RPN)
1827: {
1828:
1829: /*
1830: --------------------------------------------------------------------------------
1831: Définition
1832: --------------------------------------------------------------------------------
1833: */
1834:
1835: l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
1836: chaine_sauvegarde = chaine;
1837:
1838: while(l_element_courant != NULL)
1839: {
1.57 bertrand 1840: if ((chaine_formatee = formateur(s_etat_processus, offset_initial,
1.1 bertrand 1841: (*l_element_courant).donnee)) == NULL)
1842: {
1843: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1844: return(NULL);
1845: }
1846:
1847: if ((*(*l_element_courant).donnee).type == CHN)
1848: {
1849: chaine_tampon = chaine_formatee;
1850:
1851: if ((chaine_formatee = (unsigned char *) malloc((strlen(
1852: chaine_tampon) + 3) * sizeof(unsigned char))) == NULL)
1853: {
1854: (*s_etat_processus).erreur_systeme =
1855: d_es_allocation_memoire;
1856: return(NULL);
1857: }
1858:
1859: sprintf(chaine_formatee, "\"%s\"", chaine_tampon);
1860: free(chaine_tampon);
1861: }
1862:
1863: l_element_courant = (*l_element_courant).suivant;
1864:
1865: if (chaine != NULL)
1866: {
1867: chaine_sauvegarde = chaine;
1868:
1869: if ((chaine = (unsigned char *) malloc((strlen(
1870: chaine_sauvegarde) + strlen(chaine_formatee) + 2) *
1871: sizeof(unsigned char))) == NULL)
1872: {
1873: (*s_etat_processus).erreur_systeme =
1874: d_es_allocation_memoire;
1875: return(NULL);
1876: }
1877:
1878: strcpy(chaine, chaine_sauvegarde);
1879: free(chaine_sauvegarde);
1880: strcat(chaine, " ");
1881: strcat(chaine, chaine_formatee);
1882: free(chaine_formatee);
1883: }
1884: else
1885: {
1886: chaine = chaine_formatee;
1887: }
1888: }
1889:
1890: chaine_sauvegarde = chaine;
1891: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde) + 1) *
1892: sizeof(unsigned char));
1893:
1894: if (chaine == NULL)
1895: {
1896: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1897: return(NULL);
1898: }
1899:
1900: chaine_sauvegarde[strlen(chaine_sauvegarde)] = d_code_fin_chaine;
1901: strcpy(chaine, chaine_sauvegarde);
1902: free(chaine_sauvegarde);
1903: }
1904: else if ((*s_objet).type == INT)
1905: {
1906:
1907: /*
1908: --------------------------------------------------------------------------------
1909: Entier
1910: --------------------------------------------------------------------------------
1911: */
1912:
1.58 bertrand 1913: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 1914: ((integer8 *) ((*s_objet).objet)), 'I');
1915:
1916: if (chaine_formatee == NULL)
1917: {
1918: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1919: return(NULL);
1920: }
1921:
1922: chaine = (unsigned char *) malloc((strlen(chaine_formatee) + 1)
1923: * sizeof(unsigned char));
1924:
1925: if (chaine == NULL)
1926: {
1927: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1928: return(NULL);
1929: }
1930:
1931: strcpy(chaine, chaine_formatee);
1932: free(chaine_formatee);
1933: }
1934: else if ((*s_objet).type == FCT)
1935: {
1936:
1937: /*
1938: --------------------------------------------------------------------------------
1939: Fonction
1940: --------------------------------------------------------------------------------
1941: */
1942:
1943: chaine = (unsigned char *) malloc((strlen((*((struct_fonction *)
1944: ((*s_objet).objet))).nom_fonction) + 1) *
1945: sizeof(unsigned char));
1946:
1947: if (chaine == NULL)
1948: {
1949: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1950: return(NULL);
1951: }
1952:
1953: strcpy(chaine, (unsigned char *) (*((struct_fonction *)
1954: ((*s_objet).objet))).nom_fonction);
1955: }
1956: else if ((*s_objet).type == TBL)
1957: {
1958:
1959: /*
1960: --------------------------------------------------------------------------------
1961: Tableau
1962: --------------------------------------------------------------------------------
1963: */
1964:
1965: chaine = (unsigned char *) malloc(4 * sizeof(unsigned char));
1966:
1967: if (chaine == NULL)
1968: {
1969: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1970: return(NULL);
1971: }
1972:
1973: strcpy(chaine, "<[ ");
1.58 bertrand 1974: offset = ((integer8) strlen(chaine)) + offset_initial;
1.1 bertrand 1975:
1976: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
1977: .nombre_elements; i++)
1978: {
1979: chaine_sauvegarde = chaine;
1.60 bertrand 1980: chaine_formatee = formateur(s_etat_processus, (long) offset,
1.1 bertrand 1981: (*((struct_tableau *) (*s_objet).objet)).elements[i]);
1982:
1983: if (chaine_formatee == NULL)
1984: {
1985: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1986: return(NULL);
1987: }
1988:
1989: if ((*(*((struct_tableau *) (*s_objet).objet)).elements[i])
1990: .type == CHN)
1991: {
1992: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
1993: + strlen(chaine_sauvegarde) + 3)
1994: * sizeof(unsigned char));
1995:
1996: if (chaine == NULL)
1997: {
1998: (*s_etat_processus).erreur_systeme =
1999: d_es_allocation_memoire;
2000: return(NULL);
2001: }
2002:
2003: strcpy(chaine, chaine_sauvegarde);
2004: free(chaine_sauvegarde);
2005: strcat(chaine, "\"");
2006: strcat(chaine, chaine_formatee);
2007: free(chaine_formatee);
2008: strcat(chaine, "\"");
2009: }
2010: else if ((*(*((struct_tableau *) (*s_objet).objet))
2011: .elements[i]).type == CHN)
2012: {
2013: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
2014: + strlen(chaine_sauvegarde) + 1)
2015: * sizeof(unsigned char));
2016:
2017: if (chaine == NULL)
2018: {
2019: (*s_etat_processus).erreur_systeme =
2020: d_es_allocation_memoire;
2021: return(NULL);
2022: }
2023:
2024: sprintf(chaine, "%s%s", chaine_sauvegarde, chaine_formatee);
2025: free(chaine_sauvegarde);
2026: free(chaine_formatee);
2027: }
2028: else
2029: {
2030: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
2031: + strlen(chaine_sauvegarde) + 1)
2032: * sizeof(unsigned char));
2033:
2034: if (chaine == NULL)
2035: {
2036: (*s_etat_processus).erreur_systeme =
2037: d_es_allocation_memoire;
2038: return(NULL);
2039: }
2040:
2041: sprintf(chaine, "%s%s", chaine_sauvegarde, chaine_formatee);
2042: free(chaine_sauvegarde);
2043: free(chaine_formatee);
2044: }
2045:
2046: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2047: {
2048: chaine_sauvegarde = chaine;
2049:
2050: chaine = (unsigned char *) malloc(
2051: (strlen(chaine_sauvegarde) + 2)
2052: * sizeof(unsigned char));
2053:
2054: if (chaine == NULL)
2055: {
2056: (*s_etat_processus).erreur_systeme =
2057: d_es_allocation_memoire;
2058: return(NULL);
2059: }
2060:
2061: strcpy(chaine, chaine_sauvegarde);
2062: free(chaine_sauvegarde);
2063: strcat(chaine, "\n");
2064:
2065: if ((*((struct_tableau *) (*s_objet).objet))
2066: .nombre_elements != (i + 1))
2067: {
2068: chaine_sauvegarde = chaine;
2069:
2070: chaine = (unsigned char *) malloc(
1.58 bertrand 2071: (strlen(chaine_sauvegarde) + 1 + ((size_t) offset))
1.1 bertrand 2072: * sizeof(unsigned char));
2073:
2074: if (chaine == NULL)
2075: {
2076: (*s_etat_processus).erreur_systeme =
2077: d_es_allocation_memoire;
2078: return(NULL);
2079: }
2080:
2081: strcpy(chaine, chaine_sauvegarde);
2082: free(chaine_sauvegarde);
2083: ptre = &(chaine[strlen(chaine)]);
2084:
2085: for(k = 0; k < offset; k++, *(ptre++) = ' ');
2086:
2087: (*ptre) = d_code_fin_chaine;
2088: }
2089: }
2090: else
2091: {
2092: if ((*((struct_tableau *) (*s_objet).objet))
2093: .nombre_elements != (i + 1))
2094: {
2095: chaine_sauvegarde = chaine;
2096:
2097: chaine = (unsigned char *) malloc(
2098: (strlen(chaine_sauvegarde) + 2)
2099: * sizeof(unsigned char));
2100:
2101: if (chaine == NULL)
2102: {
2103: (*s_etat_processus).erreur_systeme =
2104: d_es_allocation_memoire;
2105: return(NULL);
2106: }
2107:
2108: strcpy(chaine, chaine_sauvegarde);
2109: free(chaine_sauvegarde);
2110: strcat(chaine, " ");
2111: }
2112: }
2113: }
2114:
2115: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2116: {
2117: if (chaine[strlen(chaine) - 1] == '\n')
2118: {
2119: chaine[strlen(chaine) - 1] = d_code_fin_chaine;
2120: }
2121: }
2122:
2123: if ((*((struct_tableau *) (*s_objet).objet)).nombre_elements != 0)
2124: {
2125: chaine_sauvegarde = chaine;
2126: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde) + 4)
2127: * sizeof(unsigned char));
2128:
2129: if (chaine == NULL)
2130: {
2131: (*s_etat_processus).erreur_systeme =
2132: d_es_allocation_memoire;
2133: return(NULL);
2134: }
2135:
2136: strcpy(chaine, chaine_sauvegarde);
2137: free(chaine_sauvegarde);
2138: strcat(chaine, " ]>");
2139: }
2140: else
2141: {
2142: chaine_sauvegarde = chaine;
2143: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde) + 3)
2144: * sizeof(unsigned char));
2145:
2146: if (chaine == NULL)
2147: {
2148: (*s_etat_processus).erreur_systeme =
2149: d_es_allocation_memoire;
2150: return(NULL);
2151: }
2152:
2153: strcpy(chaine, chaine_sauvegarde);
2154: free(chaine_sauvegarde);
2155: strcat(chaine, "]>");
2156: }
2157: }
2158: else if ((*s_objet).type == LST)
2159: {
2160:
2161: /*
2162: --------------------------------------------------------------------------------
2163: Liste
2164: --------------------------------------------------------------------------------
2165: */
2166:
2167: chaine = (unsigned char *) malloc(3 * sizeof(unsigned char));
2168:
2169: if (chaine == NULL)
2170: {
2171: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2172: return(NULL);
2173: }
2174:
2175: strcpy(chaine, "{ ");
2176:
2177: l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
2178: nombre_elements = 0;
1.58 bertrand 2179: offset = ((integer8) strlen(chaine)) + offset_initial;
1.1 bertrand 2180:
2181: while(l_element_courant != NULL)
2182: {
2183: chaine_sauvegarde = chaine;
1.60 bertrand 2184: chaine_formatee = formateur(s_etat_processus, (long) offset,
1.1 bertrand 2185: (*l_element_courant).donnee);
2186:
2187: if (chaine_formatee == NULL)
2188: {
2189: (*s_etat_processus).erreur_systeme =
2190: d_es_allocation_memoire;
2191: return(NULL);
2192: }
2193:
2194: if ((*(*l_element_courant).donnee).type == CHN)
2195: {
2196: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
2197: + strlen(chaine_sauvegarde) + 3)
2198: * sizeof(unsigned char));
2199:
2200: if (chaine == NULL)
2201: {
2202: (*s_etat_processus).erreur_systeme =
2203: d_es_allocation_memoire;
2204: return(NULL);
2205: }
2206:
2207: strcpy(chaine, chaine_sauvegarde);
2208: free(chaine_sauvegarde);
2209: strcat(chaine, "\"");
2210: strcat(chaine, chaine_formatee);
2211: free(chaine_formatee);
2212: strcat(chaine, "\"");
2213: }
2214: else if ((*(*l_element_courant).donnee).type == NOM)
2215: {
2216: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
2217: + strlen(chaine_sauvegarde) + 1)
2218: * sizeof(unsigned char));
2219:
2220: if (chaine == NULL)
2221: {
2222: (*s_etat_processus).erreur_systeme =
2223: d_es_allocation_memoire;
2224: return(NULL);
2225: }
2226:
2227: sprintf(chaine, "%s%s", chaine_sauvegarde, chaine_formatee);
2228: free(chaine_sauvegarde);
2229: free(chaine_formatee);
2230: }
2231: else
2232: {
2233: chaine = (unsigned char *) malloc((strlen(chaine_formatee)
2234: + strlen(chaine_sauvegarde) + 1)
2235: * sizeof(unsigned char));
2236:
2237: if (chaine == NULL)
2238: {
2239: (*s_etat_processus).erreur_systeme =
2240: d_es_allocation_memoire;
2241: return(NULL);
2242: }
2243:
2244: sprintf(chaine, "%s%s", chaine_sauvegarde, chaine_formatee);
2245: free(chaine_sauvegarde);
2246: free(chaine_formatee);
2247: }
2248:
2249: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2250: {
2251: chaine_sauvegarde = chaine;
2252:
2253: chaine = (unsigned char *) malloc(
2254: (strlen(chaine_sauvegarde) + 2)
2255: * sizeof(unsigned char));
2256:
2257: if (chaine == NULL)
2258: {
2259: (*s_etat_processus).erreur_systeme =
2260: d_es_allocation_memoire;
2261: return(NULL);
2262: }
2263:
2264: strcpy(chaine, chaine_sauvegarde);
2265: free(chaine_sauvegarde);
2266: strcat(chaine, "\n");
2267:
2268: if ((*l_element_courant).suivant != NULL)
2269: {
2270: chaine_sauvegarde = chaine;
2271:
2272: chaine = (unsigned char *) malloc(
1.58 bertrand 2273: (strlen(chaine_sauvegarde) + 1 + ((size_t) offset))
1.1 bertrand 2274: * sizeof(unsigned char));
2275:
2276: if (chaine == NULL)
2277: {
2278: (*s_etat_processus).erreur_systeme =
2279: d_es_allocation_memoire;
2280: return(NULL);
2281: }
2282:
2283: strcpy(chaine, chaine_sauvegarde);
2284: free(chaine_sauvegarde);
2285: ptre = &(chaine[strlen(chaine)]);
2286:
2287: for(k = 0; k < offset; k++, *(ptre++) = ' ');
2288:
2289: (*ptre) = d_code_fin_chaine;
2290: }
2291: }
2292: else
2293: {
2294: if ((*l_element_courant).suivant != NULL)
2295: {
2296: chaine_sauvegarde = chaine;
2297:
2298: chaine = (unsigned char *) malloc(
2299: (strlen(chaine_sauvegarde) + 2)
2300: * sizeof(unsigned char));
2301:
2302: if (chaine == NULL)
2303: {
2304: (*s_etat_processus).erreur_systeme =
2305: d_es_allocation_memoire;
2306: return(NULL);
2307: }
2308:
2309: strcpy(chaine, chaine_sauvegarde);
2310: free(chaine_sauvegarde);
2311: strcat(chaine, " ");
2312: }
2313: }
2314:
2315: nombre_elements++;
2316: l_element_courant = (*l_element_courant).suivant;
2317: }
2318:
2319: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2320: {
2321: if (chaine[strlen(chaine) - 1] == '\n')
2322: {
2323: chaine[strlen(chaine) - 1] = d_code_fin_chaine;
2324: }
2325: }
2326:
2327: if (nombre_elements != 0)
2328: {
2329: chaine_sauvegarde = chaine;
2330: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde) + 3)
2331: * sizeof(unsigned char));
2332:
2333: if (chaine == NULL)
2334: {
2335: (*s_etat_processus).erreur_systeme =
2336: d_es_allocation_memoire;
2337: return(NULL);
2338: }
2339:
2340: strcpy(chaine, chaine_sauvegarde);
2341: free(chaine_sauvegarde);
2342: strcat(chaine, " }");
2343: }
2344: else
2345: {
2346: chaine_sauvegarde = chaine;
2347: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde) + 2)
2348: * sizeof(unsigned char));
2349:
2350: if (chaine == NULL)
2351: {
2352: (*s_etat_processus).erreur_systeme =
2353: d_es_allocation_memoire;
2354: return(NULL);
2355: }
2356:
2357: strcpy(chaine, chaine_sauvegarde);
2358: free(chaine_sauvegarde);
2359: strcat(chaine, "}");
2360: }
2361: }
2362: else if ((*s_objet).type == MCX)
2363: {
2364:
2365: /*
2366: --------------------------------------------------------------------------------
2367: Matrice complexe
2368: --------------------------------------------------------------------------------
2369: */
2370:
2371: nombre_lignes = (*((struct_matrice *) ((*s_objet).objet)))
2372: .nombre_lignes;
2373: nombre_colonnes = (*((struct_matrice *) ((*s_objet).objet)))
2374: .nombre_colonnes;
2375:
2376: chaine = (unsigned char *) malloc(3 * sizeof(unsigned char));
2377:
2378: if (chaine != NULL)
2379: {
2380: strcpy(chaine, "[[");
1.58 bertrand 2381: offset = ((integer8) strlen(chaine)) + offset_initial - 1;
1.1 bertrand 2382:
1.59 bertrand 2383: if ((longueurs_maximales = malloc(sizeof(integer8) * 2 *
1.58 bertrand 2384: ((size_t) nombre_colonnes))) == NULL)
1.1 bertrand 2385: {
2386: (*s_etat_processus).erreur_systeme =
2387: d_es_allocation_memoire;
2388: return(NULL);
2389: }
2390:
2391: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2392: {
2393: for(j = 0; j < (2 * nombre_colonnes); j++)
2394: {
2395: longueurs_maximales[j] = 0;
2396: }
2397:
2398: for(i = 0; i < nombre_lignes; i++)
2399: {
2400: for(j = 0; j < nombre_colonnes; j++)
2401: {
2402: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2403: &(((struct_complexe16 **)
1.1 bertrand 2404: ((*((struct_matrice *)
2405: ((*s_objet).objet))).tableau))[i][j]), 'C');
2406:
2407: if (chaine_formatee == NULL)
2408: {
2409: (*s_etat_processus).erreur_systeme =
2410: d_es_allocation_memoire;
2411: return(NULL);
2412: }
2413:
1.58 bertrand 2414: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2415: longueur_decimale_courante = 0;
2416:
2417: if ((ptrl = index(chaine_formatee,
2418: (test_cfsf(s_etat_processus, 48) == d_vrai)
2419: ? '.' : ',')) != NULL)
2420: {
2421: longueur_decimale_courante = longueur_courante
2422: - (ptrl - chaine_formatee);
2423: longueur_courante = ptrl - chaine_formatee;
2424: }
2425:
2426: free(chaine_formatee);
2427:
2428: if (longueurs_maximales[2 * j] < longueur_courante)
2429: {
2430: longueurs_maximales[2 * j] = longueur_courante;
2431: }
2432:
2433: if (longueurs_maximales[(2 * j) + 1] <
2434: longueur_decimale_courante)
2435: {
2436: longueurs_maximales[(2 * j) + 1] =
2437: longueur_decimale_courante;
2438: }
2439: }
2440: }
2441: }
2442:
2443: for(i = 0; i < nombre_lignes; i++)
2444: {
2445: for(j = 0; j < nombre_colonnes; j++)
2446: {
2447: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2448: &(((struct_complexe16 **)
1.1 bertrand 2449: ((*((struct_matrice *)
2450: ((*s_objet).objet))).tableau))[i][j]), 'C');
2451:
2452: if (chaine_formatee == NULL)
2453: {
2454: (*s_etat_processus).erreur_systeme =
2455: d_es_allocation_memoire;
2456: return(NULL);
2457: }
2458:
1.58 bertrand 2459: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2460: longueur_decimale_courante = 0;
2461:
2462: if ((ptrl = index(chaine_formatee,
2463: (test_cfsf(s_etat_processus, 48) == d_vrai)
2464: ? '.' : ',')) != NULL)
2465: {
2466: longueur_decimale_courante = longueur_courante
2467: - (ptrl - chaine_formatee);
2468: longueur_courante = ptrl - chaine_formatee;
2469: }
2470:
2471: chaine_sauvegarde = chaine;
2472:
2473: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2474: {
2475:
2476: chaine = (unsigned char *) malloc(
2477: (strlen(chaine_sauvegarde) +
1.58 bertrand 2478: ((size_t) longueur_courante) +
2479: ((size_t) longueur_decimale_courante) +
2480: ((size_t) longueurs_maximales[2 * j]) +
2481: ((size_t) longueurs_maximales[(2 * j) + 1]) + 2)
1.1 bertrand 2482: * sizeof(unsigned char));
2483:
2484: if (chaine == NULL)
2485: {
2486: (*s_etat_processus).erreur_systeme =
2487: d_es_allocation_memoire;
2488: return(NULL);
2489: }
2490:
2491: strcpy(chaine, chaine_sauvegarde);
2492: free(chaine_sauvegarde);
2493: strcat(chaine, " ");
2494:
2495: ptre = &(chaine[strlen(chaine)]);
2496:
2497: for (k = 0; k < (longueurs_maximales[2 * j]
2498: - longueur_courante); k++, *(ptre++) = ' ');
2499:
2500: (*ptre) = d_code_fin_chaine;
2501: strcat(chaine, chaine_formatee);
2502: ptre = &(chaine[strlen(chaine)]);
2503:
2504: for(k = 0; k < (longueurs_maximales[(2 * j) + 1]
2505: - longueur_decimale_courante);
2506: k++, *(ptre++) = ' ');
2507:
2508: (*ptre) = d_code_fin_chaine;
2509: }
2510: else
2511: {
2512: chaine = (unsigned char *) malloc(
2513: (strlen(chaine_sauvegarde) +
1.58 bertrand 2514: ((size_t) longueur_courante) +
2515: ((size_t) longueur_decimale_courante)
1.1 bertrand 2516: + 2) * sizeof(unsigned char));
2517:
2518: if (chaine == NULL)
2519: {
2520: (*s_etat_processus).erreur_systeme =
2521: d_es_allocation_memoire;
2522: return(NULL);
2523: }
2524:
2525: strcpy(chaine, chaine_sauvegarde);
2526: free(chaine_sauvegarde);
2527: strcat(chaine, " ");
2528: strcat(chaine, chaine_formatee);
2529: }
2530:
2531: free(chaine_formatee);
2532: }
2533:
2534: chaine_sauvegarde = chaine;
2535:
2536: if (i != (nombre_lignes - 1))
2537: {
2538: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2539: {
2540: chaine = (unsigned char *) malloc(
1.58 bertrand 2541: (strlen(chaine_sauvegarde) + 5 +
2542: ((size_t) offset)) * sizeof(unsigned char));
1.1 bertrand 2543:
2544: if (chaine == NULL)
2545: {
2546: (*s_etat_processus).erreur_systeme =
2547: d_es_allocation_memoire;
2548: return(NULL);
2549: }
2550:
2551: strcpy(chaine, chaine_sauvegarde);
2552: free(chaine_sauvegarde);
2553: strcat(chaine, " ]\n");
2554: ptre = &(chaine[strlen(chaine)]);
2555:
2556: for(k = 0; k < offset; k++, *(ptre++) = ' ');
2557:
2558: (*ptre) = d_code_fin_chaine;
2559: strcat(chaine, "[");
2560: }
2561: else
2562: {
2563: chaine = (unsigned char *) malloc(
2564: (strlen(chaine_sauvegarde) + 4)
2565: * sizeof(unsigned char));
2566:
2567: if (chaine == NULL)
2568: {
2569: (*s_etat_processus).erreur_systeme =
2570: d_es_allocation_memoire;
2571: return(NULL);
2572: }
2573:
2574: strcpy(chaine, chaine_sauvegarde);
2575: free(chaine_sauvegarde);
2576: strcat(chaine, " ][");
2577: }
2578: }
2579: }
2580:
2581: free(longueurs_maximales);
2582:
2583: chaine_sauvegarde = chaine;
2584: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde)
2585: + 4) * sizeof(unsigned char));
2586:
2587: if (chaine == NULL)
2588: {
2589: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2590: return(NULL);
2591: }
2592:
2593: strcpy(chaine, chaine_sauvegarde);
2594: free(chaine_sauvegarde);
2595: strcat(chaine, " ]]");
2596: }
2597: }
2598: else if ((*s_objet).type == MIN)
2599: {
2600:
2601: /*
2602: --------------------------------------------------------------------------------
2603: Matrice entière
2604: --------------------------------------------------------------------------------
2605: */
2606:
2607: nombre_lignes = (*((struct_matrice *) ((*s_objet).objet)))
2608: .nombre_lignes;
2609: nombre_colonnes = (*((struct_matrice *) ((*s_objet).objet)))
2610: .nombre_colonnes;
2611:
2612: chaine = (unsigned char *) malloc(3 * sizeof(unsigned char));
2613:
2614: if (chaine != NULL)
2615: {
2616: strcpy(chaine, "[[");
1.58 bertrand 2617: offset = ((integer8) strlen(chaine)) + offset_initial - 1;
1.1 bertrand 2618:
1.59 bertrand 2619: if ((longueurs_maximales = malloc(sizeof(integer8) *
1.58 bertrand 2620: ((size_t) nombre_colonnes))) == NULL)
1.1 bertrand 2621: {
2622: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2623: return(NULL);
2624: }
2625:
2626: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2627: {
2628: for(j = 0; j < nombre_colonnes; j++)
2629: {
2630: longueurs_maximales[j] = 0;
2631: }
2632:
2633: for(i = 0; i < nombre_lignes; i++)
2634: {
2635: for(j = 0; j < nombre_colonnes; j++)
2636: {
2637: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2638: &(((integer8 **) ((*((struct_matrice *)
1.1 bertrand 2639: ((*s_objet).objet))).tableau))[i][j]), 'I');
2640:
2641: if (chaine_formatee == NULL)
2642: {
2643: (*s_etat_processus).erreur_systeme =
2644: d_es_allocation_memoire;
2645: return(NULL);
2646: }
2647:
1.58 bertrand 2648: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2649: free(chaine_formatee);
2650:
2651: if (longueurs_maximales[j] < longueur_courante)
2652: {
2653: longueurs_maximales[j] = longueur_courante;
2654: }
2655: }
2656: }
2657: }
2658:
2659: for(i = 0; i < nombre_lignes; i++)
2660: {
2661: for(j = 0; j < nombre_colonnes; j++)
2662: {
2663: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2664: &(((integer8 **) ((*((struct_matrice *)
1.1 bertrand 2665: ((*s_objet).objet))).tableau))[i][j]), 'I');
2666:
2667: if (chaine_formatee == NULL)
2668: {
2669: (*s_etat_processus).erreur_systeme =
2670: d_es_allocation_memoire;
2671: return(NULL);
2672: }
2673:
1.58 bertrand 2674: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2675: chaine_sauvegarde = chaine;
2676:
2677: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2678: {
2679: chaine = (unsigned char *) malloc(
1.58 bertrand 2680: (strlen(chaine_sauvegarde) +
2681: ((size_t) longueur_courante)
2682: + ((size_t) longueurs_maximales[j]) + 2)
1.1 bertrand 2683: * sizeof(unsigned char));
2684:
2685: if (chaine == NULL)
2686: {
2687: (*s_etat_processus).erreur_systeme =
2688: d_es_allocation_memoire;
2689: return(NULL);
2690: }
2691:
2692: strcpy(chaine, chaine_sauvegarde);
2693: free(chaine_sauvegarde);
2694: strcat(chaine, " ");
2695:
2696: ptre = &(chaine[strlen(chaine)]);
2697:
2698: for(k = 0; k < (longueurs_maximales[j]
2699: - longueur_courante); k++, *(ptre++) = ' ');
2700:
2701: (*ptre) = d_code_fin_chaine;
2702: }
2703: else
2704: {
2705: chaine = (unsigned char *) malloc(
1.58 bertrand 2706: (strlen(chaine_sauvegarde) +
2707: ((size_t) longueur_courante)
1.1 bertrand 2708: + 2) * sizeof(unsigned char));
2709:
2710: if (chaine == NULL)
2711: {
2712: (*s_etat_processus).erreur_systeme =
2713: d_es_allocation_memoire;
2714: return(NULL);
2715: }
2716:
2717: strcpy(chaine, chaine_sauvegarde);
2718: free(chaine_sauvegarde);
2719: strcat(chaine, " ");
2720: }
2721:
2722: strcat(chaine, chaine_formatee);
2723: free(chaine_formatee);
2724: }
2725:
2726: chaine_sauvegarde = chaine;
2727:
2728: if (i != (nombre_lignes - 1))
2729: {
2730: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2731: {
2732: chaine = (unsigned char *) malloc(
1.58 bertrand 2733: (strlen(chaine_sauvegarde) + 5 +
2734: ((size_t) offset)) * sizeof(unsigned char));
1.1 bertrand 2735:
2736: if (chaine == NULL)
2737: {
2738: (*s_etat_processus).erreur_systeme =
2739: d_es_allocation_memoire;
2740: return(NULL);
2741: }
2742:
2743: strcpy(chaine, chaine_sauvegarde);
2744: free(chaine_sauvegarde);
2745: strcat(chaine, " ]\n");
2746: ptre = &(chaine[strlen(chaine)]);
2747:
2748: for(k = 0; k < offset; k++, *(ptre++) = ' ');
2749:
2750: (*ptre) = d_code_fin_chaine;
2751: strcat(chaine, "[");
2752: }
2753: else
2754: {
2755: chaine = (unsigned char *) malloc(
2756: (strlen(chaine_sauvegarde) + 4)
2757: * sizeof(unsigned char));
2758:
2759: if (chaine == NULL)
2760: {
2761: (*s_etat_processus).erreur_systeme =
2762: d_es_allocation_memoire;
2763: return(NULL);
2764: }
2765:
2766: strcpy(chaine, chaine_sauvegarde);
2767: free(chaine_sauvegarde);
2768: strcat(chaine, " ][");
2769: }
2770: }
2771: }
2772:
2773: free(longueurs_maximales);
2774:
2775: chaine_sauvegarde = chaine;
2776: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde)
2777: + 4) * sizeof(unsigned char));
2778:
2779: if (chaine == NULL)
2780: {
2781: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2782: return(NULL);
2783: }
2784:
2785: strcpy(chaine, chaine_sauvegarde);
2786: free(chaine_sauvegarde);
2787: strcat(chaine, " ]]");
2788: }
2789: }
2790: else if ((*s_objet).type == MRL)
2791: {
2792:
2793: /*
2794: --------------------------------------------------------------------------------
2795: Matrice réelle
2796: --------------------------------------------------------------------------------
2797: */
2798:
2799: nombre_lignes = (*((struct_matrice *) ((*s_objet).objet)))
2800: .nombre_lignes;
2801: nombre_colonnes = (*((struct_matrice *) ((*s_objet).objet)))
2802: .nombre_colonnes;
2803:
2804: chaine = (unsigned char *) malloc(3 * sizeof(unsigned char));
2805:
2806: if (chaine != NULL)
2807: {
2808: strcpy(chaine, "[[");
1.58 bertrand 2809: offset = ((integer8) strlen(chaine)) + offset_initial - 1;
1.1 bertrand 2810:
1.59 bertrand 2811: if ((longueurs_maximales = malloc(sizeof(integer8) * 2 *
1.58 bertrand 2812: ((size_t) nombre_colonnes))) == NULL)
1.1 bertrand 2813: {
2814: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2815: return(NULL);
2816: }
2817:
2818: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2819: {
2820: for(j = 0; j < (2 * nombre_colonnes); j++)
2821: {
2822: longueurs_maximales[j] = 0;
2823: }
2824:
2825: for(i = 0; i < nombre_lignes; i++)
2826: {
2827: for(j = 0; j < nombre_colonnes; j++)
2828: {
2829: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2830: &(((real8 **) ((*((struct_matrice *)
1.1 bertrand 2831: ((*s_objet).objet))).tableau))[i][j]), 'R');
2832:
2833: if (chaine_formatee == NULL)
2834: {
2835: (*s_etat_processus).erreur_systeme =
2836: d_es_allocation_memoire;
2837: return(NULL);
2838: }
2839:
1.58 bertrand 2840: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2841: longueur_decimale_courante = 0;
2842:
2843: if ((ptrl = index(chaine_formatee,
2844: (test_cfsf(s_etat_processus, 48) == d_vrai)
2845: ? ',' : '.')) != NULL)
2846: {
2847: longueur_decimale_courante = longueur_courante
2848: - (ptrl - chaine_formatee);
2849: longueur_courante = ptrl - chaine_formatee;
2850: }
2851:
2852: free(chaine_formatee);
2853:
2854: if (longueurs_maximales[2 * j] < longueur_courante)
2855: {
2856: longueurs_maximales[2 * j] = longueur_courante;
2857: }
2858:
2859: if (longueurs_maximales[(2 * j) + 1] <
2860: longueur_decimale_courante)
2861: {
2862: longueurs_maximales[(2 * j) + 1] =
2863: longueur_decimale_courante;
2864: }
2865: }
2866: }
2867: }
2868:
2869: for(i = 0; i < nombre_lignes; i++)
2870: {
2871: for(j = 0; j < nombre_colonnes; j++)
2872: {
2873: chaine_formatee = formateur_nombre(s_etat_processus,
1.58 bertrand 2874: &(((real8 **) ((*((struct_matrice *)
1.1 bertrand 2875: ((*s_objet).objet))).tableau))[i][j]), 'R');
2876:
2877: if (chaine_formatee == NULL)
2878: {
2879: (*s_etat_processus).erreur_systeme =
2880: d_es_allocation_memoire;
2881: return(NULL);
2882: }
2883:
1.58 bertrand 2884: longueur_courante = (integer8) strlen(chaine_formatee);
1.1 bertrand 2885: longueur_decimale_courante = 0;
2886:
2887: if ((ptrl = index(chaine_formatee,
2888: (test_cfsf(s_etat_processus, 48) == d_vrai)
2889: ? ',' : '.')) != NULL)
2890: {
2891: longueur_decimale_courante = longueur_courante
2892: - (ptrl - chaine_formatee);
2893: longueur_courante = ptrl - chaine_formatee;
2894: }
2895:
2896: chaine_sauvegarde = chaine;
2897:
2898: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2899: {
2900: chaine = (unsigned char *) malloc(
2901: (strlen(chaine_sauvegarde) +
1.58 bertrand 2902: ((size_t) longueur_courante) +
2903: ((size_t) longueur_decimale_courante) +
2904: ((size_t) longueurs_maximales[2 * j]) +
2905: ((size_t) longueurs_maximales[(2 * j) + 1]) + 2)
1.1 bertrand 2906: * sizeof(unsigned char));
2907:
2908: if (chaine == NULL)
2909: {
2910: (*s_etat_processus).erreur_systeme =
2911: d_es_allocation_memoire;
2912: return(NULL);
2913: }
2914:
2915: strcpy(chaine, chaine_sauvegarde);
2916: free(chaine_sauvegarde);
2917: strcat(chaine, " ");
2918:
2919: ptre = &(chaine[strlen(chaine)]);
2920:
2921: for(k = 0; k < (longueurs_maximales[2 * j]
2922: - longueur_courante); k++, *(ptre++) = ' ');
2923:
2924: (*ptre) = d_code_fin_chaine;
2925: strcat(chaine, chaine_formatee);
2926: ptre = &(chaine[strlen(chaine)]);
2927:
2928: for(k = 0; k < (longueurs_maximales[(2 * j) + 1]
2929: - longueur_decimale_courante);
2930: k++, *(ptre++) = ' ');
2931:
2932: (*ptre) = d_code_fin_chaine;
2933: }
2934: else
2935: {
2936: chaine = (unsigned char *) malloc(
2937: (strlen(chaine_sauvegarde) +
1.58 bertrand 2938: ((size_t) longueur_courante) +
2939: ((size_t) longueur_decimale_courante)
1.1 bertrand 2940: + 2) * sizeof(unsigned char));
2941:
2942: if (chaine == NULL)
2943: {
2944: (*s_etat_processus).erreur_systeme =
2945: d_es_allocation_memoire;
2946: return(NULL);
2947: }
2948:
2949: strcpy(chaine, chaine_sauvegarde);
2950: free(chaine_sauvegarde);
2951: strcat(chaine, " ");
2952: strcat(chaine, chaine_formatee);
2953: }
2954:
2955: free(chaine_formatee);
2956: }
2957:
2958: chaine_sauvegarde = chaine;
2959:
2960: if (i != (nombre_lignes - 1))
2961: {
2962: if (test_cfsf(s_etat_processus, 45) == d_vrai)
2963: {
2964: chaine = (unsigned char *) malloc(
1.58 bertrand 2965: (strlen(chaine_sauvegarde) + 5 +
2966: ((size_t) offset)) * sizeof(unsigned char));
1.1 bertrand 2967:
2968: if (chaine == NULL)
2969: {
2970: (*s_etat_processus).erreur_systeme =
2971: d_es_allocation_memoire;
2972: return(NULL);
2973: }
2974:
2975: strcpy(chaine, chaine_sauvegarde);
2976: free(chaine_sauvegarde);
2977: strcat(chaine, " ]\n");
2978: ptre = &(chaine[strlen(chaine)]);
2979:
2980: for(k = 0; k < offset; k++, *(ptre++) = ' ');
2981:
2982: (*ptre) = d_code_fin_chaine;
2983: strcat(chaine, "[");
2984: }
2985: else
2986: {
2987: chaine = (unsigned char *) malloc(
2988: (strlen(chaine_sauvegarde) + 4)
2989: * sizeof(unsigned char));
2990:
2991: if (chaine == NULL)
2992: {
2993: (*s_etat_processus).erreur_systeme =
2994: d_es_allocation_memoire;
2995: return(NULL);
2996: }
2997:
2998: strcpy(chaine, chaine_sauvegarde);
2999: free(chaine_sauvegarde);
3000: strcat(chaine, " ][");
3001: }
3002: }
3003: }
3004:
3005: free(longueurs_maximales);
3006:
3007: chaine_sauvegarde = chaine;
3008: chaine = (unsigned char *) malloc((strlen(chaine_sauvegarde)
3009: + 4) * sizeof(unsigned char));
3010:
3011: if (chaine == NULL)
3012: {
3013: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3014: return(NULL);
3015: }
3016:
3017: strcpy(chaine, chaine_sauvegarde);
3018: free(chaine_sauvegarde);
3019: strcat(chaine, " ]]");
3020: }
3021: }
3022: else if ((*s_objet).type == MTX)
3023: {
1.61 bertrand 3024: if (alsprintf(&chaine, "Mutex $ %016llX owned by $ %016llX",
1.60 bertrand 3025: &((*((struct_mutex *) (*s_objet).objet)).mutex),
1.59 bertrand 3026: (logical8) (*((struct_mutex *) (*s_objet).objet)).tid) < 0)
1.1 bertrand 3027: {
3028: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3029: return(NULL);
3030: }
3031: }
3032: else if ((*s_objet).type == NOM)
3033: {
3034:
3035: /*
3036: --------------------------------------------------------------------------------
3037: Nom
3038: --------------------------------------------------------------------------------
3039: */
3040:
3041: if ((*((struct_nom *) (*s_objet).objet)).symbole == d_vrai)
3042: {
3043: chaine = (unsigned char *) malloc((strlen((*((struct_nom *)
3044: (*s_objet).objet)).nom) + 3) * sizeof(unsigned char));
3045:
3046: if (chaine == NULL)
3047: {
3048: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3049: return(NULL);
3050: }
3051:
3052: sprintf(chaine, "'%s'", (*((struct_nom *) (*s_objet).objet)).nom);
3053: }
3054: else
3055: {
3056: chaine = (unsigned char *) malloc((strlen((*((struct_nom *)
3057: (*s_objet).objet)).nom) + 1) * sizeof(unsigned char));
3058:
3059: if (chaine == NULL)
3060: {
3061: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3062: return(NULL);
3063: }
3064:
3065: sprintf(chaine, "%s", (*((struct_nom *) (*s_objet).objet)).nom);
3066: }
3067: }
3068: else if ((*s_objet).type == REL)
3069: {
3070:
3071: /*
3072: --------------------------------------------------------------------------------
3073: Réel
3074: --------------------------------------------------------------------------------
3075: */
3076:
1.58 bertrand 3077: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 3078: ((real8 *) ((*s_objet).objet)), 'R');
3079:
3080: if (chaine_formatee == NULL)
3081: {
3082: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3083: return(NULL);
3084: }
3085:
3086: chaine = (unsigned char *) malloc((strlen(chaine_formatee) + 1)
3087: * sizeof(unsigned char));
3088:
3089: if (chaine == NULL)
3090: {
3091: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3092: return(NULL);
3093: }
3094:
3095: strcpy(chaine, chaine_formatee);
3096: free(chaine_formatee);
3097: }
3098: else if ((*s_objet).type == VCX)
3099: {
3100:
3101: /*
3102: --------------------------------------------------------------------------------
3103: Vecteur complexe
3104: --------------------------------------------------------------------------------
3105: */
3106:
3107: nombre_colonnes = (*((struct_vecteur *) ((*s_objet).objet)))
3108: .taille;
3109:
3110: chaine = (unsigned char *) malloc(2 * sizeof(unsigned char));
3111:
3112: if (chaine != NULL)
3113: {
3114: strcpy(chaine, "[");
3115:
3116: for(i = 0; i < nombre_colonnes; i++)
3117: {
1.58 bertrand 3118: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 3119: &(((struct_complexe16 *) ((*((struct_vecteur *)
3120: ((*s_objet).objet))).tableau))[i]), 'C');
3121:
3122: if (chaine_formatee == NULL)
3123: {
3124: (*s_etat_processus).erreur_systeme =
3125: d_es_allocation_memoire;
3126: return(NULL);
3127: }
3128:
3129: chaine_sauvegarde = chaine;
3130: chaine = (unsigned char *) malloc(
3131: (strlen(chaine_sauvegarde) + strlen(chaine_formatee)
3132: + 2) * sizeof(unsigned char));
3133:
3134: if (chaine == NULL)
3135: {
3136: (*s_etat_processus).erreur_systeme =
3137: d_es_allocation_memoire;
3138: return(NULL);
3139: }
3140:
3141: strcpy(chaine, chaine_sauvegarde);
3142: free(chaine_sauvegarde);
3143: strcat(chaine, " ");
3144: strcat(chaine, chaine_formatee);
3145: free(chaine_formatee);
3146: }
3147:
3148: chaine_sauvegarde = chaine;
3149: chaine = (unsigned char *) malloc(
3150: (strlen(chaine_sauvegarde) + 3)
3151: * sizeof(unsigned char));
3152:
3153: if (chaine == NULL)
3154: {
3155: (*s_etat_processus).erreur_systeme =
3156: d_es_allocation_memoire;
3157: return(NULL);
3158: }
3159:
3160: strcpy(chaine, chaine_sauvegarde);
3161: free(chaine_sauvegarde);
3162: strcat(chaine, " ]");
3163: }
3164: }
3165: else if ((*s_objet).type == VIN)
3166: {
3167:
3168: /*
3169: --------------------------------------------------------------------------------
3170: Vecteur entier
3171: --------------------------------------------------------------------------------
3172: */
3173:
3174: nombre_colonnes = (*((struct_vecteur *) ((*s_objet).objet)))
3175: .taille;
3176:
3177: chaine = (unsigned char *) malloc(2 * sizeof(unsigned char));
3178:
3179: if (chaine != NULL)
3180: {
3181: strcpy(chaine, "[");
3182:
3183: for(i = 0; i < nombre_colonnes; i++)
3184: {
1.58 bertrand 3185: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 3186: &(((integer8 *) ((*((struct_vecteur *)
3187: ((*s_objet).objet))).tableau))[i]), 'I');
3188:
3189: if (chaine_formatee == NULL)
3190: {
3191: (*s_etat_processus).erreur_systeme =
3192: d_es_allocation_memoire;
3193: return(NULL);
3194: }
3195:
3196: chaine_sauvegarde = chaine;
3197: chaine = (unsigned char *) malloc(
3198: (strlen(chaine_sauvegarde) + strlen(chaine_formatee)
3199: + 2) * sizeof(unsigned char));
3200:
3201: if (chaine == NULL)
3202: {
3203: (*s_etat_processus).erreur_systeme =
3204: d_es_allocation_memoire;
3205: return(NULL);
3206: }
3207:
3208: strcpy(chaine, chaine_sauvegarde);
3209: free(chaine_sauvegarde);
3210: strcat(chaine, " ");
3211: strcat(chaine, chaine_formatee);
3212: free(chaine_formatee);
3213: }
3214:
3215: chaine_sauvegarde = chaine;
3216: chaine = (unsigned char *) malloc(
3217: (strlen(chaine_sauvegarde) + 3)
3218: * sizeof(unsigned char));
3219:
3220: if (chaine == NULL)
3221: {
3222: (*s_etat_processus).erreur_systeme =
3223: d_es_allocation_memoire;
3224: return(NULL);
3225: }
3226:
3227: strcpy(chaine, chaine_sauvegarde);
3228: free(chaine_sauvegarde);
3229: strcat(chaine, " ]");
3230: }
3231: }
3232: else if ((*s_objet).type == VRL)
3233: {
3234:
3235: /*
3236: --------------------------------------------------------------------------------
3237: Vecteur réel
3238: --------------------------------------------------------------------------------
3239: */
3240:
3241: nombre_colonnes = (*((struct_vecteur *) ((*s_objet).objet)))
3242: .taille;
3243:
3244: chaine = (unsigned char *) malloc(2 * sizeof(unsigned char));
3245:
3246: if (chaine != NULL)
3247: {
3248: strcpy(chaine, "[");
3249:
3250: for(i = 0; i < nombre_colonnes; i++)
3251: {
1.58 bertrand 3252: chaine_formatee = formateur_nombre(s_etat_processus,
1.1 bertrand 3253: &(((real8 *) ((*((struct_vecteur *)
3254: ((*s_objet).objet))).tableau))[i]), 'R');
3255:
3256: if (chaine_formatee == NULL)
3257: {
3258: (*s_etat_processus).erreur_systeme =
3259: d_es_allocation_memoire;
3260: return(NULL);
3261: }
3262:
3263: chaine_sauvegarde = chaine;
3264: chaine = (unsigned char *) malloc(
3265: (strlen(chaine_sauvegarde) + strlen(chaine_formatee)
3266: + 2) * sizeof(unsigned char));
3267:
3268: if (chaine == NULL)
3269: {
3270: (*s_etat_processus).erreur_systeme =
3271: d_es_allocation_memoire;
3272: return(NULL);
3273: }
3274:
3275: strcpy(chaine, chaine_sauvegarde);
3276: free(chaine_sauvegarde);
3277: strcat(chaine, " ");
3278: strcat(chaine, chaine_formatee);
3279: free(chaine_formatee);
3280: }
3281:
3282: chaine_sauvegarde = chaine;
3283: chaine = (unsigned char *) malloc(
3284: (strlen(chaine_sauvegarde) + 3)
3285: * sizeof(unsigned char));
3286:
3287: if (chaine == NULL)
3288: {
3289: (*s_etat_processus).erreur_systeme =
3290: d_es_allocation_memoire;
3291: return(NULL);
3292: }
3293:
3294: strcpy(chaine, chaine_sauvegarde);
3295: free(chaine_sauvegarde);
3296: strcat(chaine, " ]");
3297: }
3298: }
3299:
3300: return(chaine);
3301: }
3302:
3303:
3304: /*
3305: ================================================================================
3306: Routines qui transforment un nombre entier, réel ou complexe en chaîne de
3307: caractères suivant le format courant
3308: ================================================================================
3309: Entrées : pointeur générique sur la donnée numérique à convertir,
3310: type de l'entité (I, R ou C).
3311: --------------------------------------------------------------------------------
3312: Sorties : chaîne de caractères allouée dans la routine
3313: --------------------------------------------------------------------------------
3314: Effets de bord : néant
3315: ================================================================================
3316: */
3317:
3318: /*
3319: --------------------------------------------------------------------------------
3320: Formatage des complexes, réels et entiers
3321: --------------------------------------------------------------------------------
3322: */
3323:
3324: unsigned char *
3325: formateur_nombre(struct_processus *s_etat_processus,
3326: void *valeur_numerique, unsigned char type)
3327: {
3328: unsigned char *chaine;
3329: unsigned char *construction_chaine;
3330: unsigned char *sauvegarde;
3331: unsigned char *tampon;
3332:
3333: chaine = NULL;
3334:
3335: switch(type)
3336: {
3337: case 'C' :
3338: {
3339: construction_chaine = (unsigned char *) malloc(
3340: 2 * sizeof(unsigned char));
3341:
3342: if (construction_chaine == NULL)
3343: {
3344: (*s_etat_processus).erreur_systeme =
3345: d_es_allocation_memoire;
3346: return(NULL);
3347: }
3348:
3349: strcpy(construction_chaine, "(");
3350:
3351: tampon = formateur_reel(s_etat_processus,
1.58 bertrand 3352: &((*((struct_complexe16 *)
1.1 bertrand 3353: valeur_numerique)).partie_reelle), 'R');
3354:
3355: if (tampon == NULL)
3356: {
3357: (*s_etat_processus).erreur_systeme =
3358: d_es_allocation_memoire;
3359: return(NULL);
3360: }
3361:
3362: sauvegarde = construction_chaine;
3363:
3364: construction_chaine = (unsigned char *) malloc(
3365: (strlen(sauvegarde) + strlen(tampon) + 2)
3366: * sizeof(unsigned char));
3367:
3368: if (construction_chaine == NULL)
3369: {
3370: (*s_etat_processus).erreur_systeme =
3371: d_es_allocation_memoire;
3372: return(NULL);
3373: }
3374:
3375: strcpy(construction_chaine, sauvegarde);
3376: free(sauvegarde);
3377: strcat(construction_chaine, tampon);
3378: free(tampon);
3379:
3380: if (test_cfsf(s_etat_processus, 48) == d_faux)
3381: {
3382: strcat(construction_chaine, ",");
3383: }
3384: else
3385: {
3386: strcat(construction_chaine, ".");
3387: }
3388:
3389: tampon = formateur_reel(s_etat_processus,
1.58 bertrand 3390: &((*((struct_complexe16 *)
1.1 bertrand 3391: valeur_numerique)).partie_imaginaire), 'R');
3392:
3393: if (tampon == NULL)
3394: {
3395: (*s_etat_processus).erreur_systeme =
3396: d_es_allocation_memoire;
3397: return(NULL);
3398: }
3399:
3400: sauvegarde = construction_chaine;
3401:
3402: construction_chaine = (unsigned char *) malloc(
3403: (strlen(sauvegarde) + strlen(tampon) + 2)
3404: * sizeof(unsigned char));
3405:
3406: if (construction_chaine == NULL)
3407: {
3408: (*s_etat_processus).erreur_systeme =
3409: d_es_allocation_memoire;
3410: return(NULL);
3411: }
3412:
3413: strcpy(construction_chaine, sauvegarde);
3414: free(sauvegarde);
3415: strcat(construction_chaine, tampon);
3416: free(tampon);
3417: strcat(construction_chaine, ")");
3418:
3419: chaine = construction_chaine;
3420:
3421: break;
3422: }
3423:
3424: case 'R' :
3425: {
3426: chaine = formateur_reel(s_etat_processus, valeur_numerique, 'R');
3427:
3428: if (chaine == NULL)
3429: {
3430: (*s_etat_processus).erreur_systeme =
3431: d_es_allocation_memoire;
3432: return(NULL);
3433: }
3434:
3435: break;
3436: }
3437:
3438: default :
3439: case 'I' :
3440: {
3441: chaine = formateur_reel(s_etat_processus, valeur_numerique, 'I');
3442:
3443: if (chaine == NULL)
3444: {
3445: (*s_etat_processus).erreur_systeme =
3446: d_es_allocation_memoire;
3447: return(NULL);
3448: }
3449:
3450: break;
3451: }
3452: }
3453:
3454: return(chaine);
3455: }
3456:
3457:
3458: /*
3459: --------------------------------------------------------------------------------
3460: Formateur des réels et entiers
3461: --------------------------------------------------------------------------------
3462: */
3463:
3464: unsigned char *
3465: formateur_reel(struct_processus *s_etat_processus,
3466: void *valeur_numerique, unsigned char type)
3467: {
3468: real8 mantisse;
3469: real8 tampon_reel;
3470:
3471: integer8 tampon_entier;
3472:
3473: logical1 i49;
3474: logical1 i50;
3475:
3476: long correction;
1.4 bertrand 3477: long dernier_chiffre_significatif;
1.1 bertrand 3478: long exposant;
1.58 bertrand 3479: long i;
3480: long j;
1.1 bertrand 3481: long longueur_utile;
3482: long longueur_utile_limite;
3483:
3484: unsigned char *chaine;
1.3 bertrand 3485: unsigned char format[32 + 1];
1.1 bertrand 3486: unsigned char mode[3 + 1];
3487: unsigned char *ptr;
1.3 bertrand 3488: unsigned char tampon[32 + 1];
1.1 bertrand 3489:
3490: chaine = (unsigned char *) malloc((32 + 1) * sizeof(unsigned char));
3491:
3492: if (chaine == NULL)
3493: {
3494: (*s_etat_processus).erreur_systeme =
3495: d_es_allocation_memoire;
3496: return(NULL);
3497: }
3498:
3499: if (type == 'R')
3500: {
1.36 bertrand 3501: # ifdef FP_INFINITE
1.38 bertrand 3502: int signe;
3503:
3504: if ((signe = isinf((*((real8 *) valeur_numerique)))) != 0)
1.36 bertrand 3505: {
1.38 bertrand 3506: if (signe > 0)
3507: {
3508: strcpy(chaine, "infinity");
3509: }
3510: else
3511: {
3512: strcpy(chaine, "-infinity");
3513: }
3514:
1.36 bertrand 3515: return(chaine);
3516: }
3517: # endif
3518:
1.37 bertrand 3519: if (isnan((*((real8 *) valeur_numerique))))
3520: {
3521: strcpy(chaine, "undef");
3522: return(chaine);
3523: }
3524:
1.1 bertrand 3525: tampon_reel = *((real8 *) valeur_numerique);
3526:
3527: if (tampon_reel > ((real8) 0))
3528: {
3529: exposant = (long) floor(log10(tampon_reel));
3530: }
3531: else if (tampon_reel < ((real8) 0))
3532: {
3533: exposant = (long) floor(log10(-tampon_reel));
3534: }
3535: else
3536: {
3537: exposant = 0;
3538: }
3539:
1.58 bertrand 3540: mantisse = (*((real8 *) valeur_numerique)) / pow(10, (double) exposant);
1.1 bertrand 3541: }
3542: else
3543: {
3544: tampon_entier = *((integer8 *) valeur_numerique);
3545:
3546: if (tampon_entier > ((integer8) 0))
3547: {
1.58 bertrand 3548: exposant = (long) floor(log10((double) tampon_entier));
1.1 bertrand 3549: }
3550: else if (tampon_entier < ((integer8) 0))
3551: {
1.56 bertrand 3552: if (tampon_entier != INT64_MIN)
3553: {
1.58 bertrand 3554: exposant = (long) floor(log10((double) -tampon_entier));
1.56 bertrand 3555: }
3556: else
3557: {
3558: tampon_reel = (real8) tampon_entier;
3559: exposant = (long) floor(log10(-tampon_reel));
3560: }
1.1 bertrand 3561: }
3562: else
3563: {
3564: exposant = 0;
3565: }
3566:
1.58 bertrand 3567: mantisse = ((real8) (*((integer8 *) valeur_numerique))) /
3568: pow(10, (double) exposant);
1.1 bertrand 3569: }
3570:
3571: longueur_utile = 0;
3572: j = 1;
3573:
3574: for(i = 53; i <= 56; i++)
3575: {
3576: longueur_utile += (test_cfsf(s_etat_processus, (unsigned char) i)
3577: == d_vrai) ? j : 0;
3578: j *= 2;
3579: }
3580:
3581: longueur_utile_limite = 15;
3582:
3583: if (longueur_utile > longueur_utile_limite)
3584: {
3585: longueur_utile = longueur_utile_limite;
3586: }
3587:
3588: i49 = test_cfsf(s_etat_processus, 49);
3589: i50 = test_cfsf(s_etat_processus, 50);
3590:
3591: if (i49 == d_faux)
3592: {
3593: if (i50 == d_faux)
3594: {
3595:
3596: /*
3597: --------------------------------------------------------------------------------
3598: Mode standard
3599: --------------------------------------------------------------------------------
3600: */
3601:
3602: strcpy(mode, "STD");
3603: }
3604: else
3605: {
3606:
3607: /*
3608: --------------------------------------------------------------------------------
3609: Mode scientifique
3610: --------------------------------------------------------------------------------
3611: */
3612:
3613: strcpy(mode, "SCI");
3614: }
3615: }
3616: else
3617: {
3618: if (i50 == d_faux)
3619: {
3620:
3621: /*
3622: --------------------------------------------------------------------------------
3623: Mode fixe
3624: --------------------------------------------------------------------------------
3625: */
3626:
3627: strcpy(mode, "FIX");
3628: }
3629: else
3630: {
3631:
3632: /*
3633: --------------------------------------------------------------------------------
3634: Mode ingénieur
3635: --------------------------------------------------------------------------------
3636: */
3637:
3638: strcpy(mode, "ENG");
3639: }
3640: }
3641:
1.4 bertrand 3642: // Test portant sur le nombre de chiffres significatifs dans
3643: // le cas du format STD pour que 1.2E-15 apparaisse en notation
3644: // SCI car il y a une perte de précision dans l'affichage.
3645:
3646: if ((strcmp(mode, "STD") == 0) && (type == 'R'))
3647: {
3648: if (abs(*((real8 *) valeur_numerique)) < 1)
3649: {
3650: dernier_chiffre_significatif = -exposant;
3651: sprintf(tampon, ".%f", mantisse);
3652:
3653: ptr = &(tampon[strlen(tampon) - 1]);
3654:
3655: while((*ptr) != '.')
3656: {
3657: if ((*ptr) != '0')
3658: {
3659: dernier_chiffre_significatif++;
3660: }
3661:
3662: ptr--;
3663: }
3664: }
3665: else
3666: {
3667: dernier_chiffre_significatif = 0;
3668: }
3669: }
3670: else
3671: {
3672: dernier_chiffre_significatif = 0;
3673: }
3674:
1.1 bertrand 3675: if ((strcmp(mode, "SCI") == 0) ||
3676: ((strcmp(mode, "STD") == 0) && ((exposant >
1.4 bertrand 3677: longueur_utile_limite) || (dernier_chiffre_significatif > 15) ||
1.1 bertrand 3678: (exposant < -longueur_utile_limite))) ||
3679: ((strcmp(mode, "FIX") == 0) &&
3680: ((exposant >= longueur_utile_limite) ||
3681: (exposant < -longueur_utile))))
3682: {
3683: chaine[0] = d_code_fin_chaine;
3684: format[0] = d_code_fin_chaine;
3685:
3686: if (strcmp(mode, "STD") == 0)
3687: {
3688: longueur_utile = longueur_utile_limite - 1;
3689: }
3690:
3691: sprintf(format, "%%.%luf", longueur_utile);
3692: sprintf(tampon, format, mantisse);
3693: strcpy(chaine, tampon);
3694:
3695: if (strcmp(mode, "STD") == 0)
3696: {
3697: ptr = &(chaine[strlen(chaine) - 1]);
3698: while(((*ptr) == '0') || ((*ptr) == '.'))
3699: {
3700: (*ptr) = d_code_fin_chaine;
3701: ptr--;
3702: }
3703: }
3704:
3705: strcat(chaine, "E");
3706: sprintf(tampon, "%ld", exposant);
3707: strcat(chaine, tampon);
3708: }
3709: else if (strcmp(mode, "FIX") == 0)
3710: {
3711: chaine[0] = d_code_fin_chaine;
3712: format[0] = d_code_fin_chaine;
3713:
3714: if (longueur_utile + exposant >= longueur_utile_limite)
3715: {
3716: longueur_utile = longueur_utile_limite - (exposant + 1);
3717: }
3718:
3719: sprintf(format, "%%.%luf", longueur_utile);
3720:
1.58 bertrand 3721: sprintf(tampon, format, (mantisse * pow(10, (double) exposant)));
1.1 bertrand 3722: strcpy(chaine, tampon);
3723: }
3724: else if (strcmp(mode, "ENG") == 0)
3725: {
3726: chaine[0] = d_code_fin_chaine;
3727: format[0] = d_code_fin_chaine;
3728:
3729: correction = labs(exposant) % 3;
3730:
3731: if (exposant < 0)
3732: {
3733: if (correction == 0)
3734: {
3735: correction = 3;
3736: }
3737:
3738: correction = 3 - correction;
3739: }
3740:
3741: longueur_utile -= correction;
3742: sprintf(format, "%%.%luf", longueur_utile);
3743:
1.58 bertrand 3744: sprintf(tampon, format, (mantisse * pow(10, (double) correction)));
1.1 bertrand 3745: strcpy(chaine, tampon);
3746: strcat(chaine, "E");
3747: sprintf(tampon, "%ld", (exposant - correction));
3748: strcat(chaine, tampon);
3749: }
3750: else
3751: {
3752: if (type == 'I')
3753: {
3754: chaine[0] = d_code_fin_chaine;
3755: sprintf(tampon, "%lld", *((integer8 *) valeur_numerique));
3756: }
3757: else
3758: {
3759: chaine[0] = d_code_fin_chaine;
3760: format[0] = d_code_fin_chaine;
3761:
3762: if (exposant >= 0)
3763: {
1.27 bertrand 3764: if ((exposant + 1) < longueur_utile_limite)
3765: {
3766: sprintf(format, "%%.%luf", (longueur_utile_limite - exposant
3767: - 1));
3768: }
3769: else
3770: {
3771: strcpy(format, "%.0f.");
3772: }
1.1 bertrand 3773: }
3774: else
3775: {
3776: sprintf(format, "%%.%luf", longueur_utile_limite);
3777: }
3778:
3779: sprintf(tampon, format, *((real8 *) valeur_numerique));
3780:
1.58 bertrand 3781: i = ((long) strlen(tampon)) - 1;
1.1 bertrand 3782: while(tampon[i] == '0')
3783: {
3784: tampon[i] = d_code_fin_chaine;
3785: i--;
3786: }
3787:
3788: if (ds_imposition_separateur_decimal == d_faux)
3789: {
1.58 bertrand 3790: i = ((long) strlen(tampon)) - 1;
1.1 bertrand 3791: if (tampon[i] == '.')
3792: {
3793: tampon[i] = d_code_fin_chaine;
3794: }
3795: }
3796: }
1.4 bertrand 3797:
1.1 bertrand 3798: strcpy(chaine, tampon);
3799: }
3800:
3801: if (test_cfsf(s_etat_processus, 48) == d_vrai)
3802: {
1.58 bertrand 3803: for(i = 0; i < (long) strlen(chaine); i++)
1.1 bertrand 3804: {
3805: if (chaine[i] == '.')
3806: {
3807: chaine[i] = ',';
3808: }
3809: }
3810: }
3811:
3812: return(chaine);
3813: }
3814:
3815: // vim: ts=4