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