1: /*
2: ================================================================================
3: RPL/2 (R) version 4.0.18
4: Copyright (C) 1989-2010 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: INSTRUCTION("KILL", instruction_kill);
463: INSTRUCTION("KIND", instruction_kind);
464: INSTRUCTION("LAST", instruction_last);
465: INSTRUCTION("LEGV", instruction_legv);
466: INSTRUCTION("LINE", instruction_line);
467: INSTRUCTION("LNP1", instruction_lnp1);
468: INSTRUCTION("LOCK", instruction_lock);
469: INSTRUCTION("MANT", instruction_mant);
470: INSTRUCTION("MARK", instruction_mark);
471: //INSTRUCTION("MAXR")
472: INSTRUCTION("MAXS", instruction_maxs);
473: INSTRUCTION("MEAN", instruction_mean);
474: //INSTRUCTION("MINR");
475: INSTRUCTION("MINS", instruction_mins); // MAXDOUBLE/MINDOUBLE
476: INSTRUCTION("NEXT", instruction_next);
477: //INSTRUCTION("NUMX");
478: //INSTRUCTION("NUMY");
479: INSTRUCTION("OPEN", instruction_open);
480: INSTRUCTION("OVER", instruction_over);
481: //INSTRUCTION("PATH");
482: INSTRUCTION("PCOV", instruction_pcov);
483: INSTRUCTION("PEEK", instruction_peek);
484: INSTRUCTION("PERM", instruction_perm);
485: INSTRUCTION("PICK", instruction_pick);
486: INSTRUCTION("PLOT", instruction_plot);
487: INSTRUCTION("PMAX", instruction_pmax);
488: INSTRUCTION("PMIN", instruction_pmin);
489: INSTRUCTION("POKE", instruction_poke);
490: INSTRUCTION("PPAR", instruction_ppar);
491: INSTRUCTION("PRMD", instruction_prmd);
492: INSTRUCTION("PRST", instruction_prst);
493: INSTRUCTION("PUTC", instruction_putc);
494: INSTRUCTION("PUTI", instruction_puti);
495: INSTRUCTION("PUTR", instruction_putr);
496: INSTRUCTION("PVAR", instruction_pvar);
497: INSTRUCTION("P->R", instruction_p_vers_r);
498: //INSTRUCTION("QUAD");
499: INSTRUCTION("RAND", instruction_rand);
500: INSTRUCTION("RANK", instruction_rank);
501: //INSTRUCTION("RANM")
502: //Instruction HP48 (crée une matrice aléatoire
503: //{ nb_lignes nb_colonnes } ou tableau quelconque dont les éléments seront
504: //modifiés pour prendre des valeurs aléatoires entre -9 et 9)
505: INSTRUCTION("RCEQ", instruction_rceq);
506: INSTRUCTION("RCIJ", instruction_rcij);
507: INSTRUCTION("RCLF", instruction_rclf);
508: INSTRUCTION("RCLS", instruction_rcls);
509: INSTRUCTION("RCWS", instruction_rcws);
510: INSTRUCTION("RDGN", instruction_rdgn);
511: INSTRUCTION("READ", instruction_read);
512: INSTRUCTION("RECV", instruction_recv);
513: INSTRUCTION("REGV", instruction_regv);
514: INSTRUCTION("REPL", instruction_repl);
515: INSTRUCTION("RNRM", instruction_rnrm);
516: INSTRUCTION("ROLL", instruction_roll);
517: //INSTRUCTION("ROOT")
518: INSTRUCTION("ROW-", instruction_row_moins);
519: INSTRUCTION("ROW+", instruction_row_plus);
520: //INSTRUCTION("RREF")
521: //Instruction HP48 (transforme [A B] en [I C] par combinaisons linéaires
522: //de lignes)
523: INSTRUCTION("RSWP", instruction_rswp);
524: INSTRUCTION("R->B", instruction_r_vers_b);
525: INSTRUCTION("R->C", instruction_r_vers_c);
526: INSTRUCTION("R->D", instruction_r_vers_d);
527: INSTRUCTION("R->P", instruction_r_vers_p);
528: INSTRUCTION("SAME", instruction_same);
529: INSTRUCTION("SAVE", instruction_save);
530: INSTRUCTION("SCLS", instruction_scls);
531: INSTRUCTION("SDEV", instruction_sdev);
532: INSTRUCTION("SEND", instruction_send);
533: //INSTRUCTION("SHOW");
534: INSTRUCTION("SIGN", instruction_sign);
535: INSTRUCTION("SINH", instruction_sinh);
536: INSTRUCTION("SINV", instruction_sinv);
537: INSTRUCTION("SIZE", instruction_size);
538: INSTRUCTION("SNEG", instruction_sneg);
539: INSTRUCTION("SORT", instruction_sort);
540: INSTRUCTION("SPAR", instruction_spar);
541: INSTRUCTION("SQRT", instruction_sqrt);
542: //INSTRUCTION("SRAD");
543: //INSTRUCTION("SRNM")
544: //Instruction HP48 (renvoie la norme spectrale d'un tableau. Pour une
545: //matrice,
546: //la norme spectrale est égale à sa plus grande valeur singulière. Pour un
547: //vecteur, la fonction est équivalente à ABS.
548: INSTRUCTION("STEP", instruction_step);
549: INSTRUCTION("STEQ", instruction_steq);
550: INSTRUCTION("STO*", instruction_sto_fois);
551: INSTRUCTION("STO+", instruction_sto_plus);
552: INSTRUCTION("STO-", instruction_sto_moins);
553: INSTRUCTION("STO/", instruction_sto_division);
554: INSTRUCTION("STOF", instruction_stof);
555: INSTRUCTION("STOP", instruction_stop);
556: INSTRUCTION("STOS", instruction_stos);
557: INSTRUCTION("STWS", instruction_stws);
558: INSTRUCTION("SWAP", instruction_swap);
559: INSTRUCTION("SYNC", instruction_sync);
560: INSTRUCTION("TAIL", instruction_tail);
561: INSTRUCTION("TANH", instruction_tanh);
562: INSTRUCTION("THEN", instruction_then);
563: INSTRUCTION("TIME", instruction_time);
564: INSTRUCTION("TRIM", instruction_trim);
565: INSTRUCTION("TRNC", instruction_trnc);
566: INSTRUCTION("TRUE", instruction_true);
567: INSTRUCTION("TYPE", instruction_type);
568: INSTRUCTION("UTPC", instruction_utpc);
569: INSTRUCTION("UTPF", instruction_utpf);
570: INSTRUCTION("UTPN", instruction_utpn);
571: INSTRUCTION("UTPT", instruction_utpt);
572: INSTRUCTION("VARS", instruction_vars);
573: INSTRUCTION("WAIT", instruction_wait);
574: INSTRUCTION("XCOL", instruction_xcol);
575: INSTRUCTION("XPON", instruction_xpon);
576: //INSTRUCTION("XRNG")
577: //INSTRUCTION("XVOL")
578: INSTRUCTION("YCOL", instruction_ycol);
579: //INSTRUCTION("YRNG")
580: //INSTRUCTION("YVOL")
581: //INSTRUCTION("ZVOL")
582: //INSTRUCTION("->V2")
583: //Instruction HP48 (combine deux réels x et y en un vecteur 2D en fonction
584: //du mode de coordonnées en cours => [ x y ] et ce quel que soit le système
585: //de coordonnées courant)
586: //INSTRUCTION("->V3")
587:
588: INSTRUCTION("ABORT", instruction_abort);
589: INSTRUCTION("ACOSH", instruction_acosh);
590: INSTRUCTION("ALARM", instruction_alarm);
591: INSTRUCTION("ASINH", instruction_asinh);
592: INSTRUCTION("ATANH", instruction_atanh);
593: //INSTRUCTION("BYTES");
594: INSTRUCTION("CENTR", instruction_centr);
595: //INSTRUCTION("CIRCL");
596: INSTRUCTION("CLEAR", instruction_clear);
597: INSTRUCTION("CLLCD", instruction_cllcd);
598: INSTRUCTION("CLOSE", instruction_close);
599: INSTRUCTION("CLUSR", instruction_clusr);
600: //INSTRUCTION("CLVAR");
601: //INSTRUCTION("COLCT")
602: INSTRUCTION("COL->", instruction_col_fleche);
603: //INSTRUCTION("CONIC")
604: //Instruction HP48 (sélectionne le type de tracé CONIC)
605: //Permet de tracer des coniques en fonction d'équations
606: //de type f(x, y) = 0.
607: //INSTRUCTION("CRDIR")
608: INSTRUCTION("CRMTX", instruction_crmtx);
609: INSTRUCTION("CROSS", instruction_cross);
610: INSTRUCTION("CRTAB", instruction_crtab);
611: INSTRUCTION("CSTOP", instruction_cstop);
612: INSTRUCTION("CYCLE", instruction_cycle);
613: //INSTRUCTION("CYLIN")
614: //Instruction HP48 (sélectionne le type de tracé CYLINDRIC)
615: INSTRUCTION("DEPND", instruction_depnd);
616: INSTRUCTION("DEPTH", instruction_depth);
617: //INSTRUCTION("DOSUB")
618: //Instruction HP48 (application séquentielle d'une fonction à une liste)
619: //liste nombre_elements_traites_a_chaque_iteration fonction DOSUB
620: //{ 1 2 3 4 5 }
621: //2
622: //<< + 2 / >>
623: //DOSUB
624: //=> { 1.5 2.5 3.5 4.5 }
625: INSTRUCTION("DGTIZ", instruction_dgtiz);
626: INSTRUCTION("DROP2", instruction_drop2);
627: INSTRUCTION("DROPN", instruction_dropn);
628: INSTRUCTION("ERASE", instruction_erase);
629: INSTRUCTION("EXGET", instruction_exget);
630: //INSTRUCTION("EXPAN");
631: INSTRUCTION("EXSUB", instruction_exsub);
632: INSTRUCTION("EYEPT", instruction_eyept);
633: INSTRUCTION("FALSE", instruction_false);
634: INSTRUCTION("FLOOR", instruction_floor);
635: INSTRUCTION("GAMMA", instruction_gamma);
636: INSTRUCTION("GEGVL", instruction_gegvl);
637: INSTRUCTION("GLEGV", instruction_glegv);
638: INSTRUCTION("GREGV", instruction_gregv);
639: INSTRUCTION("HMS->", instruction_hms_fleche);
640: INSTRUCTION("IFERR", instruction_iferr);
641: INSTRUCTION("INDEP", instruction_indep);
642: INSTRUCTION("INPUT", instruction_input);
643: INSTRUCTION("JDATE", instruction_jdate);
644: INSTRUCTION("LABEL", instruction_label);
645: INSTRUCTION("LCASE", instruction_lcase);
646: INSTRUCTION("LCHOL", instruction_lchol);
647: INSTRUCTION("LCD->", instruction_lcd_fleche);
648: //INSTRUCTION("NDIST")
649: //Instruction HP48 (distribution normale, prend la moyenne au niveau 3,
650: //la variance au niveau 2, un réel x au niveau 1 et renvoie la probabilité
651: //qu'une variable aléatoire normale soit égale à x dans une distribution
652: //normale).
653: INSTRUCTION("NRAND", instruction_nrand);
654: INSTRUCTION("OBGET", instruction_obget);
655: INSTRUCTION("OBSUB", instruction_obsub);
656: INSTRUCTION("PAPER", instruction_paper);
657: //INSTRUCTION("PCOEFF")
658: //INSTRUCTION("PEVAL")
659: //INSTRUCTION("PGDIR")
660: //INSTRUCTION("PIXEL")
661: //INSTRUCTION("PLIST")
662: //Instruction HP48 (produit des termes d'une liste)
663: INSTRUCTION("POLAR", instruction_polar);
664: INSTRUCTION("PRINT", instruction_print);
665: //INSTRUCTION("PREDV");
666: INSTRUCTION("PRLCD", instruction_prlcd);
667: //INSTRUCTION("PROOT")
668: //Instruction HP48 (calcule les racines d'un polynôme en fonction du tableau
669: //de coefficients)
670: INSTRUCTION("PRSTC", instruction_prstc);
671: INSTRUCTION("PRUSR", instruction_prusr);
672: INSTRUCTION("PRVAR", instruction_prvar);
673: INSTRUCTION("PSDEV", instruction_psdev);
674: INSTRUCTION("PURGE", instruction_purge);
675: INSTRUCTION("RDATE", instruction_rdate);
676: INSTRUCTION("RELAX", instruction_relax);
677: INSTRUCTION("RFUSE", instruction_rfuse);
678: INSTRUCTION("RSTOP", instruction_rstop);
679: INSTRUCTION("ROLLD", instruction_rolld);
680: INSTRUCTION("ROW->", instruction_row_fleche);
681: INSTRUCTION("SCALE", instruction_scale);
682: INSTRUCTION("SCHED", instruction_sched);
683: INSTRUCTION("SCHUR", instruction_schur);
684: INSTRUCTION("SCONJ", instruction_sconj);
685: INSTRUCTION("SLICE", instruction_slice);
686: //INSTRUCTION("SLIST")
687: //Instruction HP48 (somme des termes d'une liste)
688: INSTRUCTION("SPAWN", instruction_spawn);
689: INSTRUCTION("START", instruction_start);
690: INSTRUCTION("STORE", instruction_store);
691: INSTRUCTION("STR->", instruction_str_fleche);
692: INSTRUCTION("TAYLR", instruction_taylr);
693: INSTRUCTION("TITLE", instruction_title);
694: //INSTRUCTION("TRACE")
695: //INSTRUCTION("TRUTH")
696: INSTRUCTION("UCASE", instruction_ucase);
697: INSTRUCTION("UCHOL", instruction_uchol);
698: INSTRUCTION("UNTIL", instruction_until);
699: //INSTRUCTION("UPDIR")
700: INSTRUCTION("VISIT", instruction_visit);
701: INSTRUCTION("WFACK", instruction_wfack);
702: INSTRUCTION("WFSWI", instruction_wfswi);
703: INSTRUCTION("WHILE", instruction_while);
704: //INSTRUCTION("WIDTH")
705: INSTRUCTION("WRITE", instruction_write);
706: INSTRUCTION("XROOT", instruction_xroot);
707: INSTRUCTION("YIELD", instruction_yield);
708: INSTRUCTION("->COL", instruction_fleche_col);
709: INSTRUCTION("->HMS", instruction_fleche_hms);
710: INSTRUCTION("->LCD", instruction_fleche_lcd);
711: INSTRUCTION("->NUM", instruction_fleche_num);
712: INSTRUCTION("->ROW", instruction_fleche_row);
713: INSTRUCTION("->STR", instruction_fleche_str);
714:
715: INSTRUCTION("APPEND", instruction_append);
716: INSTRUCTION("ARRY->", instruction_array_fleche);
717: INSTRUCTION("ATEXIT", instruction_atexit);
718: INSTRUCTION("ATPOKE", instruction_atpoke);
719: INSTRUCTION("BESSEL", instruction_bessel);
720: INSTRUCTION("CLRERR", instruction_clrerr);
721: INSTRUCTION("CLRMTX", instruction_clrmtx);
722: INSTRUCTION("CLRSWI", instruction_clrswi);
723: INSTRUCTION("CREATE", instruction_create);
724: INSTRUCTION("DELETE", instruction_delete);
725: INSTRUCTION("DETACH", instruction_detach);
726: INSTRUCTION("DIAG->", instruction_diag_fleche);
727: //INSTRUCTION("DOLIST")
728: //Instruction HP48 (application d'une fonction à une liste)
729: //liste(s) nombre_de_listes_a_traiter fonction DOLIST
730: //{ 1 2 3 }
731: //{ 4 5 6 }
732: //{ 7 8 9 }
733: //3
734: //<< * + >>
735: //DOLIST
736: //=> { 29 42 57 }
737: INSTRUCTION("ELSEIF", instruction_elseif);
738: INSTRUCTION("FORMAT", instruction_format);
739: //INSTRUCTION("HEIGHT")
740: INSTRUCTION("ITRACE", instruction_itrace);
741: INSTRUCTION("LIST->", instruction_list_fleche);
742: INSTRUCTION("LOGGER", instruction_logger);
743: INSTRUCTION("MCLRIN", instruction_mclrin);
744: INSTRUCTION("NRPROC", instruction_nrproc);
745: INSTRUCTION("PROCID", instruction_procid);
746: INSTRUCTION("PROMPT", instruction_prompt);
747: INSTRUCTION("RCLSWI", instruction_rclswi);
748: INSTRUCTION("RECALL", instruction_recall);
749: INSTRUCTION("RECODE", instruction_recode);
750: INSTRUCTION("REDRAW", instruction_redraw);
751: INSTRUCTION("REMOVE", instruction_remove);
752: INSTRUCTION("REPEAT", instruction_repeat);
753: INSTRUCTION("RETURN", instruction_return);
754: INSTRUCTION("REWIND", instruction_rewind);
755: //INSTRUCTION("SCREEN")
756: INSTRUCTION("SELECT", instruction_select);
757: //INSTRUCTION("SPHERE")
758: INSTRUCTION("SHARED", instruction_shared);
759: INSTRUCTION("SPLASH", instruction_splash);
760: INSTRUCTION("STATIC", instruction_static);
761: INSTRUCTION("STOSWI", instruction_stoswi);
762: //INSTRUCTION("STREAM", instruction_stream);
763: //{ 1 2 3 4 5 } << * >> STREAM => 120
764: INSTRUCTION("TARGET", instruction_target);
765: INSTRUCTION("UNLOCK", instruction_unlock);
766: INSTRUCTION("VERIFY", instruction_verify);
767: INSTRUCTION("WFDATA", instruction_wfdata);
768: INSTRUCTION("WFLOCK", instruction_wflock);
769: INSTRUCTION("WFPOKE", instruction_wfpoke);
770: INSTRUCTION("WFPROC", instruction_wfproc);
771: INSTRUCTION("WFSOCK", instruction_wfsock);
772: INSTRUCTION("->ARRY", instruction_fleche_array);
773: INSTRUCTION("->DIAG", instruction_fleche_diag);
774: INSTRUCTION("->LIST", instruction_fleche_list);
775:
776: INSTRUCTION("ARRAY->", instruction_array_fleche);
777: //INSTRUCTION("BARPLOT")
778: //INSTRUCTION("BESTFIT")
779: //Instruction HP48 (choisit le meilleur modèle de régression)
780: INSTRUCTION("CLRFUSE", instruction_clrfuse);
781: INSTRUCTION("CONVERT", instruction_convert);
782: INSTRUCTION("CRSMPHR", instruction_crsmphr);
783: INSTRUCTION("CURRENC", instruction_currenc);
784: INSTRUCTION("DEFAULT", instruction_default);
785: INSTRUCTION("EPSILON", instruction_epsilon);
786: //INSTRUCTION("GRIDMAP")
787: //Instruction HP48 (sélectionne le mode de tracé GRIDMAP)
788: //Le tracé GRIDMAP transforme la grille d'échantillonnage rectiligne
789: //en appliquant la fonction en cours à valeurs complexes.
790: //Les coordonnées de chaque point de la grille (un nombre complexe)
791: //constituent
792: //les données d'entrée de la fonction qui les projette ensuite dans le
793: //grille
794: //de sortie.
795: //f(x,y)=fnct complexe évaluée sur la grille (x,y) et affichée comme une
796: //fonction paramétrique.
797: INSTRUCTION("INQUIRE", instruction_inquire);
798: INSTRUCTION("MEMLOCK", instruction_memlock);
799: INSTRUCTION("MTXLOCK", instruction_mtxlock);
800: INSTRUCTION("PERSIST", instruction_persist);
801: INSTRUCTION("PLOTTER", instruction_plotter);
802: INSTRUCTION("PRIVATE", instruction_private);
803: INSTRUCTION("PROTECT", instruction_protect);
804: INSTRUCTION("PSHPRFL", instruction_pshprfl);
805: INSTRUCTION("PULPRFL", instruction_pulprfl);
806: INSTRUCTION("REVLIST", instruction_revlist);
807: INSTRUCTION("SCATTER", instruction_scatter);
808: INSTRUCTION("SUSPEND", instruction_suspend);
809: INSTRUCTION("SWILOCK", instruction_swilock);
810: INSTRUCTION("SYSEVAL", instruction_syseval);
811: INSTRUCTION("TABLE->", instruction_table_fleche);
812: INSTRUCTION("VERSION", instruction_version);
813: INSTRUCTION("WORKDIR", instruction_workdir);
814: INSTRUCTION("->ARRAY", instruction_fleche_array);
815: INSTRUCTION("->TABLE", instruction_fleche_table);
816:
817: INSTRUCTION("CLRCNTXT", instruction_clrcntxt);
818: INSTRUCTION("CLRSMPHR", instruction_clrsmphr);
819: INSTRUCTION("CONTINUE", instruction_continue);
820: INSTRUCTION("DUPCNTXT", instruction_dupcntxt);
821: INSTRUCTION("FUNCTION", instruction_function);
822: INSTRUCTION("IMPLICIT", instruction_implicit);
823: INSTRUCTION("KEYLABEL", instruction_keylabel);
824: INSTRUCTION("KEYTITLE", instruction_keytitle);
825: INSTRUCTION("LOGSCALE", instruction_logscale);
826: INSTRUCTION("NEWPLANE", instruction_newplane);
827: INSTRUCTION("PSHCNTXT", instruction_pshcntxt);
828: INSTRUCTION("PULCNTXT", instruction_pulcntxt);
829: INSTRUCTION("SQLQUERY", instruction_sqlquery);
830: INSTRUCTION("SWIQUEUE", instruction_swiqueue);
831: INSTRUCTION("TOKENIZE", instruction_tokenize);
832: INSTRUCTION("VARIABLE", instruction_variable);
833: INSTRUCTION("VOLATILE", instruction_volatile);
834: INSTRUCTION("WARRANTY", instruction_warranty);
835:
836: INSTRUCTION("AUTOSCALE", instruction_autoscale);
837: INSTRUCTION("BACKSPACE", instruction_backspace);
838: INSTRUCTION("BACKTRACE", instruction_backtrace);
839: INSTRUCTION("CLRATEXIT", instruction_clratexit);
840: INSTRUCTION("CLRATPOKE", instruction_clratpoke);
841: INSTRUCTION("COPYRIGHT", instruction_copyright);
842: //INSTRUCTION("CYLINDRIC");
843: INSTRUCTION("DAEMONIZE", instruction_daemonize);
844: INSTRUCTION("DROPCNTXT", instruction_dropcntxt);
845: INSTRUCTION("EXTERNALS", instruction_externals);
846: INSTRUCTION("HISTOGRAM", instruction_histogram);
847: INSTRUCTION("MEMUNLOCK", instruction_memunlock);
848: INSTRUCTION("MTXSTATUS", instruction_mtxstatus);
849: INSTRUCTION("MTXUNLOCK", instruction_mtxunlock);
850: INSTRUCTION("PARAMETER", instruction_parameter);
851: //INSTRUCTION("PSCONTOUR")
852: //INSTRUCTION("SCATRPLOT")
853: //(trace un nuage de points de SDAT et la courbe de régression)
854: INSTRUCTION("SMPHRDECR", instruction_smphrdecr);
855: INSTRUCTION("SMPHRGETV", instruction_smphrgetv);
856: INSTRUCTION("SMPHRINCR", instruction_smphrincr);
857: INSTRUCTION("SWAPCNTXT", instruction_swapcntxt);
858: INSTRUCTION("SWISTATUS", instruction_swistatus);
859: INSTRUCTION("SWIUNLOCK", instruction_swiunlock);
860: INSTRUCTION("UNPROTECT", instruction_unprotect);
861: INSTRUCTION("WIREFRAME", instruction_wireframe);
862:
863: INSTRUCTION("MTXTRYLOCK", instruction_mtxtrylock);
864: INSTRUCTION("PARAMETRIC", instruction_parametric);
865: //INSTRUCTION("PARSURFACE")
866: //Instruction HP48 (tracé PARSURFACE) Equation sous forme de liste
867: INSTRUCTION("SLICESCALE", instruction_slicescale);
868: INSTRUCTION("SQLCONNECT", instruction_sqlconnect);
869: //INSTRUCTION("SLOPEFIELD")
870: //Instruction HP48 (type de tracé)
871: //Tracé 3D en courbes de niveaux.
872: //Le type de tracé 'SLOPEFIELD' dessine un réseau de segments dont les
873: //pentes
874: //représentent la valeur de la fonction (x,y) en leur milieu.
875: //=> utile pour y'=F(x,y)
876:
877: INSTRUCTION("LOCALIZATION", instruction_localization);
878: INSTRUCTION("SMPHRTRYDECR", instruction_smphrtrydecr);
879:
880: INSTRUCTION("SQLDISCONNECT", instruction_sqldisconnect);
881: #undef INSTRUCTION
882:
883: return;
884: }
885:
886:
887: #ifndef OS2
888: extern inline
889: #endif
890: void *
891: analyse_instruction(struct_processus *s_etat_processus, unsigned char *ptr)
892: {
893: int pointeur;
894:
895: struct_instruction *l_instruction_courante;
896:
897: l_instruction_courante = (*s_etat_processus).arbre_instructions;
898:
899: while((*ptr) != d_code_fin_chaine)
900: {
901: pointeur = (*s_etat_processus).pointeurs_caracteres[*ptr];
902:
903: if (pointeur < 0)
904: {
905: // Caractère hors de l'alphabet des instructions
906:
907: return(NULL);
908: }
909:
910: if ((*l_instruction_courante).noeud[pointeur] == NULL)
911: {
912: // Le chemin de l'instruction candidate n'existe pas.
913:
914: return(NULL);
915: }
916:
917: l_instruction_courante = (*l_instruction_courante).noeud[pointeur];
918: ptr++;
919:
920: if ((l_instruction_courante == NULL) && ((*ptr) != d_code_fin_chaine))
921: {
922: // Le chemin de l'instruction candidate est incomplet.
923:
924: return(NULL);
925: }
926: }
927:
928: if ((*l_instruction_courante).feuille != NULL)
929: {
930: return((*l_instruction_courante).feuille);
931: }
932:
933: return(NULL);
934: }
935:
936:
937: void
938: analyse(struct_processus *s_etat_processus, void (*fonction)())
939: {
940: static logical1 initialisation = d_faux;
941:
942: real8 attente;
943: real8 pourcentage;
944: real8 temps_cpu;
945: real8 temps_reel;
946:
947: static struct timeval horodatage_initial;
948: struct timeval horodatage_final;
949:
950: static struct rusage usage_initial;
951: struct rusage usage_final;
952:
953: struct timespec temporisation;
954:
955: unsigned char *position;
956: unsigned char *bibliotheque_candidate;
957: unsigned char instruction_majuscule
958: [d_longueur_maximale_instruction];
959: unsigned char registre_instruction_valide;
960:
961: void (*instruction)();
962:
963: errno = 0;
964: (*s_etat_processus).var_volatile_exception_gsl = 0;
965:
966: (*s_etat_processus).instruction_valide = 'Y';
967: (*s_etat_processus).constante_symbolique = 'N';
968: (*s_etat_processus).nombre_arguments = -2;
969: (*s_etat_processus).instruction_intrinseque = 'I';
970:
971: /*
972: * On autorise l'exécution d'un fork() dans un thread concurrent.
973: */
974:
975: # ifndef SEMAPHORES_NOMMES
976: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
977: {
978: (*s_etat_processus).erreur_systeme = d_es_processus;
979: return;
980: }
981:
982: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
983: {
984: if (errno != EINTR)
985: {
986: (*s_etat_processus).erreur_systeme = d_es_processus;
987: return;
988: }
989: }
990: # else
991: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
992: {
993: (*s_etat_processus).erreur_systeme = d_es_processus;
994: return;
995: }
996:
997: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
998: {
999: if (errno != EINTR)
1000: {
1001: (*s_etat_processus).erreur_systeme = d_es_processus;
1002: return;
1003: }
1004: }
1005: # endif
1006:
1007: scrutation_injection(s_etat_processus);
1008:
1009: if (fonction == NULL)
1010: {
1011: conversion_majuscule_limitee((*s_etat_processus).instruction_courante,
1012: instruction_majuscule, d_longueur_maximale_instruction);
1013: instruction = analyse_instruction(s_etat_processus,
1014: instruction_majuscule);
1015:
1016: if (instruction == NULL)
1017: {
1018: // L'instruction n'existe pas.
1019:
1020: (*s_etat_processus).instruction_valide = 'N';
1021: }
1022: else
1023: {
1024: // Exécution de l'instruction associée. Le drapeau
1025: // (*s_etat_processus).instruction_valide peut passer à 'N'
1026: // dans le cas d'instructions sensibles à la casse.
1027:
1028: if ((*s_etat_processus).niveau_profilage >= 2)
1029: {
1030: profilage(s_etat_processus, instruction_majuscule);
1031: }
1032:
1033: (*s_etat_processus).instruction_valide = 'Y';
1034: instruction(s_etat_processus);
1035:
1036: if ((*s_etat_processus).niveau_profilage >= 2)
1037: {
1038: profilage(s_etat_processus, NULL);
1039: }
1040: }
1041: }
1042: else
1043: {
1044: if ((*s_etat_processus).niveau_profilage >= 2)
1045: {
1046: profilage(s_etat_processus,
1047: (*s_etat_processus).instruction_courante);
1048: }
1049:
1050: (*s_etat_processus).instruction_valide = 'Y';
1051: fonction(s_etat_processus);
1052:
1053: if ((*s_etat_processus).niveau_profilage >= 2)
1054: {
1055: profilage(s_etat_processus, NULL);
1056: }
1057: }
1058:
1059: if ((*s_etat_processus).instruction_valide == 'Y')
1060: {
1061: (*s_etat_processus).instruction_intrinseque = 'Y';
1062: }
1063:
1064: if ((*s_etat_processus).instruction_valide == 'N')
1065: {
1066: if ((position = index((*s_etat_processus).instruction_courante, '$'))
1067: != NULL)
1068: {
1069: if ((bibliotheque_candidate = malloc((position + 1
1070: - (*s_etat_processus).instruction_courante)
1071: * sizeof(unsigned char))) == NULL)
1072: {
1073: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1074: return;
1075: }
1076:
1077: (*bibliotheque_candidate) = d_code_fin_chaine;
1078: strncat(bibliotheque_candidate,
1079: (*s_etat_processus).instruction_courante,
1080: position - (*s_etat_processus).instruction_courante);
1081:
1082: position++;
1083:
1084: if (execution_fonction_de_bibliotheque(s_etat_processus, position,
1085: bibliotheque_candidate) == d_vrai)
1086: {
1087: (*s_etat_processus).instruction_valide = 'Y';
1088: (*s_etat_processus).instruction_intrinseque = 'N';
1089: }
1090: else
1091: {
1092: (*s_etat_processus).instruction_valide = 'N';
1093: }
1094:
1095: free(bibliotheque_candidate);
1096: }
1097: else
1098: {
1099: if (execution_fonction_de_bibliotheque(s_etat_processus,
1100: (*s_etat_processus).instruction_courante, NULL)
1101: == 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: }
1112:
1113: /*
1114: --------------------------------------------------------------------------------
1115: Gestion des interruptions logicielles
1116: --------------------------------------------------------------------------------
1117: */
1118:
1119: if (((*s_etat_processus).erreur_systeme == d_es) &&
1120: ((*s_etat_processus).erreur_execution == d_ex) &&
1121: ((*s_etat_processus).exception == d_ep))
1122: {
1123: if ((*s_etat_processus).test_instruction == 'N')
1124: {
1125: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
1126: {
1127: affectation_interruptions_logicielles(s_etat_processus);
1128: }
1129:
1130: if (((*s_etat_processus).nombre_interruptions_en_queue != 0) &&
1131: ((*s_etat_processus).erreur_systeme == d_es) &&
1132: ((*s_etat_processus).erreur_execution == d_ex))
1133: {
1134:
1135: registre_instruction_valide =
1136: (*s_etat_processus).instruction_valide;
1137: traitement_interruptions_logicielles(s_etat_processus);
1138: (*s_etat_processus).instruction_valide =
1139: registre_instruction_valide;
1140: }
1141: }
1142: }
1143:
1144: /*
1145: --------------------------------------------------------------------------------
1146: Limitation du pourcetage de temps CPU
1147: --------------------------------------------------------------------------------
1148: */
1149:
1150: # ifndef OS2
1151: if ((*s_etat_processus).pourcentage_maximal_cpu < 100)
1152: {
1153: getrusage(RUSAGE_SELF, &usage_final);
1154: gettimeofday(&horodatage_final, NULL);
1155:
1156: if (initialisation == d_vrai)
1157: {
1158: temps_reel = ((real8) (horodatage_final.tv_sec -
1159: horodatage_initial.tv_sec)) +
1160: (((real8) (horodatage_final.tv_usec -
1161: horodatage_initial.tv_usec)) / ((real8) 1E6));
1162:
1163: if (temps_reel >= 0.1)
1164: {
1165: temps_cpu = ((real8) ((usage_final.ru_utime.tv_sec +
1166: usage_final.ru_stime.tv_sec) -
1167: (usage_initial.ru_utime.tv_sec +
1168: usage_initial.ru_stime.tv_sec))) +
1169: (((real8) ((usage_final.ru_utime.tv_usec +
1170: usage_final.ru_stime.tv_usec) -
1171: (usage_initial.ru_utime.tv_usec +
1172: usage_initial.ru_stime.tv_usec))) / ((real8) 1E6));
1173:
1174: pourcentage = 100 * temps_cpu / temps_reel;
1175:
1176: if (pourcentage > 100)
1177: {
1178: pourcentage = 100;
1179: }
1180:
1181: if (pourcentage > (*s_etat_processus).pourcentage_maximal_cpu)
1182: {
1183: attente = ((pourcentage * temps_cpu) /
1184: (*s_etat_processus).pourcentage_maximal_cpu)
1185: - (pourcentage * temps_cpu / 100);
1186:
1187: temporisation.tv_sec = floor(attente);
1188: temporisation.tv_nsec = (attente - temporisation.tv_sec) *
1189: 1E9;
1190:
1191: nanosleep(&temporisation, NULL);
1192: }
1193:
1194: horodatage_initial = horodatage_final;
1195: usage_initial = usage_final;
1196: }
1197: }
1198: else
1199: {
1200: initialisation = d_vrai;
1201:
1202: horodatage_initial = horodatage_final;
1203: usage_initial = usage_final;
1204: }
1205: }
1206: # endif
1207:
1208: /*
1209: --------------------------------------------------------------------------------
1210: Introduction des erreurs générées
1211: --------------------------------------------------------------------------------
1212: */
1213:
1214: if (((*s_etat_processus).test_instruction == 'N') &&
1215: ((*s_etat_processus).instruction_valide == 'Y'))
1216: {
1217: traitement_asynchrone_exceptions_gsl(s_etat_processus);
1218:
1219: if ((*s_etat_processus).erreur_processus_fils == d_vrai)
1220: {
1221: (*s_etat_processus).erreur_processus_fils = d_faux;
1222:
1223: (*s_etat_processus).erreur_systeme =
1224: (*s_etat_processus).erreur_systeme_processus_fils;
1225: (*s_etat_processus).erreur_execution =
1226: (*s_etat_processus).erreur_execution_processus_fils;
1227: (*s_etat_processus).arret_si_exception = d_vrai;
1228:
1229: if ((*s_etat_processus).pid_erreur_processus_fils == getpid())
1230: {
1231: (*s_etat_processus).invalidation_message_erreur = d_faux;
1232: }
1233: else
1234: {
1235: (*s_etat_processus).invalidation_message_erreur = d_vrai;
1236: }
1237: }
1238:
1239: if (((*s_etat_processus).erreur_execution != d_ex) ||
1240: ((*s_etat_processus).erreur_systeme != d_es) ||
1241: ((*s_etat_processus).exception != d_ep))
1242: {
1243: (*s_etat_processus).niveau_derniere_erreur =
1244: (*s_etat_processus).niveau_courant;
1245:
1246: if ((*s_etat_processus).mode_execution_programme == 'Y')
1247: {
1248: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1249: {
1250: free((*s_etat_processus).instruction_derniere_erreur);
1251: (*s_etat_processus).instruction_derniere_erreur = NULL;
1252: }
1253:
1254: if ((*s_etat_processus).instruction_courante == NULL)
1255: {
1256: if (((*s_etat_processus).instruction_derniere_erreur =
1257: malloc(16 * sizeof(unsigned char))) == NULL)
1258: {
1259: (*s_etat_processus).erreur_systeme =
1260: d_es_allocation_memoire;
1261: return;
1262: }
1263:
1264: strcpy((*s_etat_processus).instruction_derniere_erreur,
1265: "<not available>");
1266: }
1267: else
1268: {
1269: if (((*s_etat_processus).instruction_derniere_erreur =
1270: malloc((strlen((*s_etat_processus)
1271: .instruction_courante) + 1) *
1272: sizeof(unsigned char))) == NULL)
1273: {
1274: (*s_etat_processus).erreur_systeme =
1275: d_es_allocation_memoire;
1276: return;
1277: }
1278:
1279: strcpy((*s_etat_processus).instruction_derniere_erreur,
1280: (*s_etat_processus).instruction_courante);
1281: }
1282: }
1283: else
1284: {
1285: if ((*s_etat_processus).objet_courant != NULL)
1286: {
1287: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1288: {
1289: free((*s_etat_processus).instruction_derniere_erreur);
1290: (*s_etat_processus).instruction_derniere_erreur = NULL;
1291: }
1292:
1293: if (((*s_etat_processus).instruction_derniere_erreur =
1294: formateur(s_etat_processus, 0,
1295: (*s_etat_processus).objet_courant)) == NULL)
1296: {
1297: return;
1298: }
1299:
1300: (*s_etat_processus).objet_courant = NULL;
1301: }
1302: }
1303: }
1304: }
1305:
1306: return;
1307: }
1308:
1309:
1310: /*
1311: ================================================================================
1312: Traitement asynchrone des erreurs de la bibliothèque GSL
1313: ================================================================================
1314: Entrées :
1315: --------------------------------------------------------------------------------
1316: Sorties :
1317: --------------------------------------------------------------------------------
1318: Effets de bord : néant
1319: ================================================================================
1320: */
1321:
1322: void
1323: traitement_asynchrone_exceptions_gsl(struct_processus *s_etat_processus)
1324: {
1325: if ((*s_etat_processus).var_volatile_exception_gsl != 0)
1326: {
1327: switch((*s_etat_processus).var_volatile_exception_gsl)
1328: {
1329: case GSL_EINVAL :
1330: {
1331: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1332: break;
1333: }
1334:
1335: case GSL_EDOM :
1336: {
1337: (*s_etat_processus).exception = d_ep_domaine_definition;
1338: break;
1339: }
1340:
1341: case GSL_ERANGE :
1342: {
1343: (*s_etat_processus).exception = d_ep_resultat_indefini;
1344: break;
1345: }
1346:
1347: case GSL_EZERODIV :
1348: {
1349: (*s_etat_processus).exception = d_ep_division_par_zero;
1350: break;
1351: }
1352:
1353: case GSL_EUNDRFLW :
1354: {
1355: (*s_etat_processus).exception = d_ep_underflow;
1356: break;
1357: }
1358:
1359: case GSL_EOVRFLW :
1360: {
1361: (*s_etat_processus).exception = d_ep_overflow;
1362: break;
1363: }
1364:
1365: case GSL_ENOMEM :
1366: {
1367: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1368: break;
1369: }
1370:
1371: case GSL_ELOSS :
1372: {
1373: (*s_etat_processus).exception = d_ep_perte_precision;
1374: break;
1375: }
1376:
1377: default :
1378: {
1379: (*s_etat_processus).erreur_execution =
1380: d_ex_routines_mathematiques;
1381: break;
1382: }
1383: }
1384:
1385: (*s_etat_processus).var_volatile_exception_gsl = 0;
1386: }
1387:
1388: return;
1389: }
1390:
1391: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>