File:
[local] /
rpl /
src /
instructions_k1.c
Revision
1.22:
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Jun 21 15:26:32 2011 UTC (13 years, 10 months ago) by
bertrand
Branches:
MAIN
CVS tags:
HEAD
Correction d'une réinitialisation sauvage de la pile des variables par niveau
dans la copie de la structure de description du processus. Cela corrige
la fonction SPAWN qui échouait sur un segmentation fault car la pile des
variables par niveau était vide alors même que l'arbre des variables contenait
bien les variables. Passage à la prerelease 2.
1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.0.prerelease.2
4: Copyright (C) 1989-2011 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25:
26: /*
27: ================================================================================
28: Fonction 'kill'
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_kill(struct_processus *s_etat_processus)
40: {
41: (*s_etat_processus).erreur_execution = d_ex;
42:
43: if ((*s_etat_processus).affichage_arguments == 'Y')
44: {
45: printf("\n KILL ");
46:
47: if ((*s_etat_processus).langue == 'F')
48: {
49: printf("(abandon du processus en cours)\n\n");
50: printf(" Aucun argument\n");
51: }
52: else
53: {
54: printf("(current process abort)\n\n");
55: printf(" No argument\n");
56: }
57:
58: return;
59: }
60: else if ((*s_etat_processus).test_instruction == 'Y')
61: {
62: (*s_etat_processus).nombre_arguments = -1;
63: return;
64: }
65:
66: if (test_cfsf(s_etat_processus, 31) == d_vrai)
67: {
68: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
69: {
70: return;
71: }
72: }
73:
74: (*s_etat_processus).requete_arret = 'Y';
75:
76: if ((*s_etat_processus).traitement_instruction_halt == d_vrai)
77: {
78: (*s_etat_processus).execution_pas_suivant = d_vrai;
79: }
80:
81: return;
82: }
83:
84:
85: /*
86: ================================================================================
87: Fonction 'key'
88: ================================================================================
89: Entrées :
90: --------------------------------------------------------------------------------
91: Sorties :
92: --------------------------------------------------------------------------------
93: Effets de bord : néant
94: ================================================================================
95: */
96:
97: void
98: instruction_key(struct_processus *s_etat_processus)
99: {
100: int unite;
101:
102: struct_objet *s_objet_caractere;
103: struct_objet *s_objet_drapeau;
104:
105: struct termios tp;
106:
107: tcflag_t drapeaux;
108:
109: unsigned char caractere;
110:
111: (*s_etat_processus).erreur_execution = d_ex;
112:
113: if ((*s_etat_processus).affichage_arguments == 'Y')
114: {
115: printf("\n KEY ");
116:
117: if ((*s_etat_processus).langue == 'F')
118: {
119: printf("(saisit une entrée au vol)\n\n");
120: }
121: else
122: {
123: printf("(non blocking character input)\n\n");
124: }
125:
126: printf("-> 1: %s (0)\n\n", d_INT);
127:
128: printf("-> 2: %s\n", d_CHN);
129: printf(" 1: %s (-1)\n", d_INT);
130:
131: return;
132: }
133: else if ((*s_etat_processus).test_instruction == 'Y')
134: {
135: (*s_etat_processus).nombre_arguments = -1;
136: return;
137: }
138:
139: if (test_cfsf(s_etat_processus, 31) == d_vrai)
140: {
141: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
142: {
143: return;
144: }
145: }
146:
147: if (tcgetattr(0, &tp) == -1)
148: {
149: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
150: return;
151: }
152:
153: drapeaux = (ECHO | ECHOK | ICANON);
154: tp.c_lflag &= (~drapeaux);
155:
156: if (tcsetattr(0, TCSANOW, &tp) == -1)
157: {
158: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
159: return;
160: }
161:
162: if ((unite = open(ttyname(0), O_NONBLOCK|O_NOCTTY)) == -1)
163: {
164: tp.c_lflag |= drapeaux;
165:
166: if (tcsetattr(0, TCSANOW, &tp) == -1)
167: {
168: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
169: return;
170: }
171:
172: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
173: return;
174: }
175:
176: if ((s_objet_drapeau = allocation(s_etat_processus, INT)) == NULL)
177: {
178: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
179: return;
180: }
181:
182: if (read_atomic(s_etat_processus, unite, (void *) &caractere, 1) == -1)
183: {
184: (*((integer8 *) (*s_objet_drapeau).objet)) = 0;
185:
186: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
187: s_objet_drapeau) == d_erreur)
188: {
189: return;
190: }
191: }
192: else
193: {
194: if ((s_objet_caractere = allocation(s_etat_processus, CHN)) == NULL)
195: {
196: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
197: return;
198: }
199:
200: if (((*s_objet_caractere).objet = malloc(2 *
201: sizeof(unsigned char))) == NULL)
202: {
203: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
204: return;
205: }
206:
207: ((unsigned char *) (*s_objet_caractere).objet)[0] = caractere;
208: ((unsigned char *) (*s_objet_caractere).objet)[1] = d_code_fin_chaine;
209:
210: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
211: s_objet_caractere) == d_erreur)
212: {
213: return;
214: }
215:
216: (*((integer8 *) (*s_objet_drapeau).objet)) = -1;
217:
218: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
219: s_objet_drapeau) == d_erreur)
220: {
221: return;
222: }
223: }
224:
225: if (close(unite) == -1)
226: {
227: tp.c_lflag |= drapeaux;
228:
229: if (tcsetattr(0, TCSANOW, &tp) == -1)
230: {
231: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
232: return;
233: }
234:
235: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
236: return;
237: }
238:
239: tp.c_lflag |= drapeaux;
240:
241: if (tcsetattr(0, TCSANOW, &tp) == -1)
242: {
243: (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin;
244: return;
245: }
246:
247: return;
248: }
249:
250:
251: /*
252: ================================================================================
253: Fonction 'kind'
254: ================================================================================
255: Entrées : structure processus
256: --------------------------------------------------------------------------------
257: Sorties :
258: --------------------------------------------------------------------------------
259: Effets de bord : néant
260: ================================================================================
261: */
262:
263: void
264: instruction_kind(struct_processus *s_etat_processus)
265: {
266: struct_objet *s_objet_argument;
267: struct_objet *s_objet_resultat;
268:
269: (*s_etat_processus).erreur_execution = d_ex;
270:
271: if ((*s_etat_processus).affichage_arguments == 'Y')
272: {
273: printf("\n KIND ");
274:
275: if ((*s_etat_processus).langue == 'F')
276: {
277: printf("(variété d'objet)\n\n");
278: }
279: else
280: {
281: printf("(kind of object)\n\n");
282: }
283:
284: printf(" 1: %s, %s, %s, %s, %s, %s,\n"
285: " %s, %s, %s\n",
286: d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX);
287: printf("-> 1: %s\n\n", d_INT);
288:
289: if ((*s_etat_processus).langue == 'F')
290: {
291: printf(" Valeurs renvoyées : \n\n");
292: printf(" 0 : objet entier\n");
293: printf(" 1 : objet réel\n");
294: printf(" 2 : objet complexe\n");
295: }
296: else
297: {
298: printf(" Returned values : \n\n");
299: printf(" 0 : integer object\n");
300: printf(" 1 : real object\n");
301: printf(" 2 : complex object\n");
302: }
303:
304: return;
305: }
306: else if ((*s_etat_processus).test_instruction == 'Y')
307: {
308: (*s_etat_processus).nombre_arguments = -1;
309: return;
310: }
311:
312: if (test_cfsf(s_etat_processus, 31) == d_vrai)
313: {
314: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
315: {
316: return;
317: }
318: }
319:
320: if (depilement(s_etat_processus, &((*s_etat_processus)
321: .l_base_pile), &s_objet_argument) == d_erreur)
322: {
323: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
324: return;
325: }
326:
327: if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
328: {
329: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
330: return;
331: }
332:
333: if (((*s_objet_argument).type == INT) ||
334: ((*s_objet_argument).type == VIN) ||
335: ((*s_objet_argument).type == MIN))
336: {
337: (*((integer8 *) (*s_objet_resultat).objet)) = 0;
338: }
339: else if (((*s_objet_argument).type == REL) ||
340: ((*s_objet_argument).type == VRL) ||
341: ((*s_objet_argument).type == MRL))
342: {
343: (*((integer8 *) (*s_objet_resultat).objet)) = 1;
344: }
345: else if (((*s_objet_argument).type == CPL) ||
346: ((*s_objet_argument).type == VCX) ||
347: ((*s_objet_argument).type == MCX))
348: {
349: (*((integer8 *) (*s_objet_resultat).objet)) = 2;
350: }
351: else
352: {
353: /*
354: * Les autres types de données sont des types non numériques.
355: */
356:
357: liberation(s_etat_processus, s_objet_argument);
358:
359: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
360: return;
361: }
362:
363: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
364: s_objet_resultat) == d_erreur)
365: {
366: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
367: return;
368: }
369:
370: liberation(s_etat_processus, s_objet_argument);
371:
372: return;
373: }
374:
375:
376: /*
377: ================================================================================
378: Fonction 'keytitle'
379: ================================================================================
380: Entrées :
381: --------------------------------------------------------------------------------
382: Sorties :
383: --------------------------------------------------------------------------------
384: Effets de bord : néant
385: ================================================================================
386: */
387:
388: void
389: instruction_keytitle(struct_processus *s_etat_processus)
390: {
391: struct_objet *s_objet;
392:
393: (*s_etat_processus).erreur_execution = d_ex;
394:
395: if ((*s_etat_processus).affichage_arguments == 'Y')
396: {
397: printf("\n KEYTITLE ");
398:
399: if ((*s_etat_processus).langue == 'F')
400: {
401: printf("(titre de la légende d'un graphique)\n\n");
402: }
403: else
404: {
405: printf("(title of graphic key)\n\n");
406: }
407:
408: printf(" 1: %s\n", d_CHN);
409:
410: return;
411: }
412: else if ((*s_etat_processus).test_instruction == 'Y')
413: {
414: (*s_etat_processus).nombre_arguments = -1;
415: return;
416: }
417:
418: if (test_cfsf(s_etat_processus, 31) == d_vrai)
419: {
420: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
421: {
422: return;
423: }
424: }
425:
426: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
427: &s_objet) == d_erreur)
428: {
429: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
430: return;
431: }
432:
433: if ((*s_objet).type == CHN)
434: {
435: free((*s_etat_processus).legende);
436:
437: if (((*s_etat_processus).legende = malloc((strlen((unsigned char *)
438: (*s_objet).objet) + 1) * sizeof(unsigned char))) == NULL)
439: {
440: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
441: return;
442: }
443:
444: strcpy((*s_etat_processus).legende, (unsigned char *) (*s_objet).objet);
445: liberation(s_etat_processus, s_objet);
446:
447: (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
448: }
449: else
450: {
451: liberation(s_etat_processus, s_objet);
452:
453: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
454: return;
455: }
456:
457: return;
458: }
459:
460:
461: /*
462: ================================================================================
463: Fonction 'keylabel'
464: ================================================================================
465: Entrées :
466: --------------------------------------------------------------------------------
467: Sorties :
468: --------------------------------------------------------------------------------
469: Effets de bord : néant
470: ================================================================================
471: */
472:
473: void
474: instruction_keylabel(struct_processus *s_etat_processus)
475: {
476: struct_fichier_graphique *l_element_courant;
477:
478: struct_objet *s_objet;
479:
480: (*s_etat_processus).erreur_execution = d_ex;
481:
482: if ((*s_etat_processus).affichage_arguments == 'Y')
483: {
484: printf("\n KEYLABEL ");
485:
486: if ((*s_etat_processus).langue == 'F')
487: {
488: printf("(label du graphique courant)\n\n");
489: }
490: else
491: {
492: printf("(current graphic label)\n\n");
493: }
494:
495: printf(" 1: %s\n", d_CHN);
496:
497: return;
498: }
499: else if ((*s_etat_processus).test_instruction == 'Y')
500: {
501: (*s_etat_processus).nombre_arguments = -1;
502: return;
503: }
504:
505: if (test_cfsf(s_etat_processus, 31) == d_vrai)
506: {
507: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
508: {
509: return;
510: }
511: }
512:
513: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
514: &s_objet) == d_erreur)
515: {
516: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
517: return;
518: }
519:
520: if ((*s_objet).type == CHN)
521: {
522: l_element_courant = (*s_etat_processus).fichiers_graphiques;
523:
524: if (l_element_courant == NULL)
525: {
526: liberation(s_etat_processus, s_objet);
527:
528: (*s_etat_processus).erreur_execution =
529: d_ex_absence_graphique_courant;
530: return;
531: }
532:
533: while((*l_element_courant).suivant != NULL)
534: {
535: l_element_courant = (*l_element_courant).suivant;
536: }
537:
538: if ((*l_element_courant).legende != NULL)
539: {
540: free((*l_element_courant).legende);
541: }
542:
543: if (((*l_element_courant).legende = malloc((strlen((unsigned char *)
544: (*s_objet).objet) + 1) * sizeof(unsigned char))) == NULL)
545: {
546: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
547: return;
548: }
549:
550: strcpy((*l_element_courant).legende, (unsigned char *)
551: (*s_objet).objet);
552: liberation(s_etat_processus, s_objet);
553:
554: (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
555: }
556: else
557: {
558: liberation(s_etat_processus, s_objet);
559:
560: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
561: return;
562: }
563:
564: return;
565: }
566:
567: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>