File:  [local] / rpl / src / instructions_s9.c
Revision 1.61: download - view: text, annotated - select for diffs - revision graph
Mon Apr 1 15:29:38 2013 UTC (11 years, 1 month ago) by bertrand
Branches: MAIN
CVS tags: HEAD
En route pour la 4.1.14.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.14
    4:   Copyright (C) 1989-2013 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:   Fonction 'sort'
   29: ================================================================================
   30:   Entrées :
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_sort(struct_processus *s_etat_processus)
   40: {
   41:     integer8                    i;
   42:     integer8                    j;
   43:     integer8                    nombre_elements;
   44: 
   45:     logical1                    condition;
   46:     logical1                    inversion;
   47:     logical1                    presence_nom;
   48:     logical1                    terminaison_boucle_1;
   49:     logical1                    terminaison_boucle_2;
   50:     logical1                    terminaison_boucle_3;
   51:     logical1                    variable_partagee;
   52: 
   53:     struct_liste_chainee        *l_element_courant;
   54:     struct_liste_chainee        *l_element_precedent;
   55:     struct_liste_chainee        *l_element_tampon;
   56: 
   57:     struct_objet                *s_objet_copie;
   58:     struct_objet                *s_objet_critere;
   59:     struct_objet                *s_objet_liste;
   60:     struct_objet                *s_objet_registre;
   61:     struct_objet                *s_objet_test;
   62: 
   63:     integer8                    ecartement;
   64:     integer8                    indice_i;
   65:     integer8                    indice_j;
   66:     integer8                    indice_k;
   67:     integer8                    indice_l;
   68: 
   69:     (*s_etat_processus).erreur_execution = d_ex;
   70: 
   71:     if ((*s_etat_processus).affichage_arguments == 'Y')
   72:     {
   73:         printf("\n  SORT ");
   74: 
   75:         if ((*s_etat_processus).langue == 'F')
   76:         {
   77:             printf("(trie une liste selon un critère paramétrable)\n\n");
   78:         }
   79:         else
   80:         {
   81:             printf("(sort a list)\n\n");
   82:         }
   83: 
   84:         printf("    2: %s\n", d_LST);
   85:         printf("    1: %s\n", d_RPN);
   86:         printf("->  1: %s\n\n", d_LST);
   87: 
   88:         printf("    2: %s\n", d_TAB);
   89:         printf("    1: %s\n", d_RPN);
   90:         printf("->  1: %s\n\n", d_LST);
   91: 
   92:         printf("    2: %s\n", d_NOM);
   93:         printf("    1: %s\n", d_RPN);
   94: 
   95:         return;
   96:     }
   97:     else if ((*s_etat_processus).test_instruction == 'Y')
   98:     {
   99:         (*s_etat_processus).nombre_arguments = -1;
  100:         return;
  101:     }
  102:     
  103:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  104:     {
  105:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  106:         {
  107:             return;
  108:         }
  109:     }
  110: 
  111:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  112:             &s_objet_critere) == d_erreur)
  113:     {
  114:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  115:         return;
  116:     }
  117: 
  118:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  119:             &s_objet_liste) == d_erreur)
  120:     {
  121:         liberation(s_etat_processus, s_objet_critere);
  122: 
  123:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  124:         return;
  125:     }
  126: 
  127:     variable_partagee = d_faux;
  128: 
  129:     if ((*s_objet_liste).type == NOM)
  130:     {
  131:         if (recherche_variable(s_etat_processus, (*((struct_nom *)
  132:                 (*s_objet_liste).objet)).nom) == d_faux)
  133:         {
  134:             (*s_etat_processus).erreur_systeme = d_es;
  135:             (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
  136: 
  137:             liberation(s_etat_processus, s_objet_critere);
  138:             liberation(s_etat_processus, s_objet_liste);
  139: 
  140:             return;
  141:         }
  142: 
  143:         if ((*(*s_etat_processus).pointeur_variable_courante)
  144:                 .variable_verrouillee == d_vrai)
  145:         {
  146:             (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
  147: 
  148:             liberation(s_etat_processus, s_objet_critere);
  149:             liberation(s_etat_processus, s_objet_liste);
  150: 
  151:             return;
  152:         }
  153: 
  154:         if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
  155:         {
  156:             if (recherche_variable_partagee(s_etat_processus,
  157:                     (*(*s_etat_processus).pointeur_variable_courante).nom,
  158:                     (*(*s_etat_processus).pointeur_variable_courante)
  159:                     .variable_partagee, (*(*s_etat_processus)
  160:                     .pointeur_variable_courante).origine) == NULL)
  161:             {
  162:                 (*s_etat_processus).erreur_execution =
  163:                         d_ex_erreur_type_argument;
  164: 
  165:                 liberation(s_etat_processus, s_objet_critere);
  166:                 liberation(s_etat_processus, s_objet_liste);
  167: 
  168:                 return;
  169:             }
  170: 
  171:             if (((*(*(*s_etat_processus).pointeur_variable_partagee_courante)
  172:                     .objet).type != LST) && ((*(*(*s_etat_processus)
  173:                     .pointeur_variable_partagee_courante).objet).type != TBL))
  174:             {
  175:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
  176:                         .pointeur_variable_partagee_courante).mutex)) != 0)
  177:                 {
  178:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  179:                     return;
  180:                 }
  181: 
  182:                 (*s_etat_processus).erreur_execution =
  183:                         d_ex_erreur_type_argument;
  184: 
  185:                 liberation(s_etat_processus, s_objet_critere);
  186:                 liberation(s_etat_processus, s_objet_liste);
  187: 
  188:                 return;
  189:             }
  190: 
  191:             liberation(s_etat_processus, s_objet_liste);
  192: 
  193:             s_objet_liste = (*(*s_etat_processus)
  194:                     .pointeur_variable_partagee_courante).objet;
  195: 
  196:             if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
  197:                     'N')) == NULL)
  198:             {
  199:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
  200:                         .pointeur_variable_partagee_courante).mutex)) != 0)
  201:                 {
  202:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  203:                     return;
  204:                 }
  205: 
  206:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  207:                 return;
  208:             }
  209: 
  210:             variable_partagee = d_vrai;
  211:         }
  212:         else
  213:         {
  214:             if (((*(*(*s_etat_processus).pointeur_variable_courante).objet)
  215:                     .type != LST) && ((*(*(*s_etat_processus)
  216:                     .pointeur_variable_courante).objet).type != TBL))
  217:             {
  218:                 (*s_etat_processus).erreur_execution =
  219:                         d_ex_erreur_type_argument;
  220: 
  221:                 liberation(s_etat_processus, s_objet_critere);
  222:                 liberation(s_etat_processus, s_objet_liste);
  223: 
  224:                 return;
  225:             }
  226: 
  227:             liberation(s_etat_processus, s_objet_liste);
  228: 
  229:             s_objet_liste = (*(*s_etat_processus).pointeur_variable_courante)
  230:                     .objet;
  231: 
  232:             if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
  233:                     'N')) == NULL)
  234:             {
  235:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  236:                 return;
  237:             }
  238:         }
  239: 
  240:         liberation(s_etat_processus, s_objet_liste);
  241:         s_objet_liste = s_objet_copie;
  242:         (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_liste;
  243:         presence_nom = d_vrai;
  244:     }
  245:     else
  246:     {
  247:         if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 'N'))
  248:                 == NULL)
  249:         {
  250:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  251:             return;
  252:         }
  253: 
  254:         liberation(s_etat_processus, s_objet_liste);
  255:         s_objet_liste = s_objet_copie;
  256:         presence_nom = d_faux;
  257:     }
  258: 
  259:     if (((*s_objet_liste).type == LST) &&
  260:             ((*s_objet_critere).type == RPN))
  261:     {
  262:         /*
  263:          * Tri bulle de la liste chaînée. On se contente d'un tri bulle
  264:          * car on travaille sur une liste chaînée et non sur un tableau
  265:          * sur lequel on pourrait accéder directement aux données grâce à
  266:          * leur indice.
  267:          */
  268: 
  269:         nombre_elements = 0;
  270:         l_element_courant = (*s_objet_liste).objet;
  271: 
  272:         while(l_element_courant != NULL)
  273:         {
  274:             l_element_courant = (*l_element_courant).suivant;
  275:             nombre_elements++;
  276:         }
  277: 
  278:         // Si la liste est vide, on considère qu'elle est triée.
  279:         // De la même manière, on considère qu'une liste d'un
  280:         // seul élément est toujours triée.
  281: 
  282:         if (nombre_elements > 1)
  283:         {
  284:             j = nombre_elements;
  285: 
  286:             do
  287:             {
  288:                 inversion = d_faux;
  289: 
  290:                 l_element_courant = (*s_objet_liste).objet;
  291:                 l_element_precedent = NULL;
  292: 
  293:                 for(i = 0; i < j - 1; i++)
  294:                 {
  295:                     // Test des éléments adjacents. Pour cela, on
  296:                     // empile les deux éléments adjacents dans la pile dans
  297:                     // l'ordre [i] [i+1] et on évalue le critère d'ordre.
  298: 
  299:                     if ((s_objet_copie = copie_objet(s_etat_processus,
  300:                             (*l_element_courant).donnee, 'P')) == NULL)
  301:                     {
  302:                         (*s_etat_processus).erreur_systeme =
  303:                                 d_es_allocation_memoire;
  304:                         return;
  305:                     }
  306: 
  307:                     if (empilement(s_etat_processus,
  308:                             &((*s_etat_processus).l_base_pile),
  309:                             s_objet_copie) == d_erreur)
  310:                     {
  311:                         return;
  312:                     }
  313: 
  314:                     if ((s_objet_copie = copie_objet(s_etat_processus,
  315:                             (*(*l_element_courant)
  316:                             .suivant).donnee, 'P')) == NULL)
  317:                     {
  318:                         (*s_etat_processus).erreur_systeme =
  319:                                 d_es_allocation_memoire;
  320:                         return;
  321:                     }
  322: 
  323:                     if (empilement(s_etat_processus,
  324:                             &((*s_etat_processus).l_base_pile),
  325:                             s_objet_copie) == d_erreur)
  326:                     {
  327:                         return;
  328:                     }
  329: 
  330:                     if (evaluation(s_etat_processus, s_objet_critere, 'N')
  331:                             == d_erreur)
  332:                     {
  333:                         liberation(s_etat_processus, s_objet_critere);
  334:                         liberation(s_etat_processus, s_objet_liste);
  335: 
  336:                         return;
  337:                     }
  338: 
  339:                     if (depilement(s_etat_processus,
  340:                             &((*s_etat_processus).l_base_pile), &s_objet_test)
  341:                             == d_erreur)
  342:                     {
  343:                         liberation(s_etat_processus, s_objet_critere);
  344:                         liberation(s_etat_processus, s_objet_liste);
  345: 
  346:                         (*s_etat_processus).erreur_execution =
  347:                                 d_ex_manque_argument;
  348:                         return;
  349:                     }
  350: 
  351:                     if ((*s_objet_test).type == INT)
  352:                     {
  353:                         condition = ((*((integer8 *) (*s_objet_test).objet))
  354:                                 == 0) ? d_faux : d_vrai;
  355:                     }
  356:                     else if ((*s_objet_test).type == REL)
  357:                     {
  358:                         condition = ((*((real8 *) (*s_objet_test).objet))
  359:                                 == 0) ? d_faux : d_vrai;
  360:                     }
  361:                     else
  362:                     {
  363:                         liberation(s_etat_processus, s_objet_critere);
  364:                         liberation(s_etat_processus, s_objet_liste);
  365:                         liberation(s_etat_processus, s_objet_test);
  366: 
  367:                         (*s_etat_processus).erreur_execution =
  368:                                 d_ex_erreur_type_argument;
  369:                         return;
  370:                     }
  371: 
  372:                     liberation(s_etat_processus, s_objet_test);
  373: 
  374:                     if (condition == d_faux)
  375:                     {
  376:                         // On échange les deux éléments adjacents
  377: 
  378:                         inversion = d_vrai;
  379: 
  380:                         if (l_element_precedent == NULL)
  381:                         {
  382:                             // Échange des deux premiers éléments
  383:                             // de la liste.
  384: 
  385:                             l_element_tampon = (*(*l_element_courant)
  386:                                     .suivant).suivant;
  387:                             (*s_objet_liste).objet = (*l_element_courant)
  388:                                     .suivant;
  389:                             (*((struct_liste_chainee *) (*s_objet_liste)
  390:                                     .objet)).suivant = l_element_courant;
  391:                             (*l_element_courant).suivant =
  392:                                     l_element_tampon;
  393:                             l_element_courant = (*s_objet_liste).objet;
  394:                         }
  395:                         else
  396:                         {
  397:                             // Échange de deux éléments quelconques de la
  398:                             // liste.
  399: 
  400:                             l_element_tampon = (*l_element_courant).suivant;
  401:                             (*l_element_courant).suivant =
  402:                                     (*(*l_element_courant).suivant).suivant;
  403:                             (*l_element_precedent).suivant = l_element_tampon;
  404:                             (*l_element_tampon).suivant = l_element_courant;
  405: 
  406:                             l_element_courant = l_element_tampon;
  407:                         }
  408:                     }
  409: 
  410:                     l_element_precedent = l_element_courant;
  411:                     l_element_courant = (*l_element_courant).suivant;
  412:                 }
  413: 
  414:                 j--;
  415:             } while(inversion != d_faux);
  416:         }
  417:     }
  418:     else if (((*s_objet_liste).type == TBL) &&
  419:             ((*s_objet_critere).type == RPN))
  420:     {
  421:         /*
  422:          * Tri Shell-Metzner d'une table
  423:          */
  424: 
  425:         ecartement = (*((struct_tableau *) (*s_objet_liste).objet))
  426:                 .nombre_elements;
  427:         terminaison_boucle_1 = d_faux;
  428: 
  429:         do
  430:         {
  431:             ecartement = ecartement / 2;
  432: 
  433:             if (ecartement >= 1)
  434:             {
  435:                 indice_j = 0;
  436:                 indice_k = (*((struct_tableau *) (*s_objet_liste).objet))
  437:                         .nombre_elements - ecartement;
  438:                 terminaison_boucle_2 = d_faux;
  439: 
  440:                 do
  441:                 {
  442:                     indice_i = indice_j;
  443:                     terminaison_boucle_3 = d_faux;
  444: 
  445:                     do
  446:                     {
  447:                         indice_l = indice_i + ecartement;
  448: 
  449:                         if ((indice_i > 0) && (indice_l > 0))
  450:                         {
  451:                             if ((s_objet_copie = copie_objet(s_etat_processus,
  452:                                     (*((struct_tableau *) (*s_objet_liste)
  453:                                     .objet)).elements[indice_i - 1], 'P'))
  454:                                     == NULL)
  455:                             {
  456:                                 (*s_etat_processus).erreur_systeme =
  457:                                         d_es_allocation_memoire;
  458:                                 return;
  459:                             }
  460: 
  461:                             if (empilement(s_etat_processus,
  462:                                     &((*s_etat_processus).l_base_pile),
  463:                                     s_objet_copie) == d_erreur)
  464:                             {
  465:                                 return;
  466:                             }
  467: 
  468:                             if ((s_objet_copie = copie_objet(s_etat_processus,
  469:                                     (*((struct_tableau *) (*s_objet_liste)
  470:                                     .objet)).elements[indice_l - 1], 'P'))
  471:                                     == NULL)
  472:                             {
  473:                                 (*s_etat_processus).erreur_systeme =
  474:                                         d_es_allocation_memoire;
  475:                                 return;
  476:                             }
  477: 
  478:                             if (empilement(s_etat_processus,
  479:                                     &((*s_etat_processus).l_base_pile),
  480:                                     s_objet_copie) == d_erreur)
  481:                             {
  482:                                 return;
  483:                             }
  484: 
  485:                             if (evaluation(s_etat_processus, s_objet_critere,
  486:                                     'N') == d_erreur)
  487:                             {
  488:                                 liberation(s_etat_processus, s_objet_critere);
  489:                                 liberation(s_etat_processus, s_objet_liste);
  490: 
  491:                                 return;
  492:                             }
  493: 
  494:                             if (depilement(s_etat_processus,
  495:                                     &((*s_etat_processus).l_base_pile),
  496:                                     &s_objet_test) == d_erreur)
  497:                             {
  498:                                 liberation(s_etat_processus, s_objet_critere);
  499:                                 liberation(s_etat_processus, s_objet_liste);
  500: 
  501:                                 (*s_etat_processus).erreur_execution =
  502:                                         d_ex_manque_argument;
  503:                                 return;
  504:                             }
  505: 
  506:                             if ((*s_objet_test).type == INT)
  507:                             {
  508:                                 condition = ((*((integer8 *) (*s_objet_test)
  509:                                         .objet)) == 0) ? d_faux : d_vrai;
  510:                             }
  511:                             else if ((*s_objet_test).type == REL)
  512:                             {
  513:                                 condition = ((*((real8 *) (*s_objet_test)
  514:                                         .objet)) == 0) ? d_faux : d_vrai;
  515:                             }
  516:                             else
  517:                             {
  518:                                 liberation(s_etat_processus, s_objet_critere);
  519:                                 liberation(s_etat_processus, s_objet_liste);
  520:                                 liberation(s_etat_processus, s_objet_test);
  521: 
  522:                                 (*s_etat_processus).erreur_execution =
  523:                                         d_ex_erreur_type_argument;
  524:                                 return;
  525:                             }
  526: 
  527:                             liberation(s_etat_processus, s_objet_test);
  528: 
  529:                             if (condition == d_faux)
  530:                             {
  531:                                 s_objet_registre =
  532:                                         (*((struct_tableau *)
  533:                                         (*s_objet_liste).objet)).elements
  534:                                         [indice_i - 1];
  535:                                 (*((struct_tableau *) (*s_objet_liste).objet))
  536:                                         .elements[indice_i - 1] =
  537:                                         (*((struct_tableau *) (*s_objet_liste)
  538:                                         .objet)).elements[indice_l - 1];
  539:                                 (*((struct_tableau *) (*s_objet_liste)
  540:                                         .objet)).elements[indice_l - 1] =
  541:                                         s_objet_registre;
  542: 
  543:                                 indice_i -= ecartement;
  544: 
  545:                                 if (indice_i < 1)
  546:                                 {
  547:                                     terminaison_boucle_3 = d_vrai;
  548:                                 }
  549:                             }
  550:                             else
  551:                             {
  552:                                 terminaison_boucle_3 = d_vrai;
  553:                             }
  554:                         }
  555:                         else
  556:                         {
  557:                             terminaison_boucle_3 = d_vrai;
  558:                         }
  559:                     } while(terminaison_boucle_3 == d_faux);
  560: 
  561:                     indice_j++;
  562: 
  563:                     if (indice_j > indice_k)
  564:                     {
  565:                         terminaison_boucle_2 = d_vrai;
  566:                     }
  567:                 } while(terminaison_boucle_2 == d_faux);
  568:             }
  569:             else
  570:             {
  571:                 terminaison_boucle_1 = d_vrai;
  572:             }
  573:         } while(terminaison_boucle_1 == d_faux);
  574:     }
  575:     else
  576:     {
  577:         if (pthread_mutex_unlock(&((*(*s_etat_processus)
  578:                 .pointeur_variable_partagee_courante).mutex)) != 0)
  579:         {
  580:             (*s_etat_processus).erreur_systeme = d_es_processus;
  581:             return;
  582:         }
  583: 
  584:         liberation(s_etat_processus, s_objet_liste);
  585:         liberation(s_etat_processus, s_objet_critere);
  586: 
  587:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  588:         return;
  589:     }
  590: 
  591:     if (presence_nom == d_faux)
  592:     {
  593:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  594:                 s_objet_liste) == d_erreur)
  595:         {
  596:             return;
  597:         }
  598:     }
  599:     else
  600:     {
  601:         if (variable_partagee == d_vrai)
  602:         {
  603:             (*(*s_etat_processus).pointeur_variable_partagee_courante).objet =
  604:                     s_objet_liste;
  605: 
  606:             if (pthread_mutex_unlock(&((*(*s_etat_processus)
  607:                     .pointeur_variable_partagee_courante).mutex)) != 0)
  608:             {
  609:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  610:                 return;
  611:             }
  612:         }
  613:     }
  614: 
  615:     liberation(s_etat_processus, s_objet_critere);
  616: 
  617:     return;
  618: }
  619: 
  620: 
  621: /*
  622: ================================================================================
  623:   Fonction 'save'
  624: ================================================================================
  625:   Entrées : structure processus
  626: --------------------------------------------------------------------------------
  627:   Sorties :
  628: --------------------------------------------------------------------------------
  629:   Effets de bord : néant
  630: ================================================================================
  631: */
  632: 
  633: void
  634: instruction_save(struct_processus *s_etat_processus)
  635: {
  636:     struct_objet                        *s_objet_1;
  637:     struct_objet                        *s_objet_2;
  638: 
  639:     struct_variable                     s_variable;
  640: 
  641:     (*s_etat_processus).erreur_execution = d_ex;
  642: 
  643:     if ((*s_etat_processus).affichage_arguments == 'Y')
  644:     {
  645:         printf("\n  SAVE ");
  646: 
  647:         if ((*s_etat_processus).langue == 'F')
  648:         {
  649:             printf("(affecte un objet à une variable globale)\n\n");
  650:         }
  651:         else
  652:         {
  653:             printf("(store an object in a global variable)\n\n");
  654:         }
  655: 
  656:         printf("    2: %s, %s, %s, %s, %s, %s,\n"
  657:                 "       %s, %s, %s, %s, %s,\n"
  658:                 "       %s, %s, %s, %s, %s,\n"
  659:                 "       %s, %s, %s, %s,\n"
  660:                 "       %s, %s\n",
  661:                 d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
  662:                 d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
  663:                 d_SQL, d_SLB, d_PRC, d_MTX);
  664:         printf("    1: %s\n", d_NOM);
  665: 
  666:         return;
  667:     }
  668:     else if ((*s_etat_processus).test_instruction == 'Y')
  669:     {
  670:         (*s_etat_processus).nombre_arguments = -1;
  671:         return;
  672:     }
  673:     
  674:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  675:     {
  676:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  677:         {
  678:             return;
  679:         }
  680:     }
  681: 
  682:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  683:             &s_objet_1) == d_erreur)
  684:     {
  685:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  686:         return;
  687:     }
  688: 
  689:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  690:             &s_objet_2) == d_erreur)
  691:     {
  692:         liberation(s_etat_processus, s_objet_1);
  693: 
  694:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  695:         return;
  696:     }
  697: 
  698:     if ((*s_objet_1).type != NOM)
  699:     {
  700:         liberation(s_etat_processus, s_objet_1);
  701:         liberation(s_etat_processus, s_objet_2);
  702: 
  703:         (*s_etat_processus).erreur_execution = d_ex_nom_invalide;
  704:         return;
  705:     }
  706: 
  707:     if (recherche_variable_globale(s_etat_processus, (*((struct_nom *)
  708:             (*s_objet_1).objet)).nom) == d_vrai)
  709:     {
  710:         /*
  711:          * Une variable est accessible.
  712:          */
  713: 
  714:         if ((*(*s_etat_processus).pointeur_variable_courante)
  715:                 .variable_verrouillee == d_vrai)
  716:         {
  717:             liberation(s_etat_processus, s_objet_1);
  718:             liberation(s_etat_processus, s_objet_2);
  719: 
  720:             (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
  721:             return;
  722:         }
  723: 
  724:         if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
  725:         {
  726:             liberation(s_etat_processus, s_objet_1);
  727:             liberation(s_etat_processus, s_objet_2);
  728: 
  729:             (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
  730:             return;
  731:         }
  732: 
  733:         liberation(s_etat_processus,
  734:                 (*(*s_etat_processus).pointeur_variable_courante).objet);
  735:         (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_2;
  736:     }
  737:     else
  738:     {
  739:         /*
  740:          * Aucune variable n'est accessible (ni locale, ni globale).
  741:          */
  742: 
  743:         if (((*s_etat_processus).autorisation_nom_implicite == 'N') &&
  744:                 ((*((struct_nom *) (*s_objet_1).objet)).symbole == d_faux))
  745:         {
  746:             liberation(s_etat_processus, s_objet_1);
  747:             liberation(s_etat_processus, s_objet_2);
  748: 
  749:             (*s_etat_processus).erreur_systeme = d_es;
  750:             (*s_etat_processus).erreur_execution =
  751:                     d_ex_creation_variable_globale;
  752:             return;
  753:         }
  754: 
  755:         if ((s_variable.nom = malloc((strlen((*((struct_nom *)
  756:                 (*s_objet_1).objet)).nom) + 1) * sizeof(unsigned char)))
  757:                 == NULL)
  758:         {
  759:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  760:             return;
  761:         }
  762: 
  763:         strcpy(s_variable.nom, (*((struct_nom *) (*s_objet_1).objet)).nom);
  764:         s_variable.niveau = 1;
  765: 
  766:         /*
  767:          * Le niveau 0 correspond aux définitions. Les variables
  768:          * commencent à 1 car elles sont toujours incluses dans
  769:          * une définition.
  770:          */
  771: 
  772:         s_variable.objet = s_objet_2;
  773: 
  774:         if (creation_variable(s_etat_processus, &s_variable, 'V', 'P')
  775:                 == d_erreur)
  776:         {
  777:             return;
  778:         }
  779: 
  780:         (*s_etat_processus).erreur_systeme = d_es;
  781:     }
  782: 
  783:     liberation(s_etat_processus, s_objet_1);
  784: 
  785:     return;
  786: }
  787: 
  788: 
  789: /*
  790: ================================================================================
  791:   Fonction 'suspend'
  792: ================================================================================
  793:   Entrées : structure processus
  794: --------------------------------------------------------------------------------
  795:   Sorties :
  796: --------------------------------------------------------------------------------
  797:   Effets de bord : néant
  798: ================================================================================
  799: */
  800: 
  801: void
  802: instruction_suspend(struct_processus *s_etat_processus)
  803: {
  804:     struct timespec             attente;
  805: 
  806:     (*s_etat_processus).erreur_execution = d_ex;
  807: 
  808:     if ((*s_etat_processus).affichage_arguments == 'Y')
  809:     {
  810:         printf("\n  SUSPEND ");
  811: 
  812:         if ((*s_etat_processus).langue == 'F')
  813:         {
  814:             printf("(attend un signal RPL/SIGCONT)\n\n");
  815:             printf("  Aucun argument\n");
  816:         }
  817:         else
  818:         {
  819:             printf("(wait for RPL/SIGCONT signal)\n\n");
  820:             printf("  No argument\n");
  821:         }
  822: 
  823:         return;
  824:     }
  825:     else if ((*s_etat_processus).test_instruction == 'Y')
  826:     {
  827:         (*s_etat_processus).nombre_arguments = -1;
  828:         return;
  829:     }
  830: 
  831:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  832:     {
  833:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  834:         {
  835:             return;
  836:         }
  837:     }
  838: 
  839:     if ((*s_etat_processus).profilage == d_vrai)
  840:     {
  841:         profilage(s_etat_processus, "Suspend");
  842: 
  843:         if ((*s_etat_processus).erreur_systeme != d_es)
  844:         {
  845:             return;
  846:         }
  847:     }
  848: 
  849: #   ifndef SEMAPHORES_NOMMES
  850:         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  851: #   else
  852:         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  853: #   endif
  854:     {
  855:         (*s_etat_processus).erreur_systeme = d_es_processus;
  856:         return;
  857:     }
  858: 
  859:     for((*s_etat_processus).redemarrage_processus = d_faux;;)
  860:     {
  861:         scrutation_interruptions(s_etat_processus);
  862: 
  863:         if ((*s_etat_processus).redemarrage_processus == d_vrai)
  864:         {
  865:             break;
  866:         }
  867: 
  868:         nanosleep(&attente, NULL);
  869:         INCR_GRANULARITE(attente.tv_nsec);
  870:     }
  871: 
  872: #   ifndef SEMAPHORES_NOMMES
  873:         while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
  874: #   else
  875:         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
  876: #   endif
  877:     {
  878:         if (errno != EINTR)
  879:         {
  880:             (*s_etat_processus).erreur_systeme = d_es_processus;
  881:             return;
  882:         }
  883:     }
  884: 
  885:     if ((*s_etat_processus).profilage == d_vrai)
  886:     {
  887:         profilage(s_etat_processus, NULL);
  888:     }
  889: 
  890:     return;
  891: }
  892: 
  893: 
  894: /*
  895: ================================================================================
  896:   Fonction 'static'
  897: ================================================================================
  898:   Entrées : structure processus
  899: --------------------------------------------------------------------------------
  900:   Sorties :
  901: --------------------------------------------------------------------------------
  902:   Effets de bord : néant
  903: ================================================================================
  904: */
  905: 
  906: void
  907: instruction_static(struct_processus *s_etat_processus)
  908: {
  909:     (*s_etat_processus).erreur_execution = d_ex;
  910: 
  911:     if ((*s_etat_processus).affichage_arguments == 'Y')
  912:     {
  913:         printf("\n  STATIC ");
  914: 
  915:         if ((*s_etat_processus).langue == 'F')
  916:         {
  917:             printf("(déclaration de variables statiques)\n\n");
  918:             printf("  Aucun argument\n");
  919:         }
  920:         else
  921:         {
  922:             printf("(static variables declaration)\n\n");
  923:             printf("  No argument\n");
  924:         }
  925: 
  926:         return;
  927:     }
  928:     else if ((*s_etat_processus).test_instruction == 'Y')
  929:     {
  930:         (*s_etat_processus).nombre_arguments = -1;
  931:         return;
  932:     }
  933:     
  934:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  935:     {
  936:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  937:         {
  938:             return;
  939:         }
  940:     }
  941: 
  942:     if ((*s_etat_processus).creation_variables_partagees == d_vrai)
  943:     {
  944:         (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
  945:         return;
  946:     }
  947: 
  948:     (*s_etat_processus).creation_variables_statiques = d_vrai;
  949: 
  950:     return;
  951: }
  952: 
  953: 
  954: /*
  955: ================================================================================
  956:   Fonction 'shared'
  957: ================================================================================
  958:   Entrées : structure processus
  959: --------------------------------------------------------------------------------
  960:   Sorties :
  961: --------------------------------------------------------------------------------
  962:   Effets de bord : néant
  963: ================================================================================
  964: */
  965: 
  966: void
  967: instruction_shared(struct_processus *s_etat_processus)
  968: {
  969:     (*s_etat_processus).erreur_execution = d_ex;
  970: 
  971:     if ((*s_etat_processus).affichage_arguments == 'Y')
  972:     {
  973:         printf("\n  SHARED ");
  974: 
  975:         if ((*s_etat_processus).langue == 'F')
  976:         {
  977:             printf("(déclaration de variables partagées)\n\n");
  978:             printf("  Aucun argument\n");
  979:         }
  980:         else
  981:         {
  982:             printf("(shared variables declaration)\n\n");
  983:             printf("  No argument\n");
  984:         }
  985: 
  986:         return;
  987:     }
  988:     else if ((*s_etat_processus).test_instruction == 'Y')
  989:     {
  990:         (*s_etat_processus).nombre_arguments = -1;
  991:         return;
  992:     }
  993:     
  994:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  995:     {
  996:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  997:         {
  998:             return;
  999:         }
 1000:     }
 1001: 
 1002:     if ((*s_etat_processus).creation_variables_partagees == d_vrai)
 1003:     {
 1004:         (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
 1005:         return;
 1006:     }
 1007: 
 1008:     (*s_etat_processus).creation_variables_partagees = d_vrai;
 1009: 
 1010:     return;
 1011: }
 1012: 
 1013: 
 1014: /*
 1015: ================================================================================
 1016:   Fonction 'stoswi'
 1017: ================================================================================
 1018:   Entrées : structure processus
 1019: --------------------------------------------------------------------------------
 1020:   Sorties :
 1021: --------------------------------------------------------------------------------
 1022:   Effets de bord : néant
 1023: ================================================================================
 1024: */
 1025: 
 1026: void
 1027: instruction_stoswi(struct_processus *s_etat_processus)
 1028: {
 1029:     integer8                    interruption;
 1030: 
 1031:     struct_objet                *s_objet_argument_1;
 1032:     struct_objet                *s_objet_argument_2;
 1033: 
 1034:     (*s_etat_processus).erreur_execution = d_ex;
 1035: 
 1036:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1037:     {
 1038:         printf("\n  STOSWI ");
 1039: 
 1040:         if ((*s_etat_processus).langue == 'F')
 1041:         {
 1042:             printf("(définition d'une interruption logicielle)\n\n");
 1043:         }
 1044:         else
 1045:         {
 1046:             printf("(software interrupt definition)\n\n");
 1047:         }
 1048: 
 1049:         printf("    2: %s, %s\n", d_NOM, d_RPN);
 1050:         printf("    1: %s\n", d_INT);
 1051: 
 1052:         return;
 1053:     }
 1054:     else if ((*s_etat_processus).test_instruction == 'Y')
 1055:     {
 1056:         (*s_etat_processus).nombre_arguments = -1;
 1057:         return;
 1058:     }
 1059: 
 1060:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1061:     {
 1062:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
 1063:         {
 1064:             return;
 1065:         }
 1066:     }
 1067: 
 1068:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1069:             &s_objet_argument_1) == d_erreur)
 1070:     {
 1071:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1072:         return;
 1073:     }
 1074: 
 1075:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1076:             &s_objet_argument_2) == d_erreur)
 1077:     {
 1078:         liberation(s_etat_processus, s_objet_argument_1);
 1079: 
 1080:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1081:         return;
 1082:     }
 1083: 
 1084:     if ((*s_objet_argument_1).type == INT)
 1085:     {
 1086:         interruption = (*((integer8 *) (*s_objet_argument_1).objet));
 1087: 
 1088:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1089:         {
 1090:             liberation(s_etat_processus, s_objet_argument_1);
 1091:             liberation(s_etat_processus, s_objet_argument_2);
 1092: 
 1093:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 1094:             return;
 1095:         }
 1096: 
 1097:         if ((*s_objet_argument_2).type == NOM)
 1098:         {
 1099:             liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
 1100:                     [interruption - 1]);
 1101:             (*s_etat_processus).corps_interruptions[interruption - 1] =
 1102:                     s_objet_argument_2;
 1103:         }
 1104:         else if((*s_objet_argument_2).type == RPN)
 1105:         {
 1106:             liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
 1107:                     [interruption - 1]);
 1108:             (*s_etat_processus).corps_interruptions[interruption - 1] =
 1109:                     s_objet_argument_2;
 1110:         }
 1111:         else
 1112:         {
 1113:             liberation(s_etat_processus, s_objet_argument_1);
 1114:             liberation(s_etat_processus, s_objet_argument_2);
 1115: 
 1116:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1117:             return;
 1118:         }
 1119:     }
 1120:     else
 1121:     {
 1122:         liberation(s_etat_processus, s_objet_argument_1);
 1123:         liberation(s_etat_processus, s_objet_argument_2);
 1124: 
 1125:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1126:         return;
 1127:     }
 1128: 
 1129:     liberation(s_etat_processus, s_objet_argument_1);
 1130: 
 1131:     return;
 1132: }
 1133: 
 1134: 
 1135: /*
 1136: ================================================================================
 1137:   Fonction 'swi'
 1138: ================================================================================
 1139:   Entrées : structure processus
 1140: --------------------------------------------------------------------------------
 1141:   Sorties :
 1142: --------------------------------------------------------------------------------
 1143:   Effets de bord : néant
 1144: ================================================================================
 1145: */
 1146: 
 1147: void
 1148: instruction_swi(struct_processus *s_etat_processus)
 1149: {
 1150:     int                         interruption_reduite;
 1151: 
 1152:     integer8                    interruption;
 1153: 
 1154:     pid_t                       pid;
 1155: 
 1156:     pthread_t                   tid;
 1157: 
 1158:     sig_atomic_t                registre;
 1159: 
 1160:     ssize_t                     longueur_ecriture;
 1161: 
 1162:     struct_objet                *s_objet_argument;
 1163: 
 1164:     struct timespec             attente;
 1165: 
 1166:     unsigned char               tampon;
 1167: 
 1168:     (*s_etat_processus).erreur_execution = d_ex;
 1169: 
 1170:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1171:     {
 1172:         printf("\n  SWI ");
 1173: 
 1174:         if ((*s_etat_processus).langue == 'F')
 1175:         {
 1176:             printf("(interruption logicielle)\n\n");
 1177:         }
 1178:         else
 1179:         {
 1180:             printf("(software interrupt)\n\n");
 1181:         }
 1182: 
 1183:         printf("    1: %s\n", d_INT);
 1184: 
 1185:         return;
 1186:     }
 1187:     else if ((*s_etat_processus).test_instruction == 'Y')
 1188:     {
 1189:         (*s_etat_processus).nombre_arguments = -1;
 1190:         return;
 1191:     }
 1192: 
 1193:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1194:     {
 1195:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1196:         {
 1197:             return;
 1198:         }
 1199:     }
 1200: 
 1201:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1202:             &s_objet_argument) == d_erreur)
 1203:     {
 1204:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1205:         return;
 1206:     }
 1207: 
 1208:     if ((*s_objet_argument).type == INT)
 1209:     {
 1210:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 1211: 
 1212:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1213:         {
 1214:             liberation(s_etat_processus, s_objet_argument);
 1215: 
 1216:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 1217:             return;
 1218:         }
 1219: 
 1220:         if ((*s_etat_processus).presence_pipes == d_faux)
 1221:         {
 1222:             liberation(s_etat_processus, s_objet_argument);
 1223: 
 1224:             (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 1225:             return;
 1226:         }
 1227: 
 1228:         // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
 1229:         // de surveillance.
 1230: 
 1231:         registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
 1232:         (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
 1233: 
 1234:         if ((*s_etat_processus).processus_detache == d_vrai)
 1235:         {
 1236:             pid = -1;
 1237: 
 1238:             attente.tv_sec = 0;
 1239:             attente.tv_nsec = GRANULARITE_us * 1000;
 1240: 
 1241: #           ifndef SEMAPHORES_NOMMES
 1242:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1243: #           else
 1244:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1245: #           endif
 1246:             {
 1247:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1248:                 return;
 1249:             }
 1250: 
 1251:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1252:                     (*s_etat_processus).pipe_nombre_objets_attente,
 1253:                     &pid, sizeof(pid))) != sizeof(pid))
 1254:             {
 1255: #               ifndef SEMAPHORES_NOMMES
 1256:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1257: #               else
 1258:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1259: #               endif
 1260:                 {
 1261:                     if (errno != EINTR)
 1262:                     {
 1263:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1264:                         return;
 1265:                     }
 1266:                 }
 1267: 
 1268:                 if (longueur_ecriture == -1)
 1269:                 {
 1270:                     if (registre == 0)
 1271:                     {
 1272:                         if ((*s_etat_processus)
 1273:                                 .var_volatile_traitement_retarde_stop == -1)
 1274:                         {
 1275:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1276:                         }
 1277: 
 1278:                         (*s_etat_processus)
 1279:                                 .var_volatile_traitement_retarde_stop
 1280:                                 = registre;
 1281:                     }
 1282: 
 1283:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1284:                     return;
 1285:                 }
 1286: 
 1287:                 nanosleep(&attente, NULL);
 1288:                 INCR_GRANULARITE(attente.tv_nsec);
 1289: 
 1290: #               ifndef SEMAPHORES_NOMMES
 1291:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1292: #               else
 1293:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1294: #               endif
 1295:                 {
 1296:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1297:                     return;
 1298:                 }
 1299:             }
 1300: 
 1301:             scrutation_interruptions(s_etat_processus);
 1302: 
 1303: #           ifndef SEMAPHORES_NOMMES
 1304:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1305: #           else
 1306:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1307: #           endif
 1308:             {
 1309:                 if (errno != EINTR)
 1310:                 {
 1311:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1312:                     return;
 1313:                 }
 1314:             }
 1315:         }
 1316:         else
 1317:         {
 1318:             tid = (pthread_t) -1;
 1319: 
 1320:             attente.tv_sec = 0;
 1321:             attente.tv_nsec = GRANULARITE_us * 1000;
 1322: 
 1323: #           ifndef SEMAPHORES_NOMMES
 1324:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1325: #           else
 1326:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1327: #           endif
 1328:             {
 1329:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1330:                 return;
 1331:             }
 1332: 
 1333:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1334:                     (*s_etat_processus).pipe_nombre_objets_attente,
 1335:                     &tid, sizeof(tid))) != sizeof(tid))
 1336:             {
 1337: #               ifndef SEMAPHORES_NOMMES
 1338:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1339: #               else
 1340:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1341: #               endif
 1342:                 {
 1343:                     if (errno != EINTR)
 1344:                     {
 1345:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1346:                         return;
 1347:                     }
 1348:                 }
 1349: 
 1350:                 if (longueur_ecriture == -1)
 1351:                 {
 1352:                     if (registre == 0)
 1353:                     {
 1354:                         if ((*s_etat_processus)
 1355:                                 .var_volatile_traitement_retarde_stop == -1)
 1356:                         {
 1357:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1358:                         }
 1359: 
 1360:                         (*s_etat_processus)
 1361:                                 .var_volatile_traitement_retarde_stop
 1362:                                 = registre;
 1363:                     }
 1364: 
 1365:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1366:                     return;
 1367:                 }
 1368: 
 1369:                 nanosleep(&attente, NULL);
 1370:                 INCR_GRANULARITE(attente.tv_nsec);
 1371: 
 1372: #               ifndef SEMAPHORES_NOMMES
 1373:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1374: #               else
 1375:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1376: #               endif
 1377:                 {
 1378:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1379:                     return;
 1380:                 }
 1381:             }
 1382: 
 1383:             scrutation_interruptions(s_etat_processus);
 1384: 
 1385: #           ifndef SEMAPHORES_NOMMES
 1386:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1387: #           else
 1388:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1389: #           endif
 1390:             {
 1391:                 if (errno != EINTR)
 1392:                 {
 1393:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1394:                     return;
 1395:                 }
 1396:             }
 1397:         }
 1398: 
 1399:         interruption_reduite = (int) interruption;
 1400: 
 1401:         attente.tv_sec = 0;
 1402:         attente.tv_nsec = GRANULARITE_us * 1000;
 1403: 
 1404: #       ifndef SEMAPHORES_NOMMES
 1405:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1406: #       else
 1407:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1408: #       endif
 1409:         {
 1410:             (*s_etat_processus).erreur_systeme = d_es_processus;
 1411:             return;
 1412:         }
 1413: 
 1414:         while((longueur_ecriture = write_atomic(s_etat_processus,
 1415:                 (*s_etat_processus).pipe_interruptions,
 1416:                 &interruption_reduite, sizeof(interruption_reduite)))
 1417:                 != sizeof(interruption_reduite))
 1418:         {
 1419: #           ifndef SEMAPHORES_NOMMES
 1420:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1421: #           else
 1422:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1423: #           endif
 1424:             {
 1425:                 if (errno != EINTR)
 1426:                 {
 1427:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1428:                     return;
 1429:                 }
 1430:             }
 1431: 
 1432:             if (longueur_ecriture == -1)
 1433:             {
 1434:                 if (registre == 0)
 1435:                 {
 1436:                     if ((*s_etat_processus)
 1437:                             .var_volatile_traitement_retarde_stop == -1)
 1438:                     {
 1439:                         (*s_etat_processus).var_volatile_requete_arret = -1;
 1440:                     }
 1441: 
 1442:                     (*s_etat_processus)
 1443:                             .var_volatile_traitement_retarde_stop
 1444:                             = registre;
 1445:                 }
 1446: 
 1447:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1448:                 return;
 1449:             }
 1450: 
 1451:             nanosleep(&attente, NULL);
 1452:             INCR_GRANULARITE(attente.tv_nsec);
 1453: 
 1454: #           ifndef SEMAPHORES_NOMMES
 1455:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1456: #           else
 1457:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1458: #           endif
 1459:             {
 1460:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1461:                 return;
 1462:             }
 1463: 
 1464:             scrutation_interruptions(s_etat_processus);
 1465:         }
 1466: 
 1467: #       ifndef SEMAPHORES_NOMMES
 1468:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1469: #       else
 1470:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1471: #       endif
 1472:         {
 1473:             if (errno != EINTR)
 1474:             {
 1475:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1476:                 return;
 1477:             }
 1478:         }
 1479: 
 1480:         if ((*s_etat_processus).processus_detache == d_vrai)
 1481:         {
 1482:             pid = -3;
 1483: 
 1484:             attente.tv_sec = 0;
 1485:             attente.tv_nsec = GRANULARITE_us * 1000;
 1486: 
 1487: #           ifndef SEMAPHORES_NOMMES
 1488:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1489: #           else
 1490:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1491: #           endif
 1492:             {
 1493:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1494:                 return;
 1495:             }
 1496: 
 1497:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1498:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1499:                     &pid, sizeof(pid))) != sizeof(pid))
 1500:             {
 1501: #               ifndef SEMAPHORES_NOMMES
 1502:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1503: #               else
 1504:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1505: #               endif
 1506:                 {
 1507:                     if (errno != EINTR)
 1508:                     {
 1509:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1510:                         return;
 1511:                     }
 1512:                 }
 1513: 
 1514:                 if (longueur_ecriture == -1)
 1515:                 {
 1516:                     if (registre == 0)
 1517:                     {
 1518:                         if ((*s_etat_processus)
 1519:                                 .var_volatile_traitement_retarde_stop == -1)
 1520:                         {
 1521:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1522:                         }
 1523: 
 1524:                         (*s_etat_processus)
 1525:                                 .var_volatile_traitement_retarde_stop
 1526:                                 = registre;
 1527:                     }
 1528: 
 1529:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1530:                     return;
 1531:                 }
 1532: 
 1533:                 nanosleep(&attente, NULL);
 1534:                 INCR_GRANULARITE(attente.tv_nsec);
 1535: 
 1536: #               ifndef SEMAPHORES_NOMMES
 1537:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1538: #               else
 1539:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1540: #               endif
 1541:                 {
 1542:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1543:                     return;
 1544:                 }
 1545: 
 1546:                 scrutation_interruptions(s_etat_processus);
 1547:             }
 1548: 
 1549:             pid = getpid();
 1550: 
 1551:             attente.tv_sec = 0;
 1552:             attente.tv_nsec = GRANULARITE_us * 1000;
 1553: 
 1554:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1555:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1556:                     &pid, sizeof(pid))) != sizeof(pid))
 1557:             {
 1558: #               ifndef SEMAPHORES_NOMMES
 1559:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1560: #               else
 1561:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1562: #               endif
 1563:                 {
 1564:                     if (errno != EINTR)
 1565:                     {
 1566:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1567:                         return;
 1568:                     }
 1569:                 }
 1570: 
 1571:                 if (longueur_ecriture == -1)
 1572:                 {
 1573:                     if (registre == 0)
 1574:                     {
 1575:                         if ((*s_etat_processus)
 1576:                                 .var_volatile_traitement_retarde_stop == -1)
 1577:                         {
 1578:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1579:                         }
 1580: 
 1581:                         (*s_etat_processus)
 1582:                                 .var_volatile_traitement_retarde_stop
 1583:                                 = registre;
 1584:                     }
 1585: 
 1586:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1587:                     return;
 1588:                 }
 1589: 
 1590:                 nanosleep(&attente, NULL);
 1591:                 INCR_GRANULARITE(attente.tv_nsec);
 1592: 
 1593: #               ifndef SEMAPHORES_NOMMES
 1594:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1595: #               else
 1596:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1597: #               endif
 1598:                 {
 1599:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1600:                     return;
 1601:                 }
 1602:             }
 1603: 
 1604: #           ifndef SEMAPHORES_NOMMES
 1605:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1606: #           else
 1607:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1608: #           endif
 1609:             {
 1610:                 if (errno != EINTR)
 1611:                 {
 1612:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1613:                     return;
 1614:                 }
 1615:             }
 1616:         }
 1617:         else
 1618:         {
 1619:             tid = (pthread_t) -3;
 1620: 
 1621: #           ifndef SEMAPHORES_NOMMES
 1622:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1623: #           else
 1624:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1625: #           endif
 1626:             {
 1627:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1628:                 return;
 1629:             }
 1630: 
 1631:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1632:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1633:                     &tid, sizeof(tid))) != sizeof(tid))
 1634:             {
 1635: #               ifndef SEMAPHORES_NOMMES
 1636:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1637: #               else
 1638:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1639: #               endif
 1640:                 {
 1641:                     if (errno != EINTR)
 1642:                     {
 1643:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1644:                         return;
 1645:                     }
 1646:                 }
 1647: 
 1648:                 if (longueur_ecriture == -1)
 1649:                 {
 1650:                     if (registre == 0)
 1651:                     {
 1652:                         if ((*s_etat_processus)
 1653:                                 .var_volatile_traitement_retarde_stop == -1)
 1654:                         {
 1655:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1656:                         }
 1657: 
 1658:                         (*s_etat_processus)
 1659:                                 .var_volatile_traitement_retarde_stop
 1660:                                 = registre;
 1661:                     }
 1662: 
 1663:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1664:                     return;
 1665:                 }
 1666: 
 1667:                 nanosleep(&attente, NULL);
 1668:                 INCR_GRANULARITE(attente.tv_nsec);
 1669: 
 1670: #               ifndef SEMAPHORES_NOMMES
 1671:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1672: #               else
 1673:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1674: #               endif
 1675:                 {
 1676:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1677:                     return;
 1678:                 }
 1679: 
 1680:                 scrutation_interruptions(s_etat_processus);
 1681:             }
 1682: 
 1683:             tid = pthread_self();
 1684: 
 1685:             attente.tv_sec = 0;
 1686:             attente.tv_nsec = GRANULARITE_us * 1000;
 1687: 
 1688:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1689:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1690:                     &tid, sizeof(tid))) != sizeof(tid))
 1691:             {
 1692: #               ifndef SEMAPHORES_NOMMES
 1693:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1694: #               else
 1695:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1696: #               endif
 1697:                 {
 1698:                     if (errno != EINTR)
 1699:                     {
 1700:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1701:                         return;
 1702:                     }
 1703:                 }
 1704: 
 1705:                 if (longueur_ecriture == -1)
 1706: 
 1707:                 {
 1708:                     if (registre == 0)
 1709:                     {
 1710:                         if ((*s_etat_processus)
 1711:                                 .var_volatile_traitement_retarde_stop == -1)
 1712:                         {
 1713:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1714:                         }
 1715: 
 1716:                         (*s_etat_processus)
 1717:                                 .var_volatile_traitement_retarde_stop
 1718:                                 = registre;
 1719:                     }
 1720: 
 1721:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1722:                     return;
 1723:                 }
 1724: 
 1725:                 nanosleep(&attente, NULL);
 1726:                 INCR_GRANULARITE(attente.tv_nsec);
 1727: 
 1728: #               ifndef SEMAPHORES_NOMMES
 1729:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1730: #               else
 1731:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1732: #               endif
 1733:                 {
 1734:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1735:                     return;
 1736:                 }
 1737: 
 1738:                 scrutation_interruptions(s_etat_processus);
 1739:             }
 1740: 
 1741: #           ifndef SEMAPHORES_NOMMES
 1742:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1743: #           else
 1744:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1745: #           endif
 1746:             {
 1747:                 if (errno != EINTR)
 1748:                 {
 1749:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1750:                     return;
 1751:                 }
 1752:             }
 1753:         }
 1754: 
 1755:         attente.tv_sec = 0;
 1756:         attente.tv_nsec = GRANULARITE_us * 1000;
 1757: 
 1758: #       ifndef SEMAPHORES_NOMMES
 1759:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1760: #       else
 1761:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1762: #       endif
 1763:         {
 1764:             (*s_etat_processus).erreur_systeme = d_es_processus;
 1765:             return;
 1766:         }
 1767: 
 1768:         while(read_atomic(s_etat_processus,
 1769:                 (*s_etat_processus).pipe_acquittement,
 1770:                 &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
 1771:         {
 1772: #           ifndef SEMAPHORES_NOMMES
 1773:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1774: #           else
 1775:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1776: #           endif
 1777:             {
 1778:                 if (errno != EINTR)
 1779:                 {
 1780:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1781:                     return;
 1782:                 }
 1783:             }
 1784: 
 1785:             nanosleep(&attente, NULL);
 1786:             INCR_GRANULARITE(attente.tv_nsec);
 1787: 
 1788: #           ifndef SEMAPHORES_NOMMES
 1789:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1790: #           else
 1791:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1792: #           endif
 1793:             {
 1794:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1795:                 return;
 1796:             }
 1797: 
 1798:             scrutation_interruptions(s_etat_processus);
 1799:         }
 1800: 
 1801: #       ifndef SEMAPHORES_NOMMES
 1802:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1803: #       else
 1804:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1805: #       endif
 1806:         {
 1807:             if (errno != EINTR)
 1808:             {
 1809:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1810:                 return;
 1811:             }
 1812:         }
 1813: 
 1814:         if (registre == 0)
 1815:         {
 1816:             if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
 1817:             {
 1818:                 (*s_etat_processus).var_volatile_requete_arret = -1;
 1819:             }
 1820: 
 1821:             (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
 1822:         }
 1823:     }
 1824:     else
 1825:     {
 1826:         liberation(s_etat_processus, s_objet_argument);
 1827: 
 1828:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1829:         return;
 1830:     }
 1831: 
 1832:     liberation(s_etat_processus, s_objet_argument);
 1833: 
 1834:     return;
 1835: }
 1836: 
 1837: 
 1838: /*
 1839: ================================================================================
 1840:   Fonction 'swilock'
 1841: ================================================================================
 1842:   Entrées : structure processus
 1843: --------------------------------------------------------------------------------
 1844:   Sorties :
 1845: --------------------------------------------------------------------------------
 1846:   Effets de bord : néant
 1847: ================================================================================
 1848: */
 1849: 
 1850: void
 1851: instruction_swilock(struct_processus *s_etat_processus)
 1852: {
 1853:     integer8                    interruption;
 1854: 
 1855:     struct_liste_chainee        *l_element_courant;
 1856: 
 1857:     struct_objet                *s_objet_argument;
 1858: 
 1859:     (*s_etat_processus).erreur_execution = d_ex;
 1860: 
 1861:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1862:     {
 1863:         printf("\n  SWILOCK ");
 1864: 
 1865:         if ((*s_etat_processus).langue == 'F')
 1866:         {
 1867:             printf("(verrouillage des interruptions logicielles)\n\n");
 1868:         }
 1869:         else
 1870:         {
 1871:             printf("(software interrupt lock)\n\n");
 1872:         }
 1873: 
 1874:         printf("    1: %s, %s\n", d_INT, d_LST);
 1875: 
 1876:         return;
 1877:     }
 1878:     else if ((*s_etat_processus).test_instruction == 'Y')
 1879:     {
 1880:         (*s_etat_processus).nombre_arguments = -1;
 1881:         return;
 1882:     }
 1883: 
 1884:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1885:     {
 1886:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1887:         {
 1888:             return;
 1889:         }
 1890:     }
 1891: 
 1892:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1893:             &s_objet_argument) == d_erreur)
 1894:     {
 1895:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1896:         return;
 1897:     }
 1898: 
 1899:     if ((*s_objet_argument).type == INT)
 1900:     {
 1901:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 1902: 
 1903:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1904:         {
 1905:             liberation(s_etat_processus, s_objet_argument);
 1906: 
 1907:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 1908:             return;
 1909:         }
 1910: 
 1911:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
 1912:     }
 1913:     else if ((*s_objet_argument).type == LST)
 1914:     {
 1915:         l_element_courant = (*s_objet_argument).objet;
 1916: 
 1917:         while(l_element_courant)
 1918:         {
 1919:             if ((*(*l_element_courant).donnee).type != INT)
 1920:             {
 1921:                 liberation(s_etat_processus, s_objet_argument);
 1922: 
 1923:                 (*s_etat_processus).erreur_execution =
 1924:                         d_ex_erreur_type_argument;
 1925:                 return;
 1926:             }
 1927: 
 1928:             interruption = (*((integer8 *) (*(*l_element_courant)
 1929:                     .donnee).objet));
 1930: 
 1931:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1932:             {
 1933:                 liberation(s_etat_processus, s_objet_argument);
 1934: 
 1935:                 (*s_etat_processus).erreur_execution =
 1936:                         d_ex_interruption_invalide;
 1937:                 return;
 1938:             }
 1939: 
 1940:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
 1941:             l_element_courant = (*l_element_courant).suivant;
 1942:         }
 1943:     }
 1944:     else
 1945:     {
 1946:         liberation(s_etat_processus, s_objet_argument);
 1947: 
 1948:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1949:         return;
 1950:     }
 1951: 
 1952:     liberation(s_etat_processus, s_objet_argument);
 1953: 
 1954:     return;
 1955: }
 1956: 
 1957: 
 1958: /*
 1959: ================================================================================
 1960:   Fonction 'swistatus'
 1961: ================================================================================
 1962:   Entrées : structure processus
 1963: --------------------------------------------------------------------------------
 1964:   Sorties :
 1965: --------------------------------------------------------------------------------
 1966:   Effets de bord : néant
 1967: ================================================================================
 1968: */
 1969: 
 1970: void
 1971: instruction_swistatus(struct_processus *s_etat_processus)
 1972: {
 1973:     int                         i;
 1974: 
 1975:     struct_liste_chainee        *l_element_courant;
 1976:     struct_liste_chainee        *l_element_futur;
 1977:     struct_liste_chainee        *l_element_liste;
 1978: 
 1979:     struct_objet                *s_objet_resultat;
 1980: 
 1981:     (*s_etat_processus).erreur_execution = d_ex;
 1982: 
 1983:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1984:     {
 1985:         printf("\n  SWISTATUS ");
 1986: 
 1987:         if ((*s_etat_processus).langue == 'F')
 1988:         {
 1989:             printf("(état des interruptions logicielles)\n\n");
 1990:         }
 1991:         else
 1992:         {
 1993:             printf("(software interrupts status)\n\n");
 1994:         }
 1995: 
 1996:         printf("->  1: %s\n\n", d_LST);
 1997: 
 1998:         if ((*s_etat_processus).langue == 'F')
 1999:         {
 2000:             printf("  Utilisation :\n\n");
 2001:         }
 2002:         else
 2003:         {
 2004:             printf("  Usage:\n\n");
 2005:         }
 2006: 
 2007:         printf("    { { initialized interrupts }\n"
 2008:                 "      { unlocked interrupts }\n"
 2009:                 "      { queued interrupts }\n"
 2010:                 "      { locked interrupts } }\n");
 2011:         return;
 2012:     }
 2013:     else if ((*s_etat_processus).test_instruction == 'Y')
 2014:     {
 2015:         (*s_etat_processus).nombre_arguments = -1;
 2016:         return;
 2017:     }
 2018: 
 2019:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2020:     {
 2021:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 2022:         {
 2023:             return;
 2024:         }
 2025:     }
 2026: 
 2027:     if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
 2028:     {
 2029:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2030:         return;
 2031:     }
 2032: 
 2033:     if (((*s_objet_resultat).objet =
 2034:             allocation_maillon(s_etat_processus)) == NULL)
 2035:     {
 2036:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2037:         return;
 2038:     }
 2039: 
 2040:     l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
 2041: 
 2042:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2043:             == NULL)
 2044:     {
 2045:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2046:         return;
 2047:     }
 2048: 
 2049:     l_element_liste = NULL;
 2050:     l_element_futur = NULL;
 2051: 
 2052:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2053:     {
 2054:         if ((*s_etat_processus).corps_interruptions[i] != NULL)
 2055:         {
 2056:             if (l_element_liste == NULL)
 2057:             {
 2058:                 if ((l_element_liste =
 2059:                         allocation_maillon(s_etat_processus)) == NULL)
 2060:                 {
 2061:                     (*s_etat_processus).erreur_systeme =
 2062:                             d_es_allocation_memoire;
 2063:                     return;
 2064:                 }
 2065: 
 2066:                 l_element_futur = l_element_liste;
 2067:             }
 2068:             else
 2069:             {
 2070:                 if (((*l_element_liste).suivant =
 2071:                         allocation_maillon(s_etat_processus)) == NULL)
 2072:                 {
 2073:                     (*s_etat_processus).erreur_systeme =
 2074:                             d_es_allocation_memoire;
 2075:                     return;
 2076:                 }
 2077: 
 2078:                 l_element_liste = (*l_element_liste).suivant;
 2079:             }
 2080: 
 2081:             (*l_element_liste).suivant = NULL;
 2082: 
 2083:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2084:                     INT)) == NULL)
 2085:             {
 2086:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2087:                 return;
 2088:             }
 2089: 
 2090:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2091:         }
 2092:     }
 2093: 
 2094:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2095: 
 2096:     if (((*l_element_courant).suivant =
 2097:             allocation_maillon(s_etat_processus)) == NULL)
 2098:     {
 2099:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2100:         return;
 2101:     }
 2102: 
 2103:     l_element_courant = (*l_element_courant).suivant;
 2104: 
 2105:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2106:             == NULL)
 2107:     {
 2108:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2109:         return;
 2110:     }
 2111: 
 2112:     l_element_liste = NULL;
 2113:     l_element_futur = NULL;
 2114: 
 2115:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2116:     {
 2117:         if ((*s_etat_processus).masque_interruptions[i] == 'N')
 2118:         {
 2119:             if (l_element_liste == NULL)
 2120:             {
 2121:                 if ((l_element_liste =
 2122:                         allocation_maillon(s_etat_processus)) == NULL)
 2123:                 {
 2124:                     (*s_etat_processus).erreur_systeme =
 2125:                             d_es_allocation_memoire;
 2126:                     return;
 2127:                 }
 2128: 
 2129:                 l_element_futur = l_element_liste;
 2130:             }
 2131:             else
 2132:             {
 2133:                 if (((*l_element_liste).suivant =
 2134:                         allocation_maillon(s_etat_processus)) == NULL)
 2135:                 {
 2136:                     (*s_etat_processus).erreur_systeme =
 2137:                             d_es_allocation_memoire;
 2138:                     return;
 2139:                 }
 2140: 
 2141:                 l_element_liste = (*l_element_liste).suivant;
 2142:             }
 2143: 
 2144:             (*l_element_liste).suivant = NULL;
 2145: 
 2146:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2147:                     INT)) == NULL)
 2148:             {
 2149:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2150:                 return;
 2151:             }
 2152: 
 2153:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2154:         }
 2155:     }
 2156: 
 2157:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2158: 
 2159:     if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
 2160:             == NULL)
 2161:     {
 2162:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2163:         return;
 2164:     }
 2165: 
 2166:     l_element_courant = (*l_element_courant).suivant;
 2167: 
 2168:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2169:             == NULL)
 2170:     {
 2171:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2172:         return;
 2173:     }
 2174: 
 2175:     l_element_liste = NULL;
 2176:     l_element_futur = NULL;
 2177: 
 2178:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2179:     {
 2180:         if ((*s_etat_processus).masque_interruptions[i] == 'Q')
 2181:         {
 2182:             if (l_element_liste == NULL)
 2183:             {
 2184:                 if ((l_element_liste =
 2185:                         allocation_maillon(s_etat_processus)) == NULL)
 2186:                 {
 2187:                     (*s_etat_processus).erreur_systeme =
 2188:                             d_es_allocation_memoire;
 2189:                     return;
 2190:                 }
 2191: 
 2192:                 l_element_futur = l_element_liste;
 2193:             }
 2194:             else
 2195:             {
 2196:                 if (((*l_element_liste).suivant =
 2197:                         allocation_maillon(s_etat_processus)) == NULL)
 2198:                 {
 2199:                     (*s_etat_processus).erreur_systeme =
 2200:                             d_es_allocation_memoire;
 2201:                     return;
 2202:                 }
 2203: 
 2204:                 l_element_liste = (*l_element_liste).suivant;
 2205:             }
 2206: 
 2207:             (*l_element_liste).suivant = NULL;
 2208: 
 2209:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2210:                     INT)) == NULL)
 2211:             {
 2212:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2213:                 return;
 2214:             }
 2215: 
 2216:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2217:         }
 2218:     }
 2219: 
 2220:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2221: 
 2222:     if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
 2223:             == NULL)
 2224:     {
 2225:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2226:         return;
 2227:     }
 2228: 
 2229:     l_element_courant = (*l_element_courant).suivant;
 2230: 
 2231:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2232:             == NULL)
 2233:     {
 2234:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2235:         return;
 2236:     }
 2237: 
 2238:     l_element_liste = NULL;
 2239:     l_element_futur = NULL;
 2240: 
 2241:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2242:     {
 2243:         if ((*s_etat_processus).masque_interruptions[i] == 'I')
 2244:         {
 2245:             if (l_element_liste == NULL)
 2246:             {
 2247:                 if ((l_element_liste =
 2248:                         allocation_maillon(s_etat_processus)) == NULL)
 2249:                 {
 2250:                     (*s_etat_processus).erreur_systeme =
 2251:                             d_es_allocation_memoire;
 2252:                     return;
 2253:                 }
 2254: 
 2255:                 l_element_futur = l_element_liste;
 2256:             }
 2257:             else
 2258:             {
 2259:                 if (((*l_element_liste).suivant =
 2260:                         allocation_maillon(s_etat_processus)) == NULL)
 2261:                 {
 2262:                     (*s_etat_processus).erreur_systeme =
 2263:                             d_es_allocation_memoire;
 2264:                     return;
 2265:                 }
 2266: 
 2267:                 l_element_liste = (*l_element_liste).suivant;
 2268:             }
 2269: 
 2270:             (*l_element_liste).suivant = NULL;
 2271: 
 2272:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2273:                     INT)) == NULL)
 2274:             {
 2275:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2276:                 return;
 2277:             }
 2278: 
 2279:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2280:         }
 2281:     }
 2282: 
 2283:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2284: 
 2285:     (*l_element_courant).suivant = NULL;
 2286: 
 2287:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2288:             s_objet_resultat) == d_erreur)
 2289:     {
 2290:         return;
 2291:     }
 2292: 
 2293:     return;
 2294: }
 2295: 
 2296: 
 2297: /*
 2298: ================================================================================
 2299:   Fonction 'swiunlock'
 2300: ================================================================================
 2301:   Entrées : structure processus
 2302: --------------------------------------------------------------------------------
 2303:   Sorties :
 2304: --------------------------------------------------------------------------------
 2305:   Effets de bord : néant
 2306: ================================================================================
 2307: */
 2308: 
 2309: void
 2310: instruction_swiunlock(struct_processus *s_etat_processus)
 2311: {
 2312:     integer8                    interruption;
 2313: 
 2314:     struct_liste_chainee        *l_element_courant;
 2315: 
 2316:     struct_objet                *s_objet_argument;
 2317: 
 2318:     (*s_etat_processus).erreur_execution = d_ex;
 2319: 
 2320:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2321:     {
 2322:         printf("\n  SWIUNLOCK ");
 2323: 
 2324:         if ((*s_etat_processus).langue == 'F')
 2325:         {
 2326:             printf("(déverrouillage des interruptions logicielles)\n\n");
 2327:         }
 2328:         else
 2329:         {
 2330:             printf("(software interrupt unlock)\n\n");
 2331:         }
 2332: 
 2333:         printf("    1: %s, %s\n", d_INT, d_LST);
 2334: 
 2335:         return;
 2336:     }
 2337:     else if ((*s_etat_processus).test_instruction == 'Y')
 2338:     {
 2339:         (*s_etat_processus).nombre_arguments = -1;
 2340:         return;
 2341:     }
 2342: 
 2343:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2344:     {
 2345:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2346:         {
 2347:             return;
 2348:         }
 2349:     }
 2350: 
 2351:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2352:             &s_objet_argument) == d_erreur)
 2353:     {
 2354:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2355:         return;
 2356:     }
 2357: 
 2358:     if ((*s_objet_argument).type == INT)
 2359:     {
 2360:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 2361: 
 2362:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2363:         {
 2364:             liberation(s_etat_processus, s_objet_argument);
 2365: 
 2366:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 2367:             return;
 2368:         }
 2369: 
 2370:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
 2371:     }
 2372:     else if ((*s_objet_argument).type == LST)
 2373:     {
 2374:         l_element_courant = (*s_objet_argument).objet;
 2375: 
 2376:         while(l_element_courant)
 2377:         {
 2378:             if ((*(*l_element_courant).donnee).type != INT)
 2379:             {
 2380:                 liberation(s_etat_processus, s_objet_argument);
 2381: 
 2382:                 (*s_etat_processus).erreur_execution =
 2383:                         d_ex_erreur_type_argument;
 2384:                 return;
 2385:             }
 2386: 
 2387:             interruption = (*((integer8 *) (*(*l_element_courant)
 2388:                     .donnee).objet));
 2389: 
 2390:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2391:             {
 2392:                 liberation(s_etat_processus, s_objet_argument);
 2393: 
 2394:                 (*s_etat_processus).erreur_execution =
 2395:                         d_ex_interruption_invalide;
 2396:                 return;
 2397:             }
 2398: 
 2399:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
 2400:             l_element_courant = (*l_element_courant).suivant;
 2401:         }
 2402:     }
 2403:     else
 2404:     {
 2405:         liberation(s_etat_processus, s_objet_argument);
 2406: 
 2407:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2408:         return;
 2409:     }
 2410: 
 2411:     liberation(s_etat_processus, s_objet_argument);
 2412: 
 2413:     return;
 2414: }
 2415: 
 2416: 
 2417: /*
 2418: ================================================================================
 2419:   Fonction 'swiqueue'
 2420: ================================================================================
 2421:   Entrées : structure processus
 2422: --------------------------------------------------------------------------------
 2423:   Sorties :
 2424: --------------------------------------------------------------------------------
 2425:   Effets de bord : néant
 2426: ================================================================================
 2427: */
 2428: 
 2429: void
 2430: instruction_swiqueue(struct_processus *s_etat_processus)
 2431: {
 2432:     integer8                    interruption;
 2433: 
 2434:     struct_liste_chainee        *l_element_courant;
 2435: 
 2436:     struct_objet                *s_objet_argument;
 2437: 
 2438:     (*s_etat_processus).erreur_execution = d_ex;
 2439: 
 2440:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2441:     {
 2442:         printf("\n  SWIQUEUE ");
 2443: 
 2444:         if ((*s_etat_processus).langue == 'F')
 2445:         {
 2446:             printf("(enregistre des interruptions logicielles)\n\n");
 2447:         }
 2448:         else
 2449:         {
 2450:             printf("(software interrupt record)\n\n");
 2451:         }
 2452: 
 2453:         printf("    1: %s, %s\n", d_INT, d_LST);
 2454: 
 2455:         return;
 2456:     }
 2457:     else if ((*s_etat_processus).test_instruction == 'Y')
 2458:     {
 2459:         (*s_etat_processus).nombre_arguments = -1;
 2460:         return;
 2461:     }
 2462: 
 2463:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2464:     {
 2465:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2466:         {
 2467:             return;
 2468:         }
 2469:     }
 2470: 
 2471:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2472:             &s_objet_argument) == d_erreur)
 2473:     {
 2474:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2475:         return;
 2476:     }
 2477: 
 2478:     if ((*s_objet_argument).type == INT)
 2479:     {
 2480:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 2481: 
 2482:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2483:         {
 2484:             liberation(s_etat_processus, s_objet_argument);
 2485: 
 2486:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 2487:             return;
 2488:         }
 2489: 
 2490:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
 2491:     }
 2492:     else if ((*s_objet_argument).type == LST)
 2493:     {
 2494:         l_element_courant = (*s_objet_argument).objet;
 2495: 
 2496:         while(l_element_courant)
 2497:         {
 2498:             if ((*(*l_element_courant).donnee).type != INT)
 2499:             {
 2500:                 liberation(s_etat_processus, s_objet_argument);
 2501: 
 2502:                 (*s_etat_processus).erreur_execution =
 2503:                         d_ex_erreur_type_argument;
 2504:                 return;
 2505:             }
 2506: 
 2507:             interruption = (*((integer8 *) (*(*l_element_courant)
 2508:                     .donnee).objet));
 2509: 
 2510:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2511:             {
 2512:                 liberation(s_etat_processus, s_objet_argument);
 2513: 
 2514:                 (*s_etat_processus).erreur_execution =
 2515:                         d_ex_interruption_invalide;
 2516:                 return;
 2517:             }
 2518: 
 2519:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
 2520:             l_element_courant = (*l_element_courant).suivant;
 2521:         }
 2522:     }
 2523:     else
 2524:     {
 2525:         liberation(s_etat_processus, s_objet_argument);
 2526: 
 2527:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2528:         return;
 2529:     }
 2530: 
 2531:     liberation(s_etat_processus, s_objet_argument);
 2532: 
 2533:     return;
 2534: }
 2535: 
 2536: 
 2537: /*
 2538: ================================================================================
 2539:   Fonction 'sched'
 2540: ================================================================================
 2541:   Entrées : structure processus
 2542: --------------------------------------------------------------------------------
 2543:   Sorties :
 2544: --------------------------------------------------------------------------------
 2545:   Effets de bord : néant
 2546: ================================================================================
 2547: */
 2548: 
 2549: void
 2550: instruction_sched(struct_processus *s_etat_processus)
 2551: {
 2552:     real8                       pourcentage;
 2553: 
 2554:     struct_objet                *s_objet_argument;
 2555: 
 2556:     (*s_etat_processus).erreur_execution = d_ex;
 2557: 
 2558:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2559:     {
 2560:         printf("\n  SCHED ");
 2561: 
 2562:         if ((*s_etat_processus).langue == 'F')
 2563:         {
 2564:             printf("(limitation des ressources de calcul)\n\n");
 2565:         }
 2566:         else
 2567:         {
 2568:             printf("(CPU ressources limitation)\n\n");
 2569:         }
 2570: 
 2571:         printf("    1: %s, %s\n", d_INT, d_REL);
 2572: 
 2573:         return;
 2574:     }
 2575:     else if ((*s_etat_processus).test_instruction == 'Y')
 2576:     {
 2577:         (*s_etat_processus).nombre_arguments = -1;
 2578:         return;
 2579:     }
 2580: 
 2581:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2582:     {
 2583:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2584:         {
 2585:             return;
 2586:         }
 2587:     }
 2588: 
 2589:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2590:             &s_objet_argument) == d_erreur)
 2591:     {
 2592:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2593:         return;
 2594:     }
 2595: 
 2596:     if ((*s_objet_argument).type == INT)
 2597:     {
 2598:         pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
 2599:     }
 2600:     else if ((*s_objet_argument).type == REL)
 2601:     {
 2602:         pourcentage = (*((real8 *) (*s_objet_argument).objet));
 2603:     }
 2604:     else
 2605:     {
 2606:         liberation(s_etat_processus, s_objet_argument);
 2607: 
 2608:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2609:         return;
 2610:     }
 2611: 
 2612:     liberation(s_etat_processus, s_objet_argument);
 2613: 
 2614:     if ((pourcentage <= 0) || (pourcentage > 100))
 2615:     {
 2616:         (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
 2617:         return;
 2618:     }
 2619: 
 2620:     (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
 2621: 
 2622:     return;
 2623: }
 2624: 
 2625: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>