File:  [local] / rpl / src / instructions_w1.c
Revision 1.70: download - view: text, annotated - select for diffs - revision graph
Fri Dec 21 12:09:50 2012 UTC (11 years, 4 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout de la gestion de SQLITE_BUSY et SQLITE_LOCKED.

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

CVSweb interface <joel.bertrand@systella.fr>