Annotation of rpl/src/compilation.c, revision 1.40
1.1 bertrand 1: /*
2: ================================================================================
1.38 bertrand 3: RPL/2 (R) version 4.1.6
1.37 bertrand 4: Copyright (C) 1989-2012 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.15 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Procédure de vérification syntaxique du source et de précompilation
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: - renvoi : erreur
34: --------------------------------------------------------------------------------
35: Effets de bord :
36: ================================================================================
37: */
38:
39: logical1
40: compilation(struct_processus *s_etat_processus)
41: {
42: struct_objet *s_objet;
43:
44: struct_variable *s_variable;
45:
46: unsigned char apostrophe_ouverte;
47: unsigned char apostrophe_ouverte_registre;
48: unsigned char caractere_courant;
49: unsigned char caractere_precedent;
50: unsigned char caractere_suivant;
51: unsigned char *definition;
52: unsigned char fermeture_definition;
53: unsigned char guillemet_ouvert;
54: unsigned char ouverture_definition;
55: unsigned char position_debut_nom_definition_valide;
56:
57: unsigned long *adresse;
58: unsigned long i;
59: unsigned long niveau_definition;
60: unsigned long niveau_definition_registre;
61: unsigned long position_courante;
62: unsigned long position_debut_nom_definition;
63: unsigned long position_fin_nom_definition;
64: unsigned long validation;
65: unsigned long validation_registre;
66:
67: (*s_etat_processus).erreur_compilation = d_ec;
68: (*s_etat_processus).erreur_systeme = d_es;
69: (*s_etat_processus).erreur_execution = d_ex;
70: (*s_etat_processus).exception = d_ep;
71: (*s_etat_processus).arret_si_exception = d_vrai;
72:
73: (*s_etat_processus).position_courante = 0;
74:
75: /*
76: --------------------------------------------------------------------------------
77: Recheche des définitions
78: --------------------------------------------------------------------------------
79: */
80:
81: niveau_definition = 0;
82: niveau_definition_registre = 0;
83: position_courante = 0;
84: position_debut_nom_definition = 0;
85: validation = 0;
86:
87: apostrophe_ouverte = d_faux;
88: apostrophe_ouverte_registre = d_faux;
89: guillemet_ouvert = d_faux;
90: position_debut_nom_definition_valide = d_faux;
91:
92: if ((*s_etat_processus).debug == d_vrai)
93: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
94: {
95: printf("\n");
96: printf("[%d] Compilation\n", (int) getpid());
97: fflush(stdout);
98: }
99:
100: while((*s_etat_processus).definitions_chainees[position_courante] !=
101: d_code_fin_chaine)
102: {
103: caractere_courant = (*s_etat_processus)
104: .definitions_chainees[position_courante];
105:
106: fermeture_definition = d_faux;
107: ouverture_definition = d_faux;
108:
109: if (position_courante >= 1)
110: {
111: if (position_courante >= 2)
112: {
113: if (((*s_etat_processus).definitions_chainees
114: [position_courante - 2] == '\\') &&
115: ((*s_etat_processus).definitions_chainees
116: [position_courante - 1] == '\\'))
117: {
118: caractere_precedent = '*';
119: }
120: else
121: {
122: caractere_precedent = (*s_etat_processus)
123: .definitions_chainees[position_courante - 1];
124: }
125: }
126: else
127: {
128: caractere_precedent = (*s_etat_processus)
129: .definitions_chainees[position_courante - 1];
130: }
131: }
132: else
133: {
134: caractere_precedent = ' ';
135: }
136:
137: caractere_suivant = (*s_etat_processus)
138: .definitions_chainees[position_courante + 1];
139:
140: if (caractere_suivant == d_code_fin_chaine)
141: {
142: caractere_suivant = ' ';
143: }
144:
145: if ((caractere_courant == '[') || (caractere_courant == '{'))
146: {
147: validation++;
148: }
149: else if ((caractere_courant == ']') || (caractere_courant == '}'))
150: {
151: validation--;
152: }
153: else if (caractere_courant == '\'')
154: {
155: if (apostrophe_ouverte == d_faux)
156: {
157: validation++;
158: apostrophe_ouverte = d_vrai;
159: }
160: else
161: {
162: validation--;
163: apostrophe_ouverte = d_faux;
164: }
165: }
166: else if (caractere_courant == '"')
167: {
168: if (caractere_precedent != '\\')
169: {
170: swap((void *) &validation, (void *) &validation_registre,
171: sizeof(validation));
172: swap((void *) &apostrophe_ouverte,
173: (void *) &apostrophe_ouverte_registre,
174: sizeof(apostrophe_ouverte));
175: swap((void *) &niveau_definition,
176: (void *) &niveau_definition_registre,
177: sizeof(niveau_definition));
178:
179: guillemet_ouvert = (guillemet_ouvert == d_faux)
180: ? d_vrai : d_faux;
181: }
182: }
183: else if ((caractere_courant == '<') &&
184: (caractere_precedent == ' ') &&
185: (caractere_suivant == '<'))
186: {
187: if ((*s_etat_processus)
188: .definitions_chainees[position_courante + 2] == ' ')
189: {
190: niveau_definition++;
191: ouverture_definition = d_vrai;
192: }
193: }
194: else if ((caractere_courant == '>') &&
195: (caractere_precedent == ' ') &&
196: (caractere_suivant == '>'))
197: {
198: if (((*s_etat_processus)
199: .definitions_chainees[position_courante + 2] == ' ') ||
200: ((*s_etat_processus).definitions_chainees
201: [position_courante + 2] == d_code_fin_chaine))
202: {
203: if (niveau_definition == 0)
204: {
205: (*s_etat_processus).erreur_compilation =
206: d_ec_niveau_definition_negatif;
207: return(d_erreur);
208: }
209: else
210: {
211: niveau_definition--;
212: fermeture_definition = d_vrai;
213: position_courante++;
214: }
215: }
216: }
217:
218: if ((niveau_definition == 0) && (guillemet_ouvert == d_faux) &&
219: (caractere_courant != ' ') && (fermeture_definition == d_faux))
220: {
221: if (position_debut_nom_definition_valide == d_faux)
222: {
223: position_debut_nom_definition_valide = d_vrai;
224: position_debut_nom_definition = position_courante;
225: }
226: }
227:
228: if (((niveau_definition == 1) && (ouverture_definition == d_vrai)) &&
229: (position_debut_nom_definition_valide == d_vrai))
230: {
231: position_fin_nom_definition = position_courante - 1;
232: position_debut_nom_definition_valide = d_faux;
233:
234: while((*s_etat_processus).definitions_chainees
235: [position_fin_nom_definition] == ' ')
236: {
237: position_fin_nom_definition--;
238: }
239:
240: i = position_debut_nom_definition;
241:
242: while(i <= position_fin_nom_definition)
243: {
244: if ((*s_etat_processus).definitions_chainees[i] == ' ')
245: {
246: (*s_etat_processus).erreur_compilation =
247: d_ec_nom_definition_invalide;
248: return(d_erreur);
249: }
250: else
251: {
252: i++;
253: }
254: }
255:
256: s_objet = allocation(s_etat_processus, ADR);
257: s_variable = (struct_variable *)
258: malloc(sizeof(struct_variable));
259: adresse = (*s_objet).objet;
260: definition = (unsigned char *) malloc(
261: (position_fin_nom_definition -
262: position_debut_nom_definition + 2) *
263: sizeof(unsigned char));
264:
265: if ((s_objet == NULL) || (s_variable == NULL) ||
266: (adresse == NULL) || definition == NULL)
267: {
268: (*s_etat_processus).erreur_systeme =
269: d_es_allocation_memoire;
270: return(d_erreur);
271: }
272: else
273: {
274: (*adresse) = position_fin_nom_definition + 1;
275:
276: (*s_variable).nom = definition;
277: (*s_variable).niveau = (*s_etat_processus).niveau_courant;
278: (*s_variable).objet = s_objet;
279:
280: i = position_debut_nom_definition;
281:
282: while(i <= position_fin_nom_definition)
283: {
284: *(definition++) = (*s_etat_processus)
285: .definitions_chainees[i++];
286: }
287:
288: *definition = d_code_fin_chaine;
289:
290: if (recherche_variable(s_etat_processus, (*s_variable).nom)
291: == d_vrai)
292: {
293: if ((*s_etat_processus).langue == 'F')
294: {
295: printf("+++Attention : Plusieurs définitions de"
296: " même nom\n");
297: }
298: else
299: {
300: printf("+++Warning : Same name for several"
301: " definitions\n");
302: }
303:
304: fflush(stdout);
305: return(d_erreur);
306: }
307:
308: (*s_etat_processus).erreur_systeme = d_es;
309: creation_variable(s_etat_processus, s_variable, 'V', 'P');
310:
311: if ((*s_etat_processus).erreur_systeme != d_es)
312: {
313: free(s_variable);
314:
315: return(d_erreur);
316: }
317:
318: if ((*s_etat_processus).debug == d_vrai)
319: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
320: {
321: if ((*s_etat_processus).langue == 'F')
322: {
323: printf("[%d] Compilation : Définition %s ($ %016lX) "
324: "\n", (int) getpid(), (*s_variable).nom,
325: (*adresse));
326: }
327: else
328: {
329: printf("[%d] Compilation : %s definition ($ %016lX) "
330: "\n", (int) getpid(), (*s_variable).nom,
331: (*adresse));
332: }
333:
334: fflush(stdout);
335: }
336: }
337:
338: free(s_variable);
339: }
340:
341: position_courante++;
342: }
343:
344: return(analyse_syntaxique(s_etat_processus));
345: }
346:
347:
348: /*
349: ================================================================================
350: Procédure de d'analyse syntaxique du source
351: ================================================================================
352: Entrées :
353: --------------------------------------------------------------------------------
354: Sorties :
355: - renvoi : erreur
356: --------------------------------------------------------------------------------
357: Effets de bord :
358: ================================================================================
359: */
360:
361: logical1
362: analyse_syntaxique(struct_processus *s_etat_processus)
363: {
364: enum t_condition { AN_IF = 1, AN_IFERR, AN_THEN, AN_ELSE, AN_ELSEIF,
365: AN_END, AN_DO, AN_UNTIL, AN_WHILE, AN_REPEAT, AN_SELECT,
366: AN_CASE, AN_DEFAULT, AN_UP, AN_DOWN, AN_FOR, AN_START,
367: AN_NEXT, AN_STEP };
368:
369: unsigned char *instruction;
370: unsigned char registre;
371:
372: typedef struct pile
373: {
374: enum t_condition condition;
375: struct pile *suivant;
376: } struct_pile_analyse;
377:
378: struct_pile_analyse *l_base_pile;
379: struct_pile_analyse *l_nouvelle_base_pile;
380:
381: inline struct_pile_analyse *
382: empilement_analyse(struct_pile_analyse *ancienne_base,
383: enum t_condition condition)
384: {
385: struct_pile_analyse *nouvelle_base;
386:
387: if ((nouvelle_base = malloc(sizeof(struct_pile_analyse))) == NULL)
388: {
389: return(NULL);
390: }
391:
392: (*nouvelle_base).suivant = ancienne_base;
393: (*nouvelle_base).condition = condition;
394:
395: return(nouvelle_base);
396: }
397:
398: inline struct_pile_analyse *
399: depilement_analyse(struct_pile_analyse *ancienne_base)
400: {
401: struct_pile_analyse *nouvelle_base;
402:
403: if (ancienne_base == NULL)
404: {
405: return(NULL);
406: }
407:
408: nouvelle_base = (*ancienne_base).suivant;
409: free(ancienne_base);
410:
411: return(nouvelle_base);
412: }
413:
414: inline logical1
415: test_analyse(struct_pile_analyse *l_base_pile, enum t_condition condition)
416: {
417: if (l_base_pile == NULL)
418: {
419: return(d_faux);
420: }
421:
422: return(((*l_base_pile).condition == condition) ? d_vrai : d_faux);
423: }
424:
425: inline void
426: liberation_analyse(struct_pile_analyse *l_base_pile)
427: {
428: struct_pile_analyse *l_nouvelle_base_pile;
429:
430: while(l_base_pile != NULL)
431: {
432: l_nouvelle_base_pile = (*l_base_pile).suivant;
433: free(l_base_pile);
434: l_base_pile = l_nouvelle_base_pile;
435: }
436:
437: return;
438: }
439:
440: l_base_pile = NULL;
441: l_nouvelle_base_pile = NULL;
442:
443: if ((*s_etat_processus).debug == d_vrai)
444: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
445: {
446: if ((*s_etat_processus).langue == 'F')
447: {
448: printf("[%d] Analyse\n", (int) getpid());
449: }
450: else
451: {
452: printf("[%d] Analysis\n", (int) getpid());
453: }
454:
455: fflush(stdout);
456: }
457:
458: (*s_etat_processus).position_courante = 0;
459: registre = (*s_etat_processus).autorisation_empilement_programme;
460: (*s_etat_processus).autorisation_empilement_programme = 'N';
461:
462: /*
463: --------------------------------------------------------------------------------
464: Analyse structurelle
465: --------------------------------------------------------------------------------
466: */
467:
468: while((*s_etat_processus).definitions_chainees
469: [(*s_etat_processus).position_courante] != d_code_fin_chaine)
470: {
471: if (recherche_instruction_suivante(s_etat_processus) !=
472: d_absence_erreur)
473: {
474: liberation_analyse(l_base_pile);
475:
476: (*s_etat_processus).autorisation_empilement_programme = registre;
477: return(d_erreur);
478: }
479:
480: if ((instruction = conversion_majuscule(
481: (*s_etat_processus).instruction_courante)) == NULL)
482: {
483: liberation_analyse(l_base_pile);
484:
485: (*s_etat_processus).autorisation_empilement_programme = registre;
486: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
487: return(d_erreur);
488: }
489:
490: if (strcmp(instruction, "IF") == 0)
491: {
492: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_IF))
493: == NULL)
494: {
495: liberation_analyse(l_base_pile);
496:
497: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
498: return(d_erreur);
499: }
500:
501: l_base_pile = l_nouvelle_base_pile;
502: (*l_base_pile).condition = AN_IF;
503: }
504: else if (strcmp(instruction, "IFERR") == 0)
505: {
506: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
507: AN_IFERR)) == NULL)
508: {
509: liberation_analyse(l_base_pile);
510:
511: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
512: return(d_erreur);
513: }
514:
515: l_base_pile = l_nouvelle_base_pile;
516: }
517: else if (strcmp(instruction, "THEN") == 0)
518: {
519: if ((test_analyse(l_base_pile, AN_IF) == d_faux) &&
520: (test_analyse(l_base_pile, AN_ELSEIF) == d_faux) &&
521: (test_analyse(l_base_pile, AN_CASE) == d_faux) &&
522: (test_analyse(l_base_pile, AN_IFERR) == d_faux))
523: {
524: liberation_analyse(l_base_pile);
525:
526: (*s_etat_processus).autorisation_empilement_programme =
527: registre;
528:
529: (*s_etat_processus).erreur_compilation =
530: d_ec_erreur_instruction_then;
531: return(d_erreur);
532: }
533:
534: (*l_base_pile).condition = AN_THEN;
535: }
536: else if (strcmp(instruction, "ELSE") == 0)
537: {
538: if (test_analyse(l_base_pile, AN_THEN) == d_faux)
539: {
540: liberation_analyse(l_base_pile);
541:
542: (*s_etat_processus).autorisation_empilement_programme =
543: registre;
544:
545: (*s_etat_processus).erreur_compilation =
546: d_ec_erreur_instruction_else;
547: return(d_erreur);
548: }
549:
550: (*l_base_pile).condition = AN_ELSE;
551: }
552: else if (strcmp(instruction, "ELSEIF") == 0)
553: {
554: if (test_analyse(l_base_pile, AN_THEN) == d_faux)
555: {
556: liberation_analyse(l_base_pile);
557:
558: (*s_etat_processus).autorisation_empilement_programme =
559: registre;
560:
561: (*s_etat_processus).erreur_compilation =
562: d_ec_erreur_instruction_elseif;
563: return(d_erreur);
564: }
565:
566: (*l_base_pile).condition = AN_ELSEIF;
567: }
568: else if (strcmp(instruction, "END") == 0)
569: {
570: if ((test_analyse(l_base_pile, AN_UNTIL) == d_faux) &&
571: (test_analyse(l_base_pile, AN_REPEAT) == d_faux) &&
572: (test_analyse(l_base_pile, AN_DEFAULT) == d_faux) &&
573: (test_analyse(l_base_pile, AN_SELECT) == d_faux) &&
574: (test_analyse(l_base_pile, AN_THEN) == d_faux) &&
575: (test_analyse(l_base_pile, AN_ELSE) == d_faux))
576: {
577: liberation_analyse(l_base_pile);
578:
579: (*s_etat_processus).autorisation_empilement_programme =
580: registre;
581:
582: (*s_etat_processus).erreur_compilation =
583: d_ec_erreur_instruction_end;
584: return(d_erreur);
585: }
586:
587: l_base_pile = depilement_analyse(l_base_pile);
588: }
589: else if (strcmp(instruction, "DO") == 0)
590: {
591: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_DO))
592: == NULL)
593: {
594: liberation_analyse(l_base_pile);
595:
596: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
597: return(d_erreur);
598: }
599:
600: l_base_pile = l_nouvelle_base_pile;
601: }
602: else if (strcmp(instruction, "UNTIL") == 0)
603: {
604: if (test_analyse(l_base_pile, AN_DO) == d_faux)
605: {
606: liberation_analyse(l_base_pile);
607:
608: (*s_etat_processus).autorisation_empilement_programme =
609: registre;
610:
611: (*s_etat_processus).erreur_compilation =
612: d_ec_erreur_instruction_until;
613: return(d_erreur);
614: }
615:
616: (*l_base_pile).condition = AN_UNTIL;
617: }
618: else if (strcmp(instruction, "WHILE") == 0)
619: {
620: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
621: AN_WHILE)) == NULL)
622: {
623: liberation_analyse(l_base_pile);
624:
625: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
626: return(d_erreur);
627: }
628:
629: l_base_pile = l_nouvelle_base_pile;
630: }
631: else if (strcmp(instruction, "REPEAT") == 0)
632: {
633: if (test_analyse(l_base_pile, AN_WHILE) == d_faux)
634: {
635: liberation_analyse(l_base_pile);
636:
637: (*s_etat_processus).autorisation_empilement_programme =
638: registre;
639:
640: (*s_etat_processus).erreur_compilation =
641: d_ec_erreur_instruction_while;
642: return(d_erreur);
643: }
644:
645: (*l_base_pile).condition = AN_REPEAT;
646: }
647: else if (strcmp(instruction, "SELECT") == 0)
648: {
649: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
650: AN_SELECT)) == NULL)
651: {
652: liberation_analyse(l_base_pile);
653:
654: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
655: return(d_erreur);
656: }
657:
658: l_base_pile = l_nouvelle_base_pile;
659: }
660: else if (strcmp(instruction, "CASE") == 0)
661: {
662: if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
663: {
664: liberation_analyse(l_base_pile);
665:
666: (*s_etat_processus).autorisation_empilement_programme =
667: registre;
668:
669: (*s_etat_processus).erreur_compilation =
670: d_ec_erreur_instruction_case;
671: return(d_erreur);
672: }
673:
674: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
675: AN_CASE)) == NULL)
676: {
677: liberation_analyse(l_base_pile);
678:
679: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
680: return(d_erreur);
681: }
682:
683: l_base_pile = l_nouvelle_base_pile;
684: }
685: else if (strcmp(instruction, "DEFAULT") == 0)
686: {
687: if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
688: {
689: liberation_analyse(l_base_pile);
690:
691: (*s_etat_processus).autorisation_empilement_programme =
692: registre;
693:
694: (*s_etat_processus).erreur_compilation =
695: d_ec_erreur_instruction_select;
696: return(d_erreur);
697: }
698:
699: (*l_base_pile).condition = AN_DEFAULT;
700: }
701: else if (strcmp(instruction, "<<") == 0)
702: {
703: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_UP))
704: == NULL)
705: {
706: liberation_analyse(l_base_pile);
707:
708: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
709: return(d_erreur);
710: }
711:
712: l_base_pile = l_nouvelle_base_pile;
713: }
714: else if (strcmp(instruction, ">>") == 0)
715: {
716: if (test_analyse(l_base_pile, AN_UP) == d_faux)
717: {
718: liberation_analyse(l_base_pile);
719:
720: (*s_etat_processus).autorisation_empilement_programme =
721: registre;
722:
723: (*s_etat_processus).erreur_compilation =
724: d_ec_source_incoherent;
725: return(d_erreur);
726: }
727:
728: l_base_pile = depilement_analyse(l_base_pile);
729: }
730: else if (strcmp(instruction, "FOR") == 0)
731: {
732: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_FOR))
733: == NULL)
734: {
735: liberation_analyse(l_base_pile);
736:
737: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
738: return(d_erreur);
739: }
740:
741: l_base_pile = l_nouvelle_base_pile;
742: }
743: else if (strcmp(instruction, "START") == 0)
744: {
745: if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
746: AN_START)) == NULL)
747: {
748: liberation_analyse(l_base_pile);
749:
750: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
751: return(d_erreur);
752: }
753:
754: l_base_pile = l_nouvelle_base_pile;
755: }
756: else if (strcmp(instruction, "NEXT") == 0)
757: {
758: if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
759: (test_analyse(l_base_pile, AN_START) == d_faux))
760: {
761: liberation_analyse(l_base_pile);
762:
763: (*s_etat_processus).autorisation_empilement_programme =
764: registre;
765:
766: (*s_etat_processus).erreur_compilation =
767: d_ec_erreur_boucle_definie;
768: return(d_erreur);
769: }
770:
771: l_base_pile = depilement_analyse(l_base_pile);
772: }
773: else if (strcmp(instruction, "STEP") == 0)
774: {
775: if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
776: (test_analyse(l_base_pile, AN_START) == d_faux))
777: {
778: liberation_analyse(l_base_pile);
779:
780: (*s_etat_processus).autorisation_empilement_programme =
781: registre;
782:
783: (*s_etat_processus).erreur_compilation =
784: d_ec_erreur_boucle_definie;
785: return(d_erreur);
786: }
787:
788: l_base_pile = depilement_analyse(l_base_pile);
789: }
790:
791: // Invalidation de l'instruction courante dans le fichier rpl-core
792: free((*s_etat_processus).instruction_courante);
793: (*s_etat_processus).instruction_courante = NULL;
794: free(instruction);
795: }
796:
797: (*s_etat_processus).autorisation_empilement_programme = registre;
798:
799: if (l_base_pile != NULL)
800: {
801: liberation_analyse(l_base_pile);
802:
803: (*s_etat_processus).autorisation_empilement_programme = registre;
804: (*s_etat_processus).erreur_compilation = d_ec_source_incoherent;
805: return(d_erreur);
806: }
807:
808: return(d_absence_erreur);
809: }
810:
811:
812: /*
813: ================================================================================
1.39 bertrand 814: Procédure de d'analyse syntaxique du source pour readline
815: ================================================================================
816: Entrées :
817: --------------------------------------------------------------------------------
818: Sorties :
819: - rl_done à 0 ou à 1.
820: --------------------------------------------------------------------------------
821: Effets de bord :
822: ================================================================================
823: */
824:
1.40 ! bertrand 825: static char *ligne = NULL;
! 826: static unsigned int niveau = 0;
! 827:
1.39 bertrand 828: int
829: readline_analyse_syntaxique(int count, int key)
830: {
1.40 ! bertrand 831: char prompt[] = "+ %03d> ";
! 832: char prompt2[8];
! 833: char *registre;
! 834:
1.39 bertrand 835: struct_processus s_etat_processus;
836:
837: if ((*rl_line_buffer) == d_code_fin_chaine)
838: {
1.40 ! bertrand 839: if (ligne == NULL)
! 840: {
! 841: rl_done = 1;
! 842: }
! 843: else
! 844: {
! 845: rl_done = 0;
! 846: }
1.39 bertrand 847: }
848: else
849: {
1.40 ! bertrand 850: if (ligne == NULL)
! 851: {
! 852: if ((ligne = malloc((strlen(rl_line_buffer) + 1)
! 853: * sizeof(char))) == NULL)
! 854: {
! 855: rl_done = 1;
! 856: return(0);
! 857: }
! 858:
! 859: strcpy(ligne, rl_line_buffer);
! 860: }
! 861: else
! 862: {
! 863: registre = ligne;
! 864:
! 865: if ((ligne = malloc((strlen(registre)
! 866: + strlen(rl_line_buffer) + 1) * sizeof(char))) == NULL)
! 867: {
! 868: rl_done = 1;
! 869: return(0);
! 870: }
! 871:
! 872: sprintf(ligne, "%s%s", registre, rl_line_buffer);
! 873: }
! 874:
! 875: rl_replace_line("", 1);
! 876:
! 877: s_etat_processus.definitions_chainees = ligne;
! 878: s_etat_processus.debug = d_faux;
! 879: s_etat_processus.erreur_systeme = d_es;
! 880: s_etat_processus.erreur_execution = d_ex;
! 881:
1.39 bertrand 882: if (analyse_syntaxique(&s_etat_processus) == d_absence_erreur)
883: {
884: rl_done = 1;
885: }
886: else
887: {
1.40 ! bertrand 888: if (s_etat_processus.erreur_systeme != d_es)
! 889: {
! 890: rl_done = 1;
! 891: }
! 892: else
! 893: {
! 894: rl_done = 0;
! 895: rl_crlf();
! 896:
! 897: sprintf(prompt2, prompt, ++niveau);
! 898:
! 899: rl_expand_prompt(prompt2);
! 900: rl_on_new_line();
! 901: }
1.39 bertrand 902: }
903: }
904:
905: if (rl_done != 0)
906: {
907: uprintf("\n");
1.40 ! bertrand 908:
! 909: if (ligne != NULL)
! 910: {
! 911: rl_replace_line(ligne, 1);
! 912:
! 913: free(ligne);
! 914: ligne = NULL;
! 915: }
! 916:
! 917: niveau = 0;
1.39 bertrand 918: }
919:
920: return(0);
921: }
922:
1.40 ! bertrand 923: int
! 924: readline_effacement(int count, int key)
! 925: {
! 926: rl_done = 0;
! 927: rl_replace_line("", 1);
! 928:
! 929: free(ligne);
! 930: ligne = NULL;
! 931: niveau = 0;
! 932:
! 933: uprintf("annulation\n");
! 934: rl_expand_prompt("RPL/2> ");
! 935: rl_on_new_line();
! 936: return(0);
! 937: }
1.39 bertrand 938:
939: /*
940: ================================================================================
1.1 bertrand 941: Routine d'échange de deux variables
942: ================================================================================
943: Entrées :
944: - pointeurs génériques sur les deux variables,
945: - longueur en octet des objets à permuter.
946: --------------------------------------------------------------------------------
947: Sorties : idem.
948: --------------------------------------------------------------------------------
949: Effets de bord : néant.
950: ================================================================================
951: */
952:
953: void
954: swap(void *variable_1, void *variable_2, unsigned long taille)
955: {
956: register unsigned char *t_var_1;
957: register unsigned char *t_var_2;
958: register unsigned char variable_temporaire;
959:
1.14 bertrand 960: register unsigned long i;
1.1 bertrand 961:
962: t_var_1 = (unsigned char *) variable_1;
963: t_var_2 = (unsigned char *) variable_2;
964:
1.14 bertrand 965: for(i = 0; i < taille; i++)
1.1 bertrand 966: {
1.14 bertrand 967: variable_temporaire = (*t_var_1);
968: (*(t_var_1++)) = (*t_var_2);
969: (*(t_var_2++)) = variable_temporaire;
1.1 bertrand 970: }
1.14 bertrand 971:
972: return;
1.1 bertrand 973: }
974:
975:
976: /*
977: ================================================================================
978: Routine recherchant l'instruction suivante dans le programme compilé
979: ================================================================================
980: Entrée :
981: --------------------------------------------------------------------------------
982: Sortie :
983: --------------------------------------------------------------------------------
984: Effets de bord : néant.
985: ================================================================================
986: */
987:
988: logical1
989: recherche_instruction_suivante(struct_processus *s_etat_processus)
990: {
991: logical1 drapeau_fin_objet;
992: logical1 erreur;
993: logical1 erreur_analyse;
994: logical1 erreur_format;
995:
996: unsigned char base_binaire;
997: unsigned char *pointeur_caractere_courant;
998: unsigned char *pointeur_caractere_destination;
999: unsigned char *pointeur_debut_instruction;
1000: unsigned char *pointeur_fin_instruction;
1001:
1002: signed long niveau;
1003: signed long niveau_annexe;
1004:
1005: erreur_analyse = d_ex;
1006: erreur_format = d_ex;
1007: erreur = d_absence_erreur;
1008:
1009: drapeau_fin_objet = d_faux;
1010: niveau = 0;
1011:
1012: pointeur_caractere_courant = (*s_etat_processus).definitions_chainees +
1013: (*s_etat_processus).position_courante;
1014:
1015: while(((*pointeur_caractere_courant) == d_code_espace) &&
1016: ((*pointeur_caractere_courant) != d_code_fin_chaine))
1017: {
1018: pointeur_caractere_courant++;
1019: }
1020:
1021: if ((*pointeur_caractere_courant) == d_code_fin_chaine)
1022: {
1023: (*s_etat_processus).instruction_courante = (unsigned char *)
1024: malloc(sizeof(unsigned char));
1025:
1026: if ((*s_etat_processus).instruction_courante == NULL)
1027: {
1028: erreur = d_erreur;
1029: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1030: }
1031: else
1032: {
1033: erreur = d_absence_erreur;
1034: (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
1035: (*s_etat_processus).position_courante = pointeur_caractere_courant
1036: - (*s_etat_processus).definitions_chainees;
1037: }
1038:
1039: return(erreur);
1040: }
1041:
1042: pointeur_debut_instruction = pointeur_caractere_courant;
1043:
1044: while(((*pointeur_caractere_courant) != d_code_espace) &&
1045: ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
1046: (drapeau_fin_objet == d_faux) &&
1047: (erreur_analyse == d_ex) &&
1048: (erreur_format == d_ex))
1049: {
1050: switch(*pointeur_caractere_courant++)
1051: {
1052: case ']' :
1053: case '}' :
1054: case ')' :
1055: {
1056: erreur_format = d_ex_syntaxe;
1057: break;
1058: }
1059:
1060: case '"' :
1061: {
1062: if (pointeur_debut_instruction !=
1063: (pointeur_caractere_courant - 1))
1064: {
1065: erreur_format = d_ex_syntaxe;
1066: }
1067:
1068: while((*pointeur_caractere_courant != '"') &&
1069: ((*pointeur_caractere_courant) != d_code_fin_chaine))
1070: {
1071: if (*pointeur_caractere_courant == '\\')
1072: {
1073: pointeur_caractere_courant++;
1074:
1075: switch(*pointeur_caractere_courant)
1076: {
1077: case '\\' :
1078: case '"' :
1079: {
1080: pointeur_caractere_courant++;
1081: break;
1082: }
1083: }
1084: }
1085: else
1086: {
1087: pointeur_caractere_courant++;
1088: }
1089: }
1090:
1091: if ((*pointeur_caractere_courant) != '"')
1092: {
1093: erreur_analyse = d_ex_syntaxe;
1094: }
1095:
1096: if (erreur_analyse == d_ex)
1097: {
1098: pointeur_caractere_courant++;
1099: }
1100:
1101: drapeau_fin_objet = d_vrai;
1102: break;
1103: }
1104:
1105: case '\'' :
1106: {
1107: if (pointeur_debut_instruction !=
1108: (pointeur_caractere_courant - 1))
1109: {
1110: erreur_format = d_ex_syntaxe;
1111: }
1112:
1113: while(((*pointeur_caractere_courant) != '\'') &&
1114: ((*pointeur_caractere_courant) != d_code_fin_chaine))
1115: {
1116: if ((*pointeur_caractere_courant) == '(')
1117: {
1118: niveau++;
1119: }
1120: else if ((*pointeur_caractere_courant) == ')')
1121: {
1122: niveau--;
1123: }
1124:
1125: pointeur_caractere_courant++;
1126: }
1127:
1128: if ((*pointeur_caractere_courant) != '\'')
1129: {
1130: erreur_analyse = d_ex_syntaxe;
1131: }
1132: else if (niveau != 0)
1133: {
1134: erreur_analyse = d_ex_syntaxe;
1135: }
1136:
1137: if (erreur_analyse == d_ex)
1138: {
1139: pointeur_caractere_courant++;
1140: }
1141:
1142: drapeau_fin_objet = d_vrai;
1143: break;
1144: }
1145:
1146: case '(' :
1147: {
1148: if (pointeur_debut_instruction !=
1149: (pointeur_caractere_courant - 1))
1150: {
1151: erreur_format = d_ex_syntaxe;
1152: }
1153:
1154: while(((*pointeur_caractere_courant) != ')') &&
1155: ((*pointeur_caractere_courant) != d_code_fin_chaine)
1156: && (erreur_analyse == d_ex))
1157: {
1158: switch(*pointeur_caractere_courant)
1159: {
1160: case '0' :
1161: case '1' :
1162: case '2' :
1163: case '3' :
1164: case '4' :
1165: case '5' :
1166: case '6' :
1167: case '7' :
1168: case '8' :
1169: case '9' :
1170: case 'e' :
1171: case 'E' :
1172: case ',' :
1173: case '.' :
1174: case ' ' :
1175: case '-' :
1176: case '+' :
1177: case ')' :
1178: {
1179: break;
1180: }
1181:
1182: default :
1183: {
1184: erreur_analyse = d_ex_syntaxe;
1185: break;
1186: }
1187: }
1188:
1189: pointeur_caractere_courant++;
1190: }
1191:
1192: if ((*pointeur_caractere_courant) != ')')
1193: {
1194: erreur_analyse = d_ex_syntaxe;
1195: }
1196:
1197: if (erreur_analyse == d_ex)
1198: {
1199: pointeur_caractere_courant++;
1200: }
1201:
1202: drapeau_fin_objet = d_vrai;
1203: break;
1204: }
1205:
1206: case '#' :
1207: {
1208: if (pointeur_debut_instruction !=
1209: (pointeur_caractere_courant - 1))
1210: {
1211: erreur_format = d_ex_syntaxe;
1212: }
1213:
1214: while(((*pointeur_caractere_courant) != 'b') &&
1215: ((*pointeur_caractere_courant) != 'o') &&
1216: ((*pointeur_caractere_courant) != 'd') &&
1217: ((*pointeur_caractere_courant) != 'h') &&
1218: ((*pointeur_caractere_courant) !=
1219: d_code_fin_chaine) &&
1220: (erreur_analyse == d_ex))
1221: {
1222: switch(*pointeur_caractere_courant)
1223: {
1224: case ' ' :
1225: case '0' :
1226: case '1' :
1227: case '2' :
1228: case '3' :
1229: case '4' :
1230: case '5' :
1231: case '6' :
1232: case '7' :
1233: case '8' :
1234: case '9' :
1235: case 'A' :
1236: case 'B' :
1237: case 'C' :
1238: case 'D' :
1239: case 'E' :
1240: case 'F' :
1241: case 'b' :
1242: case 'o' :
1243: case 'd' :
1244: case 'h' :
1245: {
1246: break;
1247: }
1248:
1249: default :
1250: {
1251: erreur_analyse = d_ex_syntaxe;
1252: break;
1253: }
1254: }
1255:
1256: pointeur_caractere_courant++;
1257: }
1258:
1259: base_binaire = (*pointeur_caractere_courant);
1260: pointeur_caractere_courant++;
1261:
1262: if (((*pointeur_caractere_courant) != d_code_fin_chaine) &&
1263: ((*pointeur_caractere_courant) != ' '))
1264: {
1265: erreur_analyse = d_ex_syntaxe;
1266: }
1267: else
1268: {
1269: pointeur_caractere_courant = pointeur_debut_instruction + 1;
1270:
1271: switch(base_binaire)
1272: {
1273: case 'b' :
1274: case 'o' :
1275: case 'd' :
1276: case 'h' :
1277: {
1278: break;
1279: }
1280:
1281: default :
1282: {
1283: erreur_analyse = d_ex_syntaxe;
1284: break;
1285: }
1286: }
1287: }
1288:
1289: while(((*pointeur_caractere_courant) != base_binaire) &&
1290: ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
1291: (erreur_analyse == d_ex))
1292: {
1293: if (base_binaire == 'b')
1294: {
1295: switch(*pointeur_caractere_courant)
1296: {
1297: case ' ' :
1298: case '0' :
1299: case '1' :
1300: {
1301: break;
1302: }
1303:
1304: default :
1305: {
1306: erreur_analyse = d_ex_syntaxe;
1307: break;
1308: }
1309: }
1310: }
1311: else if (base_binaire == 'o')
1312: {
1313: switch(*pointeur_caractere_courant)
1314: {
1315: case ' ' :
1316: case '0' :
1317: case '1' :
1318: case '2' :
1319: case '3' :
1320: case '4' :
1321: case '5' :
1322: case '6' :
1323: case '7' :
1324: {
1325: break;
1326: }
1327:
1328: default :
1329: {
1330: erreur_analyse = d_ex_syntaxe;
1331: break;
1332: }
1333: }
1334: }
1335: else if (base_binaire == 'd')
1336: {
1337: switch(*pointeur_caractere_courant)
1338: {
1339: case ' ' :
1340: case '0' :
1341: case '1' :
1342: case '2' :
1343: case '3' :
1344: case '4' :
1345: case '5' :
1346: case '6' :
1347: case '7' :
1348: case '8' :
1349: case '9' :
1350: {
1351: break;
1352: }
1353:
1354: default :
1355: {
1356: erreur_analyse = d_ex_syntaxe;
1357: break;
1358: }
1359: }
1360: }
1361: else if (base_binaire != 'h')
1362: {
1363: erreur_analyse = d_ex_syntaxe;
1364: }
1365:
1366: pointeur_caractere_courant++;
1367: }
1368:
1369: if (erreur_analyse == d_ex)
1370: {
1371: pointeur_caractere_courant++;
1372: }
1373:
1374: drapeau_fin_objet = d_vrai;
1375: break;
1376: }
1377:
1378: case '{' :
1379: {
1380: if (pointeur_debut_instruction !=
1381: (pointeur_caractere_courant - 1))
1382: {
1383: erreur_format = d_ex_syntaxe;
1384: }
1385:
1386: niveau = 1;
1387: niveau_annexe = 0;
1388:
1389: while((niveau != 0) && ((*pointeur_caractere_courant) !=
1390: d_code_fin_chaine))
1391: {
1392: switch(*pointeur_caractere_courant)
1393: {
1394: case '{' :
1395: {
1396: if (niveau_annexe == 0)
1397: {
1398: niveau++;
1399: }
1400: else
1401: {
1402: erreur_analyse = d_ex_syntaxe;
1403: }
1404:
1405: break;
1406: }
1407:
1408: case '}' :
1409: {
1410: if (niveau_annexe == 0)
1411: {
1412: niveau--;
1413: }
1414: else
1415: {
1416: erreur_analyse = d_ex_syntaxe;
1417: }
1418:
1419: break;
1420: }
1421:
1422: case '[' :
1423: {
1424: niveau_annexe++;
1425:
1426: if (niveau_annexe > 2)
1427: {
1428: erreur_analyse = d_ex_syntaxe;
1429: }
1430:
1431: break;
1432: }
1433:
1434: case ']' :
1435: {
1436: niveau_annexe--;
1437:
1438: if (niveau_annexe < 0)
1439: {
1440: erreur_analyse = d_ex_syntaxe;
1441: }
1442:
1443: break;
1444: }
1445:
1446: case '"' :
1447: {
1448: if (niveau_annexe == 0)
1449: {
1450: pointeur_caractere_courant++;
1451:
1452: while((*pointeur_caractere_courant != '"') &&
1453: ((*pointeur_caractere_courant) !=
1454: d_code_fin_chaine))
1455: {
1456: if (*pointeur_caractere_courant == '\\')
1457: {
1458: pointeur_caractere_courant++;
1459:
1460: switch(*pointeur_caractere_courant)
1461: {
1462: case '\\' :
1463: case '"' :
1464: {
1465: pointeur_caractere_courant++;
1466: break;
1467: }
1468: }
1469: }
1470: else
1471: {
1472: pointeur_caractere_courant++;
1473: }
1474: }
1475: }
1476: else
1477: {
1478: erreur_analyse = d_ex_syntaxe;
1479: }
1480:
1481: break;
1482: }
1483: }
1484:
1485: pointeur_caractere_courant++;
1486: }
1487:
1488: if ((niveau != 0) || (niveau_annexe != 0))
1489: {
1490: erreur_analyse = d_ex_syntaxe;
1491: }
1492:
1493: drapeau_fin_objet = d_vrai;
1494: break;
1495: }
1496:
1497: case '[' :
1498: {
1499: if (pointeur_debut_instruction !=
1500: (pointeur_caractere_courant - 1))
1501: {
1502: erreur_format = d_ex_syntaxe;
1503: }
1504:
1505: niveau = 1;
1506:
1507: while((niveau > 0) && ((*pointeur_caractere_courant) !=
1508: d_code_fin_chaine) && (erreur_analyse == d_ex))
1509: {
1510: switch(*pointeur_caractere_courant)
1511: {
1512: case '[' :
1513: {
1514: niveau++;
1515: break;
1516: }
1517:
1518: case ']' :
1519: {
1520: niveau--;
1521: break;
1522: }
1523:
1524: case '0' :
1525: case '1' :
1526: case '2' :
1527: case '3' :
1528: case '4' :
1529: case '5' :
1530: case '6' :
1531: case '7' :
1532: case '8' :
1533: case '9' :
1534: case '+' :
1535: case '-' :
1536: case 'e' :
1537: case 'E' :
1538: case '.' :
1539: case ',' :
1540: case '(' :
1541: case ')' :
1542: case ' ' :
1543: {
1544: break;
1545: }
1546:
1547: default :
1548: {
1549: erreur_analyse = d_ex_syntaxe;
1550: break;
1551: }
1552: }
1553:
1554: if (niveau < 0)
1555: {
1556: erreur_analyse = d_ex_syntaxe;
1557: }
1558: else if (niveau > 2)
1559: {
1560: erreur_format = d_ex_syntaxe;
1561: }
1562:
1563: pointeur_caractere_courant++;
1564: }
1565:
1566: if (niveau != 0)
1567: {
1568: erreur_analyse = d_ex_syntaxe;
1569: }
1570:
1571: drapeau_fin_objet = d_vrai;
1572: break;
1573: }
1574:
1575: case '<' :
1576: {
1577: if (((*s_etat_processus).autorisation_empilement_programme
1578: == 'Y') && ((*pointeur_caractere_courant) == '<'))
1579: {
1580: if (pointeur_debut_instruction !=
1581: (pointeur_caractere_courant - 1))
1582: {
1583: erreur_format = d_ex_syntaxe;
1584: }
1585:
1586: niveau = 1;
1587:
1588: while((niveau != 0) && ((*pointeur_caractere_courant) !=
1589: d_code_fin_chaine))
1590: {
1591: if (((*pointeur_caractere_courant) == '<') &&
1592: ((*(pointeur_caractere_courant + 1)) == '<'))
1593: {
1594: niveau++;
1595: pointeur_caractere_courant++;
1596: }
1597: else if (((*pointeur_caractere_courant) == '>') &&
1598: ((*(pointeur_caractere_courant + 1)) == '>'))
1599: {
1600: niveau--;
1601: pointeur_caractere_courant++;
1602: }
1603: else if ((*pointeur_caractere_courant) == '"')
1604: {
1605: pointeur_caractere_courant++;
1606:
1607: while((*pointeur_caractere_courant != '"') &&
1608: ((*pointeur_caractere_courant) !=
1609: d_code_fin_chaine))
1610: {
1611: if (*pointeur_caractere_courant == '\\')
1612: {
1613: pointeur_caractere_courant++;
1614:
1615: switch(*pointeur_caractere_courant)
1616: {
1617: case '\\' :
1618: case '"' :
1619: {
1620: pointeur_caractere_courant++;
1621: break;
1622: }
1623: }
1624: }
1625: else
1626: {
1627: pointeur_caractere_courant++;
1628: }
1629: }
1630: }
1631:
1632: pointeur_caractere_courant++;
1633: }
1634:
1635: if (niveau != 0)
1636: {
1637: erreur_analyse = d_ex_syntaxe;
1638: }
1639:
1640: drapeau_fin_objet = d_vrai;
1641: }
1642: else if ((*pointeur_caractere_courant) == '[')
1643: {
1644: if (pointeur_debut_instruction !=
1645: (pointeur_caractere_courant - 1))
1646: {
1647: erreur_format = d_ex_syntaxe;
1648: }
1649:
1650: pointeur_caractere_courant++;
1651: drapeau_fin_objet = d_faux;
1652:
1653: while(((*pointeur_caractere_courant) != d_code_fin_chaine)
1654: && (erreur_format == d_absence_erreur))
1655: {
1656: while((*pointeur_caractere_courant) == d_code_espace)
1657: {
1658: pointeur_caractere_courant++;
1659: }
1660:
1661: if ((*pointeur_caractere_courant) == ']')
1662: {
1663: if ((*(++pointeur_caractere_courant)) == '>')
1664: {
1665: drapeau_fin_objet = d_vrai;
1666: }
1667: else
1668: {
1669: erreur_analyse = d_ex_syntaxe;
1670: }
1671:
1672: pointeur_caractere_courant++;
1673: break;
1674: }
1675:
1676: if ((erreur_format == d_absence_erreur) &&
1677: (drapeau_fin_objet == d_faux))
1678: {
1679: (*s_etat_processus).position_courante =
1680: pointeur_caractere_courant
1681: - (*s_etat_processus).definitions_chainees;
1682:
1683: if ((erreur = recherche_instruction_suivante(
1684: s_etat_processus)) != d_absence_erreur)
1685: {
1686: if ((*s_etat_processus).instruction_courante
1687: != NULL)
1688: {
1689: free((*s_etat_processus)
1690: .instruction_courante);
1691: }
1692:
1693: return(d_erreur);
1694: }
1695:
1696: pointeur_caractere_courant = (*s_etat_processus)
1697: .definitions_chainees + (*s_etat_processus)
1698: .position_courante;
1699:
1700: free((*s_etat_processus).instruction_courante);
1701: }
1702: }
1703:
1704: if (drapeau_fin_objet == d_faux)
1705: {
1706: erreur_analyse = d_ex_syntaxe;
1707: drapeau_fin_objet = d_vrai;
1708: }
1709: }
1710:
1711: break;
1712: }
1713: }
1714: }
1715:
1716: pointeur_fin_instruction = pointeur_caractere_courant;
1717:
1718: (*s_etat_processus).instruction_courante = (unsigned char *)
1719: malloc(((pointeur_fin_instruction - pointeur_debut_instruction)
1720: + 1) * sizeof(unsigned char));
1721:
1722: if ((*s_etat_processus).instruction_courante == NULL)
1723: {
1724: erreur = d_erreur;
1725: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1726: }
1727: else if (pointeur_fin_instruction != pointeur_debut_instruction)
1728: {
1729: pointeur_caractere_courant = pointeur_debut_instruction;
1730: pointeur_caractere_destination =
1731: (*s_etat_processus).instruction_courante;
1732:
1733: do
1734: {
1735: *pointeur_caractere_destination++ = *pointeur_caractere_courant++;
1736: } while(pointeur_caractere_courant < pointeur_fin_instruction);
1737:
1738: (*pointeur_caractere_destination) = d_code_fin_chaine;
1739:
1740: erreur = ((erreur_analyse == d_ex) && (erreur_format == d_ex))
1741: ? d_absence_erreur : d_erreur;
1742: (*s_etat_processus).erreur_execution = erreur_analyse;
1743: }
1744: else
1745: {
1746: (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
1747: }
1748:
1749: (*s_etat_processus).position_courante = pointeur_fin_instruction
1750: - (*s_etat_processus).definitions_chainees;
1751:
1752: return(erreur);
1753: }
1754:
1755:
1756: /*
1757: ================================================================================
1758: Routine mettant la chaine d'entrée en majuscule
1759: ================================================================================
1760: Entrée : pointeur sur une chaine en minuscules.
1761: --------------------------------------------------------------------------------
1762: Sortie : pointeur sur la chaine en majuscules. Si le pointeur retourné
1763: est nul, il s'est produit une erreur. L'allocation est faite dans la
1764: routine.
1765: --------------------------------------------------------------------------------
1766: Effets de bord : néant.
1767: ================================================================================
1768: */
1769:
1770: unsigned char *
1771: conversion_majuscule(unsigned char *chaine)
1772: {
1773: register unsigned char *caractere_courant;
1774: register unsigned char *caractere_courant_converti;
1775: register unsigned char *chaine_convertie;
1776:
1777: unsigned long longueur_chaine_plus_terminaison;
1778:
1779: longueur_chaine_plus_terminaison = 0;
1780: caractere_courant = chaine;
1781:
1782: while((*caractere_courant) != d_code_fin_chaine)
1783: {
1784: caractere_courant++;
1785: longueur_chaine_plus_terminaison++;
1786: }
1787:
1788: caractere_courant = chaine;
1789: caractere_courant_converti = chaine_convertie = (unsigned char *) malloc(
1790: (longueur_chaine_plus_terminaison + 1) * sizeof(unsigned char));
1791:
1792: if (chaine_convertie != NULL)
1793: {
1794: while((*caractere_courant) != d_code_fin_chaine)
1795: {
1796: if (isalpha((*caractere_courant)))
1797: {
1798: (*caractere_courant_converti) = (unsigned char)
1799: toupper((*caractere_courant));
1800: }
1801: else
1802: {
1803: (*caractere_courant_converti) = (*caractere_courant);
1804: }
1805:
1806: caractere_courant++;
1807: caractere_courant_converti++;
1808: }
1809:
1810: (*caractere_courant_converti) = d_code_fin_chaine;
1811: }
1812:
1813: return(chaine_convertie);
1814: }
1815:
1.9 bertrand 1816: void
1817: conversion_majuscule_limitee(unsigned char *chaine_entree,
1818: unsigned char *chaine_sortie, unsigned long longueur)
1819: {
1820: unsigned long i;
1821:
1822: for(i = 0; i < longueur; i++)
1823: {
1824: if (isalpha((*chaine_entree)))
1825: {
1826: (*chaine_sortie) = (unsigned char) toupper((*chaine_entree));
1827: }
1828: else
1829: {
1830: (*chaine_sortie) = (*chaine_entree);
1831: }
1832:
1833: if ((*chaine_entree) == d_code_fin_chaine)
1834: {
1835: break;
1836: }
1837:
1838: chaine_entree++;
1839: chaine_sortie++;
1840: }
1841:
1842: return;
1843: }
1844:
1.1 bertrand 1845:
1846: /*
1847: ================================================================================
1848: Initialisation de l'état du calculateur
1849: Configuration par défaut d'un calculateur HP-28S
1850: ================================================================================
1851: Entrée : pointeur sur la structure struct_processus
1852: --------------------------------------------------------------------------------
1853: Sortie : néant
1854: --------------------------------------------------------------------------------
1855: Effets de bord : néant
1856: ================================================================================
1857: */
1858:
1859: void
1860: initialisation_drapeaux(struct_processus *s_etat_processus)
1861: {
1862: unsigned long i;
1863:
1864: for(i = 0; i < 31; cf(s_etat_processus, i++));
1865:
1866: if ((*s_etat_processus).lancement_interactif == d_vrai)
1867: {
1868: sf(s_etat_processus, 31);
1869: /* LAST autorisé */
1870: }
1871: else
1872: {
1873: cf(s_etat_processus, 31);
1874: /* LAST invalidé */
1875: }
1876:
1877: cf(s_etat_processus, 32); /* Impression automatique */
1878: cf(s_etat_processus, 33); /* CR automatique (disp) */
1.23 bertrand 1879: sf(s_etat_processus, 34); /* Évaluation des caractères de contrôle */
1880: sf(s_etat_processus, 35); /* Évaluation symbolique des constantes */
1881: sf(s_etat_processus, 36); /* Évaluation symbolique des fonctions */
1.1 bertrand 1882: sf(s_etat_processus, 37); /* Taille de mot pour les entiers binaires */
1883: sf(s_etat_processus, 38); /* Taille de mot pour les entiers binaires */
1884: sf(s_etat_processus, 39); /* Taille de mot pour les entiers binaires */
1885: sf(s_etat_processus, 40); /* Taille de mot pour les entiers binaires */
1886: sf(s_etat_processus, 41); /* Taille de mot pour les entiers binaires */
1887: sf(s_etat_processus, 42); /* Taille de mot pour les entiers binaires */
1888: /*
1889: 37 : bit de poids faible
1890: 42 : bit de poids fort
1891: Les six drapeaux peuvent être nuls. Dans ce cas, la longueur des mots
1892: binaires reste de un bit.
1893: */
1894: cf(s_etat_processus, 43); /* Base de numération binaire */
1895: cf(s_etat_processus, 44); /* Base de numération binaire */
1896: /*
1897: 43 44 = 00 => décimal
1898: 43 44 = 01 => binaire
1899: 43 44 = 10 => octal
1900: 43 44 = 11 => hexadécimal
1901: */
1902: sf(s_etat_processus, 45); /* Affichage multiligne du niveau 1 */
1903: cf(s_etat_processus, 46); /* Réservé */
1904: cf(s_etat_processus, 47); /* Réservé */
1905: /*
1906: 46 et 47 réservés sur le calculateur HP28S
1907: 46 47 = 00 => système rectangulaire
1908: 46 47 = 01 => système cylindrique
1909: 46 47 = 10 => système sphérique
1910: */
1911: cf(s_etat_processus, 48); /* Séparateur décimal */
1912: cf(s_etat_processus, 49); /* Format des nombres réels */
1913: cf(s_etat_processus, 50); /* Format des nombres réels */
1914: /*
1915: 49 50 = 00 => standard
1916: 49 50 = 01 => scientifique
1917: 49 50 = 10 => virgule fixe
1918: 49 50 = 11 => ingénieur
1919: */
1920: cf(s_etat_processus, 51); /* Tonalité */
1921: cf(s_etat_processus, 52); /* REDRAW automatique */
1922: cf(s_etat_processus, 53); /* Nombre de chiffres décimaux */
1923: cf(s_etat_processus, 54); /* Nombre de chiffres décimaux */
1924: cf(s_etat_processus, 55); /* Nombre de chiffres décimaux */
1925: cf(s_etat_processus, 56); /* Nombre de chiffres décimaux */
1926: /*
1927: 53 : bit de poids faible
1928: 56 : bit de poids fort
1929: */
1930: cf(s_etat_processus, 57); /* Underflow traité normalement */
1931: cf(s_etat_processus, 58); /* Overflow traité normalement */
1932: sf(s_etat_processus, 59); /* Infinite result traité normalement */
1933: sf(s_etat_processus, 60); /* Angles */
1934: /*
1935: 60 = 0 => degrés
1936: 60 = 1 => radians
1937: */
1938: cf(s_etat_processus, 61); /* Underflow- traité en exception */
1939: cf(s_etat_processus, 62); /* Underflow+ traité en exception */
1940: cf(s_etat_processus, 63); /* Overflow traité en exception */
1941: cf(s_etat_processus, 64); /* Infinite result traité en exception */
1942: }
1943:
1944: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>