File:  [local] / rpl / src / instructions_s9.c
Revision 1.53: download - view: text, annotated - select for diffs - revision graph
Sun Oct 7 08:18:36 2012 UTC (11 years, 6 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Autre série de patches pour les variables statiques. Attention, il
reste une erreur de violation d'accès.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.11
    4:   Copyright (C) 1989-2012 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_etat_processus).autorisation_nom_implicite == 'N') &&
  764:                 ((*((struct_nom *) (*s_objet_1).objet)).symbole == d_faux))
  765:         {
  766:             liberation(s_etat_processus, s_objet_1);
  767:             liberation(s_etat_processus, s_objet_2);
  768: 
  769:             (*s_etat_processus).erreur_systeme = d_es;
  770:             (*s_etat_processus).erreur_execution =
  771:                     d_ex_creation_variable_globale;
  772:             return;
  773:         }
  774: 
  775:         if ((s_variable.nom = malloc((strlen((*((struct_nom *)
  776:                 (*s_objet_1).objet)).nom) + 1) * sizeof(unsigned char)))
  777:                 == NULL)
  778:         {
  779:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  780:             return;
  781:         }
  782: 
  783:         strcpy(s_variable.nom, (*((struct_nom *) (*s_objet_1).objet)).nom);
  784:         s_variable.niveau = 1;
  785: 
  786:         /*
  787:          * Le niveau 0 correspond aux définitions. Les variables
  788:          * commencent à 1 car elles sont toujours incluses dans
  789:          * une définition.
  790:          */
  791: 
  792:         s_variable.objet = s_objet_2;
  793: 
  794:         if (creation_variable(s_etat_processus, &s_variable, 'V', 'P')
  795:                 == d_erreur)
  796:         {
  797:             return;
  798:         }
  799: 
  800:         (*s_etat_processus).erreur_systeme = d_es;
  801:     }
  802: 
  803:     liberation(s_etat_processus, s_objet_1);
  804: 
  805:     return;
  806: }
  807: 
  808: 
  809: /*
  810: ================================================================================
  811:   Fonction 'suspend'
  812: ================================================================================
  813:   Entrées : structure processus
  814: --------------------------------------------------------------------------------
  815:   Sorties :
  816: --------------------------------------------------------------------------------
  817:   Effets de bord : néant
  818: ================================================================================
  819: */
  820: 
  821: void
  822: instruction_suspend(struct_processus *s_etat_processus)
  823: {
  824:     struct timespec             attente;
  825: 
  826:     (*s_etat_processus).erreur_execution = d_ex;
  827: 
  828:     if ((*s_etat_processus).affichage_arguments == 'Y')
  829:     {
  830:         printf("\n  SUSPEND ");
  831: 
  832:         if ((*s_etat_processus).langue == 'F')
  833:         {
  834:             printf("(attend un signal RPL/SIGCONT)\n\n");
  835:             printf("  Aucun argument\n");
  836:         }
  837:         else
  838:         {
  839:             printf("(wait for RPL/SIGCONT signal)\n\n");
  840:             printf("  No argument\n");
  841:         }
  842: 
  843:         return;
  844:     }
  845:     else if ((*s_etat_processus).test_instruction == 'Y')
  846:     {
  847:         (*s_etat_processus).nombre_arguments = -1;
  848:         return;
  849:     }
  850: 
  851:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  852:     {
  853:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  854:         {
  855:             return;
  856:         }
  857:     }
  858: 
  859:     if ((*s_etat_processus).profilage == d_vrai)
  860:     {
  861:         profilage(s_etat_processus, "Suspend");
  862: 
  863:         if ((*s_etat_processus).erreur_systeme != d_es)
  864:         {
  865:             return;
  866:         }
  867:     }
  868: 
  869: #   ifndef SEMAPHORES_NOMMES
  870:         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  871: #   else
  872:         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  873: #   endif
  874:     {
  875:         (*s_etat_processus).erreur_systeme = d_es_processus;
  876:         return;
  877:     }
  878: 
  879:     for((*s_etat_processus).redemarrage_processus = d_faux;;)
  880:     {
  881:         scrutation_interruptions(s_etat_processus);
  882: 
  883:         if ((*s_etat_processus).redemarrage_processus == d_vrai)
  884:         {
  885:             break;
  886:         }
  887: 
  888:         nanosleep(&attente, NULL);
  889:         INCR_GRANULARITE(attente.tv_nsec);
  890:     }
  891: 
  892: #   ifndef SEMAPHORES_NOMMES
  893:         while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
  894: #   else
  895:         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
  896: #   endif
  897:     {
  898:         if (errno != EINTR)
  899:         {
  900:             (*s_etat_processus).erreur_systeme = d_es_processus;
  901:             return;
  902:         }
  903:     }
  904: 
  905:     if ((*s_etat_processus).profilage == d_vrai)
  906:     {
  907:         profilage(s_etat_processus, NULL);
  908:     }
  909: 
  910:     return;
  911: }
  912: 
  913: 
  914: /*
  915: ================================================================================
  916:   Fonction 'static'
  917: ================================================================================
  918:   Entrées : structure processus
  919: --------------------------------------------------------------------------------
  920:   Sorties :
  921: --------------------------------------------------------------------------------
  922:   Effets de bord : néant
  923: ================================================================================
  924: */
  925: 
  926: void
  927: instruction_static(struct_processus *s_etat_processus)
  928: {
  929:     (*s_etat_processus).erreur_execution = d_ex;
  930: 
  931:     if ((*s_etat_processus).affichage_arguments == 'Y')
  932:     {
  933:         printf("\n  STATIC ");
  934: 
  935:         if ((*s_etat_processus).langue == 'F')
  936:         {
  937:             printf("(déclaration de variables statiques)\n\n");
  938:             printf("  Aucun argument\n");
  939:         }
  940:         else
  941:         {
  942:             printf("(static variables declaration)\n\n");
  943:             printf("  No argument\n");
  944:         }
  945: 
  946:         return;
  947:     }
  948:     else if ((*s_etat_processus).test_instruction == 'Y')
  949:     {
  950:         (*s_etat_processus).nombre_arguments = -1;
  951:         return;
  952:     }
  953:     
  954:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  955:     {
  956:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  957:         {
  958:             return;
  959:         }
  960:     }
  961: 
  962:     if ((*s_etat_processus).creation_variables_partagees == d_vrai)
  963:     {
  964:         (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
  965:         return;
  966:     }
  967: 
  968:     (*s_etat_processus).creation_variables_statiques = d_vrai;
  969: 
  970:     return;
  971: }
  972: 
  973: 
  974: /*
  975: ================================================================================
  976:   Fonction 'shared'
  977: ================================================================================
  978:   Entrées : structure processus
  979: --------------------------------------------------------------------------------
  980:   Sorties :
  981: --------------------------------------------------------------------------------
  982:   Effets de bord : néant
  983: ================================================================================
  984: */
  985: 
  986: void
  987: instruction_shared(struct_processus *s_etat_processus)
  988: {
  989:     (*s_etat_processus).erreur_execution = d_ex;
  990: 
  991:     if ((*s_etat_processus).affichage_arguments == 'Y')
  992:     {
  993:         printf("\n  SHARED ");
  994: 
  995:         if ((*s_etat_processus).langue == 'F')
  996:         {
  997:             printf("(déclaration de variables partagées)\n\n");
  998:             printf("  Aucun argument\n");
  999:         }
 1000:         else
 1001:         {
 1002:             printf("(shared variables declaration)\n\n");
 1003:             printf("  No argument\n");
 1004:         }
 1005: 
 1006:         return;
 1007:     }
 1008:     else if ((*s_etat_processus).test_instruction == 'Y')
 1009:     {
 1010:         (*s_etat_processus).nombre_arguments = -1;
 1011:         return;
 1012:     }
 1013:     
 1014:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1015:     {
 1016:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 1017:         {
 1018:             return;
 1019:         }
 1020:     }
 1021: 
 1022:     if ((*s_etat_processus).creation_variables_partagees == d_vrai)
 1023:     {
 1024:         (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
 1025:         return;
 1026:     }
 1027: 
 1028:     (*s_etat_processus).creation_variables_partagees = d_vrai;
 1029: 
 1030:     return;
 1031: }
 1032: 
 1033: 
 1034: /*
 1035: ================================================================================
 1036:   Fonction 'stoswi'
 1037: ================================================================================
 1038:   Entrées : structure processus
 1039: --------------------------------------------------------------------------------
 1040:   Sorties :
 1041: --------------------------------------------------------------------------------
 1042:   Effets de bord : néant
 1043: ================================================================================
 1044: */
 1045: 
 1046: void
 1047: instruction_stoswi(struct_processus *s_etat_processus)
 1048: {
 1049:     integer8                    interruption;
 1050: 
 1051:     struct_objet                *s_objet_argument_1;
 1052:     struct_objet                *s_objet_argument_2;
 1053: 
 1054:     (*s_etat_processus).erreur_execution = d_ex;
 1055: 
 1056:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1057:     {
 1058:         printf("\n  STOSWI ");
 1059: 
 1060:         if ((*s_etat_processus).langue == 'F')
 1061:         {
 1062:             printf("(définition d'une interruption logicielle)\n\n");
 1063:         }
 1064:         else
 1065:         {
 1066:             printf("(software interrupt definition)\n\n");
 1067:         }
 1068: 
 1069:         printf("    2: %s, %s\n", d_NOM, d_RPN);
 1070:         printf("    1: %s\n", d_INT);
 1071: 
 1072:         return;
 1073:     }
 1074:     else if ((*s_etat_processus).test_instruction == 'Y')
 1075:     {
 1076:         (*s_etat_processus).nombre_arguments = -1;
 1077:         return;
 1078:     }
 1079: 
 1080:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1081:     {
 1082:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
 1083:         {
 1084:             return;
 1085:         }
 1086:     }
 1087: 
 1088:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1089:             &s_objet_argument_1) == d_erreur)
 1090:     {
 1091:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1092:         return;
 1093:     }
 1094: 
 1095:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1096:             &s_objet_argument_2) == d_erreur)
 1097:     {
 1098:         liberation(s_etat_processus, s_objet_argument_1);
 1099: 
 1100:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1101:         return;
 1102:     }
 1103: 
 1104:     if ((*s_objet_argument_1).type == INT)
 1105:     {
 1106:         interruption = (*((integer8 *) (*s_objet_argument_1).objet));
 1107: 
 1108:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 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_interruption_invalide;
 1114:             return;
 1115:         }
 1116: 
 1117:         if ((*s_objet_argument_2).type == NOM)
 1118:         {
 1119:             liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
 1120:                     [interruption - 1]);
 1121:             (*s_etat_processus).corps_interruptions[interruption - 1] =
 1122:                     s_objet_argument_2;
 1123:         }
 1124:         else if((*s_objet_argument_2).type == RPN)
 1125:         {
 1126:             liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
 1127:                     [interruption - 1]);
 1128:             (*s_etat_processus).corps_interruptions[interruption - 1] =
 1129:                     s_objet_argument_2;
 1130:         }
 1131:         else
 1132:         {
 1133:             liberation(s_etat_processus, s_objet_argument_1);
 1134:             liberation(s_etat_processus, s_objet_argument_2);
 1135: 
 1136:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1137:             return;
 1138:         }
 1139:     }
 1140:     else
 1141:     {
 1142:         liberation(s_etat_processus, s_objet_argument_1);
 1143:         liberation(s_etat_processus, s_objet_argument_2);
 1144: 
 1145:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1146:         return;
 1147:     }
 1148: 
 1149:     liberation(s_etat_processus, s_objet_argument_1);
 1150: 
 1151:     return;
 1152: }
 1153: 
 1154: 
 1155: /*
 1156: ================================================================================
 1157:   Fonction 'swi'
 1158: ================================================================================
 1159:   Entrées : structure processus
 1160: --------------------------------------------------------------------------------
 1161:   Sorties :
 1162: --------------------------------------------------------------------------------
 1163:   Effets de bord : néant
 1164: ================================================================================
 1165: */
 1166: 
 1167: void
 1168: instruction_swi(struct_processus *s_etat_processus)
 1169: {
 1170:     int                         interruption_reduite;
 1171: 
 1172:     integer8                    interruption;
 1173: 
 1174:     pid_t                       pid;
 1175: 
 1176:     pthread_t                   tid;
 1177: 
 1178:     sig_atomic_t                registre;
 1179: 
 1180:     ssize_t                     longueur_ecriture;
 1181: 
 1182:     struct_objet                *s_objet_argument;
 1183: 
 1184:     struct timespec             attente;
 1185: 
 1186:     unsigned char               tampon;
 1187: 
 1188:     (*s_etat_processus).erreur_execution = d_ex;
 1189: 
 1190:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1191:     {
 1192:         printf("\n  SWI ");
 1193: 
 1194:         if ((*s_etat_processus).langue == 'F')
 1195:         {
 1196:             printf("(interruption logicielle)\n\n");
 1197:         }
 1198:         else
 1199:         {
 1200:             printf("(software interrupt)\n\n");
 1201:         }
 1202: 
 1203:         printf("    1: %s\n", d_INT);
 1204: 
 1205:         return;
 1206:     }
 1207:     else if ((*s_etat_processus).test_instruction == 'Y')
 1208:     {
 1209:         (*s_etat_processus).nombre_arguments = -1;
 1210:         return;
 1211:     }
 1212: 
 1213:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1214:     {
 1215:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1216:         {
 1217:             return;
 1218:         }
 1219:     }
 1220: 
 1221:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1222:             &s_objet_argument) == d_erreur)
 1223:     {
 1224:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1225:         return;
 1226:     }
 1227: 
 1228:     if ((*s_objet_argument).type == INT)
 1229:     {
 1230:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 1231: 
 1232:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1233:         {
 1234:             liberation(s_etat_processus, s_objet_argument);
 1235: 
 1236:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 1237:             return;
 1238:         }
 1239: 
 1240:         if ((*s_etat_processus).presence_pipes == d_faux)
 1241:         {
 1242:             liberation(s_etat_processus, s_objet_argument);
 1243: 
 1244:             (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 1245:             return;
 1246:         }
 1247: 
 1248:         // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
 1249:         // de surveillance.
 1250: 
 1251:         registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
 1252:         (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
 1253: 
 1254:         if ((*s_etat_processus).processus_detache == d_vrai)
 1255:         {
 1256:             pid = -1;
 1257: 
 1258:             attente.tv_sec = 0;
 1259:             attente.tv_nsec = GRANULARITE_us * 1000;
 1260: 
 1261: #           ifndef SEMAPHORES_NOMMES
 1262:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1263: #           else
 1264:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1265: #           endif
 1266:             {
 1267:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1268:                 return;
 1269:             }
 1270: 
 1271:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1272:                     (*s_etat_processus).pipe_nombre_objets_attente,
 1273:                     &pid, sizeof(pid))) != sizeof(pid))
 1274:             {
 1275: #               ifndef SEMAPHORES_NOMMES
 1276:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1277: #               else
 1278:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1279: #               endif
 1280:                 {
 1281:                     if (errno != EINTR)
 1282:                     {
 1283:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1284:                         return;
 1285:                     }
 1286:                 }
 1287: 
 1288:                 if (longueur_ecriture == -1)
 1289:                 {
 1290:                     if (registre == 0)
 1291:                     {
 1292:                         if ((*s_etat_processus)
 1293:                                 .var_volatile_traitement_retarde_stop == -1)
 1294:                         {
 1295:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1296:                         }
 1297: 
 1298:                         (*s_etat_processus)
 1299:                                 .var_volatile_traitement_retarde_stop
 1300:                                 = registre;
 1301:                     }
 1302: 
 1303:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1304:                     return;
 1305:                 }
 1306: 
 1307:                 nanosleep(&attente, NULL);
 1308:                 INCR_GRANULARITE(attente.tv_nsec);
 1309: 
 1310: #               ifndef SEMAPHORES_NOMMES
 1311:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1312: #               else
 1313:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1314: #               endif
 1315:                 {
 1316:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1317:                     return;
 1318:                 }
 1319:             }
 1320: 
 1321:             scrutation_interruptions(s_etat_processus);
 1322: 
 1323: #           ifndef SEMAPHORES_NOMMES
 1324:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1325: #           else
 1326:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1327: #           endif
 1328:             {
 1329:                 if (errno != EINTR)
 1330:                 {
 1331:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1332:                     return;
 1333:                 }
 1334:             }
 1335:         }
 1336:         else
 1337:         {
 1338:             tid = (pthread_t) -1;
 1339: 
 1340:             attente.tv_sec = 0;
 1341:             attente.tv_nsec = GRANULARITE_us * 1000;
 1342: 
 1343: #           ifndef SEMAPHORES_NOMMES
 1344:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1345: #           else
 1346:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1347: #           endif
 1348:             {
 1349:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1350:                 return;
 1351:             }
 1352: 
 1353:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1354:                     (*s_etat_processus).pipe_nombre_objets_attente,
 1355:                     &tid, sizeof(tid))) != sizeof(tid))
 1356:             {
 1357: #               ifndef SEMAPHORES_NOMMES
 1358:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1359: #               else
 1360:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1361: #               endif
 1362:                 {
 1363:                     if (errno != EINTR)
 1364:                     {
 1365:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1366:                         return;
 1367:                     }
 1368:                 }
 1369: 
 1370:                 if (longueur_ecriture == -1)
 1371:                 {
 1372:                     if (registre == 0)
 1373:                     {
 1374:                         if ((*s_etat_processus)
 1375:                                 .var_volatile_traitement_retarde_stop == -1)
 1376:                         {
 1377:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1378:                         }
 1379: 
 1380:                         (*s_etat_processus)
 1381:                                 .var_volatile_traitement_retarde_stop
 1382:                                 = registre;
 1383:                     }
 1384: 
 1385:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1386:                     return;
 1387:                 }
 1388: 
 1389:                 nanosleep(&attente, NULL);
 1390:                 INCR_GRANULARITE(attente.tv_nsec);
 1391: 
 1392: #               ifndef SEMAPHORES_NOMMES
 1393:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1394: #               else
 1395:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1396: #               endif
 1397:                 {
 1398:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1399:                     return;
 1400:                 }
 1401:             }
 1402: 
 1403:             scrutation_interruptions(s_etat_processus);
 1404: 
 1405: #           ifndef SEMAPHORES_NOMMES
 1406:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1407: #           else
 1408:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1409: #           endif
 1410:             {
 1411:                 if (errno != EINTR)
 1412:                 {
 1413:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1414:                     return;
 1415:                 }
 1416:             }
 1417:         }
 1418: 
 1419:         interruption_reduite = interruption;
 1420: 
 1421:         attente.tv_sec = 0;
 1422:         attente.tv_nsec = GRANULARITE_us * 1000;
 1423: 
 1424: #       ifndef SEMAPHORES_NOMMES
 1425:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1426: #       else
 1427:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1428: #       endif
 1429:         {
 1430:             (*s_etat_processus).erreur_systeme = d_es_processus;
 1431:             return;
 1432:         }
 1433: 
 1434:         while((longueur_ecriture = write_atomic(s_etat_processus,
 1435:                 (*s_etat_processus).pipe_interruptions,
 1436:                 &interruption_reduite, sizeof(interruption_reduite)))
 1437:                 != sizeof(interruption_reduite))
 1438:         {
 1439: #           ifndef SEMAPHORES_NOMMES
 1440:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1441: #           else
 1442:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1443: #           endif
 1444:             {
 1445:                 if (errno != EINTR)
 1446:                 {
 1447:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1448:                     return;
 1449:                 }
 1450:             }
 1451: 
 1452:             if (longueur_ecriture == -1)
 1453:             {
 1454:                 if (registre == 0)
 1455:                 {
 1456:                     if ((*s_etat_processus)
 1457:                             .var_volatile_traitement_retarde_stop == -1)
 1458:                     {
 1459:                         (*s_etat_processus).var_volatile_requete_arret = -1;
 1460:                     }
 1461: 
 1462:                     (*s_etat_processus)
 1463:                             .var_volatile_traitement_retarde_stop
 1464:                             = registre;
 1465:                 }
 1466: 
 1467:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1468:                 return;
 1469:             }
 1470: 
 1471:             nanosleep(&attente, NULL);
 1472:             INCR_GRANULARITE(attente.tv_nsec);
 1473: 
 1474: #           ifndef SEMAPHORES_NOMMES
 1475:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1476: #           else
 1477:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1478: #           endif
 1479:             {
 1480:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1481:                 return;
 1482:             }
 1483: 
 1484:             scrutation_interruptions(s_etat_processus);
 1485:         }
 1486: 
 1487: #       ifndef SEMAPHORES_NOMMES
 1488:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1489: #       else
 1490:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1491: #       endif
 1492:         {
 1493:             if (errno != EINTR)
 1494:             {
 1495:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1496:                 return;
 1497:             }
 1498:         }
 1499: 
 1500:         if ((*s_etat_processus).processus_detache == d_vrai)
 1501:         {
 1502:             pid = -3;
 1503: 
 1504:             attente.tv_sec = 0;
 1505:             attente.tv_nsec = GRANULARITE_us * 1000;
 1506: 
 1507: #           ifndef SEMAPHORES_NOMMES
 1508:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1509: #           else
 1510:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1511: #           endif
 1512:             {
 1513:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1514:                 return;
 1515:             }
 1516: 
 1517:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1518:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1519:                     &pid, sizeof(pid))) != sizeof(pid))
 1520:             {
 1521: #               ifndef SEMAPHORES_NOMMES
 1522:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1523: #               else
 1524:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1525: #               endif
 1526:                 {
 1527:                     if (errno != EINTR)
 1528:                     {
 1529:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1530:                         return;
 1531:                     }
 1532:                 }
 1533: 
 1534:                 if (longueur_ecriture == -1)
 1535:                 {
 1536:                     if (registre == 0)
 1537:                     {
 1538:                         if ((*s_etat_processus)
 1539:                                 .var_volatile_traitement_retarde_stop == -1)
 1540:                         {
 1541:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1542:                         }
 1543: 
 1544:                         (*s_etat_processus)
 1545:                                 .var_volatile_traitement_retarde_stop
 1546:                                 = registre;
 1547:                     }
 1548: 
 1549:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1550:                     return;
 1551:                 }
 1552: 
 1553:                 nanosleep(&attente, NULL);
 1554:                 INCR_GRANULARITE(attente.tv_nsec);
 1555: 
 1556: #               ifndef SEMAPHORES_NOMMES
 1557:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1558: #               else
 1559:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1560: #               endif
 1561:                 {
 1562:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1563:                     return;
 1564:                 }
 1565: 
 1566:                 scrutation_interruptions(s_etat_processus);
 1567:             }
 1568: 
 1569:             pid = getpid();
 1570: 
 1571:             attente.tv_sec = 0;
 1572:             attente.tv_nsec = GRANULARITE_us * 1000;
 1573: 
 1574:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1575:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1576:                     &pid, sizeof(pid))) != sizeof(pid))
 1577:             {
 1578: #               ifndef SEMAPHORES_NOMMES
 1579:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1580: #               else
 1581:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1582: #               endif
 1583:                 {
 1584:                     if (errno != EINTR)
 1585:                     {
 1586:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1587:                         return;
 1588:                     }
 1589:                 }
 1590: 
 1591:                 if (longueur_ecriture == -1)
 1592:                 {
 1593:                     if (registre == 0)
 1594:                     {
 1595:                         if ((*s_etat_processus)
 1596:                                 .var_volatile_traitement_retarde_stop == -1)
 1597:                         {
 1598:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1599:                         }
 1600: 
 1601:                         (*s_etat_processus)
 1602:                                 .var_volatile_traitement_retarde_stop
 1603:                                 = registre;
 1604:                     }
 1605: 
 1606:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1607:                     return;
 1608:                 }
 1609: 
 1610:                 nanosleep(&attente, NULL);
 1611:                 INCR_GRANULARITE(attente.tv_nsec);
 1612: 
 1613: #               ifndef SEMAPHORES_NOMMES
 1614:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1615: #               else
 1616:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1617: #               endif
 1618:                 {
 1619:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1620:                     return;
 1621:                 }
 1622:             }
 1623: 
 1624: #           ifndef SEMAPHORES_NOMMES
 1625:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1626: #           else
 1627:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1628: #           endif
 1629:             {
 1630:                 if (errno != EINTR)
 1631:                 {
 1632:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1633:                     return;
 1634:                 }
 1635:             }
 1636:         }
 1637:         else
 1638:         {
 1639:             tid = (pthread_t) -3;
 1640: 
 1641: #           ifndef SEMAPHORES_NOMMES
 1642:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1643: #           else
 1644:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1645: #           endif
 1646:             {
 1647:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1648:                 return;
 1649:             }
 1650: 
 1651:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1652:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1653:                     &tid, sizeof(tid))) != sizeof(tid))
 1654:             {
 1655: #               ifndef SEMAPHORES_NOMMES
 1656:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1657: #               else
 1658:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1659: #               endif
 1660:                 {
 1661:                     if (errno != EINTR)
 1662:                     {
 1663:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1664:                         return;
 1665:                     }
 1666:                 }
 1667: 
 1668:                 if (longueur_ecriture == -1)
 1669:                 {
 1670:                     if (registre == 0)
 1671:                     {
 1672:                         if ((*s_etat_processus)
 1673:                                 .var_volatile_traitement_retarde_stop == -1)
 1674:                         {
 1675:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1676:                         }
 1677: 
 1678:                         (*s_etat_processus)
 1679:                                 .var_volatile_traitement_retarde_stop
 1680:                                 = registre;
 1681:                     }
 1682: 
 1683:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1684:                     return;
 1685:                 }
 1686: 
 1687:                 nanosleep(&attente, NULL);
 1688:                 INCR_GRANULARITE(attente.tv_nsec);
 1689: 
 1690: #               ifndef SEMAPHORES_NOMMES
 1691:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1692: #               else
 1693:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1694: #               endif
 1695:                 {
 1696:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1697:                     return;
 1698:                 }
 1699: 
 1700:                 scrutation_interruptions(s_etat_processus);
 1701:             }
 1702: 
 1703:             tid = pthread_self();
 1704: 
 1705:             attente.tv_sec = 0;
 1706:             attente.tv_nsec = GRANULARITE_us * 1000;
 1707: 
 1708:             while((longueur_ecriture = write_atomic(s_etat_processus,
 1709:                     (*s_etat_processus).pipe_nombre_interruptions_attente,
 1710:                     &tid, sizeof(tid))) != sizeof(tid))
 1711:             {
 1712: #               ifndef SEMAPHORES_NOMMES
 1713:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1714: #               else
 1715:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1716: #               endif
 1717:                 {
 1718:                     if (errno != EINTR)
 1719:                     {
 1720:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1721:                         return;
 1722:                     }
 1723:                 }
 1724: 
 1725:                 if (longueur_ecriture == -1)
 1726: 
 1727:                 {
 1728:                     if (registre == 0)
 1729:                     {
 1730:                         if ((*s_etat_processus)
 1731:                                 .var_volatile_traitement_retarde_stop == -1)
 1732:                         {
 1733:                             (*s_etat_processus).var_volatile_requete_arret = -1;
 1734:                         }
 1735: 
 1736:                         (*s_etat_processus)
 1737:                                 .var_volatile_traitement_retarde_stop
 1738:                                 = registre;
 1739:                     }
 1740: 
 1741:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1742:                     return;
 1743:                 }
 1744: 
 1745:                 nanosleep(&attente, NULL);
 1746:                 INCR_GRANULARITE(attente.tv_nsec);
 1747: 
 1748: #               ifndef SEMAPHORES_NOMMES
 1749:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1750: #               else
 1751:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1752: #               endif
 1753:                 {
 1754:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1755:                     return;
 1756:                 }
 1757: 
 1758:                 scrutation_interruptions(s_etat_processus);
 1759:             }
 1760: 
 1761: #           ifndef SEMAPHORES_NOMMES
 1762:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1763: #           else
 1764:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1765: #           endif
 1766:             {
 1767:                 if (errno != EINTR)
 1768:                 {
 1769:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1770:                     return;
 1771:                 }
 1772:             }
 1773:         }
 1774: 
 1775:         attente.tv_sec = 0;
 1776:         attente.tv_nsec = GRANULARITE_us * 1000;
 1777: 
 1778: #       ifndef SEMAPHORES_NOMMES
 1779:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1780: #       else
 1781:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1782: #       endif
 1783:         {
 1784:             (*s_etat_processus).erreur_systeme = d_es_processus;
 1785:             return;
 1786:         }
 1787: 
 1788:         while(read_atomic(s_etat_processus,
 1789:                 (*s_etat_processus).pipe_acquittement,
 1790:                 &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
 1791:         {
 1792: #           ifndef SEMAPHORES_NOMMES
 1793:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1794: #           else
 1795:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1796: #           endif
 1797:             {
 1798:                 if (errno != EINTR)
 1799:                 {
 1800:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1801:                     return;
 1802:                 }
 1803:             }
 1804: 
 1805:             nanosleep(&attente, NULL);
 1806:             INCR_GRANULARITE(attente.tv_nsec);
 1807: 
 1808: #           ifndef SEMAPHORES_NOMMES
 1809:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1810: #           else
 1811:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1812: #           endif
 1813:             {
 1814:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1815:                 return;
 1816:             }
 1817: 
 1818:             scrutation_interruptions(s_etat_processus);
 1819:         }
 1820: 
 1821: #       ifndef SEMAPHORES_NOMMES
 1822:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1823: #       else
 1824:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1825: #       endif
 1826:         {
 1827:             if (errno != EINTR)
 1828:             {
 1829:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1830:                 return;
 1831:             }
 1832:         }
 1833: 
 1834:         if (registre == 0)
 1835:         {
 1836:             if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
 1837:             {
 1838:                 (*s_etat_processus).var_volatile_requete_arret = -1;
 1839:             }
 1840: 
 1841:             (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
 1842:         }
 1843:     }
 1844:     else
 1845:     {
 1846:         liberation(s_etat_processus, s_objet_argument);
 1847: 
 1848:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1849:         return;
 1850:     }
 1851: 
 1852:     liberation(s_etat_processus, s_objet_argument);
 1853: 
 1854:     return;
 1855: }
 1856: 
 1857: 
 1858: /*
 1859: ================================================================================
 1860:   Fonction 'swilock'
 1861: ================================================================================
 1862:   Entrées : structure processus
 1863: --------------------------------------------------------------------------------
 1864:   Sorties :
 1865: --------------------------------------------------------------------------------
 1866:   Effets de bord : néant
 1867: ================================================================================
 1868: */
 1869: 
 1870: void
 1871: instruction_swilock(struct_processus *s_etat_processus)
 1872: {
 1873:     integer8                    interruption;
 1874: 
 1875:     struct_liste_chainee        *l_element_courant;
 1876: 
 1877:     struct_objet                *s_objet_argument;
 1878: 
 1879:     (*s_etat_processus).erreur_execution = d_ex;
 1880: 
 1881:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1882:     {
 1883:         printf("\n  SWILOCK ");
 1884: 
 1885:         if ((*s_etat_processus).langue == 'F')
 1886:         {
 1887:             printf("(verrouillage des interruptions logicielles)\n\n");
 1888:         }
 1889:         else
 1890:         {
 1891:             printf("(software interrupt lock)\n\n");
 1892:         }
 1893: 
 1894:         printf("    1: %s, %s\n", d_INT, d_LST);
 1895: 
 1896:         return;
 1897:     }
 1898:     else if ((*s_etat_processus).test_instruction == 'Y')
 1899:     {
 1900:         (*s_etat_processus).nombre_arguments = -1;
 1901:         return;
 1902:     }
 1903: 
 1904:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1905:     {
 1906:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1907:         {
 1908:             return;
 1909:         }
 1910:     }
 1911: 
 1912:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1913:             &s_objet_argument) == d_erreur)
 1914:     {
 1915:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1916:         return;
 1917:     }
 1918: 
 1919:     if ((*s_objet_argument).type == INT)
 1920:     {
 1921:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 1922: 
 1923:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1924:         {
 1925:             liberation(s_etat_processus, s_objet_argument);
 1926: 
 1927:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 1928:             return;
 1929:         }
 1930: 
 1931:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
 1932:     }
 1933:     else if ((*s_objet_argument).type == LST)
 1934:     {
 1935:         l_element_courant = (*s_objet_argument).objet;
 1936: 
 1937:         while(l_element_courant)
 1938:         {
 1939:             if ((*(*l_element_courant).donnee).type != INT)
 1940:             {
 1941:                 liberation(s_etat_processus, s_objet_argument);
 1942: 
 1943:                 (*s_etat_processus).erreur_execution =
 1944:                         d_ex_erreur_type_argument;
 1945:                 return;
 1946:             }
 1947: 
 1948:             interruption = (*((integer8 *) (*(*l_element_courant)
 1949:                     .donnee).objet));
 1950: 
 1951:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 1952:             {
 1953:                 liberation(s_etat_processus, s_objet_argument);
 1954: 
 1955:                 (*s_etat_processus).erreur_execution =
 1956:                         d_ex_interruption_invalide;
 1957:                 return;
 1958:             }
 1959: 
 1960:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
 1961:             l_element_courant = (*l_element_courant).suivant;
 1962:         }
 1963:     }
 1964:     else
 1965:     {
 1966:         liberation(s_etat_processus, s_objet_argument);
 1967: 
 1968:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1969:         return;
 1970:     }
 1971: 
 1972:     liberation(s_etat_processus, s_objet_argument);
 1973: 
 1974:     return;
 1975: }
 1976: 
 1977: 
 1978: /*
 1979: ================================================================================
 1980:   Fonction 'swistatus'
 1981: ================================================================================
 1982:   Entrées : structure processus
 1983: --------------------------------------------------------------------------------
 1984:   Sorties :
 1985: --------------------------------------------------------------------------------
 1986:   Effets de bord : néant
 1987: ================================================================================
 1988: */
 1989: 
 1990: void
 1991: instruction_swistatus(struct_processus *s_etat_processus)
 1992: {
 1993:     int                         i;
 1994: 
 1995:     struct_liste_chainee        *l_element_courant;
 1996:     struct_liste_chainee        *l_element_futur;
 1997:     struct_liste_chainee        *l_element_liste;
 1998: 
 1999:     struct_objet                *s_objet_resultat;
 2000: 
 2001:     (*s_etat_processus).erreur_execution = d_ex;
 2002: 
 2003:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2004:     {
 2005:         printf("\n  SWISTATUS ");
 2006: 
 2007:         if ((*s_etat_processus).langue == 'F')
 2008:         {
 2009:             printf("(état des interruptions logicielles)\n\n");
 2010:         }
 2011:         else
 2012:         {
 2013:             printf("(software interrupts status)\n\n");
 2014:         }
 2015: 
 2016:         printf("->  1: %s\n\n", d_LST);
 2017: 
 2018:         if ((*s_etat_processus).langue == 'F')
 2019:         {
 2020:             printf("  Utilisation :\n\n");
 2021:         }
 2022:         else
 2023:         {
 2024:             printf("  Usage:\n\n");
 2025:         }
 2026: 
 2027:         printf("    { { initialized interrupts }\n"
 2028:                 "      { unlocked interrupts }\n"
 2029:                 "      { queued interrupts }\n"
 2030:                 "      { locked interrupts } }\n");
 2031:         return;
 2032:     }
 2033:     else if ((*s_etat_processus).test_instruction == 'Y')
 2034:     {
 2035:         (*s_etat_processus).nombre_arguments = -1;
 2036:         return;
 2037:     }
 2038: 
 2039:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2040:     {
 2041:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 2042:         {
 2043:             return;
 2044:         }
 2045:     }
 2046: 
 2047:     if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
 2048:     {
 2049:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2050:         return;
 2051:     }
 2052: 
 2053:     if (((*s_objet_resultat).objet =
 2054:             allocation_maillon(s_etat_processus)) == NULL)
 2055:     {
 2056:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2057:         return;
 2058:     }
 2059: 
 2060:     l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
 2061: 
 2062:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2063:             == NULL)
 2064:     {
 2065:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2066:         return;
 2067:     }
 2068: 
 2069:     l_element_liste = NULL;
 2070:     l_element_futur = NULL;
 2071: 
 2072:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2073:     {
 2074:         if ((*s_etat_processus).corps_interruptions[i] != NULL)
 2075:         {
 2076:             if (l_element_liste == NULL)
 2077:             {
 2078:                 if ((l_element_liste =
 2079:                         allocation_maillon(s_etat_processus)) == NULL)
 2080:                 {
 2081:                     (*s_etat_processus).erreur_systeme =
 2082:                             d_es_allocation_memoire;
 2083:                     return;
 2084:                 }
 2085: 
 2086:                 l_element_futur = l_element_liste;
 2087:             }
 2088:             else
 2089:             {
 2090:                 if (((*l_element_liste).suivant =
 2091:                         allocation_maillon(s_etat_processus)) == NULL)
 2092:                 {
 2093:                     (*s_etat_processus).erreur_systeme =
 2094:                             d_es_allocation_memoire;
 2095:                     return;
 2096:                 }
 2097: 
 2098:                 l_element_liste = (*l_element_liste).suivant;
 2099:             }
 2100: 
 2101:             (*l_element_liste).suivant = NULL;
 2102: 
 2103:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2104:                     INT)) == NULL)
 2105:             {
 2106:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2107:                 return;
 2108:             }
 2109: 
 2110:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2111:         }
 2112:     }
 2113: 
 2114:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2115: 
 2116:     if (((*l_element_courant).suivant =
 2117:             allocation_maillon(s_etat_processus)) == NULL)
 2118:     {
 2119:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2120:         return;
 2121:     }
 2122: 
 2123:     l_element_courant = (*l_element_courant).suivant;
 2124: 
 2125:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2126:             == NULL)
 2127:     {
 2128:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2129:         return;
 2130:     }
 2131: 
 2132:     l_element_liste = NULL;
 2133:     l_element_futur = NULL;
 2134: 
 2135:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2136:     {
 2137:         if ((*s_etat_processus).masque_interruptions[i] == 'N')
 2138:         {
 2139:             if (l_element_liste == NULL)
 2140:             {
 2141:                 if ((l_element_liste =
 2142:                         allocation_maillon(s_etat_processus)) == NULL)
 2143:                 {
 2144:                     (*s_etat_processus).erreur_systeme =
 2145:                             d_es_allocation_memoire;
 2146:                     return;
 2147:                 }
 2148: 
 2149:                 l_element_futur = l_element_liste;
 2150:             }
 2151:             else
 2152:             {
 2153:                 if (((*l_element_liste).suivant =
 2154:                         allocation_maillon(s_etat_processus)) == NULL)
 2155:                 {
 2156:                     (*s_etat_processus).erreur_systeme =
 2157:                             d_es_allocation_memoire;
 2158:                     return;
 2159:                 }
 2160: 
 2161:                 l_element_liste = (*l_element_liste).suivant;
 2162:             }
 2163: 
 2164:             (*l_element_liste).suivant = NULL;
 2165: 
 2166:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2167:                     INT)) == NULL)
 2168:             {
 2169:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2170:                 return;
 2171:             }
 2172: 
 2173:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2174:         }
 2175:     }
 2176: 
 2177:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2178: 
 2179:     if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
 2180:             == NULL)
 2181:     {
 2182:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2183:         return;
 2184:     }
 2185: 
 2186:     l_element_courant = (*l_element_courant).suivant;
 2187: 
 2188:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2189:             == NULL)
 2190:     {
 2191:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2192:         return;
 2193:     }
 2194: 
 2195:     l_element_liste = NULL;
 2196:     l_element_futur = NULL;
 2197: 
 2198:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2199:     {
 2200:         if ((*s_etat_processus).masque_interruptions[i] == 'Q')
 2201:         {
 2202:             if (l_element_liste == NULL)
 2203:             {
 2204:                 if ((l_element_liste =
 2205:                         allocation_maillon(s_etat_processus)) == NULL)
 2206:                 {
 2207:                     (*s_etat_processus).erreur_systeme =
 2208:                             d_es_allocation_memoire;
 2209:                     return;
 2210:                 }
 2211: 
 2212:                 l_element_futur = l_element_liste;
 2213:             }
 2214:             else
 2215:             {
 2216:                 if (((*l_element_liste).suivant =
 2217:                         allocation_maillon(s_etat_processus)) == NULL)
 2218:                 {
 2219:                     (*s_etat_processus).erreur_systeme =
 2220:                             d_es_allocation_memoire;
 2221:                     return;
 2222:                 }
 2223: 
 2224:                 l_element_liste = (*l_element_liste).suivant;
 2225:             }
 2226: 
 2227:             (*l_element_liste).suivant = NULL;
 2228: 
 2229:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2230:                     INT)) == NULL)
 2231:             {
 2232:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2233:                 return;
 2234:             }
 2235: 
 2236:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2237:         }
 2238:     }
 2239: 
 2240:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2241: 
 2242:     if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
 2243:             == NULL)
 2244:     {
 2245:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2246:         return;
 2247:     }
 2248: 
 2249:     l_element_courant = (*l_element_courant).suivant;
 2250: 
 2251:     if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
 2252:             == NULL)
 2253:     {
 2254:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2255:         return;
 2256:     }
 2257: 
 2258:     l_element_liste = NULL;
 2259:     l_element_futur = NULL;
 2260: 
 2261:     for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
 2262:     {
 2263:         if ((*s_etat_processus).masque_interruptions[i] == 'I')
 2264:         {
 2265:             if (l_element_liste == NULL)
 2266:             {
 2267:                 if ((l_element_liste =
 2268:                         allocation_maillon(s_etat_processus)) == NULL)
 2269:                 {
 2270:                     (*s_etat_processus).erreur_systeme =
 2271:                             d_es_allocation_memoire;
 2272:                     return;
 2273:                 }
 2274: 
 2275:                 l_element_futur = l_element_liste;
 2276:             }
 2277:             else
 2278:             {
 2279:                 if (((*l_element_liste).suivant =
 2280:                         allocation_maillon(s_etat_processus)) == NULL)
 2281:                 {
 2282:                     (*s_etat_processus).erreur_systeme =
 2283:                             d_es_allocation_memoire;
 2284:                     return;
 2285:                 }
 2286: 
 2287:                 l_element_liste = (*l_element_liste).suivant;
 2288:             }
 2289: 
 2290:             (*l_element_liste).suivant = NULL;
 2291: 
 2292:             if (((*l_element_liste).donnee = allocation(s_etat_processus,
 2293:                     INT)) == NULL)
 2294:             {
 2295:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2296:                 return;
 2297:             }
 2298: 
 2299:             (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
 2300:         }
 2301:     }
 2302: 
 2303:     (*(*l_element_courant).donnee).objet = l_element_futur;
 2304: 
 2305:     (*l_element_courant).suivant = NULL;
 2306: 
 2307:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2308:             s_objet_resultat) == d_erreur)
 2309:     {
 2310:         return;
 2311:     }
 2312: 
 2313:     return;
 2314: }
 2315: 
 2316: 
 2317: /*
 2318: ================================================================================
 2319:   Fonction 'swiunlock'
 2320: ================================================================================
 2321:   Entrées : structure processus
 2322: --------------------------------------------------------------------------------
 2323:   Sorties :
 2324: --------------------------------------------------------------------------------
 2325:   Effets de bord : néant
 2326: ================================================================================
 2327: */
 2328: 
 2329: void
 2330: instruction_swiunlock(struct_processus *s_etat_processus)
 2331: {
 2332:     integer8                    interruption;
 2333: 
 2334:     struct_liste_chainee        *l_element_courant;
 2335: 
 2336:     struct_objet                *s_objet_argument;
 2337: 
 2338:     (*s_etat_processus).erreur_execution = d_ex;
 2339: 
 2340:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2341:     {
 2342:         printf("\n  SWIUNLOCK ");
 2343: 
 2344:         if ((*s_etat_processus).langue == 'F')
 2345:         {
 2346:             printf("(déverrouillage des interruptions logicielles)\n\n");
 2347:         }
 2348:         else
 2349:         {
 2350:             printf("(software interrupt unlock)\n\n");
 2351:         }
 2352: 
 2353:         printf("    1: %s, %s\n", d_INT, d_LST);
 2354: 
 2355:         return;
 2356:     }
 2357:     else if ((*s_etat_processus).test_instruction == 'Y')
 2358:     {
 2359:         (*s_etat_processus).nombre_arguments = -1;
 2360:         return;
 2361:     }
 2362: 
 2363:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2364:     {
 2365:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2366:         {
 2367:             return;
 2368:         }
 2369:     }
 2370: 
 2371:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2372:             &s_objet_argument) == d_erreur)
 2373:     {
 2374:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2375:         return;
 2376:     }
 2377: 
 2378:     if ((*s_objet_argument).type == INT)
 2379:     {
 2380:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 2381: 
 2382:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2383:         {
 2384:             liberation(s_etat_processus, s_objet_argument);
 2385: 
 2386:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 2387:             return;
 2388:         }
 2389: 
 2390:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
 2391:     }
 2392:     else if ((*s_objet_argument).type == LST)
 2393:     {
 2394:         l_element_courant = (*s_objet_argument).objet;
 2395: 
 2396:         while(l_element_courant)
 2397:         {
 2398:             if ((*(*l_element_courant).donnee).type != INT)
 2399:             {
 2400:                 liberation(s_etat_processus, s_objet_argument);
 2401: 
 2402:                 (*s_etat_processus).erreur_execution =
 2403:                         d_ex_erreur_type_argument;
 2404:                 return;
 2405:             }
 2406: 
 2407:             interruption = (*((integer8 *) (*(*l_element_courant)
 2408:                     .donnee).objet));
 2409: 
 2410:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2411:             {
 2412:                 liberation(s_etat_processus, s_objet_argument);
 2413: 
 2414:                 (*s_etat_processus).erreur_execution =
 2415:                         d_ex_interruption_invalide;
 2416:                 return;
 2417:             }
 2418: 
 2419:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
 2420:             l_element_courant = (*l_element_courant).suivant;
 2421:         }
 2422:     }
 2423:     else
 2424:     {
 2425:         liberation(s_etat_processus, s_objet_argument);
 2426: 
 2427:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2428:         return;
 2429:     }
 2430: 
 2431:     liberation(s_etat_processus, s_objet_argument);
 2432: 
 2433:     return;
 2434: }
 2435: 
 2436: 
 2437: /*
 2438: ================================================================================
 2439:   Fonction 'swiqueue'
 2440: ================================================================================
 2441:   Entrées : structure processus
 2442: --------------------------------------------------------------------------------
 2443:   Sorties :
 2444: --------------------------------------------------------------------------------
 2445:   Effets de bord : néant
 2446: ================================================================================
 2447: */
 2448: 
 2449: void
 2450: instruction_swiqueue(struct_processus *s_etat_processus)
 2451: {
 2452:     integer8                    interruption;
 2453: 
 2454:     struct_liste_chainee        *l_element_courant;
 2455: 
 2456:     struct_objet                *s_objet_argument;
 2457: 
 2458:     (*s_etat_processus).erreur_execution = d_ex;
 2459: 
 2460:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2461:     {
 2462:         printf("\n  SWIQUEUE ");
 2463: 
 2464:         if ((*s_etat_processus).langue == 'F')
 2465:         {
 2466:             printf("(enregistre des interruptions logicielles)\n\n");
 2467:         }
 2468:         else
 2469:         {
 2470:             printf("(software interrupt record)\n\n");
 2471:         }
 2472: 
 2473:         printf("    1: %s, %s\n", d_INT, d_LST);
 2474: 
 2475:         return;
 2476:     }
 2477:     else if ((*s_etat_processus).test_instruction == 'Y')
 2478:     {
 2479:         (*s_etat_processus).nombre_arguments = -1;
 2480:         return;
 2481:     }
 2482: 
 2483:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2484:     {
 2485:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2486:         {
 2487:             return;
 2488:         }
 2489:     }
 2490: 
 2491:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2492:             &s_objet_argument) == d_erreur)
 2493:     {
 2494:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2495:         return;
 2496:     }
 2497: 
 2498:     if ((*s_objet_argument).type == INT)
 2499:     {
 2500:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 2501: 
 2502:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2503:         {
 2504:             liberation(s_etat_processus, s_objet_argument);
 2505: 
 2506:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 2507:             return;
 2508:         }
 2509: 
 2510:         (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
 2511:     }
 2512:     else if ((*s_objet_argument).type == LST)
 2513:     {
 2514:         l_element_courant = (*s_objet_argument).objet;
 2515: 
 2516:         while(l_element_courant)
 2517:         {
 2518:             if ((*(*l_element_courant).donnee).type != INT)
 2519:             {
 2520:                 liberation(s_etat_processus, s_objet_argument);
 2521: 
 2522:                 (*s_etat_processus).erreur_execution =
 2523:                         d_ex_erreur_type_argument;
 2524:                 return;
 2525:             }
 2526: 
 2527:             interruption = (*((integer8 *) (*(*l_element_courant)
 2528:                     .donnee).objet));
 2529: 
 2530:             if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 2531:             {
 2532:                 liberation(s_etat_processus, s_objet_argument);
 2533: 
 2534:                 (*s_etat_processus).erreur_execution =
 2535:                         d_ex_interruption_invalide;
 2536:                 return;
 2537:             }
 2538: 
 2539:             (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
 2540:             l_element_courant = (*l_element_courant).suivant;
 2541:         }
 2542:     }
 2543:     else
 2544:     {
 2545:         liberation(s_etat_processus, s_objet_argument);
 2546: 
 2547:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2548:         return;
 2549:     }
 2550: 
 2551:     liberation(s_etat_processus, s_objet_argument);
 2552: 
 2553:     return;
 2554: }
 2555: 
 2556: 
 2557: /*
 2558: ================================================================================
 2559:   Fonction 'sched'
 2560: ================================================================================
 2561:   Entrées : structure processus
 2562: --------------------------------------------------------------------------------
 2563:   Sorties :
 2564: --------------------------------------------------------------------------------
 2565:   Effets de bord : néant
 2566: ================================================================================
 2567: */
 2568: 
 2569: void
 2570: instruction_sched(struct_processus *s_etat_processus)
 2571: {
 2572:     real8                       pourcentage;
 2573: 
 2574:     struct_objet                *s_objet_argument;
 2575: 
 2576:     (*s_etat_processus).erreur_execution = d_ex;
 2577: 
 2578:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2579:     {
 2580:         printf("\n  SCHED ");
 2581: 
 2582:         if ((*s_etat_processus).langue == 'F')
 2583:         {
 2584:             printf("(limitation des ressources de calcul)\n\n");
 2585:         }
 2586:         else
 2587:         {
 2588:             printf("(CPU ressources limitation)\n\n");
 2589:         }
 2590: 
 2591:         printf("    1: %s, %s\n", d_INT, d_REL);
 2592: 
 2593:         return;
 2594:     }
 2595:     else if ((*s_etat_processus).test_instruction == 'Y')
 2596:     {
 2597:         (*s_etat_processus).nombre_arguments = -1;
 2598:         return;
 2599:     }
 2600: 
 2601:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2602:     {
 2603:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2604:         {
 2605:             return;
 2606:         }
 2607:     }
 2608: 
 2609:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2610:             &s_objet_argument) == d_erreur)
 2611:     {
 2612:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2613:         return;
 2614:     }
 2615: 
 2616:     if ((*s_objet_argument).type == INT)
 2617:     {
 2618:         pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
 2619:     }
 2620:     else if ((*s_objet_argument).type == REL)
 2621:     {
 2622:         pourcentage = (*((real8 *) (*s_objet_argument).objet));
 2623:     }
 2624:     else
 2625:     {
 2626:         liberation(s_etat_processus, s_objet_argument);
 2627: 
 2628:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2629:         return;
 2630:     }
 2631: 
 2632:     liberation(s_etat_processus, s_objet_argument);
 2633: 
 2634:     if ((pourcentage <= 0) || (pourcentage > 100))
 2635:     {
 2636:         (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
 2637:         return;
 2638:     }
 2639: 
 2640:     (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
 2641: 
 2642:     return;
 2643: }
 2644: 
 2645: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>