File:  [local] / rpl / src / instructions_w1.c
Revision 1.30: download - view: text, annotated - select for diffs - revision graph
Sun Dec 12 14:13:39 2010 UTC (13 years, 4 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Tentative de correction d'une corruption du tas.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.20
    4:   Copyright (C) 1989-2010 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'while'
   29: ================================================================================
   30:   Entrées :
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_while(struct_processus *s_etat_processus)
   40: {
   41:     (*s_etat_processus).erreur_execution = d_ex;
   42: 
   43:     if ((*s_etat_processus).affichage_arguments == 'Y')
   44:     {
   45:         printf("\n  WHILE ");
   46: 
   47:         if ((*s_etat_processus).langue == 'F')
   48:         {
   49:             printf("(structure de contrôle)\n\n");
   50:             printf("  Utilisation :\n\n");
   51:         }
   52:         else
   53:         {
   54:             printf("(control statement)\n\n");
   55:             printf("  Usage:\n\n");
   56:         }
   57: 
   58:         printf("    WHILE\n");
   59:         printf("        (clause)\n");
   60:         printf("    REPEAT\n");
   61:         printf("        (expression 1)\n");
   62:         printf("        EXIT\n");
   63:         printf("        (expression 2)\n");
   64:         printf("    END\n\n");
   65: 
   66:         printf("    WHILE\n");
   67:         printf("        (clause)\n");
   68:         printf("    REPEAT\n");
   69:         printf("        (expression)\n");
   70:         printf("    END\n");
   71: 
   72:         return;
   73:     }
   74:     else if ((*s_etat_processus).test_instruction == 'Y')
   75:     {
   76:         (*s_etat_processus).nombre_arguments = -1;
   77:         return;
   78:     }
   79: 
   80:     empilement_pile_systeme(s_etat_processus);
   81: 
   82:     if ((*s_etat_processus).erreur_systeme != d_es)
   83:     {
   84:         return;
   85:     }
   86: 
   87:     (*(*s_etat_processus).l_base_pile_systeme).type_cloture = 'W';
   88:     (*(*s_etat_processus).l_base_pile_systeme).clause = 'W';
   89: 
   90:     if ((*s_etat_processus).mode_execution_programme == 'Y')
   91:     {
   92:         (*(*s_etat_processus).l_base_pile_systeme).adresse_retour =
   93:                 (*s_etat_processus).position_courante;
   94:     }
   95:     else
   96:     {
   97:         if ((*s_etat_processus).expression_courante == NULL)
   98:         {
   99:             (*s_etat_processus).erreur_execution =
  100:                     d_ex_erreur_traitement_boucle;
  101:             return;
  102:         }
  103: 
  104:         (*(*s_etat_processus).l_base_pile_systeme).pointeur_objet_retour =
  105:                 (*s_etat_processus).expression_courante;
  106:     }
  107: 
  108:     return;
  109: }
  110: 
  111: 
  112: /*
  113: ================================================================================
  114:   Fonction 'warranty'
  115: ================================================================================
  116:   Entrées :
  117: --------------------------------------------------------------------------------
  118:   Sorties :
  119: --------------------------------------------------------------------------------
  120:   Effets de bord : néant
  121: ================================================================================
  122: */
  123: 
  124: void
  125: instruction_warranty(struct_processus *s_etat_processus)
  126: {
  127: #   include                 "garanties-conv.h"
  128: 
  129:     (*s_etat_processus).erreur_execution = d_ex;
  130: 
  131:     if ((*s_etat_processus).affichage_arguments == 'Y')
  132:     {
  133:         printf("\n  WARRANTY ");
  134: 
  135:         if ((*s_etat_processus).langue == 'F')
  136:         {
  137:             printf("(garantie)\n\n");
  138:             printf("  Aucun argument\n");
  139:         }
  140:         else
  141:         {
  142:             printf("(warranty)\n\n");
  143:             printf("  No argument\n");
  144:         }
  145: 
  146:         return;
  147:     }
  148:     else if ((*s_etat_processus).test_instruction == 'Y')
  149:     {
  150:         (*s_etat_processus).nombre_arguments = -1;
  151:         return;
  152:     }
  153: 
  154:     printf("%s\n", warranty);
  155: 
  156:     if ((*s_etat_processus).hauteur_pile_operationnelle == 0)
  157:     {
  158:         printf("\n");
  159:     }
  160: 
  161:     return;
  162: }
  163: 
  164: 
  165: /*
  166: ================================================================================
  167:   Fonction 'wait'
  168: ================================================================================
  169:   Entrées :
  170: --------------------------------------------------------------------------------
  171:   Sorties :
  172: --------------------------------------------------------------------------------
  173:   Effets de bord : néant
  174: ================================================================================
  175: */
  176: 
  177: void
  178: instruction_wait(struct_processus *s_etat_processus)
  179: {
  180:     int                         code_retour;
  181:     int                         erreur;
  182: 
  183:     real8                       attente;
  184: 
  185:     struct_objet                *s_objet;
  186: 
  187:     struct timespec             temporisation;
  188: 
  189:     (*s_etat_processus).erreur_execution = d_ex;
  190: 
  191:     if ((*s_etat_processus).affichage_arguments == 'Y')
  192:     {
  193:         printf("\n  WAIT ");
  194: 
  195:         if ((*s_etat_processus).langue == 'F')
  196:         {
  197:             printf("(attente exprimée en secondes)\n\n");
  198:         }
  199:         else
  200:         {
  201:             printf("(wait a number of seconds)\n\n");
  202:         }
  203: 
  204:         printf("    1: %s, %s\n", d_INT, d_REL);
  205: 
  206:         return;
  207:     }
  208:     else if ((*s_etat_processus).test_instruction == 'Y')
  209:     {
  210:         (*s_etat_processus).nombre_arguments = -1;
  211:         return;
  212:     }
  213: 
  214:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  215:     {
  216:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  217:         {
  218:             return;
  219:         }
  220:     }
  221: 
  222:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  223:             &s_objet) == d_erreur)
  224:     {
  225:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  226:         return;
  227:     }
  228:     
  229:     if (((*s_objet).type == INT) || ((*s_objet).type == REL))
  230:     {
  231:         if ((*s_objet).type == INT)
  232:         {
  233:             attente = (real8) (*((integer8 *) (*s_objet).objet));
  234:         }
  235:         else
  236:         {
  237:             attente = (*((real8 *) (*s_objet).objet));
  238:         }
  239: 
  240:         if (attente < 0)
  241:         {
  242:             liberation(s_etat_processus, s_objet);
  243: 
  244:             (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
  245:             return;
  246:         }
  247: 
  248:         temporisation.tv_sec = (long) floor((double) attente);
  249:         temporisation.tv_nsec = (attente - temporisation.tv_sec) *
  250:                 (long) 1000000000;
  251: 
  252:         if ((*s_etat_processus).profilage == d_vrai)
  253:         {
  254:             profilage(s_etat_processus, "Sleep function (WAIT)");
  255: 
  256:             if ((*s_etat_processus).erreur_systeme != d_es)
  257:             {
  258:                 return;
  259:             }
  260:         }
  261: 
  262:         do
  263:         {
  264: #           ifndef SEMAPHORES_NOMMES
  265:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  266:             {
  267:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  268:                 return;
  269:             }
  270: #           else
  271:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  272:             {
  273:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  274:                 return;
  275:             }
  276: #           endif
  277: 
  278:             code_retour = nanosleep(&temporisation, &temporisation);
  279:             erreur = errno;
  280: 
  281: #           ifndef SEMAPHORES_NOMMES
  282:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
  283: #           else
  284:             while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
  285: #           endif
  286:             {
  287:                 if (errno != EINTR)
  288:                 {
  289:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  290:                     return;
  291:                 }
  292:             }
  293: 
  294:             scrutation_injection(s_etat_processus);
  295: 
  296:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
  297:             {
  298:                 affectation_interruptions_logicielles(s_etat_processus);
  299:             }
  300: 
  301:             if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
  302:             {
  303:                 traitement_interruptions_logicielles(s_etat_processus);
  304:             }
  305:         } while(((code_retour == -1) && (erreur == EINTR))
  306:                 && ((*s_etat_processus).var_volatile_requete_arret == 0));
  307: 
  308:         if ((*s_etat_processus).profilage == d_vrai)
  309:         {
  310:             profilage(s_etat_processus, NULL);
  311:         }
  312:     }
  313:     else
  314:     {
  315:         liberation(s_etat_processus, s_objet);
  316: 
  317:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  318:         return;
  319:     }
  320: 
  321:     liberation(s_etat_processus, s_objet);
  322: 
  323:     return;
  324: }
  325: 
  326: 
  327: /*
  328: ================================================================================
  329:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
  330: ================================================================================
  331:   Entrées : structure processus
  332: --------------------------------------------------------------------------------
  333:   Sorties :
  334: --------------------------------------------------------------------------------
  335:   Effets de bord : néant
  336: ================================================================================
  337: */
  338: 
  339: void
  340: instruction_wireframe(struct_processus *s_etat_processus)
  341: {
  342:     (*s_etat_processus).erreur_execution = d_ex;
  343: 
  344:     if ((*s_etat_processus).affichage_arguments == 'Y')
  345:     {
  346:         printf("\n  WIREFRAME ");
  347: 
  348:         if ((*s_etat_processus).langue == 'F')
  349:         {
  350:             printf("(graphique tridimensionnel grillagé)\n\n");
  351:             printf("  Aucun argument\n");
  352:         }
  353:         else
  354:         {
  355:             printf("(wireframe 3D graph)\n\n");
  356:             printf("  No argument\n");
  357:         }
  358: 
  359:         return;
  360:     }
  361:     else if ((*s_etat_processus).test_instruction == 'Y')
  362:     {
  363:         (*s_etat_processus).nombre_arguments = -1;
  364:         return;
  365:     }
  366: 
  367:     strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
  368: 
  369:     return;
  370: }
  371: 
  372: 
  373: /*
  374: ================================================================================
  375:   Fonction 'write'
  376: ================================================================================
  377:   Entrées : structure processus
  378: --------------------------------------------------------------------------------
  379:   Sorties :
  380: --------------------------------------------------------------------------------
  381:   Effets de bord : néant
  382: ================================================================================
  383: */
  384: 
  385: void
  386: instruction_write(struct_processus *s_etat_processus)
  387: {
  388:     const char                          *queue;
  389: 
  390:     int                                 adresse[16];
  391:     int                                 port;
  392: 
  393:     integer8                            clef;
  394:     integer8                            compteur;
  395:     integer8                            id;
  396:     integer8                            ordre;
  397: 
  398:     logical1                            mise_a_jour;
  399: 
  400:     long                                longueur_effective;
  401:     long                                recursivite;
  402: 
  403:     sqlite3_stmt                        *ppStmt;
  404: 
  405:     ssize_t                             ios;
  406: 
  407:     struct_descripteur_fichier          *descripteur;
  408: 
  409:     struct_liste_chainee                *l_element_courant;
  410:     struct_liste_chainee                *l_element_courant_format;
  411: 
  412:     struct_objet                        *s_format;
  413:     struct_objet                        *s_element;
  414:     struct_objet                        *s_objet_argument_1;
  415:     struct_objet                        *s_objet_argument_2;
  416:     struct_objet                        *s_objet_argument_3;
  417: 
  418:     struct sigaction                    action;
  419:     struct sigaction                    registre;
  420: 
  421:     struct sockaddr_in                  adresse_ipv4;
  422: #   ifdef IPV6
  423:     struct sockaddr_in6                 adresse_ipv6;
  424: #   endif
  425:     struct sockaddr_un                  adresse_unix;
  426: 
  427:     struct flock                        lock;
  428: 
  429:     uint32_t                            calcul_adresse;
  430: 
  431:     unsigned char                       *chaine;
  432:     unsigned char                       *chaine_utf8;
  433:     unsigned char                       *clef_utf8;
  434:     unsigned char                       *commande;
  435: 
  436:     unsigned long                       i;
  437: 
  438:     (*s_etat_processus).erreur_execution = d_ex;
  439: 
  440:     if ((*s_etat_processus).affichage_arguments == 'Y')
  441:     {
  442:         printf("\n  WRITE ");
  443: 
  444:         if ((*s_etat_processus).langue == 'F')
  445:         {
  446:             printf("(écriture d'un enregistrement d'un fichier)\n\n");
  447:         }
  448:         else
  449:         {
  450:             printf("(write a record of a file)\n\n");
  451:         }
  452: 
  453:         printf("    2: %s\n", d_LST);
  454:         printf("    1: %s, %s\n\n", d_FCH, d_SCK);
  455: 
  456:         printf("    3: %s\n", d_LST);
  457:         printf("    2: %s\n", d_INT);
  458:         printf("    1: %s\n", d_FCH);
  459:         return;
  460:     }
  461:     else if ((*s_etat_processus).test_instruction == 'Y')
  462:     {
  463:         (*s_etat_processus).nombre_arguments = -1;
  464:         return;
  465:     }
  466: 
  467:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  468:     {
  469:         if ((*s_etat_processus).l_base_pile == NULL)
  470:         {
  471:             (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  472:             return;
  473:         }
  474: 
  475:         if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
  476:         {
  477:             if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
  478:                     .donnee).objet)).acces == 'D')
  479:             {
  480:                 if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
  481:                 {
  482:                     return;
  483:                 }
  484:             }
  485:             else
  486:             {
  487:                 if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  488:                 {
  489:                     return;
  490:                 }
  491:             }
  492:         }
  493:         else
  494:         {
  495:             if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  496:             {
  497:                 return;
  498:             }
  499:         }
  500:     }
  501: 
  502:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  503:             &s_objet_argument_1) == d_erreur)
  504:     {
  505:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  506:         return;
  507:     }
  508:     
  509:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  510:             &s_objet_argument_2) == d_erreur)
  511:     {
  512:         liberation(s_etat_processus, s_objet_argument_1);
  513: 
  514:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  515:         return;
  516:     }
  517:     
  518:     if ((*s_objet_argument_1).type == FCH)
  519:     {
  520:         if ((descripteur = descripteur_fichier(s_etat_processus,
  521:                 (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
  522:         {
  523:             return;
  524:         }
  525: 
  526:         /*
  527:          * Vérification des verrous
  528:          */
  529: 
  530:         lock.l_type = F_WRLCK;
  531:         lock.l_whence = SEEK_SET;
  532:         lock.l_start = 0;
  533:         lock.l_len = 0;
  534:         lock.l_pid = getpid();
  535:         recursivite = 0;
  536: 
  537:         if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
  538:                 == -1)
  539:         {
  540:             liberation(s_etat_processus, s_objet_argument_2);
  541:             liberation(s_etat_processus, s_objet_argument_1);
  542: 
  543:             (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  544:             return;
  545:         }
  546: 
  547:         if (lock.l_type != F_UNLCK)
  548:         {
  549:             liberation(s_etat_processus, s_objet_argument_2);
  550:             liberation(s_etat_processus, s_objet_argument_1);
  551: 
  552:             (*s_etat_processus).erreur_execution =
  553:                     d_ex_fichier_verrouille;
  554:             return;
  555:         }
  556: 
  557:         /*
  558:          * Vérification de l'autorisation d'écriture
  559:          */
  560: 
  561:         if ((*((struct_fichier *) (*s_objet_argument_1).objet))
  562:                 .protection == 'R')
  563:         {
  564:             liberation(s_etat_processus, s_objet_argument_2);
  565:             liberation(s_etat_processus, s_objet_argument_1);
  566: 
  567:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
  568:             return;
  569:         }
  570: 
  571:         if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
  572:         {
  573:             /*
  574:              * Fichiers formatés
  575:              */
  576: 
  577:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
  578:                     == 'S')
  579:             {
  580:                 if ((*s_objet_argument_2).type != LST)
  581:                 {
  582:                     liberation(s_etat_processus, s_objet_argument_2);
  583:                     liberation(s_etat_processus, s_objet_argument_1);
  584: 
  585:                     (*s_etat_processus).erreur_execution =
  586:                             d_ex_erreur_type_argument;
  587:                     return;
  588:                 }
  589: 
  590:                 if ((chaine = formateur_fichier(s_etat_processus,
  591:                         s_objet_argument_2, (*((struct_fichier *)
  592:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
  593:                         &longueur_effective, &recursivite)) == NULL)
  594:                 {
  595:                     liberation(s_etat_processus, s_objet_argument_2);
  596:                     liberation(s_etat_processus, s_objet_argument_1);
  597: 
  598:                     return;
  599:                 }
  600: 
  601:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
  602: 
  603:                 if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
  604:                         != 0)
  605:                 {
  606:                     liberation(s_etat_processus, s_objet_argument_2);
  607:                     liberation(s_etat_processus, s_objet_argument_1);
  608: 
  609:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  610:                     return;
  611:                 }
  612: 
  613:                 if ((chaine_utf8 = transliteration(s_etat_processus,
  614:                         chaine, d_locale, "UTF-8")) == NULL)
  615:                 {
  616:                     free(chaine);
  617: 
  618:                     liberation(s_etat_processus, s_objet_argument_2);
  619:                     liberation(s_etat_processus, s_objet_argument_1);
  620: 
  621:                     return;
  622:                 }
  623: 
  624:                 free(chaine);
  625: 
  626:                 if (fprintf((*descripteur).descripteur_c, "%s\n", chaine_utf8)
  627:                         < 0)
  628:                 {
  629:                     free(chaine_utf8);
  630: 
  631:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  632:                     return;
  633:                 }
  634: 
  635:                 free(chaine_utf8);
  636:             }
  637:             else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
  638:                     == 'D')
  639:             {
  640:                 BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
  641: 
  642:                 if ((*s_objet_argument_2).type != INT)
  643:                 {
  644:                     liberation(s_etat_processus, s_objet_argument_2);
  645:                     liberation(s_etat_processus, s_objet_argument_1);
  646: 
  647:                     (*s_etat_processus).erreur_execution =
  648:                             d_ex_erreur_type_argument;
  649:                     return;
  650:                 }
  651: 
  652:                 if (depilement(s_etat_processus, &((*s_etat_processus)
  653:                         .l_base_pile), &s_objet_argument_3) == d_erreur)
  654:                 {
  655:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  656:                     return;
  657:                 }
  658: 
  659:                 if ((*s_objet_argument_3).type != LST)
  660:                 {
  661:                     liberation(s_etat_processus, s_objet_argument_3);
  662:                     liberation(s_etat_processus, s_objet_argument_2);
  663:                     liberation(s_etat_processus, s_objet_argument_1);
  664: 
  665:                     (*s_etat_processus).erreur_execution =
  666:                             d_ex_erreur_type_argument;
  667:                     return;
  668:                 }
  669: 
  670:                 // Modification ou création d'un nouvel enregistrement
  671: 
  672:                 if ((chaine = formateur_fichier(s_etat_processus,
  673:                         s_objet_argument_3, (*((struct_fichier *)
  674:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ',
  675:                         'F', &longueur_effective, &recursivite)) == NULL)
  676:                 {
  677:                     liberation(s_etat_processus, s_objet_argument_3);
  678:                     liberation(s_etat_processus, s_objet_argument_2);
  679:                     liberation(s_etat_processus, s_objet_argument_1);
  680: 
  681:                     return;
  682:                 }
  683: 
  684:                 if ((chaine_utf8 = transliteration(s_etat_processus,
  685:                         chaine, d_locale, "UTF-8")) == NULL)
  686:                 {
  687:                     free(chaine);
  688: 
  689:                     liberation(s_etat_processus, s_objet_argument_3);
  690:                     liberation(s_etat_processus, s_objet_argument_2);
  691:                     liberation(s_etat_processus, s_objet_argument_1);
  692: 
  693:                     return;
  694:                 }
  695: 
  696:                 free(chaine);
  697: 
  698:                 if (alsprintf(&commande, "insert or replace into data "
  699:                         "(id, data) values (%lld, '%s')", (*((integer8 *)
  700:                         (*s_objet_argument_2).objet)), chaine_utf8) < 0)
  701:                 {
  702:                     (*s_etat_processus).erreur_systeme =
  703:                             d_es_allocation_memoire;
  704:                     return;
  705:                 }
  706: 
  707:                 free(chaine_utf8);
  708: 
  709:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  710:                         commande, strlen(commande), &ppStmt, &queue)
  711:                         != SQLITE_OK)
  712:                 {
  713:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  714:                     return;
  715:                 }
  716: 
  717:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  718:                 {
  719:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  720:                     return;
  721:                 }
  722: 
  723:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  724:                 {
  725:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  726:                     return;
  727:                 }
  728: 
  729:                 liberation(s_etat_processus, s_objet_argument_3);
  730:                 free(commande);
  731:             }
  732:             else // Fichiers indexés
  733:             {
  734:                 BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
  735: 
  736:                 if ((*s_objet_argument_2).type != LST)
  737:                 {
  738:                     liberation(s_etat_processus, s_objet_argument_2);
  739:                     liberation(s_etat_processus, s_objet_argument_1);
  740: 
  741:                     (*s_etat_processus).erreur_execution =
  742:                             d_ex_erreur_type_argument;
  743:                     return;
  744:                 }
  745: 
  746:                 // Récupération de la position de la clef
  747: 
  748:                 if (alsprintf(&commande, "select key from control "
  749:                         "where id = 1") < 0)
  750:                 {
  751:                     (*s_etat_processus).erreur_systeme =
  752:                             d_es_allocation_memoire;
  753:                     return;
  754:                 }
  755: 
  756:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  757:                         commande, strlen(commande), &ppStmt, &queue)
  758:                         != SQLITE_OK)
  759:                 {
  760:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  761:                     return;
  762:                 }
  763: 
  764:                 if (sqlite3_step(ppStmt) != SQLITE_ROW)
  765:                 {
  766:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  767:                     return;
  768:                 }
  769: 
  770:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
  771:                 {
  772:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  773:                     return;
  774:                 }
  775: 
  776:                 clef = sqlite3_column_int64(ppStmt, 0);
  777: 
  778:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  779:                 {
  780:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  781:                     return;
  782:                 }
  783: 
  784:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  785:                 {
  786:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  787:                     return;
  788:                 }
  789: 
  790:                 free(commande);
  791: 
  792:                 l_element_courant = (struct_liste_chainee *)
  793:                         (*s_objet_argument_2).objet;
  794:                 l_element_courant_format = (struct_liste_chainee *)
  795:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
  796:                         .format).objet;
  797:                 compteur = 1;
  798: 
  799:                 while((l_element_courant != NULL) &&
  800:                         (l_element_courant_format != NULL))
  801:                 {
  802:                     if (compteur == clef)
  803:                     {
  804:                         break;
  805:                     }
  806: 
  807:                     l_element_courant = (*l_element_courant).suivant;
  808:                     l_element_courant_format = (*l_element_courant_format)
  809:                             .suivant;
  810:                     compteur++;
  811:                 }
  812: 
  813:                 if ((l_element_courant == NULL) ||
  814:                         (l_element_courant_format == NULL))
  815:                 {
  816:                     (*s_etat_processus).erreur_execution =
  817:                             d_ex_clef_inexistante;
  818:                         
  819:                     liberation(s_etat_processus, s_objet_argument_2);
  820:                     liberation(s_etat_processus, s_objet_argument_1);
  821: 
  822:                     return;
  823:                 }
  824: 
  825:                 if ((s_element = allocation(s_etat_processus, LST)) == NULL)
  826:                 {
  827:                     (*s_etat_processus).erreur_systeme =
  828:                             d_es_allocation_memoire;
  829:                     return;
  830:                 }
  831: 
  832:                 if (((*s_element).objet = allocation_maillon(s_etat_processus))
  833:                         == NULL)
  834:                 {
  835:                     (*s_etat_processus).erreur_systeme =
  836:                             d_es_allocation_memoire;
  837:                     return;
  838:                 }
  839: 
  840:                 (*((struct_liste_chainee *) (*s_element).objet)).suivant = NULL;
  841: 
  842:                 if (((*((struct_liste_chainee *) (*s_element).objet))
  843:                         .donnee = copie_objet(s_etat_processus,
  844:                         (*l_element_courant).donnee, 'N')) == NULL)
  845:                 {
  846:                     (*s_etat_processus).erreur_systeme =
  847:                             d_es_allocation_memoire;
  848:                     return;
  849:                 }
  850: 
  851:                 if ((s_format = allocation(s_etat_processus, LST)) == NULL)
  852:                 {
  853:                     (*s_etat_processus).erreur_systeme =
  854:                             d_es_allocation_memoire;
  855:                     return;
  856:                 }
  857: 
  858:                 if (((*s_format).objet = allocation_maillon(s_etat_processus))
  859:                         == NULL)
  860:                 {
  861:                     (*s_etat_processus).erreur_systeme =
  862:                             d_es_allocation_memoire;
  863:                     return;
  864:                 }
  865: 
  866:                 (*((struct_liste_chainee *) (*s_format).objet)).suivant = NULL;
  867: 
  868:                 if (((*((struct_liste_chainee *) (*s_format).objet))
  869:                         .donnee = copie_objet(s_etat_processus,
  870:                         (*l_element_courant_format).donnee, 'N')) == NULL)
  871:                 {
  872:                     (*s_etat_processus).erreur_systeme =
  873:                             d_es_allocation_memoire;
  874:                     return;
  875:                 }
  876: 
  877:                 if ((chaine = formateur_fichier(s_etat_processus,
  878:                         s_element, s_format, 0, 0, ' ',
  879:                         'F', &longueur_effective, &recursivite)) == NULL)
  880:                 {
  881:                     liberation(s_etat_processus, s_element);
  882:                     liberation(s_etat_processus, s_format);
  883:                     liberation(s_etat_processus, s_objet_argument_2);
  884:                     liberation(s_etat_processus, s_objet_argument_1);
  885: 
  886:                     return;
  887:                 }
  888: 
  889:                 liberation(s_etat_processus, s_element);
  890:                 liberation(s_etat_processus, s_format);
  891: 
  892:                 if ((clef_utf8 = transliteration(s_etat_processus,
  893:                         chaine, d_locale, "UTF-8")) == NULL)
  894:                 {
  895:                     liberation(s_etat_processus, s_objet_argument_2);
  896:                     liberation(s_etat_processus, s_objet_argument_1);
  897: 
  898:                     return;
  899:                 }
  900: 
  901:                 free(chaine);
  902: 
  903:                 // Récupération de l'identifiant de la clef
  904: 
  905:                 if (alsprintf(&commande, "select id from key where key = "
  906:                         "'%s'", clef_utf8) < 0)
  907:                 {
  908:                     (*s_etat_processus).erreur_systeme =
  909:                             d_es_allocation_memoire;
  910:                     return;
  911:                 }
  912: 
  913:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  914:                         commande, strlen(commande), &ppStmt, &queue)
  915:                         != SQLITE_OK)
  916:                 {
  917:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  918:                     return;
  919:                 }
  920: 
  921:                 switch(sqlite3_step(ppStmt))
  922:                 {
  923:                     case SQLITE_ROW:
  924:                     {
  925:                         // Une clef existe.
  926: 
  927:                         mise_a_jour = d_vrai;
  928:                         break;
  929:                     }
  930: 
  931:                     case SQLITE_DONE:
  932:                     {
  933:                         // Aucune clef n'existe.
  934: 
  935:                         mise_a_jour = d_faux;
  936: 
  937:                         if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  938:                         {
  939:                             (*s_etat_processus).erreur_systeme =
  940:                                     d_es_erreur_fichier;
  941:                             return;
  942:                         }
  943: 
  944:                         free(commande);
  945: 
  946:                         if (alsprintf(&commande, "insert into key "
  947:                                 "(key) values ('%s')", clef_utf8) < 0)
  948:                         {
  949:                             (*s_etat_processus).erreur_systeme =
  950:                                     d_es_allocation_memoire;
  951:                             return;
  952:                         }
  953: 
  954:                         if (sqlite3_prepare_v2((*descripteur)
  955:                                 .descripteur_sqlite,
  956:                                 commande, strlen(commande), &ppStmt, &queue)
  957:                                 != SQLITE_OK)
  958:                         {
  959:                             (*s_etat_processus).erreur_systeme =
  960:                                     d_es_erreur_fichier;
  961:                             return;
  962:                         }
  963: 
  964:                         if (sqlite3_step(ppStmt) != SQLITE_DONE)
  965:                         {
  966:                             (*s_etat_processus).erreur_systeme =
  967:                                     d_es_erreur_fichier;
  968:                             return;
  969:                         }
  970: 
  971:                         if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  972:                         {
  973:                             (*s_etat_processus).erreur_systeme =
  974:                                     d_es_erreur_fichier;
  975:                             return;
  976:                         }
  977: 
  978:                         free(commande);
  979: 
  980:                         if (alsprintf(&commande, "select id from key "
  981:                                 "where key = '%s'", clef_utf8) < 0)
  982:                         {
  983:                             (*s_etat_processus).erreur_systeme =
  984:                                     d_es_allocation_memoire;
  985:                             return;
  986:                         }
  987: 
  988:                         if (sqlite3_prepare_v2((*descripteur)
  989:                                 .descripteur_sqlite,
  990:                                 commande, strlen(commande), &ppStmt, &queue)
  991:                                 != SQLITE_OK)
  992:                         {
  993:                             (*s_etat_processus).erreur_systeme =
  994:                                     d_es_erreur_fichier;
  995:                             return;
  996:                         }
  997: 
  998:                         if (sqlite3_step(ppStmt) != SQLITE_ROW)
  999:                         {
 1000:                             (*s_etat_processus).erreur_systeme =
 1001:                                     d_es_erreur_fichier;
 1002:                             return;
 1003:                         }
 1004: 
 1005:                         break;
 1006:                     }
 1007: 
 1008:                     default:
 1009:                     {
 1010:                         (*s_etat_processus).erreur_systeme =
 1011:                                 d_es_erreur_fichier;
 1012:                         return;
 1013:                     }
 1014:                 }
 1015: 
 1016:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
 1017:                 {
 1018:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1019:                     return;
 1020:                 }
 1021: 
 1022:                 id = sqlite3_column_int64(ppStmt, 0);
 1023: 
 1024:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1025:                 {
 1026:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1027:                     return;
 1028:                 }
 1029: 
 1030:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1031:                 {
 1032:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1033:                     return;
 1034:                 }
 1035: 
 1036:                 free(commande);
 1037: 
 1038:                 // Modification de la clef
 1039: 
 1040:                 if (mise_a_jour == d_vrai)
 1041:                 {
 1042:                     if (alsprintf(&commande, "update key set key = '%s' where "
 1043:                             "id = %lld", clef_utf8, id) < 0)
 1044:                     {
 1045:                         (*s_etat_processus).erreur_systeme =
 1046:                                 d_es_allocation_memoire;
 1047:                         return;
 1048:                     }
 1049: 
 1050:                     if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1051:                             commande, strlen(commande), &ppStmt, &queue)
 1052:                             != SQLITE_OK)
 1053:                     {
 1054:                         (*s_etat_processus).erreur_systeme =
 1055:                                 d_es_erreur_fichier;
 1056:                         return;
 1057:                     }
 1058: 
 1059:                     if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1060:                     {
 1061:                         (*s_etat_processus).erreur_systeme =
 1062:                                 d_es_erreur_fichier;
 1063:                         return;
 1064:                     }
 1065: 
 1066:                     if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1067:                     {
 1068:                         (*s_etat_processus).erreur_systeme =
 1069:                                 d_es_erreur_fichier;
 1070:                         return;
 1071:                     }
 1072: 
 1073:                     free(commande);
 1074:                 }
 1075: 
 1076:                 // Effacement de l'enregistrement existant
 1077: 
 1078:                 if (alsprintf(&commande, "delete from data where "
 1079:                         "key_id = %lld", id) < 0)
 1080:                 {
 1081:                     (*s_etat_processus).erreur_systeme =
 1082:                             d_es_allocation_memoire;
 1083:                     return;
 1084:                 }
 1085: 
 1086:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1087:                         commande, strlen(commande), &ppStmt, &queue)
 1088:                         != SQLITE_OK)
 1089:                 {
 1090:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1091:                     return;
 1092:                 }
 1093: 
 1094:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1095:                 {
 1096:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1097:                     return;
 1098:                 }
 1099: 
 1100:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1101:                 {
 1102:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1103:                     return;
 1104:                 }
 1105: 
 1106:                 free(commande);
 1107: 
 1108:                 // Modification ou création d'un nouvel enregistrement
 1109: 
 1110:                 l_element_courant = (struct_liste_chainee *)
 1111:                         (*s_objet_argument_2).objet;
 1112:                 l_element_courant_format = (struct_liste_chainee *)
 1113:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
 1114:                         .format).objet;
 1115:                 compteur = 1;
 1116:                 ordre = 1;
 1117: 
 1118:                 while((l_element_courant != NULL) &&
 1119:                         (l_element_courant_format != NULL))
 1120:                 {
 1121:                     if (compteur == clef)
 1122:                     {
 1123:                         l_element_courant = (*l_element_courant).suivant;
 1124:                         l_element_courant_format = (*l_element_courant_format)
 1125:                                 .suivant;
 1126:                         compteur++;
 1127:                         continue;
 1128:                     }
 1129: 
 1130:                     if ((s_element = allocation(s_etat_processus, LST)) == NULL)
 1131:                     {
 1132:                         (*s_etat_processus).erreur_systeme =
 1133:                                 d_es_allocation_memoire;
 1134:                         return;
 1135:                     }
 1136: 
 1137:                     if (((*s_element).objet =
 1138:                             allocation_maillon(s_etat_processus)) == NULL)
 1139:                     {
 1140:                         (*s_etat_processus).erreur_systeme =
 1141:                                 d_es_allocation_memoire;
 1142:                         return;
 1143:                     }
 1144: 
 1145:                     (*((struct_liste_chainee *) (*s_element).objet)).suivant
 1146:                             = NULL;
 1147: 
 1148:                     if ((s_format = allocation(s_etat_processus, LST)) == NULL)
 1149:                     {
 1150:                         (*s_etat_processus).erreur_systeme =
 1151:                                 d_es_allocation_memoire;
 1152:                         return;
 1153:                     }
 1154: 
 1155:                     if (((*s_format).objet =
 1156:                             allocation_maillon(s_etat_processus)) == NULL)
 1157:                     {
 1158:                         (*s_etat_processus).erreur_systeme =
 1159:                                 d_es_allocation_memoire;
 1160:                         return;
 1161:                     }
 1162: 
 1163:                     (*((struct_liste_chainee *) (*s_format).objet)).suivant
 1164:                             = NULL;
 1165: 
 1166:                     if (((*((struct_liste_chainee *) (*s_element).objet))
 1167:                             .donnee = copie_objet(s_etat_processus,
 1168:                             (*l_element_courant).donnee, 'N')) == NULL)
 1169:                     {
 1170:                         (*s_etat_processus).erreur_systeme =
 1171:                                 d_es_allocation_memoire;
 1172:                         return;
 1173:                     }
 1174: 
 1175:                     if (((*((struct_liste_chainee *) (*s_format).objet))
 1176:                             .donnee = copie_objet(s_etat_processus,
 1177:                             (*l_element_courant_format).donnee, 'N')) == NULL)
 1178:                     {
 1179:                         (*s_etat_processus).erreur_systeme =
 1180:                                 d_es_allocation_memoire;
 1181:                         return;
 1182:                     }
 1183: 
 1184:                     if ((chaine = formateur_fichier(s_etat_processus,
 1185:                             s_element, s_format, 0, 0, ' ',
 1186:                             'F', &longueur_effective, &recursivite)) == NULL)
 1187:                     {
 1188:                         free(clef_utf8);
 1189: 
 1190:                         liberation(s_etat_processus, s_element);
 1191:                         liberation(s_etat_processus, s_format);
 1192:                         liberation(s_etat_processus, s_objet_argument_2);
 1193:                         liberation(s_etat_processus, s_objet_argument_1);
 1194: 
 1195:                         return;
 1196:                     }
 1197: 
 1198:                     if ((chaine_utf8 = transliteration(s_etat_processus,
 1199:                             chaine, d_locale, "UTF-8")) == NULL)
 1200:                     {
 1201:                         free(clef_utf8);
 1202:                         free(chaine);
 1203: 
 1204:                         liberation(s_etat_processus, s_objet_argument_2);
 1205:                         liberation(s_etat_processus, s_objet_argument_1);
 1206: 
 1207:                         return;
 1208:                     }
 1209: 
 1210:                     free(chaine);
 1211: 
 1212:                     if (alsprintf(&commande, "insert into data "
 1213:                             "(data, key_id, sequence) values "
 1214:                             "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0)
 1215:                     {
 1216:                         (*s_etat_processus).erreur_systeme =
 1217:                                 d_es_allocation_memoire;
 1218:                         return;
 1219:                     }
 1220: 
 1221:                     if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
 1222:                             commande, strlen(commande), &ppStmt, &queue)
 1223:                             != SQLITE_OK)
 1224:                     {
 1225:                         (*s_etat_processus).erreur_systeme =
 1226:                                 d_es_erreur_fichier;
 1227:                         return;
 1228:                     }
 1229: 
 1230:                     if (sqlite3_step(ppStmt) != SQLITE_DONE)
 1231:                     {
 1232:                         (*s_etat_processus).erreur_systeme =
 1233:                                 d_es_erreur_fichier;
 1234:                         return;
 1235:                     }
 1236: 
 1237:                     if (sqlite3_finalize(ppStmt) != SQLITE_OK)
 1238:                     {
 1239:                         (*s_etat_processus).erreur_systeme =
 1240:                                 d_es_erreur_fichier;
 1241:                         return;
 1242:                     }
 1243: 
 1244:                     free(commande);
 1245:                     free(chaine_utf8);
 1246: 
 1247:                     liberation(s_etat_processus, s_element);
 1248:                     liberation(s_etat_processus, s_format);
 1249: 
 1250:                     l_element_courant = (*l_element_courant).suivant;
 1251:                     l_element_courant_format = (*l_element_courant_format)
 1252:                             .suivant;
 1253: 
 1254:                     compteur++;
 1255:                     ordre++;
 1256:                 }
 1257: 
 1258:                 free(clef_utf8);
 1259: 
 1260:                 if ((l_element_courant != NULL) ||
 1261:                         (l_element_courant_format != NULL))
 1262:                 {
 1263:                     liberation(s_etat_processus, s_objet_argument_1);
 1264:                     liberation(s_etat_processus, s_objet_argument_2);
 1265: 
 1266:                     (*s_etat_processus).erreur_execution =
 1267:                             d_ex_erreur_format_fichier;
 1268:                     return;
 1269:                 }
 1270:             }
 1271:         }
 1272:         else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
 1273:                 == 'Y')
 1274:         {
 1275:             /*
 1276:              * Fichiers non formatés
 1277:              */
 1278: 
 1279:             if ((chaine = formateur_fichier(s_etat_processus,
 1280:                     s_objet_argument_2, (*((struct_fichier *)
 1281:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
 1282:                     &longueur_effective, &recursivite)) == NULL)
 1283:             {
 1284:                 liberation(s_etat_processus, s_objet_argument_2);
 1285:                 liberation(s_etat_processus, s_objet_argument_1);
 1286: 
 1287:                 return;
 1288:             }
 1289: 
 1290:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1291:                     == 'S')
 1292:             {
 1293:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
 1294: 
 1295:                 if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
 1296:                         != 0)
 1297:                 {
 1298:                     liberation(s_etat_processus, s_objet_argument_2);
 1299:                     liberation(s_etat_processus, s_objet_argument_1);
 1300: 
 1301:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1302:                     return;
 1303:                 }
 1304: 
 1305:                 if (fwrite(chaine, sizeof(unsigned char), longueur_effective,
 1306:                         (*descripteur).descripteur_c) !=
 1307:                         (size_t) longueur_effective)
 1308:                 {
 1309:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1310:                     return;
 1311:                 }
 1312:             }
 1313:             else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1314:                     == 'D')
 1315:             {
 1316:             }
 1317:             else
 1318:             {
 1319:                 /* Fichiers indexés : panique totale ! */
 1320:             }
 1321: 
 1322:             free(chaine);
 1323:         }
 1324:         else
 1325:         {
 1326:             /*
 1327:              * Fichiers de type FLOW
 1328:              */
 1329:         }
 1330:     }
 1331:     else if (((*s_objet_argument_2).type == LST) &&
 1332:             ((*s_objet_argument_1).type == SCK))
 1333:     {
 1334:         /*
 1335:          * Vérification de l'autorisation d'écriture
 1336:          */
 1337: 
 1338:         if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1339:                 .protection == 'R')
 1340:         {
 1341:             liberation(s_etat_processus, s_objet_argument_2);
 1342:             liberation(s_etat_processus, s_objet_argument_1);
 1343: 
 1344:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
 1345:             return;
 1346:         }
 1347: 
 1348:         if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
 1349:         {
 1350:             /*
 1351:              * Sockets formatées
 1352:              */
 1353: 
 1354:             if ((chaine = formateur_fichier(s_etat_processus,
 1355:                     s_objet_argument_2, (*((struct_socket *)
 1356:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
 1357:                     &longueur_effective, &recursivite)) == NULL)
 1358:             {
 1359:                 liberation(s_etat_processus, s_objet_argument_2);
 1360:                 liberation(s_etat_processus, s_objet_argument_1);
 1361: 
 1362:                 return;
 1363:             }
 1364: 
 1365:             if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
 1366:                     "STREAM") == 0) || (strcmp((*((struct_socket *)
 1367:                     (*s_objet_argument_1).objet)).type,
 1368:                     "SEQUENTIAL DATAGRAM") == 0))
 1369:             { // Sockets connectées
 1370: 
 1371:                 action.sa_handler = SIG_IGN;
 1372:                 action.sa_flags = SA_ONSTACK;
 1373: 
 1374:                 if (sigaction(SIGPIPE, &action, &registre) != 0)
 1375:                 {
 1376:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1377:                     return;
 1378:                 }
 1379: 
 1380: #               ifndef SEMAPHORES_NOMMES
 1381:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1382: #               else
 1383:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1384: #               endif
 1385:                 {
 1386:                     if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1387:                     {
 1388:                         (*s_etat_processus).erreur_systeme = d_es_signal;
 1389:                         return;
 1390:                     }
 1391: 
 1392:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1393:                     return;
 1394:                 }
 1395: 
 1396:                 if (send((*((struct_socket *) (*s_objet_argument_1).objet))
 1397:                         .socket, chaine, strlen(chaine), 0) < 0)
 1398:                 {
 1399:                     ios = errno;
 1400: 
 1401:                     if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1402:                     {
 1403:                         (*s_etat_processus).erreur_systeme = d_es_signal;
 1404:                         return;
 1405:                     }
 1406: 
 1407: #                   ifndef SEMAPHORES_NOMMES
 1408:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 1409: #                   else
 1410:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 1411: #                   endif
 1412:                     {
 1413:                         if (errno != EINTR)
 1414:                         {
 1415:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1416:                             return;
 1417:                         }
 1418:                     }
 1419: 
 1420:                     if (ios == EPIPE)
 1421:                     {
 1422:                         (*s_etat_processus).erreur_execution =
 1423:                                 d_ex_erreur_acces_fichier;
 1424:                         return;
 1425:                     }
 1426: 
 1427:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1428:                     return;
 1429:                 }
 1430: 
 1431: #               ifndef SEMAPHORES_NOMMES
 1432:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 1433: #               else
 1434:                 while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 1435: #               endif
 1436:                 {
 1437:                     if (errno != EINTR)
 1438:                     {
 1439:                         if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1440:                         {
 1441:                             (*s_etat_processus).erreur_systeme = d_es_signal;
 1442:                             return;
 1443:                         }
 1444: 
 1445:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1446:                         return;
 1447:                     }
 1448:                 }
 1449: 
 1450:                 if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1451:                 {
 1452:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1453:                     return;
 1454:                 }
 1455:             }
 1456:             else
 1457:             { // Sockets non connectées
 1458: 
 1459:                 /*
 1460:                  * Vérification de l'adresse distante
 1461:                  */
 1462: 
 1463:                 if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
 1464:                         .adresse_distante, "") == 0)
 1465:                 {
 1466:                     liberation(s_etat_processus, s_objet_argument_1);
 1467:                     liberation(s_etat_processus, s_objet_argument_2);
 1468: 
 1469:                     (*s_etat_processus).erreur_execution =
 1470:                             d_ex_erreur_acces_fichier;
 1471:                     return;
 1472:                 }
 1473: 
 1474:                 /*
 1475:                  * Création de l'adresse logique
 1476:                  */
 1477: 
 1478:                 if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1479:                         .domaine == PF_UNIX)
 1480:                 {
 1481:                     adresse_unix.sun_family = AF_UNIX;
 1482:                     strncpy(adresse_unix.sun_path, (*((struct_socket *)
 1483:                             (*s_objet_argument_1).objet)).adresse_distante,
 1484:                             UNIX_PATH_MAX);
 1485:                     adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
 1486:                             d_code_fin_chaine;
 1487: 
 1488: #                   ifndef SEMAPHORES_NOMMES
 1489:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1490:                     {
 1491:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1492:                         return;
 1493:                     }
 1494: #                   else
 1495:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1496:                     {
 1497:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1498:                         return;
 1499:                     }
 1500: #                   endif
 1501: 
 1502:                     if (sendto((*((struct_socket *)
 1503:                             (*s_objet_argument_1).objet)).socket, chaine,
 1504:                             strlen(chaine), 0, (struct sockaddr *)
 1505:                             &adresse_unix, sizeof(adresse_unix)) < 0)
 1506:                     {
 1507: #                       ifndef SEMAPHORES_NOMMES
 1508:                         while(sem_wait(&((*s_etat_processus)
 1509:                                 .semaphore_fork)) == -1)
 1510: #                       else
 1511:                         while(sem_wait((*s_etat_processus)
 1512:                                 .semaphore_fork) == -1)
 1513: #                       endif
 1514:                         {
 1515:                             if (errno != EINTR)
 1516:                             {
 1517:                                 (*s_etat_processus).erreur_systeme =
 1518:                                         d_es_processus;
 1519:                                 return;
 1520:                             }
 1521:                         }
 1522: 
 1523:                         (*s_etat_processus).erreur_systeme =
 1524:                                 d_es_erreur_fichier;
 1525:                         return;
 1526:                     }
 1527: 
 1528: #                   ifndef SEMAPHORES_NOMMES
 1529:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 1530: #                   else
 1531:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 1532: #                   endif
 1533:                     {
 1534:                         if (errno != EINTR)
 1535:                         {
 1536:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1537:                             return;
 1538:                         }
 1539:                     }
 1540:                 }
 1541:                 else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1542:                         .domaine == PF_INET)
 1543:                 {
 1544:                     if (sscanf((*((struct_socket *)
 1545:                             (*s_objet_argument_1).objet))
 1546:                             .adresse_distante, "%d.%d.%d.%d(%d)",
 1547:                             &(adresse[0]), &(adresse[1]), &(adresse[2]),
 1548:                             &(adresse[3]), &port) == 5)
 1549:                     { // Adresse IPv4
 1550:                         calcul_adresse = 0;
 1551:                         for(i = 0; i < 4; calcul_adresse =
 1552:                                 (256 * calcul_adresse) + adresse[i++]);
 1553: 
 1554:                         memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
 1555:                         adresse_ipv4.sin_family = AF_INET;
 1556:                         adresse_ipv4.sin_port = htons(port);
 1557:                         adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
 1558: 
 1559: #                       ifndef SEMAPHORES_NOMMES
 1560:                         if (sem_post(&((*s_etat_processus)
 1561:                                 .semaphore_fork)) != 0)
 1562:                         {
 1563:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1564:                             return;
 1565:                         }
 1566: #                       else
 1567:                         if (sem_post((*s_etat_processus) .semaphore_fork) != 0)
 1568:                         {
 1569:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1570:                             return;
 1571:                         }
 1572: #                       endif
 1573: 
 1574:                         if (sendto((*((struct_socket *)
 1575:                                 (*s_objet_argument_1).objet)).socket, chaine,
 1576:                                 strlen(chaine), 0, (struct sockaddr *)
 1577:                                 &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
 1578:                         {
 1579: #                           ifndef SEMAPHORES_NOMMES
 1580:                             while(sem_wait(&((*s_etat_processus)
 1581:                                     .semaphore_fork)) == -1)
 1582: #                           else
 1583:                             while(sem_wait((*s_etat_processus)
 1584:                                     .semaphore_fork) == -1)
 1585: #                           endif
 1586:                             {
 1587:                                 if (errno != EINTR)
 1588:                                 {
 1589:                                     (*s_etat_processus).erreur_systeme =
 1590:                                             d_es_processus;
 1591:                                     return;
 1592:                                 }
 1593:                             }
 1594: 
 1595:                             (*s_etat_processus).erreur_systeme =
 1596:                                     d_es_erreur_fichier;
 1597:                             return;
 1598:                         }
 1599: 
 1600: #                       ifndef SEMAPHORES_NOMMES
 1601:                         while(sem_wait(&((*s_etat_processus)
 1602:                                 .semaphore_fork)) == -1)
 1603: #                       else
 1604:                         while(sem_wait((*s_etat_processus)
 1605:                                 .semaphore_fork) == -1)
 1606: #                       endif
 1607:                         {
 1608:                             if (errno != EINTR)
 1609:                             {
 1610:                                 (*s_etat_processus).erreur_systeme =
 1611:                                         d_es_processus;
 1612:                                 return;
 1613:                             }
 1614:                         }
 1615:                     }
 1616:                     else
 1617:                     {
 1618:                         liberation(s_etat_processus, s_objet_argument_1);
 1619:                         liberation(s_etat_processus, s_objet_argument_2);
 1620: 
 1621:                         (*s_etat_processus).erreur_execution =
 1622:                                 d_ex_erreur_parametre_fichier;
 1623:                         return;
 1624:                     }
 1625:                 }
 1626:                 else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1627:                         .domaine == PF_INET6)
 1628:                 {
 1629:                     if (sscanf((*((struct_socket *) (*s_objet_argument_1)
 1630:                             .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
 1631:                             "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
 1632:                             &(adresse[0]), &(adresse[1]), &(adresse[2]),
 1633:                             &(adresse[3]), &(adresse[4]), &(adresse[5]),
 1634:                             &(adresse[6]), &(adresse[7]), &(adresse[8]),
 1635:                             &(adresse[9]), &(adresse[10]), &(adresse[11]),
 1636:                             &(adresse[12]), &(adresse[13]), &(adresse[14]),
 1637:                             &(adresse[15]), &port)== 17)
 1638:                     { // Adresse IPv6
 1639: #                       ifdef IPV6
 1640:                         memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
 1641:                         adresse_ipv6.sin6_family = AF_INET6;
 1642:                         adresse_ipv6.sin6_port = htons((uint16_t) port);
 1643: 
 1644:                         for(i = 0; i < 16;
 1645:                                 adresse_ipv6.sin6_addr.s6_addr[i] =
 1646:                                 adresse[i], i++);
 1647: 
 1648: #                       ifndef SEMAPHORES_NOMMES
 1649:                         if (sem_post(&((*s_etat_processus)
 1650:                                 .semaphore_fork)) != 0)
 1651:                         {
 1652:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1653:                             return;
 1654:                         }
 1655: #                       else
 1656:                         if (sem_post((*s_etat_processus) .semaphore_fork) != 0)
 1657:                         {
 1658:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1659:                             return;
 1660:                         }
 1661: #                       endif
 1662: 
 1663:                         if (sendto((*((struct_socket *)
 1664:                                 (*s_objet_argument_1).objet)).socket, chaine,
 1665:                                 strlen(chaine), 0, (struct sockaddr *)
 1666:                                 &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
 1667:                         {
 1668: #                           ifndef SEMAPHORES_NOMMES
 1669:                             while(sem_wait(&((*s_etat_processus)
 1670:                                     .semaphore_fork)) == -1)
 1671: #                           else
 1672:                             while(sem_wait((*s_etat_processus)
 1673:                                     .semaphore_fork) == -1)
 1674: #                           endif
 1675:                             {
 1676:                                 if (errno != EINTR)
 1677:                                 {
 1678:                                     (*s_etat_processus).erreur_systeme =
 1679:                                             d_es_processus;
 1680:                                     return;
 1681:                                 }
 1682:                             }
 1683: 
 1684:                             (*s_etat_processus).erreur_systeme =
 1685:                                     d_es_erreur_fichier;
 1686:                             return;
 1687:                         }
 1688: 
 1689: #                       ifndef SEMAPHORES_NOMMES
 1690:                         while(sem_wait(&((*s_etat_processus)
 1691:                                 .semaphore_fork)) == -1)
 1692: #                       else
 1693:                         while(sem_wait((*s_etat_processus)
 1694:                                 .semaphore_fork) == -1)
 1695: #                       endif
 1696:                         {
 1697:                             if (errno != EINTR)
 1698:                             {
 1699:                                 (*s_etat_processus).erreur_systeme =
 1700:                                         d_es_processus;
 1701:                                 return;
 1702:                             }
 1703:                         }
 1704: #                       else
 1705:                         if ((*s_etat_processus).langue == 'F')
 1706:                         {
 1707:                             printf("+++Attention : Support du protocole"
 1708:                                     " IPv6 indisponible\n");
 1709:                         }
 1710:                         else
 1711:                         {
 1712:                             printf("+++Warning : IPv6 support "
 1713:                                     "unavailable\n");
 1714:                         }
 1715: #                       endif
 1716:                     }
 1717:                     else
 1718:                     {
 1719:                         liberation(s_etat_processus, s_objet_argument_1);
 1720:                         liberation(s_etat_processus, s_objet_argument_2);
 1721: 
 1722:                         (*s_etat_processus).erreur_execution =
 1723:                                 d_ex_erreur_parametre_fichier;
 1724:                         return;
 1725:                     }
 1726:                 }
 1727:                 else 
 1728:                 {
 1729:                     liberation(s_etat_processus, s_objet_argument_1);
 1730:                     liberation(s_etat_processus, s_objet_argument_2);
 1731: 
 1732:                     (*s_etat_processus).erreur_execution =
 1733:                             d_ex_erreur_parametre_fichier;
 1734:                     return;
 1735:                 }
 1736:             }
 1737: 
 1738:             free(chaine);
 1739:         }
 1740:         else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
 1741:                 == 'Y')
 1742:         {
 1743:             /*
 1744:              * Sockets non formatées
 1745:              */
 1746:         }
 1747:         else
 1748:         {
 1749:             /*
 1750:              *  Sockets de type FLOW
 1751:              */
 1752:         }
 1753:     }
 1754:     else
 1755:     {
 1756:         liberation(s_etat_processus, s_objet_argument_2);
 1757:         liberation(s_etat_processus, s_objet_argument_1);
 1758: 
 1759:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1760:         return;
 1761:     }
 1762: 
 1763:     liberation(s_etat_processus, s_objet_argument_2);
 1764:     liberation(s_etat_processus, s_objet_argument_1);
 1765: 
 1766:     return;
 1767: }
 1768: 
 1769: 
 1770: /*
 1771: ================================================================================
 1772:   Fonction 'wflock'
 1773: ================================================================================
 1774:   Entrées : pointeur sur une structure struct_processus
 1775: --------------------------------------------------------------------------------
 1776:   Sorties :
 1777: --------------------------------------------------------------------------------
 1778:   Effets de bord : néant
 1779: ================================================================================
 1780: */
 1781: 
 1782: void
 1783: instruction_wflock(struct_processus *s_etat_processus)
 1784: {
 1785:     logical1                    drapeau;
 1786: 
 1787:     struct flock                lock;
 1788: 
 1789:     struct timespec             attente;
 1790: 
 1791:     struct_descripteur_fichier  *descripteur;
 1792: 
 1793:     struct_objet                *s_objet_argument_1;
 1794:     struct_objet                *s_objet_argument_2;
 1795: 
 1796:     unsigned char               *chaine;
 1797:     unsigned char               registre_instruction_valide;
 1798: 
 1799:     attente.tv_sec = 0;
 1800:     attente.tv_nsec = GRANULARITE_us * 1000;
 1801: 
 1802:     (*s_etat_processus).erreur_execution = d_ex;
 1803: 
 1804:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1805:     {
 1806:         printf("\n  WFLOCK ");
 1807:         
 1808:         if ((*s_etat_processus).langue == 'F')
 1809:         {
 1810:             printf("(attente du positionnement d'un verrou sur un fichier)"
 1811:                     "\n\n");
 1812:         }
 1813:         else
 1814:         {
 1815:             printf("(wait for file lock)\n\n");
 1816:         }
 1817: 
 1818:         printf("    2: %s\n", d_FCH);
 1819:         printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
 1820: 
 1821:         return;
 1822:     }
 1823:     else if ((*s_etat_processus).test_instruction == 'Y')
 1824:     {
 1825:         (*s_etat_processus).nombre_arguments = -1;
 1826:         return;
 1827:     }
 1828: 
 1829:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1830:     {
 1831:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
 1832:         {
 1833:             return;
 1834:         }
 1835:     }
 1836: 
 1837:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1838:             &s_objet_argument_1) == d_erreur)
 1839:     {
 1840:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1841:         return;
 1842:     }
 1843: 
 1844:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1845:             &s_objet_argument_2) == d_erreur)
 1846:     {
 1847:         liberation(s_etat_processus, s_objet_argument_1);
 1848: 
 1849:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1850:         return;
 1851:     }
 1852: 
 1853:     if (((*s_objet_argument_2).type == FCH) &&
 1854:             ((*s_objet_argument_1).type == CHN))
 1855:     {
 1856:         drapeau = d_faux;
 1857: 
 1858:         do
 1859:         {
 1860:             if ((chaine = conversion_majuscule((unsigned char *)
 1861:                     (*s_objet_argument_1).objet)) == NULL)
 1862:             {
 1863:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1864:                 return;
 1865:             }
 1866: 
 1867:             if (strcmp(chaine, "WRITE") == 0)
 1868:             {
 1869:                 lock.l_type = F_WRLCK;
 1870:             }
 1871:             else if (strcmp(chaine, "READ") == 0)
 1872:             {
 1873:                 lock.l_type = F_RDLCK;
 1874:             }
 1875:             else if (strcmp(chaine, "NONE") == 0)
 1876:             {
 1877:                 lock.l_type = F_UNLCK;
 1878:             }
 1879:             else
 1880:             {
 1881:                 free(chaine);
 1882: 
 1883:                 liberation(s_etat_processus, s_objet_argument_1);
 1884:                 liberation(s_etat_processus, s_objet_argument_2);
 1885: 
 1886:                 (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
 1887:                 return;
 1888:             }
 1889: 
 1890:             free(chaine);
 1891: 
 1892:             lock.l_whence = SEEK_SET;
 1893:             lock.l_start = 0;
 1894:             lock.l_len = 0;
 1895:             lock.l_pid = getpid();
 1896: 
 1897:             if ((descripteur = descripteur_fichier(s_etat_processus,
 1898:                     (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
 1899:             {
 1900:                 return;
 1901:             }
 1902: 
 1903:             if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
 1904:                     == -1)
 1905:             {
 1906:                 liberation(s_etat_processus, s_objet_argument_1);
 1907:                 liberation(s_etat_processus, s_objet_argument_2);
 1908: 
 1909:                 (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
 1910:                 return;
 1911:             }
 1912: 
 1913: #           ifndef SEMAPHORES_NOMMES
 1914:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1915:             {
 1916:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1917:                 return;
 1918:             }
 1919: #           else
 1920:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1921:             {
 1922:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1923:                 return;
 1924:             }
 1925: #           endif
 1926: 
 1927: #           ifndef SEMAPHORES_NOMMES
 1928:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 1929: #           else
 1930:             while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 1931: #           endif
 1932:             {
 1933:                 if (errno != EINTR)
 1934:                 {
 1935:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1936:                     return;
 1937:                 }
 1938:             }
 1939: 
 1940:             if (lock.l_type == F_UNLCK)
 1941:             {
 1942:                 drapeau = d_vrai;
 1943:             }
 1944:             else
 1945:             {
 1946:                 if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 1947:                 {
 1948:                     affectation_interruptions_logicielles(s_etat_processus);
 1949:                 }
 1950: 
 1951:                 if ((*s_etat_processus).nombre_interruptions_en_queue
 1952:                         != 0)
 1953:                 {
 1954:                     registre_instruction_valide =
 1955:                             (*s_etat_processus).instruction_valide;
 1956:                     traitement_interruptions_logicielles(
 1957:                             s_etat_processus);
 1958:                     (*s_etat_processus).instruction_valide =
 1959:                             registre_instruction_valide;
 1960:                 }
 1961: 
 1962:                 nanosleep(&attente, NULL);
 1963:                 scrutation_injection(s_etat_processus);
 1964: 
 1965:                 INCR_GRANULARITE(attente.tv_nsec);
 1966:             }
 1967:         } while((drapeau == d_faux) && ((*s_etat_processus)
 1968:                 .var_volatile_requete_arret != -1));
 1969:     }
 1970:     else
 1971:     {
 1972:         liberation(s_etat_processus, s_objet_argument_1);
 1973:         liberation(s_etat_processus, s_objet_argument_2);
 1974: 
 1975:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1976:         return;
 1977:     }
 1978: 
 1979:     return;
 1980: }
 1981: 
 1982: 
 1983: /*
 1984: ================================================================================
 1985:   Fonction 'wfproc'
 1986: ================================================================================
 1987:   Entrées : pointeur sur une structure struct_processus
 1988: --------------------------------------------------------------------------------
 1989:   Sorties :
 1990: --------------------------------------------------------------------------------
 1991:   Effets de bord : néant
 1992: ================================================================================
 1993: */
 1994: 
 1995: void
 1996: instruction_wfproc(struct_processus *s_etat_processus)
 1997: {
 1998:     logical1                    drapeau_fin;
 1999: 
 2000:     struct_liste_chainee        *l_element_courant;
 2001: 
 2002:     struct_objet                *s_objet_argument;
 2003: 
 2004:     struct timespec             attente;
 2005: 
 2006:     unsigned char               registre_instruction_valide;
 2007: 
 2008:     (*s_etat_processus).erreur_execution = d_ex;
 2009: 
 2010:     attente.tv_sec = 0;
 2011:     attente.tv_nsec = GRANULARITE_us * 1000;
 2012: 
 2013:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2014:     {
 2015:         printf("\n  WFPROC ");
 2016: 
 2017:         if ((*s_etat_processus).langue == 'F')
 2018:         {
 2019:             printf("(attente de la fin d'un processus fils)\n\n");
 2020:         }
 2021:         else
 2022:         {
 2023:             printf("(wait for child process end)\n\n");
 2024:         }
 2025: 
 2026:         printf("    1: %s\n", d_PRC);
 2027: 
 2028:         return;
 2029:     }
 2030:     else if ((*s_etat_processus).test_instruction == 'Y')
 2031:     {
 2032:         (*s_etat_processus).nombre_arguments = -1;
 2033:         return;
 2034:     }
 2035: 
 2036:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2037:     {
 2038:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2039:         {
 2040:             return;
 2041:         }
 2042:     }
 2043: 
 2044:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2045:             &s_objet_argument) == d_erreur)
 2046:     {
 2047:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2048:         return;
 2049:     }
 2050: 
 2051:     if ((*s_objet_argument).type == PRC)
 2052:     {
 2053:         drapeau_fin = d_faux;
 2054: 
 2055:         if ((*s_etat_processus).profilage == d_vrai)
 2056:         {
 2057:             profilage(s_etat_processus, "Interprocess or interthread "
 2058:                     "communications (WFPROC)");
 2059: 
 2060:             if ((*s_etat_processus).erreur_systeme != d_es)
 2061:             {
 2062:                 return;
 2063:             }
 2064:         }
 2065: 
 2066:         if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2067:         {
 2068:             if ((*s_etat_processus).profilage == d_vrai)
 2069:             {
 2070:                 profilage(s_etat_processus, NULL);
 2071:             }
 2072: 
 2073:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2074:             return;
 2075:         }
 2076: 
 2077:         while(drapeau_fin == d_faux)
 2078:         {
 2079:             l_element_courant = (struct_liste_chainee *)
 2080:                     (*s_etat_processus).l_base_pile_processus;
 2081: 
 2082:             while(l_element_courant != NULL)
 2083:             {
 2084:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2085:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2086:                 {
 2087:                     if ((*(*((struct_processus_fils *)
 2088:                             (*s_objet_argument).objet)).thread)
 2089:                             .processus_detache == d_vrai)
 2090:                     {
 2091:                         if ((*(*((struct_processus_fils *)
 2092:                                 (*(*l_element_courant)
 2093:                                 .donnee).objet)).thread).pid ==
 2094:                                 (*(*((struct_processus_fils *)
 2095:                                 (*s_objet_argument).objet)).thread).pid)
 2096:                         {
 2097:                             break;
 2098:                         }
 2099:                     }
 2100:                 }
 2101:                 else
 2102:                 {
 2103:                     if ((*(*((struct_processus_fils *)
 2104:                             (*s_objet_argument).objet)).thread)
 2105:                             .processus_detache == d_faux)
 2106:                     {
 2107:                         if ((pthread_equal((*(*((struct_processus_fils *)
 2108:                                 (*(*l_element_courant).donnee).objet)).thread)
 2109:                                 .tid, (*(*((struct_processus_fils *)
 2110:                                 (*s_objet_argument).objet)).thread).tid) != 0)
 2111:                                 && ((*(*((struct_processus_fils *)
 2112:                                 (*(*l_element_courant).donnee).objet)).thread)
 2113:                                 .pid == (*(*((struct_processus_fils *)
 2114:                                 (*s_objet_argument).objet)).thread).pid))
 2115:                         {
 2116:                             break;
 2117:                         }
 2118:                     }
 2119:                 }
 2120: 
 2121:                 l_element_courant = (*l_element_courant).suivant;
 2122:             }
 2123: 
 2124:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2125:             {
 2126:                 if ((*s_etat_processus).profilage == d_vrai)
 2127:                 {
 2128:                     profilage(s_etat_processus, NULL);
 2129:                 }
 2130: 
 2131:                 if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2132:                 {
 2133:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2134:                     return;
 2135:                 }
 2136: 
 2137:                 liberation(s_etat_processus, s_objet_argument);
 2138:                 return;
 2139:             }
 2140: 
 2141:             if (l_element_courant == NULL)
 2142:             {
 2143:                 /*
 2144:                  * Si l_element_courant vaut NULL, le processus n'existe plus.
 2145:                  */
 2146: 
 2147:                 drapeau_fin = d_vrai;
 2148:             }
 2149:             else
 2150:             {
 2151:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2152:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2153:                 {
 2154:                     if (kill((*(*((struct_processus_fils *)
 2155:                             (*(*l_element_courant).donnee).objet)).thread).pid,
 2156:                             0) != 0)
 2157:                     {
 2158:                         drapeau_fin = d_vrai;
 2159:                     }
 2160:                     else
 2161:                     {
 2162:                         drapeau_fin = d_faux;
 2163:                     }
 2164:                 }
 2165:                 else
 2166:                 {
 2167:                     if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2168:                             (*(*l_element_courant).donnee).objet)).thread)
 2169:                             .mutex)) != 0)
 2170:                     {
 2171:                         if ((*s_etat_processus).profilage == d_vrai)
 2172:                         {
 2173:                             profilage(s_etat_processus, NULL);
 2174:                         }
 2175: 
 2176:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2177:                         return;
 2178:                     }
 2179: 
 2180:                     if ((*(*((struct_processus_fils *)
 2181:                             (*(*l_element_courant).donnee).objet)).thread)
 2182:                             .thread_actif == d_faux)
 2183:                     {
 2184:                         drapeau_fin = d_vrai;
 2185:                     }
 2186:                     else
 2187:                     {
 2188:                         drapeau_fin = d_faux;
 2189:                     }
 2190: 
 2191:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2192:                             (*(*l_element_courant).donnee).objet)).thread)
 2193:                             .mutex)) != 0)
 2194:                     {
 2195:                         if ((*s_etat_processus).profilage == d_vrai)
 2196:                         {
 2197:                             profilage(s_etat_processus, NULL);
 2198:                         }
 2199: 
 2200:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2201:                         return;
 2202:                     }
 2203:                 }
 2204: 
 2205:                 if (drapeau_fin == d_faux)
 2206:                 {
 2207:                     /*
 2208:                      * Le processus n'est pas terminé
 2209:                      */
 2210: 
 2211:                     if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2212:                     {
 2213:                         if ((*s_etat_processus).profilage == d_vrai)
 2214:                         {
 2215:                             profilage(s_etat_processus, NULL);
 2216:                         }
 2217: 
 2218:                         (*s_etat_processus).erreur_systeme =
 2219:                                 d_es_processus;
 2220:                         return;
 2221:                     }
 2222: 
 2223:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2224:                             != 0)
 2225:                     {
 2226:                         affectation_interruptions_logicielles(s_etat_processus);
 2227:                     }
 2228: 
 2229:                     if ((*s_etat_processus).nombre_interruptions_en_queue
 2230:                             != 0)
 2231:                     {
 2232:                         registre_instruction_valide =
 2233:                                 (*s_etat_processus).instruction_valide;
 2234:                         traitement_interruptions_logicielles(
 2235:                                 s_etat_processus);
 2236:                         (*s_etat_processus).instruction_valide =
 2237:                                 registre_instruction_valide;
 2238:                     }
 2239: 
 2240: #                   ifndef SEMAPHORES_NOMMES
 2241:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2242:                     {
 2243:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2244:                         return;
 2245:                     }
 2246: #                   else
 2247:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2248:                     {
 2249:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2250:                         return;
 2251:                     }
 2252: #                   endif
 2253: 
 2254:                     nanosleep(&attente, NULL);
 2255: 
 2256: #                   ifndef SEMAPHORES_NOMMES
 2257:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2258: #                   else
 2259:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2260: #                   endif
 2261:                     {
 2262:                         if (errno != EINTR)
 2263:                         {
 2264:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2265:                             return;
 2266:                         }
 2267:                     }
 2268: 
 2269:                     scrutation_injection(s_etat_processus);
 2270: 
 2271:                     if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2272:                     {
 2273:                         if ((*s_etat_processus).profilage == d_vrai)
 2274:                         {
 2275:                             profilage(s_etat_processus, NULL);
 2276:                         }
 2277: 
 2278:                         (*s_etat_processus).erreur_systeme =
 2279:                                 d_es_processus;
 2280:                         return;
 2281:                     }
 2282:                 }
 2283:             }
 2284: 
 2285:             INCR_GRANULARITE(attente.tv_nsec);
 2286:         }
 2287: 
 2288:         if ((*s_etat_processus).profilage == d_vrai)
 2289:         {
 2290:             profilage(s_etat_processus, NULL);
 2291:         }
 2292: 
 2293:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2294:         {
 2295:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2296:             return;
 2297:         }
 2298:     }
 2299:     else
 2300:     {
 2301:         liberation(s_etat_processus, s_objet_argument);
 2302: 
 2303:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2304:         return;
 2305:     }
 2306: 
 2307:     liberation(s_etat_processus, s_objet_argument);
 2308: 
 2309:     return;
 2310: }
 2311: 
 2312: 
 2313: /*
 2314: ================================================================================
 2315:   Fonction 'wfdata'
 2316: ================================================================================
 2317:   Entrées : pointeur sur une structure struct_processus
 2318: --------------------------------------------------------------------------------
 2319:   Sorties :
 2320: --------------------------------------------------------------------------------
 2321:   Effets de bord : néant
 2322: ================================================================================
 2323: */
 2324: 
 2325: void
 2326: instruction_wfdata(struct_processus *s_etat_processus)
 2327: {
 2328:     logical1                    drapeau_fin;
 2329: 
 2330:     struct_liste_chainee        *l_element_courant;
 2331: 
 2332:     struct_objet                *s_objet_argument;
 2333: 
 2334:     struct timespec             attente;
 2335: 
 2336:     unsigned char               registre_instruction_valide;
 2337: 
 2338:     (*s_etat_processus).erreur_execution = d_ex;
 2339: 
 2340:     attente.tv_sec = 0;
 2341:     attente.tv_nsec = GRANULARITE_us * 1000;
 2342: 
 2343:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2344:     {
 2345:         printf("\n  WFDATA ");
 2346: 
 2347:         if ((*s_etat_processus).langue == 'F')
 2348:         {
 2349:             printf("(attente de données d'un processus fils)\n\n");
 2350:         }
 2351:         else
 2352:         {
 2353:             printf("(wait for data from child process)\n\n");
 2354:         }
 2355: 
 2356:         printf("    1: %s\n", d_PRC);
 2357: 
 2358:         return;
 2359:     }
 2360:     else if ((*s_etat_processus).test_instruction == 'Y')
 2361:     {
 2362:         (*s_etat_processus).nombre_arguments = -1;
 2363:         return;
 2364:     }
 2365: 
 2366:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2367:     {
 2368:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2369:         {
 2370:             return;
 2371:         }
 2372:     }
 2373: 
 2374:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2375:             &s_objet_argument) == d_erreur)
 2376:     {
 2377:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2378:         return;
 2379:     }
 2380: 
 2381:     if ((*s_objet_argument).type == PRC)
 2382:     {
 2383:         drapeau_fin = d_faux;
 2384: 
 2385:         if ((*s_etat_processus).profilage == d_vrai)
 2386:         {
 2387:             profilage(s_etat_processus, "Interprocess or interthread "
 2388:                     "communications (WFDATA)");
 2389: 
 2390:             if ((*s_etat_processus).erreur_systeme != d_es)
 2391:             {
 2392:                 return;
 2393:             }
 2394:         }
 2395: 
 2396:         if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2397:         {
 2398:             if ((*s_etat_processus).profilage == d_vrai)
 2399:             {
 2400:                 profilage(s_etat_processus, NULL);
 2401:             }
 2402: 
 2403:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2404:             return;
 2405:         }
 2406: 
 2407:         while(drapeau_fin == d_faux)
 2408:         {
 2409:             l_element_courant = (struct_liste_chainee *)
 2410:                     (*s_etat_processus).l_base_pile_processus;
 2411: 
 2412:             while(l_element_courant != NULL)
 2413:             {
 2414:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2415:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2416:                 {
 2417:                     if (((*(*((struct_processus_fils *) (*(*l_element_courant)
 2418:                             .donnee).objet)).thread).pid ==
 2419:                             (*(*((struct_processus_fils *)
 2420:                             (*s_objet_argument).objet)).thread).pid)
 2421:                             && ((*(*((struct_processus_fils *)
 2422:                             (*s_objet_argument).objet)).thread)
 2423:                             .processus_detache == d_vrai))
 2424:                     {
 2425:                         break;
 2426:                     }
 2427:                 }
 2428:                 else
 2429:                 {
 2430:                     if ((pthread_equal((*(*((struct_processus_fils *)
 2431:                             (*(*l_element_courant).donnee).objet)).thread).tid,
 2432:                             (*(*((struct_processus_fils *) (*s_objet_argument)
 2433:                             .objet)).thread).tid) != 0) &&
 2434:                             ((*(*((struct_processus_fils *)
 2435:                             (*(*l_element_courant).donnee).objet)).thread).pid
 2436:                             == (*(*((struct_processus_fils *)
 2437:                             (*s_objet_argument).objet)).thread).pid) &&
 2438:                             ((*(*((struct_processus_fils *)
 2439:                             (*s_objet_argument).objet)).thread)
 2440:                             .processus_detache == d_faux))
 2441:                     {
 2442:                         break;
 2443:                     }
 2444:                 }
 2445: 
 2446:                 l_element_courant = (*l_element_courant).suivant;
 2447:             }
 2448: 
 2449:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2450:             {
 2451:                 if ((*s_etat_processus).profilage == d_vrai)
 2452:                 {
 2453:                     profilage(s_etat_processus, NULL);
 2454:                 }
 2455: 
 2456:                 if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2457:                 {
 2458:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2459:                     return;
 2460:                 }
 2461: 
 2462:                 liberation(s_etat_processus, s_objet_argument);
 2463:                 return;
 2464:             }
 2465: 
 2466:             if (l_element_courant != NULL)
 2467:             {
 2468:                 if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2469:                         (*(*l_element_courant).donnee).objet)).thread).mutex))
 2470:                         != 0)
 2471:                 {
 2472:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2473:                     return;
 2474:                 }
 2475: 
 2476:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2477:                         .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
 2478:                 {
 2479:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2480:                             (*(*l_element_courant).donnee).objet)).thread)
 2481:                             .mutex)) != 0)
 2482:                     {
 2483:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2484:                         return;
 2485:                     }
 2486: 
 2487:                     drapeau_fin = d_vrai;
 2488:                 }
 2489:                 else
 2490:                 {
 2491:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2492:                             (*(*l_element_courant).donnee).objet)).thread)
 2493:                             .mutex)) != 0)
 2494:                     {
 2495:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2496:                         return;
 2497:                     }
 2498: 
 2499:                     if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2500:                     {
 2501:                         if ((*s_etat_processus).profilage == d_vrai)
 2502:                         {
 2503:                             profilage(s_etat_processus, NULL);
 2504:                         }
 2505: 
 2506:                         (*s_etat_processus).erreur_systeme =
 2507:                                 d_es_processus;
 2508:                         return;
 2509:                     }
 2510: 
 2511: #                   ifndef SEMAPHORES_NOMMES
 2512:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2513:                     {
 2514:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2515:                         return;
 2516:                     }
 2517: #                   else
 2518:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2519:                     {
 2520:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2521:                         return;
 2522:                     }
 2523: #                   endif
 2524: 
 2525:                     nanosleep(&attente, NULL);
 2526: 
 2527: #                   ifndef SEMAPHORES_NOMMES
 2528:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2529: #                   else
 2530:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2531: #                   endif
 2532:                     {
 2533:                         if (errno != EINTR)
 2534:                         {
 2535:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2536:                             return;
 2537:                         }
 2538:                     }
 2539: 
 2540:                     scrutation_injection(s_etat_processus);
 2541: 
 2542:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2543:                             != 0)
 2544:                     {
 2545:                         affectation_interruptions_logicielles(s_etat_processus);
 2546:                     }
 2547: 
 2548:                     if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 2549:                     {
 2550:                         registre_instruction_valide =
 2551:                                 (*s_etat_processus).instruction_valide;
 2552:                         traitement_interruptions_logicielles(s_etat_processus);
 2553:                         (*s_etat_processus).instruction_valide =
 2554:                                 registre_instruction_valide;
 2555:                     }
 2556: 
 2557:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2558:                     {
 2559:                         if ((*s_etat_processus).profilage == d_vrai)
 2560:                         {
 2561:                             profilage(s_etat_processus, NULL);
 2562:                         }
 2563: 
 2564:                         return;
 2565:                     }
 2566: 
 2567:                     if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
 2568:                     {
 2569:                         if ((*s_etat_processus).profilage == d_vrai)
 2570:                         {
 2571:                             profilage(s_etat_processus, NULL);
 2572:                         }
 2573: 
 2574:                         (*s_etat_processus).erreur_systeme =
 2575:                                 d_es_processus;
 2576:                         return;
 2577:                     }
 2578:                 }
 2579:             }
 2580:             else
 2581:             {
 2582:                 drapeau_fin = d_vrai;
 2583:                 (*s_etat_processus).erreur_execution = d_ex_processus;
 2584:             }
 2585: 
 2586:             INCR_GRANULARITE(attente.tv_nsec);
 2587:         }
 2588: 
 2589:         if ((*s_etat_processus).profilage == d_vrai)
 2590:         {
 2591:             profilage(s_etat_processus, NULL);
 2592:         }
 2593: 
 2594:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
 2595:         {
 2596:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2597:             return;
 2598:         }
 2599:     }
 2600:     else
 2601:     {
 2602:         liberation(s_etat_processus, s_objet_argument);
 2603: 
 2604:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2605:         return;
 2606:     }
 2607: 
 2608:     liberation(s_etat_processus, s_objet_argument);
 2609: 
 2610:     return;
 2611: }
 2612: 
 2613: 
 2614: /*
 2615: ================================================================================
 2616:   Fonction 'wfsock'
 2617: ================================================================================
 2618:   Entrées : pointeur sur une structure struct_processus
 2619: --------------------------------------------------------------------------------
 2620:   Sorties :
 2621: --------------------------------------------------------------------------------
 2622:   Effets de bord : néant
 2623: ================================================================================
 2624: */
 2625: 
 2626: void
 2627: instruction_wfsock(struct_processus *s_etat_processus)
 2628: {
 2629:     int                     erreur;
 2630: 
 2631:     logical1                drapeau;
 2632: 
 2633:     socklen_t               longueur;
 2634: 
 2635:     struct_liste_chainee    *l_element_courant;
 2636: 
 2637:     struct_objet            *s_objet_argument;
 2638:     struct_objet            *s_objet_resultat;
 2639: 
 2640:     struct sockaddr_in      adresse_ipv4;
 2641: #   ifdef IPV6
 2642:     struct sockaddr_in6     adresse_ipv6;
 2643: #   endif
 2644: 
 2645:     unsigned long           i;
 2646: 
 2647:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2648:     {
 2649:         printf("\n  WFSOCK ");
 2650: 
 2651:         if ((*s_etat_processus).langue == 'F')
 2652:         {
 2653:             printf("(attente d'une connexion sur une socket)\n\n");
 2654:         }
 2655:         else
 2656:         {
 2657:             printf("(wait for connection on a socket)\n\n");
 2658:         }
 2659: 
 2660:         printf("    1: %s\n", d_SCK);
 2661:         printf("->  2: %s\n", d_SCK);
 2662:         printf("    1: %s\n", d_SCK);
 2663: 
 2664:         return;
 2665:     }
 2666:     else if ((*s_etat_processus).test_instruction == 'Y')
 2667:     {
 2668:         (*s_etat_processus).nombre_arguments = -1;
 2669:         return;
 2670:     }
 2671: 
 2672:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2673:     {
 2674:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2675:         {
 2676:             return;
 2677:         }
 2678:     }
 2679: 
 2680:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2681:             &s_objet_argument) == d_erreur)
 2682:     {
 2683:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2684:         return;
 2685:     }
 2686: 
 2687:     if ((*s_objet_argument).type == SCK)
 2688:     {
 2689:         if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
 2690:                 "STREAM") != 0) && (strcmp((*((struct_socket *)
 2691:                 (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
 2692:         {
 2693:             liberation(s_etat_processus, s_objet_argument);
 2694: 
 2695:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
 2696:             return;
 2697:         }
 2698: 
 2699:         if ((s_objet_resultat = copie_objet(s_etat_processus, s_objet_argument,
 2700:                 'O')) == NULL)
 2701:         {
 2702:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2703:             return;
 2704:         }
 2705: 
 2706:         (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute = 'N';
 2707:         (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
 2708: 
 2709:         if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine == PF_INET)
 2710:         {
 2711:             longueur = sizeof(adresse_ipv4);
 2712: 
 2713:             do
 2714:             {
 2715:                 drapeau = d_vrai;
 2716: 
 2717: #               ifndef SEMAPHORES_NOMMES
 2718:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2719:                 {
 2720:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2721:                     return;
 2722:                 }
 2723: #               else
 2724:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2725:                 {
 2726:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2727:                     return;
 2728:                 }
 2729: #               endif
 2730: 
 2731:                 if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
 2732:                         accept((*((struct_socket *) (*s_objet_argument).objet))
 2733:                         .socket, (struct sockaddr *) &adresse_ipv4, &longueur))
 2734:                         < 0)
 2735:                 {
 2736:                     erreur = errno;
 2737: 
 2738: #                   ifndef SEMAPHORES_NOMMES
 2739:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2740: #                   else
 2741:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2742: #                   endif
 2743:                     {
 2744:                         if (errno != EINTR)
 2745:                         {
 2746:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2747:                             return;
 2748:                         }
 2749:                     }
 2750: 
 2751:                     if (erreur != EINTR)
 2752:                     {
 2753:                         liberation(s_etat_processus, s_objet_argument);
 2754:                         liberation(s_etat_processus, s_objet_resultat);
 2755: 
 2756:                         (*s_etat_processus).erreur_execution =
 2757:                                 d_ex_erreur_acces_fichier;
 2758:                         return;
 2759:                     }
 2760: 
 2761:                     scrutation_injection(s_etat_processus);
 2762: 
 2763:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2764:                     {
 2765:                         drapeau = d_vrai;
 2766:                     }
 2767:                     else
 2768:                     {
 2769:                         drapeau = d_faux;
 2770:                     }
 2771:                 }
 2772:                 else
 2773:                 {
 2774: #                   ifndef SEMAPHORES_NOMMES
 2775:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2776: #                   else
 2777:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2778: #                   endif
 2779:                     {
 2780:                         if (errno != EINTR)
 2781:                         {
 2782:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2783:                             return;
 2784:                         }
 2785:                     }
 2786:                 }
 2787:             } while(drapeau == d_faux);
 2788: 
 2789:             if (((*((struct_socket *) (*s_objet_resultat).objet))
 2790:                     .adresse_distante = malloc(22 *
 2791:                     sizeof(unsigned char))) == NULL)
 2792:             {
 2793:                 (*s_etat_processus).erreur_systeme =
 2794:                         d_es_allocation_memoire;
 2795:                 return;
 2796:             }
 2797: 
 2798:             sprintf((*((struct_socket *) (*s_objet_resultat).objet))
 2799:                     .adresse_distante, "%d.%d.%d.%d(%d)",
 2800:                     (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
 2801:                     (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
 2802:                     (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
 2803:                     ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
 2804:                     ntohs(adresse_ipv4.sin_port));
 2805:         }
 2806:         else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
 2807:                 PF_INET6)
 2808:         {
 2809: #           ifdef IPV6
 2810:             longueur = sizeof(adresse_ipv6);
 2811: 
 2812:             do
 2813:             {
 2814:                 drapeau = d_vrai;
 2815: 
 2816: #               ifndef SEMAPHORES_NOMMES
 2817:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2818:                 {
 2819:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2820:                     return;
 2821:                 }
 2822: #               else
 2823:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2824:                 {
 2825:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2826:                     return;
 2827:                 }
 2828: #               endif
 2829: 
 2830:                 if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
 2831:                         accept((*((struct_socket *) (*s_objet_argument).objet))
 2832:                         .socket, (struct sockaddr *) &adresse_ipv6, &longueur))
 2833:                         < 0)
 2834:                 {
 2835:                     erreur = errno;
 2836: 
 2837: #                   ifndef SEMAPHORES_NOMMES
 2838:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2839: #                   else
 2840:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2841: #                   endif
 2842:                     {
 2843:                         if (errno != EINTR)
 2844:                         {
 2845:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2846:                             return;
 2847:                         }
 2848:                     }
 2849: 
 2850:                     if (erreur != EINTR)
 2851:                     {
 2852:                         liberation(s_etat_processus, s_objet_argument);
 2853:                         liberation(s_etat_processus, s_objet_resultat);
 2854: 
 2855:                         (*s_etat_processus).erreur_execution =
 2856:                                 d_ex_erreur_acces_fichier;
 2857:                         return;
 2858:                     }
 2859: 
 2860:                     scrutation_injection(s_etat_processus);
 2861: 
 2862:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2863:                     {
 2864:                         drapeau = d_vrai;
 2865:                     }
 2866:                     else
 2867:                     {
 2868:                         drapeau = d_faux;
 2869:                     }
 2870:                 }
 2871:                 else
 2872:                 {
 2873: #                   ifndef SEMAPHORES_NOMMES
 2874:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2875: #                   else
 2876:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2877: #                   endif
 2878:                     {
 2879:                         if (errno != EINTR)
 2880:                         {
 2881:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2882:                             return;
 2883:                         }
 2884:                     }
 2885:                 }
 2886:             } while(drapeau == d_faux);
 2887: 
 2888:             if (((*((struct_socket *) (*s_objet_resultat).objet))
 2889:                     .adresse_distante = malloc(55 *
 2890:                     sizeof(unsigned char))) == NULL)
 2891:             {
 2892:                 (*s_etat_processus).erreur_systeme =
 2893:                         d_es_allocation_memoire;
 2894:                 return;
 2895:             }
 2896: 
 2897:             (*((struct_socket *) (*s_objet_resultat).objet))
 2898:                     .adresse_distante = d_code_fin_chaine;
 2899: 
 2900:             for(i = 0; i < 16; i++)
 2901:             {
 2902:                 sprintf((*((struct_socket *) (*s_objet_resultat)
 2903:                         .objet)).adresse_distante, (i == 0) ? "%s%X" : "%s:%X",
 2904:                         (*((struct_socket *) (*s_objet_resultat)
 2905:                         .objet)).adresse_distante,
 2906:                         adresse_ipv6.sin6_addr.s6_addr[i]);
 2907:             }
 2908: 
 2909:             sprintf((*((struct_socket *) (*s_objet_resultat)
 2910:                     .objet)).adresse_distante, "%s(%u)",
 2911:                     (*((struct_socket *) (*s_objet_resultat)
 2912:                     .objet)).adresse_distante, ntohs(adresse_ipv6.sin6_port));
 2913: #           else
 2914:             if ((*s_etat_processus).langue == 'F')
 2915:             {
 2916:                 printf("+++Attention : Support du protocole"
 2917:                         " IPv6 indisponible\n");
 2918:             }
 2919:             else
 2920:             {
 2921:                 printf("+++Warning : IPv6 support "
 2922:                         "unavailable\n");
 2923:             }
 2924: #           endif
 2925:         }
 2926:         else
 2927:         {
 2928:             longueur = 0;
 2929: 
 2930:             do
 2931:             {
 2932:                 drapeau = d_vrai;
 2933: 
 2934: #               ifndef SEMAPHORES_NOMMES
 2935:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2936:                 {
 2937:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2938:                     return;
 2939:                 }
 2940: #               else
 2941:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2942:                 {
 2943:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2944:                     return;
 2945:                 }
 2946: #               endif
 2947: 
 2948:                 if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
 2949:                         accept((*((struct_socket *) (*s_objet_argument).objet))
 2950:                         .socket, NULL, &longueur)) < 0)
 2951:                 {
 2952:                     erreur = errno;
 2953: 
 2954: #                   ifndef SEMAPHORES_NOMMES
 2955:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2956: #                   else
 2957:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2958: #                   endif
 2959:                     {
 2960:                         if (errno != EINTR)
 2961:                         {
 2962:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2963:                             return;
 2964:                         }
 2965:                     }
 2966: 
 2967:                     if (erreur != EINTR)
 2968:                     {
 2969:                         liberation(s_etat_processus, s_objet_argument);
 2970:                         liberation(s_etat_processus, s_objet_resultat);
 2971: 
 2972:                         (*s_etat_processus).erreur_execution =
 2973:                                 d_ex_erreur_acces_fichier;
 2974:                         return;
 2975:                     }
 2976: 
 2977:                     scrutation_injection(s_etat_processus);
 2978: 
 2979:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2980:                     {
 2981:                         drapeau = d_vrai;
 2982:                     }
 2983:                     else
 2984:                     {
 2985:                         drapeau = d_faux;
 2986:                     }
 2987:                 }
 2988:                 else
 2989:                 {
 2990: #                   ifndef SEMAPHORES_NOMMES
 2991:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 2992: #                   else
 2993:                     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 2994: #                   endif
 2995:                     {
 2996:                         if (errno != EINTR)
 2997:                         {
 2998:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2999:                             return;
 3000:                         }
 3001:                     }
 3002:                 }
 3003:             } while(drapeau == d_faux);
 3004:         }
 3005: 
 3006:         // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
 3007:         // que de EINTR sachant qu'une requête d'arrêt est en court de
 3008:         // traitement.
 3009: 
 3010:         if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
 3011:         {
 3012:             l_element_courant = (*s_etat_processus).s_sockets;
 3013: 
 3014:             if (l_element_courant == NULL)
 3015:             {
 3016:                 if (((*s_etat_processus).s_sockets =
 3017:                         allocation_maillon(s_etat_processus)) == NULL)
 3018:                 {
 3019:                     (*s_etat_processus).erreur_systeme =
 3020:                             d_es_allocation_memoire;
 3021:                     return;
 3022:                 }
 3023: 
 3024:                 (*(*s_etat_processus).s_sockets).suivant = NULL;
 3025:                 l_element_courant = (*s_etat_processus).s_sockets;
 3026:             }
 3027:             else
 3028:             {
 3029:                 /*
 3030:                  * Ajout d'un élément à la fin de la liste chaînée
 3031:                  */
 3032: 
 3033:                 while((*l_element_courant).suivant != NULL)
 3034:                 {
 3035:                     l_element_courant = (*l_element_courant).suivant;
 3036:                 }
 3037: 
 3038:                 if (((*l_element_courant).suivant =
 3039:                         allocation_maillon(s_etat_processus)) == NULL)
 3040:                 {
 3041:                     (*s_etat_processus).erreur_systeme =
 3042:                             d_es_allocation_memoire;
 3043:                     return;
 3044:                 }
 3045: 
 3046:                 l_element_courant = (*l_element_courant).suivant;
 3047:                 (*l_element_courant).suivant = NULL;
 3048:             }
 3049: 
 3050:             if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
 3051:                     s_objet_resultat, 'O')) == NULL)
 3052:             {
 3053:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 3054:                 return;
 3055:             }
 3056:         }
 3057: 
 3058:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3059:                 s_objet_argument) == d_erreur)
 3060:         {
 3061:             return;
 3062:         }
 3063: 
 3064:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3065:                 s_objet_resultat) == d_erreur)
 3066:         {
 3067:             return;
 3068:         }
 3069:     }
 3070:     else
 3071:     {
 3072:         liberation(s_etat_processus, s_objet_argument);
 3073: 
 3074:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3075:         return;
 3076:     }
 3077: 
 3078:     return;
 3079: }
 3080: 
 3081: 
 3082: /*
 3083: ================================================================================
 3084:   Fonction 'wfswi'
 3085: ================================================================================
 3086:   Entrées : pointeur sur une structure struct_processus
 3087: --------------------------------------------------------------------------------
 3088:   Sorties :
 3089: --------------------------------------------------------------------------------
 3090:   Effets de bord : néant
 3091: ================================================================================
 3092: */
 3093: 
 3094: void
 3095: instruction_wfswi(struct_processus *s_etat_processus)
 3096: {
 3097:     integer8                    interruption;
 3098: 
 3099:     logical1                    drapeau_fin;
 3100: 
 3101:     struct_objet                *s_objet_argument;
 3102: 
 3103:     struct timespec             attente;
 3104: 
 3105:     (*s_etat_processus).erreur_execution = d_ex;
 3106: 
 3107:     attente.tv_sec = 0;
 3108:     attente.tv_nsec = GRANULARITE_us * 1000;
 3109: 
 3110:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3111:     {
 3112:         printf("\n  WFSWI ");
 3113: 
 3114:         if ((*s_etat_processus).langue == 'F')
 3115:         {
 3116:             printf("(attente d'une interruption)\n\n");
 3117:         }
 3118:         else
 3119:         {
 3120:             printf("(wait for interrupt)\n\n");
 3121:         }
 3122: 
 3123:         printf("    1: %s\n", d_INT);
 3124: 
 3125:         return;
 3126:     }
 3127:     else if ((*s_etat_processus).test_instruction == 'Y')
 3128:     {
 3129:         (*s_etat_processus).nombre_arguments = -1;
 3130:         return;
 3131:     }
 3132: 
 3133:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3134:     {
 3135:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 3136:         {
 3137:             return;
 3138:         }
 3139:     }
 3140: 
 3141:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3142:             &s_objet_argument) == d_erreur)
 3143:     {
 3144:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 3145:         return;
 3146:     }
 3147: 
 3148:     if ((*s_objet_argument).type == INT)
 3149:     {
 3150:         drapeau_fin = d_faux;
 3151: 
 3152:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 3153: 
 3154:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 3155:         {
 3156:             liberation(s_etat_processus, s_objet_argument);
 3157: 
 3158:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 3159:             return;
 3160:         }
 3161: 
 3162:         while(drapeau_fin == d_faux)
 3163:         {
 3164:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3165:             {
 3166:                 liberation(s_etat_processus, s_objet_argument);
 3167:                 return;
 3168:             }
 3169: 
 3170:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3171:             {
 3172:                 affectation_interruptions_logicielles(s_etat_processus);
 3173:             }
 3174: 
 3175:             if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
 3176:             {
 3177:                 drapeau_fin = d_vrai;
 3178:             }
 3179:             else
 3180:             {
 3181:                 nanosleep(&attente, NULL);
 3182:                 scrutation_injection(s_etat_processus);
 3183:                 INCR_GRANULARITE(attente.tv_nsec);
 3184:             }
 3185:         }
 3186:     }
 3187:     else
 3188:     {
 3189:         liberation(s_etat_processus, s_objet_argument);
 3190: 
 3191:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3192:         return;
 3193:     }
 3194: 
 3195:     liberation(s_etat_processus, s_objet_argument);
 3196: 
 3197:     return;
 3198: }
 3199: 
 3200: 
 3201: /*
 3202: ================================================================================
 3203:   Fonction 'wfpoke'
 3204: ================================================================================
 3205:   Entrées : pointeur sur une structure struct_processus
 3206: --------------------------------------------------------------------------------
 3207:   Sorties :
 3208: --------------------------------------------------------------------------------
 3209:   Effets de bord : néant
 3210: ================================================================================
 3211: */
 3212: 
 3213: void
 3214: instruction_wfpoke(struct_processus *s_etat_processus)
 3215: {
 3216:     struct timespec             attente;
 3217: 
 3218:     unsigned char               registre_instruction_valide;
 3219: 
 3220:     (*s_etat_processus).erreur_execution = d_ex;
 3221: 
 3222:     attente.tv_sec = 0;
 3223:     attente.tv_nsec = GRANULARITE_us * 1000;
 3224: 
 3225:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3226:     {
 3227:         printf("\n  WFPOKE ");
 3228: 
 3229:         if ((*s_etat_processus).langue == 'F')
 3230:         {
 3231:             printf("(attente de données en provenance du processus père)\n\n");
 3232:             printf("  Aucun argument\n");
 3233:         }
 3234:         else
 3235:         {
 3236:             printf("(wait for data from parent process)\n\n");
 3237:             printf("  No argument\n");
 3238:         }
 3239: 
 3240:         return;
 3241:     }
 3242:     else if ((*s_etat_processus).test_instruction == 'Y')
 3243:     {
 3244:         (*s_etat_processus).nombre_arguments = -1;
 3245:         return;
 3246:     }
 3247: 
 3248:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3249:     {
 3250:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 3251:         {
 3252:             return;
 3253:         }
 3254:     }
 3255: 
 3256:     if ((*s_etat_processus).presence_pipes == d_faux)
 3257:     {
 3258:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 3259:         return;
 3260:     }
 3261: 
 3262:     if ((*s_etat_processus).nombre_objets_injectes > 0)
 3263:     {
 3264:         return;
 3265:     }
 3266: 
 3267:     if ((*s_etat_processus).profilage == d_vrai)
 3268:     {
 3269:         profilage(s_etat_processus, "Interprocess or interthread "
 3270:                 "communications (WFPOKE)");
 3271: 
 3272:         if ((*s_etat_processus).erreur_systeme != d_es)
 3273:         {
 3274:             return;
 3275:         }
 3276:     }
 3277: 
 3278:     do
 3279:     {
 3280: #       ifndef SEMAPHORES_NOMMES
 3281:         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3282:         {
 3283:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3284:             return;
 3285:         }
 3286: #       else
 3287:         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3288:         {
 3289:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3290:             return;
 3291:         }
 3292: #       endif
 3293: 
 3294:         nanosleep(&attente, NULL);
 3295: 
 3296: #       ifndef SEMAPHORES_NOMMES
 3297:         while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 3298: #       else
 3299:         while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 3300: #       endif
 3301:         {
 3302:             if (errno != EINTR)
 3303:             {
 3304:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3305:                 return;
 3306:             }
 3307:         }
 3308: 
 3309:         scrutation_injection(s_etat_processus);
 3310: 
 3311:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3312:         {
 3313:             affectation_interruptions_logicielles(s_etat_processus);
 3314:         }
 3315: 
 3316:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 3317:         {
 3318:             registre_instruction_valide =
 3319:                     (*s_etat_processus).instruction_valide;
 3320:             traitement_interruptions_logicielles(s_etat_processus);
 3321:             (*s_etat_processus).instruction_valide =
 3322:                     registre_instruction_valide;
 3323:         }
 3324: 
 3325:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3326:         {
 3327:             if ((*s_etat_processus).profilage == d_vrai)
 3328:             {
 3329:                 profilage(s_etat_processus, NULL);
 3330:             }
 3331: 
 3332:             return;
 3333:         }
 3334: 
 3335:         INCR_GRANULARITE(attente.tv_nsec);
 3336:     } while((*s_etat_processus).nombre_objets_injectes == 0);
 3337: 
 3338:     return;
 3339: }
 3340: 
 3341: 
 3342: /*
 3343: ================================================================================
 3344:   Fonction 'wfack'
 3345: ================================================================================
 3346:   Entrées : pointeur sur une structure struct_processus
 3347: --------------------------------------------------------------------------------
 3348:   Sorties :
 3349: --------------------------------------------------------------------------------
 3350:   Effets de bord : néant
 3351: ================================================================================
 3352: */
 3353: 
 3354: void
 3355: instruction_wfack(struct_processus *s_etat_processus)
 3356: {
 3357:     struct timespec             attente;
 3358: 
 3359:     unsigned char               registre_instruction_valide;
 3360: 
 3361:     (*s_etat_processus).erreur_execution = d_ex;
 3362: 
 3363:     attente.tv_sec = 0;
 3364:     attente.tv_nsec = GRANULARITE_us * 1000;
 3365: 
 3366:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3367:     {
 3368:         printf("\n  WFACK ");
 3369: 
 3370:         if ((*s_etat_processus).langue == 'F')
 3371:         {
 3372:             printf("(attente des acquittements de lecture)\n\n");
 3373:             printf("  Aucun argument\n");
 3374:         }
 3375:         else
 3376:         {
 3377:             printf("(wait for reading of data acknowledgement)\n\n");
 3378:             printf("  No argument\n");
 3379:         }
 3380: 
 3381:         return;
 3382:     }
 3383:     else if ((*s_etat_processus).test_instruction == 'Y')
 3384:     {
 3385:         (*s_etat_processus).nombre_arguments = -1;
 3386:         return;
 3387:     }
 3388: 
 3389:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3390:     {
 3391:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 3392:         {
 3393:             return;
 3394:         }
 3395:     }
 3396: 
 3397:     if ((*s_etat_processus).presence_pipes == d_faux)
 3398:     {
 3399:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 3400:         return;
 3401:     }
 3402: 
 3403:     if ((*s_etat_processus).profilage == d_vrai)
 3404:     {
 3405:         profilage(s_etat_processus, "Interprocess or interthread communications"
 3406:                 " (WFACK)");
 3407: 
 3408:         if ((*s_etat_processus).erreur_systeme != d_es)
 3409:         {
 3410:             return;
 3411:         }
 3412:     }
 3413: 
 3414:     while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
 3415:     {
 3416:         scrutation_injection(s_etat_processus);
 3417: 
 3418:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3419:         {
 3420:             affectation_interruptions_logicielles(s_etat_processus);
 3421:         }
 3422: 
 3423:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 3424:         {
 3425:             registre_instruction_valide =
 3426:                     (*s_etat_processus).instruction_valide;
 3427:             traitement_interruptions_logicielles(s_etat_processus);
 3428:             (*s_etat_processus).instruction_valide =
 3429:                     registre_instruction_valide;
 3430:         }
 3431: 
 3432:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3433:         {
 3434:             if ((*s_etat_processus).profilage == d_vrai)
 3435:             {
 3436:                 profilage(s_etat_processus, NULL);
 3437:             }
 3438: 
 3439:             return;
 3440:         }
 3441: 
 3442: #       ifndef SEMAPHORES_NOMMES
 3443:         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3444:         {
 3445:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3446:             return;
 3447:         }
 3448: #       else
 3449:         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3450:         {
 3451:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3452:             return;
 3453:         }
 3454: #       endif
 3455: 
 3456:         nanosleep(&attente, NULL);
 3457:         INCR_GRANULARITE(attente.tv_nsec);
 3458: 
 3459: #       ifndef SEMAPHORES_NOMMES
 3460:         while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
 3461: #       else
 3462:         while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
 3463: #       endif
 3464:         {
 3465:             if (errno != EINTR)
 3466:             {
 3467:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3468:                 return;
 3469:             }
 3470:         }
 3471:     }
 3472: 
 3473:     if ((*s_etat_processus).profilage == d_vrai)
 3474:     {
 3475:         profilage(s_etat_processus, NULL);
 3476:     }
 3477: 
 3478:     return;
 3479: }
 3480: 
 3481: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>