1: /*
2: ================================================================================
3: RPL/2 (R) version 4.0.23
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: Analyseur syntaxique de l'interprète RPL/2
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38:
39: static void
40: creation_instruction(struct_processus *s_etat_processus,
41: unsigned char *instruction, void (*routine)())
42: {
43: int i;
44:
45: struct_instruction *l_instruction_courante;
46:
47: unsigned char *ptr;
48:
49: BUG(strlen(instruction) >= d_longueur_maximale_instruction,
50: printf("%s -> %d >= %d\n", instruction, (int) strlen(instruction),
51: d_longueur_maximale_instruction));
52:
53: if ((*s_etat_processus).arbre_instructions == NULL)
54: {
55: if (((*s_etat_processus).arbre_instructions =
56: malloc(sizeof(struct_instruction))) == NULL)
57: {
58: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
59: return;
60: }
61:
62: (*(*s_etat_processus).arbre_instructions).feuille = NULL;
63:
64: if (((*(*s_etat_processus).arbre_instructions).noeud =
65: malloc((*s_etat_processus).nombre_caracteres
66: * sizeof(struct_instruction))) == NULL)
67: {
68: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
69: return;
70: }
71:
72: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
73: {
74: (*(*s_etat_processus).arbre_instructions).noeud[i] = NULL;
75: }
76: }
77:
78: l_instruction_courante = (*s_etat_processus).arbre_instructions;
79: ptr = instruction;
80:
81: while((*ptr) != d_code_fin_chaine)
82: {
83: BUG((*s_etat_processus).pointeurs_caracteres[*ptr] < 0,
84: printf("Instruction=\"%s\", (*ptr)='%c'\n",
85: instruction, *ptr));
86:
87: if ((*l_instruction_courante).noeud[(*s_etat_processus)
88: .pointeurs_caracteres[*ptr]] == NULL)
89: {
90: // Le noeud suivant n'existe pas, on le crée.
91:
92: if (((*l_instruction_courante).noeud[(*s_etat_processus)
93: .pointeurs_caracteres[*ptr]] =
94: malloc(sizeof(struct_instruction))) == NULL)
95: {
96: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
97: return;
98: }
99:
100: (*(*l_instruction_courante).noeud[(*s_etat_processus)
101: .pointeurs_caracteres[*ptr]]).feuille = NULL;
102:
103: if (((*(*l_instruction_courante).noeud[(*s_etat_processus)
104: .pointeurs_caracteres[*ptr]]).noeud =
105: malloc((*s_etat_processus).nombre_caracteres
106: * sizeof(struct_instruction))) == NULL)
107: {
108: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
109: return;
110: }
111:
112: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
113: {
114: (*(*l_instruction_courante).noeud[(*s_etat_processus)
115: .pointeurs_caracteres[*ptr]]).noeud[i] = NULL;
116: }
117: }
118:
119: l_instruction_courante = (*l_instruction_courante).noeud
120: [(*s_etat_processus).pointeurs_caracteres[*ptr]];
121: ptr++;
122: }
123:
124: BUG((*l_instruction_courante).feuille != NULL,
125: printf("Instruction=\"%s\"\n", instruction));
126:
127: (*l_instruction_courante).feuille = routine;
128:
129: return;
130: }
131:
132:
133: void
134: liberation_arbre_instructions(struct_processus *s_etat_processus,
135: struct_instruction *arbre)
136: {
137: int i;
138:
139: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
140: {
141: if ((*arbre).noeud[i] != NULL)
142: {
143: liberation_arbre_instructions(s_etat_processus, (*arbre).noeud[i]);
144: }
145: }
146:
147: free((*arbre).noeud);
148: free(arbre);
149:
150: return;
151: }
152:
153:
154: /*
155: * Caractères autorisés dans les instructions
156: *
157: * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
158: * e i (mais traités comme des majuscules grâce à 'instruction_*_sensible()'
159: * + - * / % ^ < > = ? 1 2
160: */
161:
162: void
163: initialisation_instructions(struct_processus *s_etat_processus)
164: {
165: int decalage;
166: int i;
167: int longueur_tableau;
168:
169: unsigned char caractere;
170:
171: // Récupération de la longueur d'un unsigned char
172:
173: longueur_tableau = 1;
174: decalage = 0;
175: caractere = 1;
176:
177: while((1L << decalage) == (long) ((unsigned char) (caractere << decalage)))
178: {
179: decalage++;
180: longueur_tableau *= 2;
181: }
182:
183: if (((*s_etat_processus).pointeurs_caracteres =
184: malloc(longueur_tableau * sizeof(int))) == NULL)
185: {
186: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
187: return;
188: }
189:
190: for(i = 0; i < longueur_tableau; i++)
191: {
192: (*s_etat_processus).pointeurs_caracteres[i] = -1;
193: }
194:
195: (*s_etat_processus).nombre_caracteres = 0;
196:
197: #define DECLARATION_CARACTERE(c) \
198: do { (*s_etat_processus).pointeurs_caracteres[c] = \
199: (*s_etat_processus).nombre_caracteres++; } while(0)
200:
201: DECLARATION_CARACTERE('A');
202: DECLARATION_CARACTERE('B');
203: DECLARATION_CARACTERE('C');
204: DECLARATION_CARACTERE('D');
205: DECLARATION_CARACTERE('E');
206: DECLARATION_CARACTERE('F');
207: DECLARATION_CARACTERE('G');
208: DECLARATION_CARACTERE('H');
209: DECLARATION_CARACTERE('I');
210: DECLARATION_CARACTERE('J');
211: DECLARATION_CARACTERE('K');
212: DECLARATION_CARACTERE('L');
213: DECLARATION_CARACTERE('M');
214: DECLARATION_CARACTERE('N');
215: DECLARATION_CARACTERE('O');
216: DECLARATION_CARACTERE('P');
217: DECLARATION_CARACTERE('Q');
218: DECLARATION_CARACTERE('R');
219: DECLARATION_CARACTERE('S');
220: DECLARATION_CARACTERE('T');
221: DECLARATION_CARACTERE('U');
222: DECLARATION_CARACTERE('V');
223: DECLARATION_CARACTERE('W');
224: DECLARATION_CARACTERE('X');
225: DECLARATION_CARACTERE('Y');
226: DECLARATION_CARACTERE('Z');
227: DECLARATION_CARACTERE('+');
228: DECLARATION_CARACTERE('-');
229: DECLARATION_CARACTERE('/');
230: DECLARATION_CARACTERE('*');
231: DECLARATION_CARACTERE('%');
232: DECLARATION_CARACTERE('^');
233: DECLARATION_CARACTERE('<');
234: DECLARATION_CARACTERE('>');
235: DECLARATION_CARACTERE('=');
236: DECLARATION_CARACTERE('?');
237: DECLARATION_CARACTERE('1');
238: DECLARATION_CARACTERE('2');
239:
240: #undef DECLARATION_CARACTERE
241:
242: #define INSTRUCTION(chaine, fonction) \
243: creation_instruction(s_etat_processus, chaine, fonction)
244:
245: INSTRUCTION("E", instruction_sensible_e);
246: INSTRUCTION("I", instruction_sensible_i);
247: INSTRUCTION("+", instruction_plus);
248: INSTRUCTION("-", instruction_moins);
249: INSTRUCTION("*", instruction_multiplication);
250: INSTRUCTION("/", instruction_division);
251: INSTRUCTION("%", instruction_pourcent);
252: INSTRUCTION("^", instruction_puissance);
253: INSTRUCTION("<", instruction_lt);
254: INSTRUCTION("=", instruction_egalite);
255: INSTRUCTION(">", instruction_gt);
256:
257: INSTRUCTION("CF", instruction_cf);
258: INSTRUCTION("CR", instruction_cr);
259: INSTRUCTION("DO", instruction_do);
260: INSTRUCTION("FP", instruction_fp);
261: INSTRUCTION("IF", instruction_if);
262: INSTRUCTION("IM", instruction_im);
263: INSTRUCTION("IN", instruction_in);
264: INSTRUCTION("IP", instruction_ip);
265: INSTRUCTION("LN", instruction_ln);
266: INSTRUCTION("LQ", instruction_lq);
267: INSTRUCTION("LU", instruction_lu);
268: INSTRUCTION("NS", instruction_ns);
269: INSTRUCTION("OR", instruction_or);
270: INSTRUCTION("PI", instruction_pi);
271: INSTRUCTION("QR", instruction_qr);
272: INSTRUCTION("RE", instruction_re);
273: INSTRUCTION("RL", instruction_rl);
274: INSTRUCTION("RR", instruction_rr);
275: INSTRUCTION("SF", instruction_sf);
276: INSTRUCTION("SL", instruction_sl);
277: INSTRUCTION("SQ", instruction_sq);
278: INSTRUCTION("SR", instruction_sr);
279: INSTRUCTION("SX", instruction_sx);
280: INSTRUCTION("SY", instruction_sy);
281: INSTRUCTION("S+", instruction_s_plus);
282: INSTRUCTION("S-", instruction_s_moins);
283: INSTRUCTION("->", instruction_fleche);
284: INSTRUCTION("*D", instruction_star_d);
285: INSTRUCTION("*H", instruction_star_h);
286: INSTRUCTION("*S", instruction_star_s);
287: INSTRUCTION("*W", instruction_star_w);
288: INSTRUCTION("**", instruction_puissance);
289: INSTRUCTION("%T", instruction_pourcent_t);
290: INSTRUCTION("<=", instruction_le);
291: INSTRUCTION("<<", instruction_vers_niveau_superieur);
292: INSTRUCTION("<>", instruction_ne);
293: INSTRUCTION("==", instruction_same);
294: INSTRUCTION("=>", instruction_ge);
295: INSTRUCTION("=<", instruction_le);
296: INSTRUCTION(">=", instruction_ge);
297: INSTRUCTION(">>", instruction_vers_niveau_inferieur);
298:
299: INSTRUCTION("ABS", instruction_abs);
300: INSTRUCTION("AND", instruction_and);
301: //INSTRUCTION("ARC")
302: //(centre, rayon, theta1, theta2 dans le sens trigonométrique)
303: INSTRUCTION("ARG", instruction_arg);
304: INSTRUCTION("ASL", instruction_asl);
305: INSTRUCTION("ASR", instruction_asr);
306: //INSTRUCTION("BAR")
307: //Instruction HP48 (sélectionne le type de graphique à barres)
308: //Chaque point est représenté par une barre verticale.
309: INSTRUCTION("BIN", instruction_bin);
310: //INSTRUCTION("BOX")
311: //(point 1, point 2)
312: INSTRUCTION("CHR", instruction_chr);
313: INSTRUCTION("CLS", instruction_cls);
314: INSTRUCTION("CON", instruction_con);
315: INSTRUCTION("COS", instruction_cos);
316: INSTRUCTION("COV", instruction_cov);
317: INSTRUCTION("DEC", instruction_dec);
318: INSTRUCTION("DEG", instruction_deg);
319: INSTRUCTION("DER", instruction_der);
320: INSTRUCTION("DET", instruction_det);
321: INSTRUCTION("DFT", instruction_dft);
322: INSTRUCTION("DOT", instruction_dot);
323: INSTRUCTION("DUP", instruction_dup);
324: INSTRUCTION("EGV", instruction_egv);
325: INSTRUCTION("END", instruction_end);
326: INSTRUCTION("ENG", instruction_eng);
327: INSTRUCTION("EXP", instruction_exp);
328: INSTRUCTION("FC?", instruction_fc_test);
329: INSTRUCTION("FFT", instruction_fft);
330: //INSTRUCTION("FIT")
331: //Extension RPL/2 (choix de la méthode de régression, par défaut, 'LINEAR'.
332: //Les types sont
333: //'LINEAR' => y = b + mx
334: //'LOGARITHMIC' => y = b + m ln(x)
335: //'EXPONENTIAL' => y = be^(mx) ou ln(y) = ln(b) + mx
336: //'POWER' => y = bx^m ou ln(y) = ln(b) + m ln(x)
337: INSTRUCTION("FIX", instruction_fix);
338: INSTRUCTION("FOR", instruction_for);
339: INSTRUCTION("FS?", instruction_fs_test);
340: INSTRUCTION("GET", instruction_get);
341: INSTRUCTION("HEX", instruction_hex);
342: INSTRUCTION("IDN", instruction_idn);
343: INSTRUCTION("IFT", instruction_ift);
344: INSTRUCTION("INT", instruction_int);
345: INSTRUCTION("INV", instruction_inv);
346: INSTRUCTION("KEY", instruction_key);
347: INSTRUCTION("LOG", instruction_log);
348: INSTRUCTION("LSQ", instruction_lsq);
349: INSTRUCTION("MAX", instruction_max);
350: INSTRUCTION("MEM", instruction_mem);
351: INSTRUCTION("MIN", instruction_min);
352: INSTRUCTION("MOD", instruction_mod);
353: INSTRUCTION("NEG", instruction_neg);
354: INSTRUCTION("NOT", instruction_not);
355: INSTRUCTION("NUM", instruction_num);
356: INSTRUCTION("OCT", instruction_oct);
357: INSTRUCTION("POS", instruction_pos);
358: INSTRUCTION("PR1", instruction_pr1);
359: INSTRUCTION("PUT", instruction_put);
360: INSTRUCTION("RAD", instruction_rad);
361: INSTRUCTION("RCI", instruction_rci);
362: INSTRUCTION("RCL", instruction_rcl);
363: INSTRUCTION("RDM", instruction_rdm);
364: INSTRUCTION("RDZ", instruction_rdz);
365: INSTRUCTION("RES", instruction_res);
366: INSTRUCTION("RLB", instruction_rlb);
367: INSTRUCTION("RND", instruction_rnd);
368: INSTRUCTION("ROT", instruction_rot);
369: INSTRUCTION("RRB", instruction_rrb);
370: INSTRUCTION("RSD", instruction_rsd);
371: INSTRUCTION("SCI", instruction_sci);
372: INSTRUCTION("SIN", instruction_sin);
373: INSTRUCTION("SLB", instruction_slb);
374: INSTRUCTION("SRB", instruction_srb);
375: INSTRUCTION("SST", instruction_sst);
376: INSTRUCTION("STD", instruction_std);
377: INSTRUCTION("STO", instruction_sto);
378: INSTRUCTION("SVD", instruction_svd);
379: INSTRUCTION("SVL", instruction_svl);
380: INSTRUCTION("SUB", instruction_sub);
381: INSTRUCTION("SWI", instruction_swi);
382: INSTRUCTION("SX2", instruction_sx2);
383: INSTRUCTION("SXY", instruction_sxy);
384: INSTRUCTION("SY2", instruction_sy2);
385: INSTRUCTION("TAN", instruction_tan);
386: INSTRUCTION("TOT", instruction_tot);
387: INSTRUCTION("TRN", instruction_trn);
388: INSTRUCTION("USE", instruction_use);
389: INSTRUCTION("VAR", instruction_var);
390: //INSTRUCTION("V->")
391: //Instruction HP48 (éclate un vecteur [ x y ] => x y quel que soit le
392: //système de
393: //coordonnées)
394: INSTRUCTION("XOR", instruction_xor);
395: INSTRUCTION("->Q", instruction_fleche_q);
396: INSTRUCTION("%CH", instruction_pourcent_ch);
397:
398: INSTRUCTION("ACOS", instruction_acos);
399: INSTRUCTION("ALOG", instruction_alog);
400: INSTRUCTION("ASIN", instruction_asin);
401: INSTRUCTION("ATAN", instruction_atan);
402: INSTRUCTION("AXES", instruction_axes);
403: INSTRUCTION("BEEP", instruction_beep);
404: INSTRUCTION("B->R", instruction_b_vers_r);
405: INSTRUCTION("CASE", instruction_case);
406: INSTRUCTION("CEIL", instruction_ceil);
407: INSTRUCTION("CLMF", instruction_clmf);
408: INSTRUCTION("CNRM", instruction_cnrm);
409: INSTRUCTION("COLS", instruction_cols);
410: INSTRUCTION("COL+", instruction_col_plus);
411: INSTRUCTION("COL-", instruction_col_moins);
412: INSTRUCTION("COMB", instruction_comb);
413: INSTRUCTION("COND", instruction_cond);
414: INSTRUCTION("CONJ", instruction_conj);
415: INSTRUCTION("CONT", instruction_cont);
416: INSTRUCTION("COPY", instruction_copy);
417: INSTRUCTION("CORR", instruction_corr);
418: INSTRUCTION("COSH", instruction_cosh);
419: INSTRUCTION("CSWP", instruction_cswp);
420: INSTRUCTION("C->R", instruction_c_vers_r);
421: INSTRUCTION("DATE", instruction_date);
422: INSTRUCTION("DECR", instruction_decr);
423: INSTRUCTION("DISP", instruction_disp);
424: INSTRUCTION("DRAW", instruction_draw);
425: INSTRUCTION("DRAX", instruction_drax);
426: INSTRUCTION("DROP", instruction_drop);
427: INSTRUCTION("DRWS", instruction_drws);
428: INSTRUCTION("DUP2", instruction_dup2);
429: INSTRUCTION("DUPN", instruction_dupn);
430: INSTRUCTION("D->R", instruction_d_vers_r);
431: INSTRUCTION("EDIT", instruction_edit);
432: INSTRUCTION("EGVL", instruction_egvl);
433: INSTRUCTION("ELSE", instruction_else);
434: INSTRUCTION("ERRM", instruction_errm);
435: INSTRUCTION("ERRN", instruction_errn);
436: INSTRUCTION("EVAL", instruction_eval);
437: INSTRUCTION("EXIT", instruction_exit);
438: INSTRUCTION("EXPM", instruction_expm);
439: INSTRUCTION("FACT", instruction_fact);
440: INSTRUCTION("FC?C", instruction_fc_test_c);
441: INSTRUCTION("FC?S", instruction_fc_test_s);
442: //INSTRUCTION("FORM")
443: INSTRUCTION("FS?C", instruction_fs_test_c);
444: INSTRUCTION("FS?S", instruction_fs_test_s);
445: INSTRUCTION("FUSE", instruction_fuse);
446: INSTRUCTION("GEGV", instruction_gegv);
447: INSTRUCTION("GETC", instruction_getc);
448: INSTRUCTION("GETI", instruction_geti);
449: INSTRUCTION("GETR", instruction_getr);
450: INSTRUCTION("HALT", instruction_halt);
451: INSTRUCTION("HEAD", instruction_head);
452: INSTRUCTION("HELP", instruction_help);
453: INSTRUCTION("HMS+", instruction_hms_plus);
454: INSTRUCTION("HMS-", instruction_hms_moins);
455: //INSTRUCTION("HOME");
456: INSTRUCTION("IDFT", instruction_idft);
457: INSTRUCTION("IFFT", instruction_ifft);
458: INSTRUCTION("IFTE", instruction_ifte);
459: INSTRUCTION("INCR", instruction_incr);
460: //INSTRUCTION("ISOL");
461: INSTRUCTION("ISWI", instruction_iswi);
462: # ifndef OS2
463: INSTRUCTION("KILL", instruction_kill);
464: # endif
465: INSTRUCTION("KIND", instruction_kind);
466: INSTRUCTION("LAST", instruction_last);
467: INSTRUCTION("LEGV", instruction_legv);
468: INSTRUCTION("LINE", instruction_line);
469: INSTRUCTION("LNP1", instruction_lnp1);
470: INSTRUCTION("LOCK", instruction_lock);
471: INSTRUCTION("L->T", instruction_l_vers_t);
472: INSTRUCTION("MANT", instruction_mant);
473: INSTRUCTION("MARK", instruction_mark);
474: //INSTRUCTION("MAXR")
475: INSTRUCTION("MAXS", instruction_maxs);
476: INSTRUCTION("MEAN", instruction_mean);
477: //INSTRUCTION("MINR");
478: INSTRUCTION("MINS", instruction_mins); // MAXDOUBLE/MINDOUBLE
479: INSTRUCTION("NEXT", instruction_next);
480: //INSTRUCTION("NUMX");
481: //INSTRUCTION("NUMY");
482: INSTRUCTION("OPEN", instruction_open);
483: INSTRUCTION("OVER", instruction_over);
484: //INSTRUCTION("PATH");
485: INSTRUCTION("PCOV", instruction_pcov);
486: INSTRUCTION("PEEK", instruction_peek);
487: INSTRUCTION("PERM", instruction_perm);
488: INSTRUCTION("PICK", instruction_pick);
489: INSTRUCTION("PLOT", instruction_plot);
490: INSTRUCTION("PMAX", instruction_pmax);
491: INSTRUCTION("PMIN", instruction_pmin);
492: # ifndef OS2
493: INSTRUCTION("POKE", instruction_poke);
494: # endif
495: INSTRUCTION("PPAR", instruction_ppar);
496: INSTRUCTION("PRMD", instruction_prmd);
497: INSTRUCTION("PRST", instruction_prst);
498: INSTRUCTION("PUTC", instruction_putc);
499: INSTRUCTION("PUTI", instruction_puti);
500: INSTRUCTION("PUTR", instruction_putr);
501: INSTRUCTION("PVAR", instruction_pvar);
502: INSTRUCTION("P->R", instruction_p_vers_r);
503: //INSTRUCTION("QUAD");
504: INSTRUCTION("RAND", instruction_rand);
505: INSTRUCTION("RANK", instruction_rank);
506: //INSTRUCTION("RANM")
507: //Instruction HP48 (crée une matrice aléatoire
508: //{ nb_lignes nb_colonnes } ou tableau quelconque dont les éléments seront
509: //modifiés pour prendre des valeurs aléatoires entre -9 et 9)
510: INSTRUCTION("RCEQ", instruction_rceq);
511: INSTRUCTION("RCIJ", instruction_rcij);
512: INSTRUCTION("RCLF", instruction_rclf);
513: INSTRUCTION("RCLS", instruction_rcls);
514: INSTRUCTION("RCWS", instruction_rcws);
515: INSTRUCTION("RDGN", instruction_rdgn);
516: INSTRUCTION("READ", instruction_read);
517: INSTRUCTION("RECV", instruction_recv);
518: INSTRUCTION("REGV", instruction_regv);
519: INSTRUCTION("REPL", instruction_repl);
520: INSTRUCTION("RNRM", instruction_rnrm);
521: INSTRUCTION("ROLL", instruction_roll);
522: //INSTRUCTION("ROOT")
523: INSTRUCTION("ROW-", instruction_row_moins);
524: INSTRUCTION("ROW+", instruction_row_plus);
525: //INSTRUCTION("RREF")
526: //Instruction HP48 (transforme [A B] en [I C] par combinaisons linéaires
527: //de lignes)
528: INSTRUCTION("RSWP", instruction_rswp);
529: INSTRUCTION("R->B", instruction_r_vers_b);
530: INSTRUCTION("R->C", instruction_r_vers_c);
531: INSTRUCTION("R->D", instruction_r_vers_d);
532: INSTRUCTION("R->P", instruction_r_vers_p);
533: INSTRUCTION("SAME", instruction_same);
534: INSTRUCTION("SAVE", instruction_save);
535: INSTRUCTION("SCLS", instruction_scls);
536: INSTRUCTION("SDEV", instruction_sdev);
537: INSTRUCTION("SEND", instruction_send);
538: //INSTRUCTION("SHOW");
539: INSTRUCTION("SIGN", instruction_sign);
540: INSTRUCTION("SINH", instruction_sinh);
541: INSTRUCTION("SINV", instruction_sinv);
542: INSTRUCTION("SIZE", instruction_size);
543: INSTRUCTION("SNEG", instruction_sneg);
544: INSTRUCTION("SORT", instruction_sort);
545: INSTRUCTION("SPAR", instruction_spar);
546: INSTRUCTION("SQRT", instruction_sqrt);
547: //INSTRUCTION("SRAD");
548: //INSTRUCTION("SRNM")
549: //Instruction HP48 (renvoie la norme spectrale d'un tableau. Pour une
550: //matrice,
551: //la norme spectrale est égale à sa plus grande valeur singulière. Pour un
552: //vecteur, la fonction est équivalente à ABS.
553: INSTRUCTION("STEP", instruction_step);
554: INSTRUCTION("STEQ", instruction_steq);
555: INSTRUCTION("STO*", instruction_sto_fois);
556: INSTRUCTION("STO+", instruction_sto_plus);
557: INSTRUCTION("STO-", instruction_sto_moins);
558: INSTRUCTION("STO/", instruction_sto_division);
559: INSTRUCTION("STOF", instruction_stof);
560: # ifndef OS2
561: INSTRUCTION("STOP", instruction_stop);
562: # endif
563: INSTRUCTION("STOS", instruction_stos);
564: INSTRUCTION("STWS", instruction_stws);
565: INSTRUCTION("SWAP", instruction_swap);
566: INSTRUCTION("SYNC", instruction_sync);
567: INSTRUCTION("TAIL", instruction_tail);
568: INSTRUCTION("TANH", instruction_tanh);
569: INSTRUCTION("THEN", instruction_then);
570: INSTRUCTION("TIME", instruction_time);
571: INSTRUCTION("TRIM", instruction_trim);
572: INSTRUCTION("TRNC", instruction_trnc);
573: INSTRUCTION("TRUE", instruction_true);
574: INSTRUCTION("TYPE", instruction_type);
575: INSTRUCTION("T->L", instruction_t_vers_l);
576: INSTRUCTION("UTPC", instruction_utpc);
577: INSTRUCTION("UTPF", instruction_utpf);
578: INSTRUCTION("UTPN", instruction_utpn);
579: INSTRUCTION("UTPT", instruction_utpt);
580: INSTRUCTION("VARS", instruction_vars);
581: INSTRUCTION("WAIT", instruction_wait);
582: INSTRUCTION("XCOL", instruction_xcol);
583: INSTRUCTION("XPON", instruction_xpon);
584: //INSTRUCTION("XRNG")
585: //INSTRUCTION("XVOL")
586: INSTRUCTION("YCOL", instruction_ycol);
587: //INSTRUCTION("YRNG")
588: //INSTRUCTION("YVOL")
589: //INSTRUCTION("ZVOL")
590: //INSTRUCTION("->V2")
591: //Instruction HP48 (combine deux réels x et y en un vecteur 2D en fonction
592: //du mode de coordonnées en cours => [ x y ] et ce quel que soit le système
593: //de coordonnées courant)
594: //INSTRUCTION("->V3")
595:
596: INSTRUCTION("ABORT", instruction_abort);
597: INSTRUCTION("ACOSH", instruction_acosh);
598: INSTRUCTION("ALARM", instruction_alarm);
599: INSTRUCTION("ASINH", instruction_asinh);
600: INSTRUCTION("ATANH", instruction_atanh);
601: //INSTRUCTION("BYTES");
602: INSTRUCTION("CENTR", instruction_centr);
603: //INSTRUCTION("CIRCL");
604: INSTRUCTION("CLEAR", instruction_clear);
605: INSTRUCTION("CLLCD", instruction_cllcd);
606: INSTRUCTION("CLOSE", instruction_close);
607: INSTRUCTION("CLUSR", instruction_clusr);
608: //INSTRUCTION("CLVAR");
609: //INSTRUCTION("COLCT")
610: INSTRUCTION("COL->", instruction_col_fleche);
611: //INSTRUCTION("CONIC")
612: //Instruction HP48 (sélectionne le type de tracé CONIC)
613: //Permet de tracer des coniques en fonction d'équations
614: //de type f(x, y) = 0.
615: //INSTRUCTION("CRDIR")
616: INSTRUCTION("CRMTX", instruction_crmtx);
617: INSTRUCTION("CROSS", instruction_cross);
618: INSTRUCTION("CRTAB", instruction_crtab);
619: INSTRUCTION("CSTOP", instruction_cstop);
620: INSTRUCTION("CYCLE", instruction_cycle);
621: //INSTRUCTION("CYLIN")
622: //Instruction HP48 (sélectionne le type de tracé CYLINDRIC)
623: INSTRUCTION("DEPND", instruction_depnd);
624: INSTRUCTION("DEPTH", instruction_depth);
625: //INSTRUCTION("DOSUB")
626: //Instruction HP48 (application séquentielle d'une fonction à une liste)
627: //liste nombre_elements_traites_a_chaque_iteration fonction DOSUB
628: //{ 1 2 3 4 5 }
629: //2
630: //<< + 2 / >>
631: //DOSUB
632: //=> { 1.5 2.5 3.5 4.5 }
633: INSTRUCTION("DGTIZ", instruction_dgtiz);
634: INSTRUCTION("DROP2", instruction_drop2);
635: INSTRUCTION("DROPN", instruction_dropn);
636: INSTRUCTION("ERASE", instruction_erase);
637: INSTRUCTION("EXGET", instruction_exget);
638: //INSTRUCTION("EXPAN");
639: INSTRUCTION("EXSUB", instruction_exsub);
640: INSTRUCTION("EYEPT", instruction_eyept);
641: INSTRUCTION("FALSE", instruction_false);
642: INSTRUCTION("FLOOR", instruction_floor);
643: INSTRUCTION("GAMMA", instruction_gamma);
644: INSTRUCTION("GEGVL", instruction_gegvl);
645: INSTRUCTION("GLEGV", instruction_glegv);
646: INSTRUCTION("GREGV", instruction_gregv);
647: INSTRUCTION("HMS->", instruction_hms_fleche);
648: INSTRUCTION("IFERR", instruction_iferr);
649: INSTRUCTION("INDEP", instruction_indep);
650: INSTRUCTION("INPUT", instruction_input);
651: INSTRUCTION("JDATE", instruction_jdate);
652: INSTRUCTION("LABEL", instruction_label);
653: INSTRUCTION("LCASE", instruction_lcase);
654: INSTRUCTION("LCHOL", instruction_lchol);
655: INSTRUCTION("LCD->", instruction_lcd_fleche);
656: //INSTRUCTION("NDIST")
657: //Instruction HP48 (distribution normale, prend la moyenne au niveau 3,
658: //la variance au niveau 2, un réel x au niveau 1 et renvoie la probabilité
659: //qu'une variable aléatoire normale soit égale à x dans une distribution
660: //normale).
661: INSTRUCTION("NRAND", instruction_nrand);
662: INSTRUCTION("OBGET", instruction_obget);
663: INSTRUCTION("OBSUB", instruction_obsub);
664: INSTRUCTION("PAPER", instruction_paper);
665: //INSTRUCTION("PCOEFF")
666: //INSTRUCTION("PEVAL")
667: //INSTRUCTION("PGDIR")
668: //INSTRUCTION("PIXEL")
669: //INSTRUCTION("PLIST")
670: //Instruction HP48 (produit des termes d'une liste)
671: INSTRUCTION("POLAR", instruction_polar);
672: INSTRUCTION("PRINT", instruction_print);
673: //INSTRUCTION("PREDV");
674: INSTRUCTION("PRLCD", instruction_prlcd);
675: //INSTRUCTION("PROOT")
676: //Instruction HP48 (calcule les racines d'un polynôme en fonction du tableau
677: //de coefficients)
678: INSTRUCTION("PRSTC", instruction_prstc);
679: INSTRUCTION("PRUSR", instruction_prusr);
680: INSTRUCTION("PRVAR", instruction_prvar);
681: INSTRUCTION("PSDEV", instruction_psdev);
682: INSTRUCTION("PURGE", instruction_purge);
683: INSTRUCTION("RDATE", instruction_rdate);
684: INSTRUCTION("RELAX", instruction_relax);
685: INSTRUCTION("RFUSE", instruction_rfuse);
686: INSTRUCTION("RSTOP", instruction_rstop);
687: INSTRUCTION("ROLLD", instruction_rolld);
688: INSTRUCTION("ROW->", instruction_row_fleche);
689: INSTRUCTION("SCALE", instruction_scale);
690: INSTRUCTION("SCHED", instruction_sched);
691: INSTRUCTION("SCHUR", instruction_schur);
692: INSTRUCTION("SCONJ", instruction_sconj);
693: INSTRUCTION("SLICE", instruction_slice);
694: //INSTRUCTION("SLIST")
695: //Instruction HP48 (somme des termes d'une liste)
696: # ifndef OS2
697: INSTRUCTION("SPAWN", instruction_spawn);
698: # endif
699: INSTRUCTION("START", instruction_start);
700: INSTRUCTION("STORE", instruction_store);
701: INSTRUCTION("STR->", instruction_str_fleche);
702: INSTRUCTION("TAYLR", instruction_taylr);
703: INSTRUCTION("TITLE", instruction_title);
704: //INSTRUCTION("TRACE")
705: //INSTRUCTION("TRUTH")
706: INSTRUCTION("UCASE", instruction_ucase);
707: INSTRUCTION("UCHOL", instruction_uchol);
708: INSTRUCTION("UNTIL", instruction_until);
709: //INSTRUCTION("UPDIR")
710: INSTRUCTION("VISIT", instruction_visit);
711: INSTRUCTION("WFACK", instruction_wfack);
712: INSTRUCTION("WFSWI", instruction_wfswi);
713: INSTRUCTION("WHILE", instruction_while);
714: //INSTRUCTION("WIDTH")
715: INSTRUCTION("WRITE", instruction_write);
716: INSTRUCTION("XROOT", instruction_xroot);
717: INSTRUCTION("YIELD", instruction_yield);
718: INSTRUCTION("->COL", instruction_fleche_col);
719: INSTRUCTION("->HMS", instruction_fleche_hms);
720: INSTRUCTION("->LCD", instruction_fleche_lcd);
721: INSTRUCTION("->NUM", instruction_fleche_num);
722: INSTRUCTION("->ROW", instruction_fleche_row);
723: INSTRUCTION("->STR", instruction_fleche_str);
724:
725: INSTRUCTION("APPEND", instruction_append);
726: INSTRUCTION("ARRY->", instruction_array_fleche);
727: INSTRUCTION("ATEXIT", instruction_atexit);
728: INSTRUCTION("ATPOKE", instruction_atpoke);
729: INSTRUCTION("BESSEL", instruction_bessel);
730: INSTRUCTION("CLRERR", instruction_clrerr);
731: INSTRUCTION("CLRMTX", instruction_clrmtx);
732: INSTRUCTION("CLRSWI", instruction_clrswi);
733: INSTRUCTION("CREATE", instruction_create);
734: INSTRUCTION("DELETE", instruction_delete);
735: # ifndef OS2
736: INSTRUCTION("DETACH", instruction_detach);
737: # endif
738: INSTRUCTION("DIAG->", instruction_diag_fleche);
739: //INSTRUCTION("DOLIST")
740: //Instruction HP48 (application d'une fonction à une liste)
741: //liste(s) nombre_de_listes_a_traiter fonction DOLIST
742: //{ 1 2 3 }
743: //{ 4 5 6 }
744: //{ 7 8 9 }
745: //3
746: //<< * + >>
747: //DOLIST
748: //=> { 29 42 57 }
749: INSTRUCTION("ELSEIF", instruction_elseif);
750: INSTRUCTION("FORMAT", instruction_format);
751: //INSTRUCTION("HEIGHT")
752: INSTRUCTION("ITRACE", instruction_itrace);
753: INSTRUCTION("LIST->", instruction_list_fleche);
754: INSTRUCTION("LOGGER", instruction_logger);
755: INSTRUCTION("MCLRIN", instruction_mclrin);
756: INSTRUCTION("NRPROC", instruction_nrproc);
757: INSTRUCTION("PROCID", instruction_procid);
758: INSTRUCTION("PROMPT", instruction_prompt);
759: INSTRUCTION("RCLSWI", instruction_rclswi);
760: INSTRUCTION("RECALL", instruction_recall);
761: INSTRUCTION("RECODE", instruction_recode);
762: INSTRUCTION("REDRAW", instruction_redraw);
763: INSTRUCTION("REMOVE", instruction_remove);
764: INSTRUCTION("REPEAT", instruction_repeat);
765: INSTRUCTION("RETURN", instruction_return);
766: INSTRUCTION("REWIND", instruction_rewind);
767: //INSTRUCTION("SCREEN")
768: INSTRUCTION("SELECT", instruction_select);
769: //INSTRUCTION("SPHERE")
770: INSTRUCTION("SHARED", instruction_shared);
771: INSTRUCTION("SPLASH", instruction_splash);
772: INSTRUCTION("STATIC", instruction_static);
773: INSTRUCTION("STOSWI", instruction_stoswi);
774: //INSTRUCTION("STREAM", instruction_stream);
775: //{ 1 2 3 4 5 } << * >> STREAM => 120
776: INSTRUCTION("TARGET", instruction_target);
777: INSTRUCTION("UNLOCK", instruction_unlock);
778: INSTRUCTION("VERIFY", instruction_verify);
779: INSTRUCTION("WFDATA", instruction_wfdata);
780: INSTRUCTION("WFLOCK", instruction_wflock);
781: INSTRUCTION("WFPOKE", instruction_wfpoke);
782: INSTRUCTION("WFPROC", instruction_wfproc);
783: INSTRUCTION("WFSOCK", instruction_wfsock);
784: INSTRUCTION("->ARRY", instruction_fleche_array);
785: INSTRUCTION("->DIAG", instruction_fleche_diag);
786: INSTRUCTION("->LIST", instruction_fleche_list);
787:
788: INSTRUCTION("ARRAY->", instruction_array_fleche);
789: //INSTRUCTION("BARPLOT")
790: //INSTRUCTION("BESTFIT")
791: //Instruction HP48 (choisit le meilleur modèle de régression)
792: INSTRUCTION("CLRFUSE", instruction_clrfuse);
793: INSTRUCTION("CONVERT", instruction_convert);
794: INSTRUCTION("CRSMPHR", instruction_crsmphr);
795: INSTRUCTION("CURRENC", instruction_currenc);
796: INSTRUCTION("DEFAULT", instruction_default);
797: INSTRUCTION("EPSILON", instruction_epsilon);
798: //INSTRUCTION("GRIDMAP")
799: //Instruction HP48 (sélectionne le mode de tracé GRIDMAP)
800: //Le tracé GRIDMAP transforme la grille d'échantillonnage rectiligne
801: //en appliquant la fonction en cours à valeurs complexes.
802: //Les coordonnées de chaque point de la grille (un nombre complexe)
803: //constituent
804: //les données d'entrée de la fonction qui les projette ensuite dans le
805: //grille
806: //de sortie.
807: //f(x,y)=fnct complexe évaluée sur la grille (x,y) et affichée comme une
808: //fonction paramétrique.
809: INSTRUCTION("INQUIRE", instruction_inquire);
810: INSTRUCTION("MEMLOCK", instruction_memlock);
811: INSTRUCTION("MTXLOCK", instruction_mtxlock);
812: INSTRUCTION("PERSIST", instruction_persist);
813: INSTRUCTION("PLOTTER", instruction_plotter);
814: INSTRUCTION("PRIVATE", instruction_private);
815: INSTRUCTION("PROTECT", instruction_protect);
816: INSTRUCTION("PSHPRFL", instruction_pshprfl);
817: INSTRUCTION("PULPRFL", instruction_pulprfl);
818: INSTRUCTION("REVLIST", instruction_revlist);
819: INSTRUCTION("SCATTER", instruction_scatter);
820: INSTRUCTION("SUSPEND", instruction_suspend);
821: INSTRUCTION("SWILOCK", instruction_swilock);
822: INSTRUCTION("SYSEVAL", instruction_syseval);
823: INSTRUCTION("TABLE->", instruction_table_fleche);
824: INSTRUCTION("VERSION", instruction_version);
825: INSTRUCTION("WORKDIR", instruction_workdir);
826: INSTRUCTION("->ARRAY", instruction_fleche_array);
827: INSTRUCTION("->TABLE", instruction_fleche_table);
828:
829: INSTRUCTION("CLRCNTXT", instruction_clrcntxt);
830: INSTRUCTION("CLRSMPHR", instruction_clrsmphr);
831: # ifndef OS2
832: INSTRUCTION("CONTINUE", instruction_continue);
833: # endif
834: INSTRUCTION("DUPCNTXT", instruction_dupcntxt);
835: INSTRUCTION("FUNCTION", instruction_function);
836: INSTRUCTION("IMPLICIT", instruction_implicit);
837: INSTRUCTION("KEYLABEL", instruction_keylabel);
838: INSTRUCTION("KEYTITLE", instruction_keytitle);
839: INSTRUCTION("LOGSCALE", instruction_logscale);
840: INSTRUCTION("NEWPLANE", instruction_newplane);
841: INSTRUCTION("PSHCNTXT", instruction_pshcntxt);
842: INSTRUCTION("PULCNTXT", instruction_pulcntxt);
843: INSTRUCTION("SQLQUERY", instruction_sqlquery);
844: INSTRUCTION("SWIQUEUE", instruction_swiqueue);
845: INSTRUCTION("TOKENIZE", instruction_tokenize);
846: INSTRUCTION("VARIABLE", instruction_variable);
847: INSTRUCTION("VOLATILE", instruction_volatile);
848: INSTRUCTION("WARRANTY", instruction_warranty);
849:
850: INSTRUCTION("AUTOSCALE", instruction_autoscale);
851: INSTRUCTION("BACKSPACE", instruction_backspace);
852: INSTRUCTION("BACKTRACE", instruction_backtrace);
853: INSTRUCTION("CLRATEXIT", instruction_clratexit);
854: INSTRUCTION("CLRATPOKE", instruction_clratpoke);
855: INSTRUCTION("COPYRIGHT", instruction_copyright);
856: //INSTRUCTION("CYLINDRIC");
857: INSTRUCTION("DAEMONIZE", instruction_daemonize);
858: INSTRUCTION("DROPCNTXT", instruction_dropcntxt);
859: INSTRUCTION("EXTERNALS", instruction_externals);
860: INSTRUCTION("HISTOGRAM", instruction_histogram);
861: INSTRUCTION("MEMUNLOCK", instruction_memunlock);
862: INSTRUCTION("MTXSTATUS", instruction_mtxstatus);
863: INSTRUCTION("MTXUNLOCK", instruction_mtxunlock);
864: INSTRUCTION("PARAMETER", instruction_parameter);
865: //INSTRUCTION("PSCONTOUR")
866: //INSTRUCTION("SCATRPLOT")
867: //(trace un nuage de points de SDAT et la courbe de régression)
868: INSTRUCTION("SMPHRDECR", instruction_smphrdecr);
869: INSTRUCTION("SMPHRGETV", instruction_smphrgetv);
870: INSTRUCTION("SMPHRINCR", instruction_smphrincr);
871: INSTRUCTION("SWAPCNTXT", instruction_swapcntxt);
872: INSTRUCTION("SWISTATUS", instruction_swistatus);
873: INSTRUCTION("SWIUNLOCK", instruction_swiunlock);
874: INSTRUCTION("UNPROTECT", instruction_unprotect);
875: INSTRUCTION("WIREFRAME", instruction_wireframe);
876:
877: INSTRUCTION("MTXTRYLOCK", instruction_mtxtrylock);
878: INSTRUCTION("PARAMETRIC", instruction_parametric);
879: //INSTRUCTION("PARSURFACE")
880: //Instruction HP48 (tracé PARSURFACE) Equation sous forme de liste
881: INSTRUCTION("SLICESCALE", instruction_slicescale);
882: INSTRUCTION("SQLCONNECT", instruction_sqlconnect);
883: //INSTRUCTION("SLOPEFIELD")
884: //Instruction HP48 (type de tracé)
885: //Tracé 3D en courbes de niveaux.
886: //Le type de tracé 'SLOPEFIELD' dessine un réseau de segments dont les
887: //pentes
888: //représentent la valeur de la fonction (x,y) en leur milieu.
889: //=> utile pour y'=F(x,y)
890:
891: INSTRUCTION("LOCALIZATION", instruction_localization);
892: INSTRUCTION("SMPHRTRYDECR", instruction_smphrtrydecr);
893:
894: INSTRUCTION("SQLDISCONNECT", instruction_sqldisconnect);
895: #undef INSTRUCTION
896:
897: return;
898: }
899:
900:
901: void *
902: analyse_instruction(struct_processus *s_etat_processus, unsigned char *ptr)
903: {
904: int pointeur;
905:
906: struct_instruction *l_instruction_courante;
907:
908: l_instruction_courante = (*s_etat_processus).arbre_instructions;
909:
910: while((*ptr) != d_code_fin_chaine)
911: {
912: pointeur = (*s_etat_processus).pointeurs_caracteres[*ptr];
913:
914: if (pointeur < 0)
915: {
916: // Caractère hors de l'alphabet des instructions
917:
918: return(NULL);
919: }
920:
921: if ((*l_instruction_courante).noeud[pointeur] == NULL)
922: {
923: // Le chemin de l'instruction candidate n'existe pas.
924:
925: return(NULL);
926: }
927:
928: l_instruction_courante = (*l_instruction_courante).noeud[pointeur];
929: ptr++;
930:
931: if ((l_instruction_courante == NULL) && ((*ptr) != d_code_fin_chaine))
932: {
933: // Le chemin de l'instruction candidate est incomplet.
934:
935: return(NULL);
936: }
937: }
938:
939: if ((*l_instruction_courante).feuille != NULL)
940: {
941: return((*l_instruction_courante).feuille);
942: }
943:
944: return(NULL);
945: }
946:
947:
948: void
949: analyse(struct_processus *s_etat_processus, void (*fonction)())
950: {
951: static logical1 initialisation = d_faux;
952:
953: real8 attente;
954: real8 pourcentage;
955: real8 temps_cpu;
956: real8 temps_reel;
957:
958: static struct timeval horodatage_initial;
959: struct timeval horodatage_final;
960:
961: static struct rusage usage_initial;
962: struct rusage usage_final;
963:
964: struct timespec temporisation;
965:
966: unsigned char *position;
967: unsigned char *bibliotheque_candidate;
968: unsigned char instruction_majuscule
969: [d_longueur_maximale_instruction];
970: unsigned char registre_instruction_valide;
971:
972: void (*instruction)();
973:
974: # ifdef DMALLOC
975: BUG(dmalloc_verify(NULL) == DMALLOC_VERIFY_ERROR,
976: printf("HEAP CORRUPTION!"));
977: # endif
978:
979: errno = 0;
980: (*s_etat_processus).var_volatile_exception_gsl = 0;
981:
982: (*s_etat_processus).instruction_valide = 'Y';
983: (*s_etat_processus).constante_symbolique = 'N';
984: (*s_etat_processus).nombre_arguments = -2;
985: (*s_etat_processus).instruction_intrinseque = 'I';
986:
987: /*
988: * On autorise l'exécution d'un fork() dans un thread concurrent.
989: */
990:
991: # ifndef SEMAPHORES_NOMMES
992: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
993: {
994: (*s_etat_processus).erreur_systeme = d_es_processus;
995: return;
996: }
997:
998: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
999: {
1000: if (errno != EINTR)
1001: {
1002: (*s_etat_processus).erreur_systeme = d_es_processus;
1003: return;
1004: }
1005: }
1006: # else
1007: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1008: {
1009: (*s_etat_processus).erreur_systeme = d_es_processus;
1010: return;
1011: }
1012:
1013: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1014: {
1015: if (errno != EINTR)
1016: {
1017: (*s_etat_processus).erreur_systeme = d_es_processus;
1018: return;
1019: }
1020: }
1021: # endif
1022:
1023: scrutation_injection(s_etat_processus);
1024:
1025: if (fonction == NULL)
1026: {
1027: conversion_majuscule_limitee((*s_etat_processus).instruction_courante,
1028: instruction_majuscule, d_longueur_maximale_instruction);
1029: instruction = analyse_instruction(s_etat_processus,
1030: instruction_majuscule);
1031:
1032: if (instruction == NULL)
1033: {
1034: // L'instruction n'existe pas.
1035:
1036: (*s_etat_processus).instruction_valide = 'N';
1037: }
1038: else
1039: {
1040: // Exécution de l'instruction associée. Le drapeau
1041: // (*s_etat_processus).instruction_valide peut passer à 'N'
1042: // dans le cas d'instructions sensibles à la casse.
1043:
1044: if ((*s_etat_processus).niveau_profilage >= 2)
1045: {
1046: profilage(s_etat_processus, instruction_majuscule);
1047: }
1048:
1049: (*s_etat_processus).instruction_valide = 'Y';
1050: instruction(s_etat_processus);
1051:
1052: if ((*s_etat_processus).niveau_profilage >= 2)
1053: {
1054: profilage(s_etat_processus, NULL);
1055: }
1056: }
1057: }
1058: else
1059: {
1060: if ((*s_etat_processus).niveau_profilage >= 2)
1061: {
1062: profilage(s_etat_processus,
1063: (*s_etat_processus).instruction_courante);
1064: }
1065:
1066: (*s_etat_processus).instruction_valide = 'Y';
1067: fonction(s_etat_processus);
1068:
1069: if ((*s_etat_processus).niveau_profilage >= 2)
1070: {
1071: profilage(s_etat_processus, NULL);
1072: }
1073: }
1074:
1075: if ((*s_etat_processus).instruction_valide == 'Y')
1076: {
1077: (*s_etat_processus).instruction_intrinseque = 'Y';
1078: }
1079:
1080: if ((*s_etat_processus).instruction_valide == 'N')
1081: {
1082: if ((position = index((*s_etat_processus).instruction_courante, '$'))
1083: != NULL)
1084: {
1085: if ((bibliotheque_candidate = malloc((position + 1
1086: - (*s_etat_processus).instruction_courante)
1087: * sizeof(unsigned char))) == NULL)
1088: {
1089: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1090: return;
1091: }
1092:
1093: (*bibliotheque_candidate) = d_code_fin_chaine;
1094: strncat(bibliotheque_candidate,
1095: (*s_etat_processus).instruction_courante,
1096: position - (*s_etat_processus).instruction_courante);
1097:
1098: position++;
1099:
1100: if (execution_fonction_de_bibliotheque(s_etat_processus, position,
1101: bibliotheque_candidate) == d_vrai)
1102: {
1103: (*s_etat_processus).instruction_valide = 'Y';
1104: (*s_etat_processus).instruction_intrinseque = 'N';
1105: }
1106: else
1107: {
1108: (*s_etat_processus).instruction_valide = 'N';
1109: }
1110:
1111: free(bibliotheque_candidate);
1112: }
1113: else
1114: {
1115: if (execution_fonction_de_bibliotheque(s_etat_processus,
1116: (*s_etat_processus).instruction_courante, NULL)
1117: == d_vrai)
1118: {
1119: (*s_etat_processus).instruction_valide = 'Y';
1120: (*s_etat_processus).instruction_intrinseque = 'N';
1121: }
1122: else
1123: {
1124: (*s_etat_processus).instruction_valide = 'N';
1125: }
1126: }
1127: }
1128:
1129: /*
1130: --------------------------------------------------------------------------------
1131: Gestion des interruptions logicielles
1132: --------------------------------------------------------------------------------
1133: */
1134:
1135: if (((*s_etat_processus).erreur_systeme == d_es) &&
1136: ((*s_etat_processus).erreur_execution == d_ex) &&
1137: ((*s_etat_processus).exception == d_ep))
1138: {
1139: if ((*s_etat_processus).test_instruction == 'N')
1140: {
1141: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
1142: {
1143: affectation_interruptions_logicielles(s_etat_processus);
1144: }
1145:
1146: if (((*s_etat_processus).nombre_interruptions_en_queue != 0) &&
1147: ((*s_etat_processus).erreur_systeme == d_es) &&
1148: ((*s_etat_processus).erreur_execution == d_ex))
1149: {
1150:
1151: registre_instruction_valide =
1152: (*s_etat_processus).instruction_valide;
1153: traitement_interruptions_logicielles(s_etat_processus);
1154: (*s_etat_processus).instruction_valide =
1155: registre_instruction_valide;
1156: }
1157: }
1158: }
1159:
1160: /*
1161: --------------------------------------------------------------------------------
1162: Limitation du pourcetage de temps CPU
1163: --------------------------------------------------------------------------------
1164: */
1165:
1166: # ifndef OS2
1167: if ((*s_etat_processus).pourcentage_maximal_cpu < 100)
1168: {
1169: getrusage(RUSAGE_SELF, &usage_final);
1170: gettimeofday(&horodatage_final, NULL);
1171:
1172: if (initialisation == d_vrai)
1173: {
1174: temps_reel = ((real8) (horodatage_final.tv_sec -
1175: horodatage_initial.tv_sec)) +
1176: (((real8) (horodatage_final.tv_usec -
1177: horodatage_initial.tv_usec)) / ((real8) 1E6));
1178:
1179: if (temps_reel >= 0.1)
1180: {
1181: temps_cpu = ((real8) ((usage_final.ru_utime.tv_sec +
1182: usage_final.ru_stime.tv_sec) -
1183: (usage_initial.ru_utime.tv_sec +
1184: usage_initial.ru_stime.tv_sec))) +
1185: (((real8) ((usage_final.ru_utime.tv_usec +
1186: usage_final.ru_stime.tv_usec) -
1187: (usage_initial.ru_utime.tv_usec +
1188: usage_initial.ru_stime.tv_usec))) / ((real8) 1E6));
1189:
1190: pourcentage = 100 * temps_cpu / temps_reel;
1191:
1192: if (pourcentage > 100)
1193: {
1194: pourcentage = 100;
1195: }
1196:
1197: if (pourcentage > (*s_etat_processus).pourcentage_maximal_cpu)
1198: {
1199: attente = ((pourcentage * temps_cpu) /
1200: (*s_etat_processus).pourcentage_maximal_cpu)
1201: - (pourcentage * temps_cpu / 100);
1202:
1203: temporisation.tv_sec = floor(attente);
1204: temporisation.tv_nsec = (attente - temporisation.tv_sec) *
1205: 1E9;
1206:
1207: nanosleep(&temporisation, NULL);
1208: }
1209:
1210: horodatage_initial = horodatage_final;
1211: usage_initial = usage_final;
1212: }
1213: }
1214: else
1215: {
1216: initialisation = d_vrai;
1217:
1218: horodatage_initial = horodatage_final;
1219: usage_initial = usage_final;
1220: }
1221: }
1222: # endif
1223:
1224: /*
1225: --------------------------------------------------------------------------------
1226: Introduction des erreurs générées
1227: --------------------------------------------------------------------------------
1228: */
1229:
1230: if (((*s_etat_processus).test_instruction == 'N') &&
1231: ((*s_etat_processus).instruction_valide == 'Y'))
1232: {
1233: traitement_asynchrone_exceptions_gsl(s_etat_processus);
1234:
1235: if ((*s_etat_processus).erreur_processus_fils == d_vrai)
1236: {
1237: (*s_etat_processus).erreur_processus_fils = d_faux;
1238:
1239: (*s_etat_processus).erreur_systeme =
1240: (*s_etat_processus).erreur_systeme_processus_fils;
1241: (*s_etat_processus).erreur_execution =
1242: (*s_etat_processus).erreur_execution_processus_fils;
1243: (*s_etat_processus).arret_si_exception = d_vrai;
1244:
1245: if ((*s_etat_processus).pid_erreur_processus_fils == getpid())
1246: {
1247: (*s_etat_processus).invalidation_message_erreur = d_faux;
1248: }
1249: else
1250: {
1251: (*s_etat_processus).invalidation_message_erreur = d_vrai;
1252: }
1253: }
1254:
1255: if (((*s_etat_processus).erreur_execution != d_ex) ||
1256: ((*s_etat_processus).erreur_systeme != d_es) ||
1257: ((*s_etat_processus).exception != d_ep))
1258: {
1259: (*s_etat_processus).niveau_derniere_erreur =
1260: (*s_etat_processus).niveau_courant;
1261:
1262: if ((*s_etat_processus).mode_execution_programme == 'Y')
1263: {
1264: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1265: {
1266: free((*s_etat_processus).instruction_derniere_erreur);
1267: (*s_etat_processus).instruction_derniere_erreur = NULL;
1268: }
1269:
1270: if ((*s_etat_processus).instruction_courante == NULL)
1271: {
1272: if (((*s_etat_processus).instruction_derniere_erreur =
1273: malloc(16 * sizeof(unsigned char))) == NULL)
1274: {
1275: (*s_etat_processus).erreur_systeme =
1276: d_es_allocation_memoire;
1277: return;
1278: }
1279:
1280: strcpy((*s_etat_processus).instruction_derniere_erreur,
1281: "<not available>");
1282: }
1283: else
1284: {
1285: if (((*s_etat_processus).instruction_derniere_erreur =
1286: malloc((strlen((*s_etat_processus)
1287: .instruction_courante) + 1) *
1288: sizeof(unsigned char))) == NULL)
1289: {
1290: (*s_etat_processus).erreur_systeme =
1291: d_es_allocation_memoire;
1292: return;
1293: }
1294:
1295: strcpy((*s_etat_processus).instruction_derniere_erreur,
1296: (*s_etat_processus).instruction_courante);
1297: }
1298: }
1299: else
1300: {
1301: if ((*s_etat_processus).objet_courant != NULL)
1302: {
1303: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1304: {
1305: free((*s_etat_processus).instruction_derniere_erreur);
1306: (*s_etat_processus).instruction_derniere_erreur = NULL;
1307: }
1308:
1309: if (((*s_etat_processus).instruction_derniere_erreur =
1310: formateur(s_etat_processus, 0,
1311: (*s_etat_processus).objet_courant)) == NULL)
1312: {
1313: return;
1314: }
1315:
1316: (*s_etat_processus).objet_courant = NULL;
1317: }
1318: }
1319: }
1320: }
1321:
1322: return;
1323: }
1324:
1325:
1326: /*
1327: ================================================================================
1328: Traitement asynchrone des erreurs de la bibliothèque GSL
1329: ================================================================================
1330: Entrées :
1331: --------------------------------------------------------------------------------
1332: Sorties :
1333: --------------------------------------------------------------------------------
1334: Effets de bord : néant
1335: ================================================================================
1336: */
1337:
1338: void
1339: traitement_asynchrone_exceptions_gsl(struct_processus *s_etat_processus)
1340: {
1341: if ((*s_etat_processus).var_volatile_exception_gsl != 0)
1342: {
1343: switch((*s_etat_processus).var_volatile_exception_gsl)
1344: {
1345: case GSL_EINVAL :
1346: {
1347: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1348: break;
1349: }
1350:
1351: case GSL_EDOM :
1352: {
1353: (*s_etat_processus).exception = d_ep_domaine_definition;
1354: break;
1355: }
1356:
1357: case GSL_ERANGE :
1358: {
1359: (*s_etat_processus).exception = d_ep_resultat_indefini;
1360: break;
1361: }
1362:
1363: case GSL_EZERODIV :
1364: {
1365: (*s_etat_processus).exception = d_ep_division_par_zero;
1366: break;
1367: }
1368:
1369: case GSL_EUNDRFLW :
1370: {
1371: (*s_etat_processus).exception = d_ep_underflow;
1372: break;
1373: }
1374:
1375: case GSL_EOVRFLW :
1376: {
1377: (*s_etat_processus).exception = d_ep_overflow;
1378: break;
1379: }
1380:
1381: case GSL_ENOMEM :
1382: {
1383: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1384: break;
1385: }
1386:
1387: case GSL_ELOSS :
1388: {
1389: (*s_etat_processus).exception = d_ep_perte_precision;
1390: break;
1391: }
1392:
1393: default :
1394: {
1395: (*s_etat_processus).erreur_execution =
1396: d_ex_routines_mathematiques;
1397: break;
1398: }
1399: }
1400:
1401: (*s_etat_processus).var_volatile_exception_gsl = 0;
1402: }
1403:
1404: return;
1405: }
1406:
1407: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>