File:  [local] / rpl / src / instructions_s9.c
Revision 1.38: download - view: text, annotated - select for diffs - revision graph
Wed Sep 14 17:55:59 2011 UTC (12 years, 7 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Suite des patches...

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

CVSweb interface <joel.bertrand@systella.fr>