1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.2
4: Copyright (C) 1989-2011 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25:
26: /*
27: ================================================================================
28: 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: 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:
48: BUG(strlen(instruction) >= d_longueur_maximale_instruction,
49: printf("%s -> %d >= %d\n", instruction, (int) strlen(instruction),
50: d_longueur_maximale_instruction));
51:
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:
63: if (((*(*s_etat_processus).arbre_instructions).noeuds =
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: {
73: (*(*s_etat_processus).arbre_instructions).noeuds[i] = NULL;
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:
86: if ((*l_instruction_courante).noeuds[(*s_etat_processus)
87: .pointeurs_caracteres[*ptr]] == NULL)
88: {
89: // Le noeud suivant n'existe pas, on le crée.
90:
91: if (((*l_instruction_courante).noeuds[(*s_etat_processus)
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:
99: (*(*l_instruction_courante).noeuds[(*s_etat_processus)
100: .pointeurs_caracteres[*ptr]]).feuille = NULL;
101:
102: if (((*(*l_instruction_courante).noeuds[(*s_etat_processus)
103: .pointeurs_caracteres[*ptr]]).noeuds =
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: {
113: (*(*l_instruction_courante).noeuds[(*s_etat_processus)
114: .pointeurs_caracteres[*ptr]]).noeuds[i] = NULL;
115: }
116: }
117:
118: l_instruction_courante = (*l_instruction_courante).noeuds
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: {
140: if ((*arbre).noeuds[i] != NULL)
141: {
142: liberation_arbre_instructions(s_etat_processus, (*arbre).noeuds[i]);
143: }
144: }
145:
146: free((*arbre).noeuds);
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: # ifndef OS2
462: INSTRUCTION("KILL", instruction_kill);
463: # endif
464: INSTRUCTION("KIND", instruction_kind);
465: INSTRUCTION("LAST", instruction_last);
466: INSTRUCTION("LEGV", instruction_legv);
467: INSTRUCTION("LINE", instruction_line);
468: INSTRUCTION("LNP1", instruction_lnp1);
469: INSTRUCTION("LOCK", instruction_lock);
470: INSTRUCTION("L->T", instruction_l_vers_t);
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("T->L", instruction_t_vers_l);
575: INSTRUCTION("UTPC", instruction_utpc);
576: INSTRUCTION("UTPF", instruction_utpf);
577: INSTRUCTION("UTPN", instruction_utpn);
578: INSTRUCTION("UTPT", instruction_utpt);
579: INSTRUCTION("VARS", instruction_vars);
580: INSTRUCTION("WAIT", instruction_wait);
581: INSTRUCTION("XCOL", instruction_xcol);
582: INSTRUCTION("XPON", instruction_xpon);
583: //INSTRUCTION("XRNG")
584: //INSTRUCTION("XVOL")
585: INSTRUCTION("YCOL", instruction_ycol);
586: //INSTRUCTION("YRNG")
587: //INSTRUCTION("YVOL")
588: //INSTRUCTION("ZVOL")
589: //INSTRUCTION("->V2")
590: //Instruction HP48 (combine deux réels x et y en un vecteur 2D en fonction
591: //du mode de coordonnées en cours => [ x y ] et ce quel que soit le système
592: //de coordonnées courant)
593: //INSTRUCTION("->V3")
594:
595: INSTRUCTION("ABORT", instruction_abort);
596: INSTRUCTION("ACOSH", instruction_acosh);
597: INSTRUCTION("ALARM", instruction_alarm);
598: INSTRUCTION("ASINH", instruction_asinh);
599: INSTRUCTION("ATANH", instruction_atanh);
600: //INSTRUCTION("BYTES");
601: INSTRUCTION("CENTR", instruction_centr);
602: //INSTRUCTION("CIRCL");
603: INSTRUCTION("CLEAR", instruction_clear);
604: INSTRUCTION("CLLCD", instruction_cllcd);
605: INSTRUCTION("CLOSE", instruction_close);
606: INSTRUCTION("CLUSR", instruction_clusr);
607: //INSTRUCTION("CLVAR");
608: //INSTRUCTION("COLCT")
609: INSTRUCTION("COL->", instruction_col_fleche);
610: //INSTRUCTION("CONIC")
611: //Instruction HP48 (sélectionne le type de tracé CONIC)
612: //Permet de tracer des coniques en fonction d'équations
613: //de type f(x, y) = 0.
614: //INSTRUCTION("CRDIR")
615: INSTRUCTION("CRMTX", instruction_crmtx);
616: INSTRUCTION("CROSS", instruction_cross);
617: INSTRUCTION("CRTAB", instruction_crtab);
618: INSTRUCTION("CSTOP", instruction_cstop);
619: INSTRUCTION("CYCLE", instruction_cycle);
620: //INSTRUCTION("CYLIN")
621: //Instruction HP48 (sélectionne le type de tracé CYLINDRIC)
622: INSTRUCTION("DEPND", instruction_depnd);
623: INSTRUCTION("DEPTH", instruction_depth);
624: //INSTRUCTION("DOSUB")
625: //Instruction HP48 (application séquentielle d'une fonction à une liste)
626: //liste nombre_elements_traites_a_chaque_iteration fonction DOSUB
627: //{ 1 2 3 4 5 }
628: //2
629: //<< + 2 / >>
630: //DOSUB
631: //=> { 1.5 2.5 3.5 4.5 }
632: INSTRUCTION("DGTIZ", instruction_dgtiz);
633: INSTRUCTION("DROP2", instruction_drop2);
634: INSTRUCTION("DROPN", instruction_dropn);
635: INSTRUCTION("ERASE", instruction_erase);
636: INSTRUCTION("EXGET", instruction_exget);
637: //INSTRUCTION("EXPAN");
638: INSTRUCTION("EXSUB", instruction_exsub);
639: INSTRUCTION("EYEPT", instruction_eyept);
640: INSTRUCTION("FALSE", instruction_false);
641: INSTRUCTION("FLOOR", instruction_floor);
642: INSTRUCTION("GAMMA", instruction_gamma);
643: INSTRUCTION("GEGVL", instruction_gegvl);
644: INSTRUCTION("GLEGV", instruction_glegv);
645: INSTRUCTION("GREGV", instruction_gregv);
646: INSTRUCTION("HMS->", instruction_hms_fleche);
647: INSTRUCTION("IFERR", instruction_iferr);
648: INSTRUCTION("INDEP", instruction_indep);
649: INSTRUCTION("INPUT", instruction_input);
650: INSTRUCTION("JDATE", instruction_jdate);
651: INSTRUCTION("LABEL", instruction_label);
652: INSTRUCTION("LCASE", instruction_lcase);
653: INSTRUCTION("LCHOL", instruction_lchol);
654: INSTRUCTION("LCD->", instruction_lcd_fleche);
655: //INSTRUCTION("NDIST")
656: //Instruction HP48 (distribution normale, prend la moyenne au niveau 3,
657: //la variance au niveau 2, un réel x au niveau 1 et renvoie la probabilité
658: //qu'une variable aléatoire normale soit égale à x dans une distribution
659: //normale).
660: INSTRUCTION("NRAND", instruction_nrand);
661: INSTRUCTION("OBGET", instruction_obget);
662: INSTRUCTION("OBSUB", instruction_obsub);
663: INSTRUCTION("PAPER", instruction_paper);
664: //INSTRUCTION("PCOEFF")
665: //INSTRUCTION("PEVAL")
666: //INSTRUCTION("PGDIR")
667: //INSTRUCTION("PIXEL")
668: //INSTRUCTION("PLIST")
669: //Instruction HP48 (produit des termes d'une liste)
670: INSTRUCTION("POLAR", instruction_polar);
671: INSTRUCTION("PRINT", instruction_print);
672: //INSTRUCTION("PREDV");
673: INSTRUCTION("PRLCD", instruction_prlcd);
674: //INSTRUCTION("PROOT")
675: //Instruction HP48 (calcule les racines d'un polynôme en fonction du tableau
676: //de coefficients)
677: INSTRUCTION("PRSTC", instruction_prstc);
678: INSTRUCTION("PRUSR", instruction_prusr);
679: INSTRUCTION("PRVAR", instruction_prvar);
680: INSTRUCTION("PSDEV", instruction_psdev);
681: INSTRUCTION("PURGE", instruction_purge);
682: INSTRUCTION("RDATE", instruction_rdate);
683: INSTRUCTION("RELAX", instruction_relax);
684: INSTRUCTION("RFUSE", instruction_rfuse);
685: INSTRUCTION("RSTOP", instruction_rstop);
686: INSTRUCTION("ROLLD", instruction_rolld);
687: INSTRUCTION("ROW->", instruction_row_fleche);
688: INSTRUCTION("SCALE", instruction_scale);
689: INSTRUCTION("SCHED", instruction_sched);
690: INSTRUCTION("SCHUR", instruction_schur);
691: INSTRUCTION("SCONJ", instruction_sconj);
692: INSTRUCTION("SLICE", instruction_slice);
693: //INSTRUCTION("SLIST")
694: //Instruction HP48 (somme des termes d'une liste)
695: # ifndef OS2
696: INSTRUCTION("SPAWN", instruction_spawn);
697: # endif
698: INSTRUCTION("START", instruction_start);
699: INSTRUCTION("STORE", instruction_store);
700: INSTRUCTION("STR->", instruction_str_fleche);
701: INSTRUCTION("TAYLR", instruction_taylr);
702: INSTRUCTION("TITLE", instruction_title);
703: //INSTRUCTION("TRACE")
704: //INSTRUCTION("TRUTH")
705: INSTRUCTION("UCASE", instruction_ucase);
706: INSTRUCTION("UCHOL", instruction_uchol);
707: INSTRUCTION("UNTIL", instruction_until);
708: //INSTRUCTION("UPDIR")
709: INSTRUCTION("VISIT", instruction_visit);
710: INSTRUCTION("WFACK", instruction_wfack);
711: INSTRUCTION("WFSWI", instruction_wfswi);
712: INSTRUCTION("WHILE", instruction_while);
713: //INSTRUCTION("WIDTH")
714: INSTRUCTION("WRITE", instruction_write);
715: INSTRUCTION("XROOT", instruction_xroot);
716: INSTRUCTION("YIELD", instruction_yield);
717: INSTRUCTION("->COL", instruction_fleche_col);
718: INSTRUCTION("->HMS", instruction_fleche_hms);
719: INSTRUCTION("->LCD", instruction_fleche_lcd);
720: INSTRUCTION("->NUM", instruction_fleche_num);
721: INSTRUCTION("->ROW", instruction_fleche_row);
722: INSTRUCTION("->STR", instruction_fleche_str);
723:
724: INSTRUCTION("APPEND", instruction_append);
725: INSTRUCTION("ARRY->", instruction_array_fleche);
726: INSTRUCTION("ATEXIT", instruction_atexit);
727: INSTRUCTION("ATPOKE", instruction_atpoke);
728: INSTRUCTION("BESSEL", instruction_bessel);
729: INSTRUCTION("CLRERR", instruction_clrerr);
730: INSTRUCTION("CLRMTX", instruction_clrmtx);
731: INSTRUCTION("CLRSWI", instruction_clrswi);
732: INSTRUCTION("CREATE", instruction_create);
733: INSTRUCTION("DELETE", instruction_delete);
734: # ifndef OS2
735: INSTRUCTION("DETACH", instruction_detach);
736: # endif
737: INSTRUCTION("DIAG->", instruction_diag_fleche);
738: //INSTRUCTION("DOLIST")
739: //Instruction HP48 (application d'une fonction à une liste)
740: //liste(s) nombre_de_listes_a_traiter fonction DOLIST
741: //{ 1 2 3 }
742: //{ 4 5 6 }
743: //{ 7 8 9 }
744: //3
745: //<< * + >>
746: //DOLIST
747: //=> { 29 42 57 }
748: INSTRUCTION("ELSEIF", instruction_elseif);
749: INSTRUCTION("FORMAT", instruction_format);
750: //INSTRUCTION("HEIGHT")
751: INSTRUCTION("ITRACE", instruction_itrace);
752: INSTRUCTION("LIST->", instruction_list_fleche);
753: INSTRUCTION("LOGGER", instruction_logger);
754: INSTRUCTION("MCLRIN", instruction_mclrin);
755: INSTRUCTION("NRPROC", instruction_nrproc);
756: INSTRUCTION("PROCID", instruction_procid);
757: INSTRUCTION("PROMPT", instruction_prompt);
758: INSTRUCTION("RCLSWI", instruction_rclswi);
759: INSTRUCTION("RECALL", instruction_recall);
760: INSTRUCTION("RECODE", instruction_recode);
761: INSTRUCTION("REDRAW", instruction_redraw);
762: INSTRUCTION("REMOVE", instruction_remove);
763: INSTRUCTION("REPEAT", instruction_repeat);
764: INSTRUCTION("RETURN", instruction_return);
765: INSTRUCTION("REWIND", instruction_rewind);
766: //INSTRUCTION("SCREEN")
767: INSTRUCTION("SELECT", instruction_select);
768: //INSTRUCTION("SPHERE")
769: INSTRUCTION("SHARED", instruction_shared);
770: INSTRUCTION("SPLASH", instruction_splash);
771: INSTRUCTION("STATIC", instruction_static);
772: INSTRUCTION("STOSWI", instruction_stoswi);
773: //INSTRUCTION("STREAM", instruction_stream);
774: //{ 1 2 3 4 5 } << * >> STREAM => 120
775: INSTRUCTION("TARGET", instruction_target);
776: INSTRUCTION("UNLOCK", instruction_unlock);
777: INSTRUCTION("VERIFY", instruction_verify);
778: INSTRUCTION("WFDATA", instruction_wfdata);
779: INSTRUCTION("WFLOCK", instruction_wflock);
780: INSTRUCTION("WFPOKE", instruction_wfpoke);
781: INSTRUCTION("WFPROC", instruction_wfproc);
782: INSTRUCTION("WFSOCK", instruction_wfsock);
783: INSTRUCTION("->ARRY", instruction_fleche_array);
784: INSTRUCTION("->DIAG", instruction_fleche_diag);
785: INSTRUCTION("->LIST", instruction_fleche_list);
786:
787: INSTRUCTION("ARRAY->", instruction_array_fleche);
788: //INSTRUCTION("BARPLOT")
789: //INSTRUCTION("BESTFIT")
790: //Instruction HP48 (choisit le meilleur modèle de régression)
791: INSTRUCTION("CLRFUSE", instruction_clrfuse);
792: INSTRUCTION("CONVERT", instruction_convert);
793: INSTRUCTION("CRSMPHR", instruction_crsmphr);
794: INSTRUCTION("CURRENC", instruction_currenc);
795: INSTRUCTION("DEFAULT", instruction_default);
796: INSTRUCTION("EPSILON", instruction_epsilon);
797: //INSTRUCTION("GRIDMAP")
798: //Instruction HP48 (sélectionne le mode de tracé GRIDMAP)
799: //Le tracé GRIDMAP transforme la grille d'échantillonnage rectiligne
800: //en appliquant la fonction en cours à valeurs complexes.
801: //Les coordonnées de chaque point de la grille (un nombre complexe)
802: //constituent
803: //les données d'entrée de la fonction qui les projette ensuite dans le
804: //grille
805: //de sortie.
806: //f(x,y)=fnct complexe évaluée sur la grille (x,y) et affichée comme une
807: //fonction paramétrique.
808: INSTRUCTION("INQUIRE", instruction_inquire);
809: INSTRUCTION("MEMLOCK", instruction_memlock);
810: INSTRUCTION("MTXLOCK", instruction_mtxlock);
811: INSTRUCTION("PERSIST", instruction_persist);
812: INSTRUCTION("PLOTTER", instruction_plotter);
813: INSTRUCTION("PRIVATE", instruction_private);
814: INSTRUCTION("PROTECT", instruction_protect);
815: INSTRUCTION("PSHPRFL", instruction_pshprfl);
816: INSTRUCTION("PULPRFL", instruction_pulprfl);
817: INSTRUCTION("REVLIST", instruction_revlist);
818: INSTRUCTION("SCATTER", instruction_scatter);
819: INSTRUCTION("SUSPEND", instruction_suspend);
820: INSTRUCTION("SWILOCK", instruction_swilock);
821: INSTRUCTION("SYSEVAL", instruction_syseval);
822: INSTRUCTION("TABLE->", instruction_table_fleche);
823: INSTRUCTION("VERSION", instruction_version);
824: INSTRUCTION("WORKDIR", instruction_workdir);
825: INSTRUCTION("->ARRAY", instruction_fleche_array);
826: INSTRUCTION("->TABLE", instruction_fleche_table);
827:
828: INSTRUCTION("CLRCNTXT", instruction_clrcntxt);
829: INSTRUCTION("CLRSMPHR", instruction_clrsmphr);
830: # ifndef OS2
831: INSTRUCTION("CONTINUE", instruction_continue);
832: # endif
833: INSTRUCTION("DUPCNTXT", instruction_dupcntxt);
834: INSTRUCTION("FUNCTION", instruction_function);
835: INSTRUCTION("IMPLICIT", instruction_implicit);
836: INSTRUCTION("INFINITY", instruction_sensible_infinity);
837: INSTRUCTION("KEYLABEL", instruction_keylabel);
838: INSTRUCTION("KEYTITLE", instruction_keytitle);
839: INSTRUCTION("LOGSCALE", instruction_logscale);
840: INSTRUCTION("NEWPLANE", instruction_newplane);
841: INSTRUCTION("PSHCNTXT", instruction_pshcntxt);
842: INSTRUCTION("PULCNTXT", instruction_pulcntxt);
843: INSTRUCTION("SQLQUERY", instruction_sqlquery);
844: INSTRUCTION("SWIQUEUE", instruction_swiqueue);
845: INSTRUCTION("TOKENIZE", instruction_tokenize);
846: INSTRUCTION("VARIABLE", instruction_variable);
847: INSTRUCTION("VOLATILE", instruction_volatile);
848: INSTRUCTION("WARRANTY", instruction_warranty);
849:
850: INSTRUCTION("AUTOSCALE", instruction_autoscale);
851: INSTRUCTION("BACKSPACE", instruction_backspace);
852: INSTRUCTION("BACKTRACE", instruction_backtrace);
853: INSTRUCTION("CLRATEXIT", instruction_clratexit);
854: INSTRUCTION("CLRATPOKE", instruction_clratpoke);
855: INSTRUCTION("COPYRIGHT", instruction_copyright);
856: //INSTRUCTION("CYLINDRIC");
857: INSTRUCTION("DAEMONIZE", instruction_daemonize);
858: INSTRUCTION("DROPCNTXT", instruction_dropcntxt);
859: INSTRUCTION("EXTERNALS", instruction_externals);
860: INSTRUCTION("HISTOGRAM", instruction_histogram);
861: INSTRUCTION("MEMUNLOCK", instruction_memunlock);
862: INSTRUCTION("MTXSTATUS", instruction_mtxstatus);
863: INSTRUCTION("MTXUNLOCK", instruction_mtxunlock);
864: INSTRUCTION("PARAMETER", instruction_parameter);
865: //INSTRUCTION("PSCONTOUR")
866: //INSTRUCTION("SCATRPLOT")
867: //(trace un nuage de points de SDAT et la courbe de régression)
868: INSTRUCTION("SMPHRDECR", instruction_smphrdecr);
869: INSTRUCTION("SMPHRGETV", instruction_smphrgetv);
870: INSTRUCTION("SMPHRINCR", instruction_smphrincr);
871: INSTRUCTION("SWAPCNTXT", instruction_swapcntxt);
872: INSTRUCTION("SWISTATUS", instruction_swistatus);
873: INSTRUCTION("SWIUNLOCK", instruction_swiunlock);
874: INSTRUCTION("UNPROTECT", instruction_unprotect);
875: INSTRUCTION("WIREFRAME", instruction_wireframe);
876:
877: INSTRUCTION("MTXTRYLOCK", instruction_mtxtrylock);
878: INSTRUCTION("PARAMETRIC", instruction_parametric);
879: //INSTRUCTION("PARSURFACE")
880: //Instruction HP48 (tracé PARSURFACE) Equation sous forme de liste
881: INSTRUCTION("SLICESCALE", instruction_slicescale);
882: INSTRUCTION("SQLCONNECT", instruction_sqlconnect);
883: //INSTRUCTION("SLOPEFIELD")
884: //Instruction HP48 (type de tracé)
885: //Tracé 3D en courbes de niveaux.
886: //Le type de tracé 'SLOPEFIELD' dessine un réseau de segments dont les
887: //pentes
888: //représentent la valeur de la fonction (x,y) en leur milieu.
889: //=> utile pour y'=F(x,y)
890:
891: INSTRUCTION("LOCALIZATION", instruction_localization);
892: INSTRUCTION("SMPHRTRYDECR", instruction_smphrtrydecr);
893:
894: INSTRUCTION("SQLDISCONNECT", instruction_sqldisconnect);
895: #undef INSTRUCTION
896:
897: return;
898: }
899:
900:
901: void *
902: analyse_instruction(struct_processus *s_etat_processus, unsigned char *ptr)
903: {
904: int pointeur;
905:
906: struct_instruction *l_instruction_courante;
907:
908: l_instruction_courante = (*s_etat_processus).arbre_instructions;
909:
910: while((*ptr) != d_code_fin_chaine)
911: {
912: pointeur = (*s_etat_processus).pointeurs_caracteres[*ptr];
913:
914: if (pointeur < 0)
915: {
916: // Caractère hors de l'alphabet des instructions
917:
918: return(NULL);
919: }
920:
921: if ((*l_instruction_courante).noeuds[pointeur] == NULL)
922: {
923: // Le chemin de l'instruction candidate n'existe pas.
924:
925: return(NULL);
926: }
927:
928: l_instruction_courante = (*l_instruction_courante).noeuds[pointeur];
929: ptr++;
930:
931: if ((l_instruction_courante == NULL) && ((*ptr) != d_code_fin_chaine))
932: {
933: // Le chemin de l'instruction candidate est incomplet.
934:
935: return(NULL);
936: }
937: }
938:
939: if ((*l_instruction_courante).feuille != NULL)
940: {
941: return((*l_instruction_courante).feuille);
942: }
943:
944: return(NULL);
945: }
946:
947:
948: void
949: analyse(struct_processus *s_etat_processus, void (*fonction)())
950: {
951: static logical1 initialisation = d_faux;
952:
953: real8 attente;
954: real8 pourcentage;
955: real8 temps_cpu;
956: real8 temps_reel;
957:
958: static struct timeval horodatage_initial;
959: struct timeval horodatage_final;
960:
961: static struct rusage usage_initial;
962: struct rusage usage_final;
963:
964: struct timespec temporisation;
965:
966: unsigned char *position;
967: unsigned char *bibliotheque_candidate;
968: unsigned char instruction_majuscule
969: [d_longueur_maximale_instruction];
970: unsigned char registre_instruction_valide;
971:
972: void (*instruction)();
973:
974: errno = 0;
975: (*s_etat_processus).var_volatile_exception_gsl = 0;
976:
977: (*s_etat_processus).instruction_valide = 'Y';
978: (*s_etat_processus).constante_symbolique = 'N';
979: (*s_etat_processus).nombre_arguments = -2;
980: (*s_etat_processus).instruction_intrinseque = 'I';
981:
982: /*
983: * On autorise l'exécution d'un fork() dans un thread concurrent.
984: */
985:
986: # ifndef SEMAPHORES_NOMMES
987: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
988: {
989: (*s_etat_processus).erreur_systeme = d_es_processus;
990: return;
991: }
992:
993: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
994: {
995: if (errno != EINTR)
996: {
997: (*s_etat_processus).erreur_systeme = d_es_processus;
998: return;
999: }
1000: }
1001: # else
1002: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1003: {
1004: (*s_etat_processus).erreur_systeme = d_es_processus;
1005: return;
1006: }
1007:
1008: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1009: {
1010: if (errno != EINTR)
1011: {
1012: (*s_etat_processus).erreur_systeme = d_es_processus;
1013: return;
1014: }
1015: }
1016: # endif
1017:
1018: scrutation_injection(s_etat_processus);
1019:
1020: if (fonction == NULL)
1021: {
1022: conversion_majuscule_limitee((*s_etat_processus).instruction_courante,
1023: instruction_majuscule, d_longueur_maximale_instruction);
1024: instruction = analyse_instruction(s_etat_processus,
1025: instruction_majuscule);
1026:
1027: if (instruction == NULL)
1028: {
1029: // L'instruction n'existe pas.
1030:
1031: (*s_etat_processus).instruction_valide = 'N';
1032: }
1033: else
1034: {
1035: // Exécution de l'instruction associée. Le drapeau
1036: // (*s_etat_processus).instruction_valide peut passer à 'N'
1037: // dans le cas d'instructions sensibles à la casse.
1038:
1039: if ((*s_etat_processus).niveau_profilage >= 2)
1040: {
1041: profilage(s_etat_processus, instruction_majuscule);
1042: }
1043:
1044: (*s_etat_processus).instruction_valide = 'Y';
1045: instruction(s_etat_processus);
1046:
1047: if ((*s_etat_processus).niveau_profilage >= 2)
1048: {
1049: profilage(s_etat_processus, NULL);
1050: }
1051: }
1052: }
1053: else
1054: {
1055: if ((*s_etat_processus).niveau_profilage >= 2)
1056: {
1057: profilage(s_etat_processus,
1058: (*s_etat_processus).instruction_courante);
1059: }
1060:
1061: (*s_etat_processus).instruction_valide = 'Y';
1062: fonction(s_etat_processus);
1063:
1064: if ((*s_etat_processus).niveau_profilage >= 2)
1065: {
1066: profilage(s_etat_processus, NULL);
1067: }
1068: }
1069:
1070: if ((*s_etat_processus).instruction_valide == 'Y')
1071: {
1072: (*s_etat_processus).instruction_intrinseque = 'Y';
1073: }
1074:
1075: if ((*s_etat_processus).instruction_valide == 'N')
1076: {
1077: if ((position = index((*s_etat_processus).instruction_courante, '$'))
1078: != NULL)
1079: {
1080: if ((bibliotheque_candidate = malloc((position + 1
1081: - (*s_etat_processus).instruction_courante)
1082: * sizeof(unsigned char))) == NULL)
1083: {
1084: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1085: return;
1086: }
1087:
1088: (*bibliotheque_candidate) = d_code_fin_chaine;
1089: strncat(bibliotheque_candidate,
1090: (*s_etat_processus).instruction_courante,
1091: position - (*s_etat_processus).instruction_courante);
1092:
1093: position++;
1094:
1095: if (execution_fonction_de_bibliotheque(s_etat_processus, position,
1096: bibliotheque_candidate) == d_vrai)
1097: {
1098: (*s_etat_processus).instruction_valide = 'Y';
1099: (*s_etat_processus).instruction_intrinseque = 'N';
1100: }
1101: else
1102: {
1103: (*s_etat_processus).instruction_valide = 'N';
1104: }
1105:
1106: free(bibliotheque_candidate);
1107: }
1108: else
1109: {
1110: if (execution_fonction_de_bibliotheque(s_etat_processus,
1111: (*s_etat_processus).instruction_courante, NULL)
1112: == d_vrai)
1113: {
1114: (*s_etat_processus).instruction_valide = 'Y';
1115: (*s_etat_processus).instruction_intrinseque = 'N';
1116: }
1117: else
1118: {
1119: (*s_etat_processus).instruction_valide = 'N';
1120: }
1121: }
1122: }
1123:
1124: /*
1125: --------------------------------------------------------------------------------
1126: Gestion des interruptions logicielles
1127: --------------------------------------------------------------------------------
1128: */
1129:
1130: if (((*s_etat_processus).erreur_systeme == d_es) &&
1131: ((*s_etat_processus).erreur_execution == d_ex) &&
1132: ((*s_etat_processus).exception == d_ep))
1133: {
1134: if ((*s_etat_processus).test_instruction == 'N')
1135: {
1136: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
1137: {
1138: affectation_interruptions_logicielles(s_etat_processus);
1139: }
1140:
1141: if (((*s_etat_processus).nombre_interruptions_en_queue != 0) &&
1142: ((*s_etat_processus).erreur_systeme == d_es) &&
1143: ((*s_etat_processus).erreur_execution == d_ex))
1144: {
1145:
1146: registre_instruction_valide =
1147: (*s_etat_processus).instruction_valide;
1148: traitement_interruptions_logicielles(s_etat_processus);
1149: (*s_etat_processus).instruction_valide =
1150: registre_instruction_valide;
1151: }
1152: }
1153: }
1154:
1155: /*
1156: --------------------------------------------------------------------------------
1157: Limitation du pourcetage de temps CPU
1158: --------------------------------------------------------------------------------
1159: */
1160:
1161: # ifndef OS2
1162: if ((*s_etat_processus).pourcentage_maximal_cpu < 100)
1163: {
1164: getrusage(RUSAGE_SELF, &usage_final);
1165: gettimeofday(&horodatage_final, NULL);
1166:
1167: if (initialisation == d_vrai)
1168: {
1169: temps_reel = ((real8) (horodatage_final.tv_sec -
1170: horodatage_initial.tv_sec)) +
1171: (((real8) (horodatage_final.tv_usec -
1172: horodatage_initial.tv_usec)) / ((real8) 1E6));
1173:
1174: if (temps_reel >= 0.1)
1175: {
1176: temps_cpu = ((real8) ((usage_final.ru_utime.tv_sec +
1177: usage_final.ru_stime.tv_sec) -
1178: (usage_initial.ru_utime.tv_sec +
1179: usage_initial.ru_stime.tv_sec))) +
1180: (((real8) ((usage_final.ru_utime.tv_usec +
1181: usage_final.ru_stime.tv_usec) -
1182: (usage_initial.ru_utime.tv_usec +
1183: usage_initial.ru_stime.tv_usec))) / ((real8) 1E6));
1184:
1185: pourcentage = 100 * temps_cpu / temps_reel;
1186:
1187: if (pourcentage > 100)
1188: {
1189: pourcentage = 100;
1190: }
1191:
1192: if (pourcentage > (*s_etat_processus).pourcentage_maximal_cpu)
1193: {
1194: attente = ((pourcentage * temps_cpu) /
1195: (*s_etat_processus).pourcentage_maximal_cpu)
1196: - (pourcentage * temps_cpu / 100);
1197:
1198: temporisation.tv_sec = floor(attente);
1199: temporisation.tv_nsec = (attente - temporisation.tv_sec) *
1200: 1E9;
1201:
1202: nanosleep(&temporisation, NULL);
1203: }
1204:
1205: horodatage_initial = horodatage_final;
1206: usage_initial = usage_final;
1207: }
1208: }
1209: else
1210: {
1211: initialisation = d_vrai;
1212:
1213: horodatage_initial = horodatage_final;
1214: usage_initial = usage_final;
1215: }
1216: }
1217: # endif
1218:
1219: /*
1220: --------------------------------------------------------------------------------
1221: Introduction des erreurs générées
1222: --------------------------------------------------------------------------------
1223: */
1224:
1225: if (((*s_etat_processus).test_instruction == 'N') &&
1226: ((*s_etat_processus).instruction_valide == 'Y'))
1227: {
1228: traitement_asynchrone_exceptions_gsl(s_etat_processus);
1229:
1230: if ((*s_etat_processus).erreur_processus_fils == d_vrai)
1231: {
1232: (*s_etat_processus).erreur_processus_fils = d_faux;
1233:
1234: (*s_etat_processus).erreur_systeme =
1235: (*s_etat_processus).erreur_systeme_processus_fils;
1236: (*s_etat_processus).erreur_execution =
1237: (*s_etat_processus).erreur_execution_processus_fils;
1238: (*s_etat_processus).arret_si_exception = d_vrai;
1239:
1240: if ((*s_etat_processus).pid_erreur_processus_fils == getpid())
1241: {
1242: (*s_etat_processus).invalidation_message_erreur = d_faux;
1243: }
1244: else
1245: {
1246: (*s_etat_processus).invalidation_message_erreur = d_vrai;
1247: }
1248: }
1249:
1250: if (((*s_etat_processus).erreur_execution != d_ex) ||
1251: ((*s_etat_processus).erreur_systeme != d_es) ||
1252: ((*s_etat_processus).exception != d_ep))
1253: {
1254: (*s_etat_processus).niveau_derniere_erreur =
1255: (*s_etat_processus).niveau_courant;
1256:
1257: if ((*s_etat_processus).mode_execution_programme == 'Y')
1258: {
1259: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1260: {
1261: free((*s_etat_processus).instruction_derniere_erreur);
1262: (*s_etat_processus).instruction_derniere_erreur = NULL;
1263: }
1264:
1265: if ((*s_etat_processus).instruction_courante == NULL)
1266: {
1267: if (((*s_etat_processus).instruction_derniere_erreur =
1268: malloc(16 * sizeof(unsigned char))) == NULL)
1269: {
1270: (*s_etat_processus).erreur_systeme =
1271: d_es_allocation_memoire;
1272: return;
1273: }
1274:
1275: strcpy((*s_etat_processus).instruction_derniere_erreur,
1276: "<not available>");
1277: }
1278: else
1279: {
1280: if (((*s_etat_processus).instruction_derniere_erreur =
1281: malloc((strlen((*s_etat_processus)
1282: .instruction_courante) + 1) *
1283: sizeof(unsigned char))) == NULL)
1284: {
1285: (*s_etat_processus).erreur_systeme =
1286: d_es_allocation_memoire;
1287: return;
1288: }
1289:
1290: strcpy((*s_etat_processus).instruction_derniere_erreur,
1291: (*s_etat_processus).instruction_courante);
1292: }
1293: }
1294: else
1295: {
1296: if ((*s_etat_processus).objet_courant != NULL)
1297: {
1298: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1299: {
1300: free((*s_etat_processus).instruction_derniere_erreur);
1301: (*s_etat_processus).instruction_derniere_erreur = NULL;
1302: }
1303:
1304: if (((*s_etat_processus).instruction_derniere_erreur =
1305: formateur(s_etat_processus, 0,
1306: (*s_etat_processus).objet_courant)) == NULL)
1307: {
1308: return;
1309: }
1310:
1311: (*s_etat_processus).objet_courant = NULL;
1312: }
1313: }
1314: }
1315: }
1316:
1317: return;
1318: }
1319:
1320:
1321: /*
1322: ================================================================================
1323: Traitement asynchrone des erreurs de la bibliothèque GSL
1324: ================================================================================
1325: Entrées :
1326: --------------------------------------------------------------------------------
1327: Sorties :
1328: --------------------------------------------------------------------------------
1329: Effets de bord : néant
1330: ================================================================================
1331: */
1332:
1333: void
1334: traitement_asynchrone_exceptions_gsl(struct_processus *s_etat_processus)
1335: {
1336: if ((*s_etat_processus).var_volatile_exception_gsl != 0)
1337: {
1338: switch((*s_etat_processus).var_volatile_exception_gsl)
1339: {
1340: case GSL_EINVAL :
1341: {
1342: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1343: break;
1344: }
1345:
1346: case GSL_EDOM :
1347: {
1348: (*s_etat_processus).exception = d_ep_domaine_definition;
1349: break;
1350: }
1351:
1352: case GSL_ERANGE :
1353: {
1354: (*s_etat_processus).exception = d_ep_resultat_indefini;
1355: break;
1356: }
1357:
1358: case GSL_EZERODIV :
1359: {
1360: (*s_etat_processus).exception = d_ep_division_par_zero;
1361: break;
1362: }
1363:
1364: case GSL_EUNDRFLW :
1365: {
1366: (*s_etat_processus).exception = d_ep_underflow;
1367: break;
1368: }
1369:
1370: case GSL_EOVRFLW :
1371: {
1372: (*s_etat_processus).exception = d_ep_overflow;
1373: break;
1374: }
1375:
1376: case GSL_ENOMEM :
1377: {
1378: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1379: break;
1380: }
1381:
1382: case GSL_ELOSS :
1383: {
1384: (*s_etat_processus).exception = d_ep_perte_precision;
1385: break;
1386: }
1387:
1388: default :
1389: {
1390: (*s_etat_processus).erreur_execution =
1391: d_ex_routines_mathematiques;
1392: break;
1393: }
1394: }
1395:
1396: (*s_etat_processus).var_volatile_exception_gsl = 0;
1397: }
1398:
1399: return;
1400: }
1401:
1402: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>