File:  [local] / rpl / src / analyse.c
Revision 1.12: download - view: text, annotated - select for diffs - revision graph
Wed Apr 28 06:41:06 2010 UTC (14 years ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Renommage de ONEXIT en ATEXIT.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.15
    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("ATEXIT", instruction_atexit);
  714:     INSTRUCTION("BESSEL", instruction_bessel);
  715:     INSTRUCTION("CLRERR", instruction_clrerr);
  716:     INSTRUCTION("CLRMTX", instruction_clrmtx);
  717:     INSTRUCTION("CLRSWI", instruction_clrswi);
  718:     INSTRUCTION("CREATE", instruction_create);
  719:     INSTRUCTION("DELETE", instruction_delete);
  720:     INSTRUCTION("DETACH", instruction_detach);
  721:     INSTRUCTION("DIAG->", instruction_diag_fleche);
  722:     //INSTRUCTION("DOLIST")
  723:     //Instruction HP48 (application d'une fonction à une liste)
  724:     //liste(s) nombre_de_listes_a_traiter fonction DOLIST
  725:     //{ 1 2 3 }
  726:     //{ 4 5 6 }
  727:     //{ 7 8 9 }
  728:     //3
  729:     //<<  * + >>
  730:     //DOLIST
  731:     //=> { 29 42 57 }
  732:     INSTRUCTION("ELSEIF", instruction_elseif);
  733:     INSTRUCTION("FORMAT", instruction_format);
  734:     //INSTRUCTION("HEIGHT")
  735:     INSTRUCTION("ITRACE", instruction_itrace);
  736:     INSTRUCTION("LIST->", instruction_list_fleche);
  737:     INSTRUCTION("LOGGER", instruction_logger);
  738:     INSTRUCTION("MCLRIN", instruction_mclrin);
  739:     INSTRUCTION("NRPROC", instruction_nrproc);
  740:     INSTRUCTION("PROMPT", instruction_prompt);
  741:     INSTRUCTION("RCLSWI", instruction_rclswi);
  742:     INSTRUCTION("RECALL", instruction_recall);
  743:     INSTRUCTION("RECODE", instruction_recode);
  744:     INSTRUCTION("REDRAW", instruction_redraw);
  745:     INSTRUCTION("REMOVE", instruction_remove);
  746:     INSTRUCTION("REPEAT", instruction_repeat);
  747:     INSTRUCTION("RETURN", instruction_return);
  748:     INSTRUCTION("REWIND", instruction_rewind);
  749:     //INSTRUCTION("SCREEN")
  750:     INSTRUCTION("SELECT", instruction_select);
  751:     //INSTRUCTION("SPHERE")
  752:     INSTRUCTION("SHARED", instruction_shared);
  753:     INSTRUCTION("SPLASH", instruction_splash);
  754:     INSTRUCTION("STATIC", instruction_static);
  755:     INSTRUCTION("STOSWI", instruction_stoswi);
  756:     //INSTRUCTION("STREAM", instruction_stream);
  757:     //{ 1 2 3 4 5 } << * >> STREAM => 120
  758:     INSTRUCTION("TARGET", instruction_target);
  759:     INSTRUCTION("UNLOCK", instruction_unlock);
  760:     INSTRUCTION("VERIFY", instruction_verify);
  761:     INSTRUCTION("WFDATA", instruction_wfdata);
  762:     INSTRUCTION("WFLOCK", instruction_wflock);
  763:     INSTRUCTION("WFPOKE", instruction_wfpoke);
  764:     INSTRUCTION("WFPROC", instruction_wfproc);
  765:     INSTRUCTION("WFSOCK", instruction_wfsock);
  766:     INSTRUCTION("->ARRY", instruction_fleche_array);
  767:     INSTRUCTION("->DIAG", instruction_fleche_diag);
  768:     INSTRUCTION("->LIST", instruction_fleche_list);
  769: 
  770:     INSTRUCTION("ARRAY->", instruction_array_fleche);
  771:     //INSTRUCTION("BARPLOT")
  772:     //INSTRUCTION("BESTFIT")
  773:     //Instruction HP48 (choisit le meilleur modèle de régression)
  774:     INSTRUCTION("CLRFUSE", instruction_clrfuse);
  775:     INSTRUCTION("CONVERT", instruction_convert);
  776:     INSTRUCTION("CRSMPHR", instruction_crsmphr);
  777:     INSTRUCTION("CURRENC", instruction_currenc);
  778:     INSTRUCTION("DEFAULT", instruction_default);
  779:     INSTRUCTION("EPSILON", instruction_epsilon);
  780:     //INSTRUCTION("GRIDMAP")
  781:     //Instruction HP48 (sélectionne le mode de tracé GRIDMAP)
  782:     //Le tracé GRIDMAP transforme la grille d'échantillonnage rectiligne
  783:     //en appliquant la fonction en cours à valeurs complexes.
  784:     //Les coordonnées de chaque point de la grille (un nombre complexe)
  785:     //constituent
  786:     //les données d'entrée de la fonction qui les projette ensuite dans le
  787:     //grille
  788:     //de sortie.
  789:     //f(x,y)=fnct complexe évaluée sur la grille (x,y) et affichée comme une
  790:     //fonction paramétrique.
  791:     INSTRUCTION("INQUIRE", instruction_inquire);
  792:     INSTRUCTION("MTXLOCK", instruction_mtxlock);
  793:     INSTRUCTION("PERSIST", instruction_persist);
  794:     INSTRUCTION("PLOTTER", instruction_plotter);
  795:     INSTRUCTION("PRIVATE", instruction_private);
  796:     INSTRUCTION("PROTECT", instruction_protect);
  797:     INSTRUCTION("PSHPRFL", instruction_pshprfl);
  798:     INSTRUCTION("PULPRFL", instruction_pulprfl);
  799:     INSTRUCTION("REVLIST", instruction_revlist);
  800:     INSTRUCTION("SCATTER", instruction_scatter);
  801:     INSTRUCTION("SUSPEND", instruction_suspend);
  802:     INSTRUCTION("SWILOCK", instruction_swilock);
  803:     INSTRUCTION("SYSEVAL", instruction_syseval);
  804:     INSTRUCTION("TABLE->", instruction_table_fleche);
  805:     INSTRUCTION("VERSION", instruction_version);
  806:     INSTRUCTION("WORKDIR", instruction_workdir);
  807:     INSTRUCTION("->ARRAY", instruction_fleche_array);
  808:     INSTRUCTION("->TABLE", instruction_fleche_table);
  809: 
  810:     INSTRUCTION("CLRCNTXT", instruction_clrcntxt);
  811:     INSTRUCTION("CLRSMPHR", instruction_clrsmphr);
  812:     INSTRUCTION("CONTINUE", instruction_continue);
  813:     INSTRUCTION("DUPCNTXT", instruction_dupcntxt);
  814:     INSTRUCTION("FUNCTION", instruction_function);
  815:     INSTRUCTION("IMPLICIT", instruction_implicit);
  816:     INSTRUCTION("KEYLABEL", instruction_keylabel);
  817:     INSTRUCTION("KEYTITLE", instruction_keytitle);
  818:     INSTRUCTION("LOGSCALE", instruction_logscale);
  819:     INSTRUCTION("NEWPLANE", instruction_newplane);
  820:     INSTRUCTION("PSHCNTXT", instruction_pshcntxt);
  821:     INSTRUCTION("PULCNTXT", instruction_pulcntxt);
  822:     INSTRUCTION("SQLQUERY", instruction_sqlquery);
  823:     INSTRUCTION("SWIQUEUE", instruction_swiqueue);
  824:     INSTRUCTION("TOKENIZE", instruction_tokenize);
  825:     INSTRUCTION("VARIABLE", instruction_variable);
  826:     INSTRUCTION("VOLATILE", instruction_volatile);
  827:     INSTRUCTION("WARRANTY", instruction_warranty);
  828: 
  829:     INSTRUCTION("AUTOSCALE", instruction_autoscale);
  830:     INSTRUCTION("BACKSPACE", instruction_backspace);
  831:     INSTRUCTION("COPYRIGHT", instruction_copyright);
  832:     //INSTRUCTION("CYLINDRIC");
  833:     INSTRUCTION("DAEMONIZE", instruction_daemonize);
  834:     INSTRUCTION("DROPCNTXT", instruction_dropcntxt);
  835:     INSTRUCTION("EXTERNALS", instruction_externals);
  836:     INSTRUCTION("HISTOGRAM", instruction_histogram);
  837:     INSTRUCTION("MTXSTATUS", instruction_mtxstatus);
  838:     INSTRUCTION("MTXUNLOCK", instruction_mtxunlock);
  839:     INSTRUCTION("PARAMETER", instruction_parameter);
  840:     //INSTRUCTION("PSCONTOUR")
  841:     //INSTRUCTION("SCATRPLOT")
  842:     //(trace un nuage de points de SDAT et la courbe de régression)
  843:     INSTRUCTION("SMPHRDECR", instruction_smphrdecr);
  844:     INSTRUCTION("SMPHRGETV", instruction_smphrgetv);
  845:     INSTRUCTION("SMPHRINCR", instruction_smphrincr);
  846:     INSTRUCTION("SWAPCNTXT", instruction_swapcntxt);
  847:     INSTRUCTION("SWISTATUS", instruction_swistatus);
  848:     INSTRUCTION("SWIUNLOCK", instruction_swiunlock);
  849:     INSTRUCTION("UNPROTECT", instruction_unprotect);
  850:     INSTRUCTION("WIREFRAME", instruction_wireframe);
  851: 
  852:     INSTRUCTION("MTXTRYLOCK", instruction_mtxtrylock);
  853:     INSTRUCTION("PARAMETRIC", instruction_parametric);
  854:     //INSTRUCTION("PARSURFACE")
  855:     //Instruction HP48 (tracé PARSURFACE) Equation sous forme de liste
  856:     INSTRUCTION("SLICESCALE", instruction_slicescale);
  857:     INSTRUCTION("SQLCONNECT", instruction_sqlconnect);
  858:     //INSTRUCTION("SLOPEFIELD")
  859:     //Instruction HP48 (type de tracé)
  860:     //Tracé 3D en courbes de niveaux.
  861:     //Le type de tracé 'SLOPEFIELD' dessine un réseau de segments dont les
  862:     //pentes
  863:     //représentent la valeur de la fonction (x,y) en leur milieu.
  864:     //=> utile pour y'=F(x,y)
  865: 
  866:     INSTRUCTION("LOCALIZATION", instruction_localization);
  867:     INSTRUCTION("SMPHRTRYDECR", instruction_smphrtrydecr);
  868: 
  869:     INSTRUCTION("SQLDISCONNECT", instruction_sqldisconnect);
  870: #undef INSTRUCTION
  871: 
  872:     return;
  873: }
  874: 
  875: 
  876: inline void *
  877: analyse_instruction(struct_processus *s_etat_processus, unsigned char *ptr)
  878: {
  879:     int                             pointeur;
  880: 
  881:     struct_instruction              *l_instruction_courante;
  882: 
  883:     l_instruction_courante = (*s_etat_processus).arbre_instructions;
  884: 
  885:     while((*ptr) != d_code_fin_chaine)
  886:     {
  887:         pointeur = (*s_etat_processus).pointeurs_caracteres[*ptr];
  888: 
  889:         if (pointeur < 0)
  890:         {
  891:             // Caractère hors de l'alphabet des instructions
  892: 
  893:             return(NULL);
  894:         }
  895: 
  896:         if ((*l_instruction_courante).noeud[pointeur] == NULL)
  897:         {
  898:             // Le chemin de l'instruction candidate n'existe pas.
  899: 
  900:             return(NULL);
  901:         }
  902: 
  903:         l_instruction_courante = (*l_instruction_courante).noeud[pointeur];
  904:         ptr++;
  905: 
  906:         if ((l_instruction_courante == NULL) && ((*ptr) != d_code_fin_chaine))
  907:         {
  908:             // Le chemin de l'instruction candidate est incomplet.
  909: 
  910:             return(NULL);
  911:         }
  912:     }
  913: 
  914:     if ((*l_instruction_courante).feuille != NULL)
  915:     {
  916:         return((*l_instruction_courante).feuille);
  917:     }
  918: 
  919:     return(NULL);
  920: }
  921: 
  922: 
  923: void
  924: analyse(struct_processus *s_etat_processus, void (*fonction)())
  925: {
  926:     static logical1                 initialisation = d_faux;
  927: 
  928:     real8                           attente;
  929:     real8                           pourcentage;
  930:     real8                           temps_cpu;
  931:     real8                           temps_reel;
  932: 
  933:     static struct timeval           horodatage_initial;
  934:     struct timeval                  horodatage_final;
  935: 
  936:     static struct rusage            usage_initial;
  937:     struct rusage                   usage_final;
  938: 
  939:     struct timespec                 temporisation;
  940: 
  941:     unsigned char                   *position;
  942:     unsigned char                   *bibliotheque_candidate;
  943:     unsigned char                   *instruction_majuscule;
  944:     unsigned char                   registre_instruction_valide;
  945: 
  946:     void                            (*instruction)();
  947: 
  948:     errno = 0;
  949:     (*s_etat_processus).var_volatile_exception_gsl = 0;
  950: 
  951:     (*s_etat_processus).instruction_valide = 'Y';
  952:     (*s_etat_processus).constante_symbolique = 'N';
  953:     (*s_etat_processus).nombre_arguments = -2;
  954:     (*s_etat_processus).instruction_intrinseque = 'I';
  955: 
  956:     /*
  957:      * On autorise l'exécution d'un fork() dans un thread concurrent.
  958:      */
  959: 
  960: #   ifndef SEMAPHORES_NOMMES
  961:     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  962:     {
  963:         (*s_etat_processus).erreur_systeme = d_es_processus;
  964:         return;
  965:     }
  966: 
  967:     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
  968:     {
  969:         if (errno != EINTR)
  970:         {
  971:             (*s_etat_processus).erreur_systeme = d_es_processus;
  972:             return;
  973:         }
  974:     }
  975: #   else
  976:     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  977:     {
  978:         (*s_etat_processus).erreur_systeme = d_es_processus;
  979:         return;
  980:     }
  981: 
  982:     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
  983:     {
  984:         if (errno != EINTR)
  985:         {
  986:             (*s_etat_processus).erreur_systeme = d_es_processus;
  987:             return;
  988:         }
  989:     }
  990: #   endif
  991: 
  992:     scrutation_injection(s_etat_processus);
  993: 
  994:     if (fonction == NULL)
  995:     {
  996:         if ((instruction_majuscule = conversion_majuscule(
  997:                 (*s_etat_processus).instruction_courante)) == NULL)
  998:         {
  999:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1000:             return;
 1001:         }
 1002: 
 1003:         instruction = analyse_instruction(s_etat_processus,
 1004:                 instruction_majuscule);
 1005: 
 1006:         if (instruction == NULL)
 1007:         {
 1008:             // L'instruction n'existe pas.
 1009: 
 1010:             (*s_etat_processus).instruction_valide = 'N';
 1011:         }
 1012:         else
 1013:         {
 1014:             // Exécution de l'instruction associée. Le drapeau
 1015:             // (*s_etat_processus).instruction_valide peut passer à 'N'
 1016:             // dans le cas d'instructions sensibles à la casse.
 1017: 
 1018:             if ((*s_etat_processus).niveau_profilage >= 2)
 1019:             {
 1020:                 profilage(s_etat_processus, instruction_majuscule);
 1021:             }
 1022: 
 1023:             (*s_etat_processus).instruction_valide = 'Y';
 1024:             instruction(s_etat_processus);
 1025: 
 1026:             if ((*s_etat_processus).niveau_profilage >= 2)
 1027:             {
 1028:                 profilage(s_etat_processus, NULL);
 1029:             }
 1030:         }
 1031: 
 1032:         free(instruction_majuscule);
 1033:     }
 1034:     else
 1035:     {
 1036:         if ((*s_etat_processus).niveau_profilage >= 2)
 1037:         {
 1038:             profilage(s_etat_processus,
 1039:                     (*s_etat_processus).instruction_courante);
 1040:         }
 1041: 
 1042:         (*s_etat_processus).instruction_valide = 'Y';
 1043:         fonction(s_etat_processus);
 1044: 
 1045:         if ((*s_etat_processus).niveau_profilage >= 2)
 1046:         {
 1047:             profilage(s_etat_processus, NULL);
 1048:         }
 1049:     }
 1050: 
 1051:     if ((*s_etat_processus).instruction_valide == 'Y')
 1052:     {
 1053:         (*s_etat_processus).instruction_intrinseque = 'Y';
 1054:     }
 1055: 
 1056:     if ((*s_etat_processus).instruction_valide == 'N')
 1057:     {
 1058:         if ((position = index((*s_etat_processus).instruction_courante, '$'))
 1059:                 != NULL)
 1060:         {
 1061:             if ((bibliotheque_candidate = malloc((position + 1
 1062:                     - (*s_etat_processus).instruction_courante)
 1063:                     * sizeof(unsigned char))) == NULL)
 1064:             {
 1065:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1066:                 return;
 1067:             }
 1068: 
 1069:             (*bibliotheque_candidate) = d_code_fin_chaine;
 1070:             strncat(bibliotheque_candidate,
 1071:                     (*s_etat_processus).instruction_courante,
 1072:                     position - (*s_etat_processus).instruction_courante);
 1073: 
 1074:             position++;
 1075: 
 1076:             if (execution_fonction_de_bibliotheque(s_etat_processus, position,
 1077:                     bibliotheque_candidate) == d_vrai)
 1078:             {
 1079:                 (*s_etat_processus).instruction_valide = 'Y';
 1080:                 (*s_etat_processus).instruction_intrinseque = 'N';
 1081:             }
 1082:             else
 1083:             {
 1084:                 (*s_etat_processus).instruction_valide = 'N';
 1085:             }
 1086: 
 1087:             free(bibliotheque_candidate);
 1088:         }
 1089:         else
 1090:         {
 1091:             if (execution_fonction_de_bibliotheque(s_etat_processus,
 1092:                     (*s_etat_processus).instruction_courante, NULL)
 1093:                     == d_vrai)
 1094:             {
 1095:                 (*s_etat_processus).instruction_valide = 'Y';
 1096:                 (*s_etat_processus).instruction_intrinseque = 'N';
 1097:             }
 1098:             else
 1099:             {
 1100:                 (*s_etat_processus).instruction_valide = 'N';
 1101:             }
 1102:         }
 1103:     }
 1104: 
 1105: /*
 1106: --------------------------------------------------------------------------------
 1107:   Gestion des interruptions logicielles
 1108: --------------------------------------------------------------------------------
 1109: */
 1110: 
 1111:     if (((*s_etat_processus).erreur_systeme == d_es) &&
 1112:             ((*s_etat_processus).erreur_execution == d_ex) &&
 1113:             ((*s_etat_processus).exception == d_ep))
 1114:     {
 1115:         if ((*s_etat_processus).test_instruction == 'N')
 1116:         {
 1117:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 1118:             {
 1119:                 affectation_interruptions_logicielles(s_etat_processus);
 1120:             }
 1121: 
 1122:             if (((*s_etat_processus).nombre_interruptions_en_queue != 0) &&
 1123:                     ((*s_etat_processus).erreur_systeme == d_es) &&
 1124:                     ((*s_etat_processus).erreur_execution == d_ex))
 1125:             {
 1126: 
 1127:                 registre_instruction_valide =
 1128:                         (*s_etat_processus).instruction_valide;
 1129:                 traitement_interruptions_logicielles(s_etat_processus);
 1130:                 (*s_etat_processus).instruction_valide =
 1131:                         registre_instruction_valide;
 1132:             }
 1133:         }
 1134:     }
 1135: 
 1136: /*
 1137: --------------------------------------------------------------------------------
 1138:   Limitation du pourcetage de temps CPU
 1139: --------------------------------------------------------------------------------
 1140: */
 1141: 
 1142:     if ((*s_etat_processus).pourcentage_maximal_cpu < 100)
 1143:     {
 1144:         getrusage(RUSAGE_SELF, &usage_final);
 1145:         gettimeofday(&horodatage_final, NULL);
 1146: 
 1147:         if (initialisation == d_vrai)
 1148:         {
 1149:             temps_reel = ((real8) (horodatage_final.tv_sec -
 1150:                     horodatage_initial.tv_sec)) +
 1151:                     (((real8) (horodatage_final.tv_usec -
 1152:                     horodatage_initial.tv_usec)) / ((real8) 1E6));
 1153: 
 1154:             if (temps_reel >= 0.1)
 1155:             {
 1156:                 temps_cpu = ((real8) ((usage_final.ru_utime.tv_sec +
 1157:                         usage_final.ru_stime.tv_sec) -
 1158:                         (usage_initial.ru_utime.tv_sec +
 1159:                         usage_initial.ru_stime.tv_sec))) +
 1160:                         (((real8) ((usage_final.ru_utime.tv_usec +
 1161:                         usage_final.ru_stime.tv_usec) -
 1162:                         (usage_initial.ru_utime.tv_usec +
 1163:                         usage_initial.ru_stime.tv_usec))) / ((real8) 1E6));
 1164: 
 1165:                 pourcentage = 100 * temps_cpu / temps_reel;
 1166: 
 1167:                 if (pourcentage > 100)
 1168:                 {
 1169:                     pourcentage = 100;
 1170:                 }
 1171: 
 1172:                 if (pourcentage > (*s_etat_processus).pourcentage_maximal_cpu)
 1173:                 {
 1174:                     attente = ((pourcentage * temps_cpu) /
 1175:                             (*s_etat_processus).pourcentage_maximal_cpu)
 1176:                             - (pourcentage * temps_cpu / 100);
 1177: 
 1178:                     temporisation.tv_sec = floor(attente);
 1179:                     temporisation.tv_nsec = (attente - temporisation.tv_sec) *
 1180:                             1E9;
 1181: 
 1182:                     nanosleep(&temporisation, NULL);
 1183:                 }
 1184: 
 1185:                 horodatage_initial = horodatage_final;
 1186:                 usage_initial = usage_final;
 1187:             }
 1188:         }
 1189:         else
 1190:         {
 1191:             initialisation = d_vrai;
 1192: 
 1193:             horodatage_initial = horodatage_final;
 1194:             usage_initial = usage_final;
 1195:         }
 1196:     }
 1197: 
 1198: /*
 1199: --------------------------------------------------------------------------------
 1200:   Introduction des erreurs générées
 1201: --------------------------------------------------------------------------------
 1202: */
 1203: 
 1204:     if (((*s_etat_processus).test_instruction == 'N') &&
 1205:             ((*s_etat_processus).instruction_valide == 'Y'))
 1206:     {
 1207:         traitement_asynchrone_exceptions_gsl(s_etat_processus);
 1208: 
 1209:         if ((*s_etat_processus).erreur_processus_fils == d_vrai)
 1210:         {
 1211:             (*s_etat_processus).erreur_processus_fils = d_faux;
 1212: 
 1213:             (*s_etat_processus).erreur_systeme =
 1214:                     (*s_etat_processus).erreur_systeme_processus_fils;
 1215:             (*s_etat_processus).erreur_execution =
 1216:                     (*s_etat_processus).erreur_execution_processus_fils;
 1217:             (*s_etat_processus).arret_si_exception = d_vrai;
 1218: 
 1219:             if ((*s_etat_processus).pid_erreur_processus_fils == getpid())
 1220:             {
 1221:                 (*s_etat_processus).invalidation_message_erreur = d_faux;
 1222:             }
 1223:             else
 1224:             {
 1225:                 (*s_etat_processus).invalidation_message_erreur = d_vrai;
 1226:             }
 1227:         }
 1228: 
 1229:         if (((*s_etat_processus).erreur_execution != d_ex) ||
 1230:                 ((*s_etat_processus).erreur_systeme != d_es) ||
 1231:                 ((*s_etat_processus).exception != d_ep))
 1232:         {
 1233:             if ((*s_etat_processus).instruction_derniere_erreur != NULL)
 1234:             {
 1235:                 free((*s_etat_processus).instruction_derniere_erreur);
 1236:                 (*s_etat_processus).instruction_derniere_erreur = NULL;
 1237:             }
 1238: 
 1239:             (*s_etat_processus).niveau_derniere_erreur =
 1240:                     (*s_etat_processus).niveau_courant;
 1241: 
 1242:             if ((*s_etat_processus).mode_execution_programme == 'Y')
 1243:             {
 1244:                 if ((*s_etat_processus).instruction_courante == NULL)
 1245:                 {
 1246:                     if (((*s_etat_processus).instruction_derniere_erreur =
 1247:                             malloc(16 * sizeof(unsigned char))) == NULL)
 1248:                     {
 1249:                         (*s_etat_processus).erreur_systeme =
 1250:                                 d_es_allocation_memoire;
 1251:                         return;
 1252:                     }
 1253: 
 1254:                     strcpy((*s_etat_processus).instruction_derniere_erreur,
 1255:                             "<not available>");
 1256:                 }
 1257:                 else
 1258:                 {
 1259:                     if (((*s_etat_processus).instruction_derniere_erreur =
 1260:                             malloc((strlen((*s_etat_processus)
 1261:                             .instruction_courante) + 1) *
 1262:                             sizeof(unsigned char))) == NULL)
 1263:                     {
 1264:                         (*s_etat_processus).erreur_systeme =
 1265:                                 d_es_allocation_memoire;
 1266:                         return;
 1267:                     }
 1268: 
 1269:                     strcpy((*s_etat_processus).instruction_derniere_erreur,
 1270:                             (*s_etat_processus).instruction_courante);
 1271:                 }
 1272:             }
 1273:             else
 1274:             {
 1275:                 if (((*s_etat_processus).instruction_derniere_erreur =
 1276:                         formateur(s_etat_processus, 0,
 1277:                         (*s_etat_processus).objet_courant)) == NULL)
 1278:                 {
 1279:                     return;
 1280:                 }
 1281:             }
 1282:         }
 1283:     }
 1284: 
 1285:     return;
 1286: }
 1287: 
 1288: 
 1289: /*
 1290: ================================================================================
 1291:   Traitement asynchrone des erreurs de la bibliothèque GSL
 1292: ================================================================================
 1293:   Entrées :
 1294: --------------------------------------------------------------------------------
 1295:   Sorties :
 1296: --------------------------------------------------------------------------------
 1297:   Effets de bord : néant
 1298: ================================================================================
 1299: */
 1300: 
 1301: void
 1302: traitement_asynchrone_exceptions_gsl(struct_processus *s_etat_processus)
 1303: {
 1304:     if ((*s_etat_processus).var_volatile_exception_gsl != 0)
 1305:     {
 1306:         switch((*s_etat_processus).var_volatile_exception_gsl)
 1307:         {
 1308:             case GSL_EINVAL :
 1309:             {
 1310:                 (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
 1311:                 break;
 1312:             }
 1313: 
 1314:             case GSL_EDOM :
 1315:             {
 1316:                 (*s_etat_processus).exception = d_ep_domaine_definition;
 1317:                 break;
 1318:             }
 1319: 
 1320:             case GSL_ERANGE :
 1321:             {
 1322:                 (*s_etat_processus).exception = d_ep_resultat_indefini;
 1323:                 break;
 1324:             }
 1325: 
 1326:             case GSL_EZERODIV :
 1327:             {
 1328:                 (*s_etat_processus).exception = d_ep_division_par_zero;
 1329:                 break;
 1330:             }
 1331: 
 1332:             case GSL_EUNDRFLW :
 1333:             {
 1334:                 (*s_etat_processus).exception = d_ep_underflow;
 1335:                 break;
 1336:             }
 1337: 
 1338:             case GSL_EOVRFLW :
 1339:             {
 1340:                 (*s_etat_processus).exception = d_ep_overflow;
 1341:                 break;
 1342:             }
 1343: 
 1344:             case GSL_ENOMEM :
 1345:             {
 1346:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1347:                 break;
 1348:             }
 1349: 
 1350:             case GSL_ELOSS :
 1351:             {
 1352:                 (*s_etat_processus).exception = d_ep_perte_precision;
 1353:                 break;
 1354:             }
 1355: 
 1356:             default :
 1357:             {
 1358:                 (*s_etat_processus).erreur_execution =
 1359:                         d_ex_routines_mathematiques;
 1360:                 break;
 1361:             }
 1362:         }
 1363: 
 1364:         (*s_etat_processus).var_volatile_exception_gsl = 0;
 1365:     }
 1366: 
 1367:     return;
 1368: }
 1369: 
 1370: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>