File:  [local] / rpl / src / analyse.c
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Wed Apr 7 13:33:22 2010 UTC (14 years ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_0_13, HEAD
Ajout de la nouvelle fonction IMPLICIT.

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

CVSweb interface <joel.bertrand@systella.fr>