File:  [local] / rpl / src / instructions_w1.c
Revision 1.131: download - view: text, annotated - select for diffs - revision graph
Wed Oct 30 13:15:21 2024 UTC (6 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Correction d'un bug dans les fichiers à accès direct et indexés.
ATTENTION : les fichiers à accès direct et indexés ne fonctionnent
que en mode "FORMATTED".

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

CVSweb interface <joel.bertrand@systella.fr>