File:  [local] / rpl / src / instructions_w1.c
Revision 1.65: download - view: text, annotated - select for diffs - revision graph
Thu Jul 5 08:05:50 2012 UTC (11 years, 10 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_9, HEAD
Correction d'un problème sérieux dans la gestion des formats.

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

CVSweb interface <joel.bertrand@systella.fr>