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