File:  [local] / rpl / src / instructions_w1.c
Revision 1.110: download - view: text, annotated - select for diffs - revision graph
Fri Jun 1 09:57:28 2018 UTC (5 years, 11 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout de la possibilité d'utiliser \ dans les expressions régulières
("^\\.SUBCKT" regex).

Le format LINE*(*) est rajouté pour lire et écrire simplement des
fichiers séquentiels orientés ligne.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.29
    4:   Copyright (C) 1989-2018 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'while'
   29: ================================================================================
   30:   Entrées :
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_while(struct_processus *s_etat_processus)
   40: {
   41:     (*s_etat_processus).erreur_execution = d_ex;
   42: 
   43:     if ((*s_etat_processus).affichage_arguments == 'Y')
   44:     {
   45:         printf("\n  WHILE ");
   46: 
   47:         if ((*s_etat_processus).langue == 'F')
   48:         {
   49:             printf("(structure de contrôle)\n\n");
   50:             printf("  Utilisation :\n\n");
   51:         }
   52:         else
   53:         {
   54:             printf("(control statement)\n\n");
   55:             printf("  Usage:\n\n");
   56:         }
   57: 
   58:         printf("    WHILE\n");
   59:         printf("        (clause)\n");
   60:         printf("    REPEAT\n");
   61:         printf("        (expression 1)\n");
   62:         printf("        EXIT\n");
   63:         printf("        (expression 2)\n");
   64:         printf("    END\n\n");
   65: 
   66:         printf("    WHILE\n");
   67:         printf("        (clause)\n");
   68:         printf("    REPEAT\n");
   69:         printf("        (expression)\n");
   70:         printf("    END\n");
   71: 
   72:         return;
   73:     }
   74:     else if ((*s_etat_processus).test_instruction == 'Y')
   75:     {
   76:         (*s_etat_processus).nombre_arguments = -1;
   77:         return;
   78:     }
   79: 
   80:     empilement_pile_systeme(s_etat_processus);
   81: 
   82:     if ((*s_etat_processus).erreur_systeme != d_es)
   83:     {
   84:         return;
   85:     }
   86: 
   87:     (*(*s_etat_processus).l_base_pile_systeme).type_cloture = 'W';
   88:     (*(*s_etat_processus).l_base_pile_systeme).clause = 'W';
   89: 
   90:     if ((*s_etat_processus).mode_execution_programme == 'Y')
   91:     {
   92:         (*(*s_etat_processus).l_base_pile_systeme).adresse_retour =
   93:                 (*s_etat_processus).position_courante;
   94:     }
   95:     else
   96:     {
   97:         if ((*s_etat_processus).expression_courante == NULL)
   98:         {
   99:             (*s_etat_processus).erreur_execution =
  100:                     d_ex_erreur_traitement_boucle;
  101:             return;
  102:         }
  103: 
  104:         (*(*s_etat_processus).l_base_pile_systeme).pointeur_objet_retour =
  105:                 (*s_etat_processus).expression_courante;
  106:     }
  107: 
  108:     return;
  109: }
  110: 
  111: 
  112: /*
  113: ================================================================================
  114:   Fonction 'warranty'
  115: ================================================================================
  116:   Entrées :
  117: --------------------------------------------------------------------------------
  118:   Sorties :
  119: --------------------------------------------------------------------------------
  120:   Effets de bord : néant
  121: ================================================================================
  122: */
  123: 
  124: void
  125: instruction_warranty(struct_processus *s_etat_processus)
  126: {
  127: #   include                 "garanties-conv.h"
  128: 
  129:     (*s_etat_processus).erreur_execution = d_ex;
  130: 
  131:     if ((*s_etat_processus).affichage_arguments == 'Y')
  132:     {
  133:         printf("\n  WARRANTY ");
  134: 
  135:         if ((*s_etat_processus).langue == 'F')
  136:         {
  137:             printf("(garantie)\n\n");
  138:             printf("  Aucun argument\n");
  139:         }
  140:         else
  141:         {
  142:             printf("(warranty)\n\n");
  143:             printf("  No argument\n");
  144:         }
  145: 
  146:         return;
  147:     }
  148:     else if ((*s_etat_processus).test_instruction == 'Y')
  149:     {
  150:         (*s_etat_processus).nombre_arguments = -1;
  151:         return;
  152:     }
  153: 
  154:     printf("%s\n", warranty);
  155: 
  156:     if ((*s_etat_processus).hauteur_pile_operationnelle == 0)
  157:     {
  158:         printf("\n");
  159:     }
  160: 
  161:     return;
  162: }
  163: 
  164: 
  165: /*
  166: ================================================================================
  167:   Fonction 'wait'
  168: ================================================================================
  169:   Entrées :
  170: --------------------------------------------------------------------------------
  171:   Sorties :
  172: --------------------------------------------------------------------------------
  173:   Effets de bord : néant
  174: ================================================================================
  175: */
  176: 
  177: void
  178: instruction_wait(struct_processus *s_etat_processus)
  179: {
  180:     int                         code_retour;
  181:     int                         erreur;
  182: 
  183:     real8                       attente;
  184: 
  185:     struct_objet                *s_objet;
  186: 
  187:     struct timespec             temporisation;
  188: 
  189:     (*s_etat_processus).erreur_execution = d_ex;
  190: 
  191:     if ((*s_etat_processus).affichage_arguments == 'Y')
  192:     {
  193:         printf("\n  WAIT ");
  194: 
  195:         if ((*s_etat_processus).langue == 'F')
  196:         {
  197:             printf("(attente exprimée en secondes)\n\n");
  198:         }
  199:         else
  200:         {
  201:             printf("(wait a number of seconds)\n\n");
  202:         }
  203: 
  204:         printf("    1: %s, %s\n", d_INT, d_REL);
  205: 
  206:         return;
  207:     }
  208:     else if ((*s_etat_processus).test_instruction == 'Y')
  209:     {
  210:         (*s_etat_processus).nombre_arguments = -1;
  211:         return;
  212:     }
  213: 
  214:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  215:     {
  216:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  217:         {
  218:             return;
  219:         }
  220:     }
  221: 
  222:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  223:             &s_objet) == d_erreur)
  224:     {
  225:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  226:         return;
  227:     }
  228:     
  229:     if (((*s_objet).type == INT) || ((*s_objet).type == REL))
  230:     {
  231:         if ((*s_objet).type == INT)
  232:         {
  233:             attente = (real8) (*((integer8 *) (*s_objet).objet));
  234:         }
  235:         else
  236:         {
  237:             attente = (*((real8 *) (*s_objet).objet));
  238:         }
  239: 
  240:         if (attente < 0)
  241:         {
  242:             liberation(s_etat_processus, s_objet);
  243: 
  244:             (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
  245:             return;
  246:         }
  247: 
  248:         temporisation.tv_sec = (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 (fwrite(chaine, sizeof(unsigned char),
 1365:                         (size_t) longueur_effective,
 1366:                         (*descripteur).descripteur_c) !=
 1367:                         (size_t) longueur_effective)
 1368:                 {
 1369:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1370:                     return;
 1371:                 }
 1372:             }
 1373:             else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1374:                     == 'D')
 1375:             {
 1376:                 if ((*s_objet_argument_2).type != INT)
 1377:                 {
 1378:                     liberation(s_etat_processus, s_objet_argument_2);
 1379:                     liberation(s_etat_processus, s_objet_argument_1);
 1380: 
 1381:                     (*s_etat_processus).erreur_execution =
 1382:                             d_ex_erreur_type_argument;
 1383:                     return;
 1384:                 }
 1385: 
 1386:                 if (depilement(s_etat_processus, &((*s_etat_processus)
 1387:                         .l_base_pile), &s_objet_argument_3) == d_erreur)
 1388:                 {
 1389:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1390:                     return;
 1391:                 }
 1392: 
 1393:                 if ((*s_objet_argument_3).type != LST)
 1394:                 {
 1395:                     liberation(s_etat_processus, s_objet_argument_3);
 1396:                     liberation(s_etat_processus, s_objet_argument_2);
 1397:                     liberation(s_etat_processus, s_objet_argument_1);
 1398: 
 1399:                     (*s_etat_processus).erreur_execution =
 1400:                             d_ex_erreur_type_argument;
 1401:                     return;
 1402:                 }
 1403: 
 1404:                 if ((chaine = formateur_fichier(s_etat_processus,
 1405:                         s_objet_argument_2, (*((struct_fichier *)
 1406:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
 1407:                         &longueur_effective, &recursivite, d_faux)) == NULL)
 1408:                 {
 1409:                     liberation(s_etat_processus, s_objet_argument_2);
 1410:                     liberation(s_etat_processus, s_objet_argument_1);
 1411: 
 1412:                     return;
 1413:                 }
 1414:             }
 1415:             else // Fichiers indexés
 1416:             {
 1417:                 if ((*s_objet_argument_2).type != LST)
 1418:                 {
 1419:                     liberation(s_etat_processus, s_objet_argument_2);
 1420:                     liberation(s_etat_processus, s_objet_argument_1);
 1421: 
 1422:                     (*s_etat_processus).erreur_execution =
 1423:                             d_ex_erreur_type_argument;
 1424:                     return;
 1425:                 }
 1426: 
 1427:                 if ((chaine = formateur_fichier(s_etat_processus,
 1428:                         s_objet_argument_2, (*((struct_fichier *)
 1429:                         (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
 1430:                         &longueur_effective, &recursivite, d_faux)) == NULL)
 1431:                 {
 1432:                     liberation(s_etat_processus, s_objet_argument_2);
 1433:                     liberation(s_etat_processus, s_objet_argument_1);
 1434: 
 1435:                     return;
 1436:                 }
 1437:             }
 1438: 
 1439:             free(chaine);
 1440:         }
 1441:         else
 1442:         {
 1443:             /*
 1444:              * Fichiers de type FLOW
 1445:              */
 1446: 
 1447:             if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
 1448:                     == 'S')
 1449:             {
 1450:                 BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
 1451: 
 1452:                 if ((*s_objet_argument_2).type != LST)
 1453:                 {
 1454:                     liberation(s_etat_processus, s_objet_argument_2);
 1455:                     liberation(s_etat_processus, s_objet_argument_1);
 1456: 
 1457:                     (*s_etat_processus).erreur_execution =
 1458:                             d_ex_erreur_type_argument;
 1459:                     return;
 1460:                 }
 1461: 
 1462:                 if ((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
 1463:                         .donnee == NULL)
 1464:                 {
 1465:                     liberation(s_etat_processus, s_objet_argument_2);
 1466:                     liberation(s_etat_processus, s_objet_argument_1);
 1467: 
 1468:                     (*s_etat_processus).erreur_execution =
 1469:                             d_ex_erreur_type_argument;
 1470:                     return;
 1471:                 }
 1472: 
 1473:                 l_element_courant = (*s_objet_argument_2).objet;
 1474:                 l_element_courant_format = (struct_liste_chainee *)
 1475:                         (*(*((struct_fichier *) (*s_objet_argument_1).objet))
 1476:                         .format).objet;
 1477: 
 1478:                 while((l_element_courant != NULL) &&
 1479:                         (l_element_courant_format != NULL))
 1480:                 {
 1481:                     if ((*(*l_element_courant).donnee).type != CHN)
 1482:                     {
 1483:                         liberation(s_etat_processus, s_objet_argument_2);
 1484:                         liberation(s_etat_processus, s_objet_argument_1);
 1485: 
 1486:                         (*s_etat_processus).erreur_execution =
 1487:                                 d_ex_erreur_type_argument;
 1488:                         return;
 1489:                     }
 1490: 
 1491:                     if ((*(*l_element_courant_format).donnee).type != CHN)
 1492:                     {
 1493:                         liberation(s_etat_processus, s_objet_argument_2);
 1494:                         liberation(s_etat_processus, s_objet_argument_1);
 1495: 
 1496:                         (*s_etat_processus).erreur_execution =
 1497:                                 d_ex_erreur_type_argument;
 1498:                         return;
 1499:                     }
 1500: 
 1501:                     if ((format_chaine = conversion_majuscule(s_etat_processus,
 1502:                             (unsigned char *) (*(*l_element_courant_format)
 1503:                             .donnee).objet)) == NULL)
 1504:                     {
 1505:                         (*s_etat_processus).erreur_systeme =
 1506:                                 d_es_allocation_memoire;
 1507:                         return;
 1508:                     }
 1509: 
 1510:                     if (strcmp("LINE*(*)", format_chaine) == 0)
 1511:                     {
 1512:                         format_oriente_ligne = d_vrai;
 1513:                         format_degenere = d_vrai;
 1514:                     }
 1515:                     else
 1516:                     {
 1517:                         format_oriente_ligne = d_faux;
 1518:                         
 1519:                         if (strncmp("LENGTH*(", format_chaine, 8) != 0)
 1520:                         {
 1521:                             free(format_chaine);
 1522: 
 1523:                             liberation(s_etat_processus, s_objet_argument_2);
 1524:                             liberation(s_etat_processus, s_objet_argument_1);
 1525: 
 1526:                             (*s_etat_processus).erreur_execution =
 1527:                                     d_ex_erreur_format_fichier;
 1528:                             return;
 1529:                         }
 1530: 
 1531:                         longueur = (integer8) strlen(format_chaine);
 1532: 
 1533:                         if (format_chaine[longueur - 1] != ')')
 1534:                         {
 1535:                             free(format_chaine);
 1536: 
 1537:                             liberation(s_etat_processus, s_objet_argument_2);
 1538:                             liberation(s_etat_processus, s_objet_argument_1);
 1539: 
 1540:                             (*s_etat_processus).erreur_execution =
 1541:                                     d_ex_erreur_format_fichier;
 1542:                             return;
 1543:                         }
 1544: 
 1545:                         format_chaine[longueur] = d_code_fin_chaine;
 1546: 
 1547:                         if (format_chaine[8] == '*')
 1548:                         {
 1549:                             format_degenere = d_vrai;
 1550:                         }
 1551:                         else
 1552:                         {
 1553:                             // Détermination de la longueur
 1554:                             format_degenere = d_faux;
 1555: 
 1556:                             if (sscanf(&(format_chaine[8]), "%lld", &longueur)
 1557:                                     != 1)
 1558:                             {
 1559:                                 free(format_chaine);
 1560: 
 1561:                                 liberation(s_etat_processus,
 1562:                                         s_objet_argument_2);
 1563:                                 liberation(s_etat_processus,
 1564:                                         s_objet_argument_1);
 1565: 
 1566:                                 (*s_etat_processus).erreur_execution =
 1567:                                         d_ex_erreur_format_fichier;
 1568:                                 return;
 1569:                             }
 1570:                         }
 1571:                     }
 1572: 
 1573:                     free(format_chaine);
 1574: 
 1575:                     if ((chaine = formateur_flux(s_etat_processus,
 1576:                             (unsigned char *) (*(*l_element_courant).donnee)
 1577:                             .objet, &longueur_effective)) == NULL)
 1578:                     {
 1579:                         (*s_etat_processus).erreur_systeme =
 1580:                                 d_es_allocation_memoire;
 1581:                         return;
 1582:                     }
 1583: 
 1584:                     if ((format_degenere == d_vrai) ||
 1585:                             (longueur_effective < longueur))
 1586:                     {
 1587:                         if (fwrite(chaine, sizeof(unsigned char),
 1588:                                 (size_t) longueur_effective,
 1589:                                 (*descripteur).descripteur_c) !=
 1590:                                 (size_t) longueur_effective)
 1591:                         {
 1592:                             (*s_etat_processus).erreur_systeme =
 1593:                                     d_es_erreur_fichier;
 1594:                             return;
 1595:                         }
 1596:                     }
 1597:                     else
 1598:                     {
 1599:                         if (fwrite(chaine, sizeof(unsigned char),
 1600:                                 (size_t) longueur_effective,
 1601:                                 (*descripteur).descripteur_c) !=
 1602:                                 (size_t) longueur)
 1603:                         {
 1604:                             (*s_etat_processus).erreur_systeme =
 1605:                                     d_es_erreur_fichier;
 1606:                             return;
 1607:                         }
 1608:                     }
 1609: 
 1610:                     free(chaine);
 1611: 
 1612:                     if (format_oriente_ligne == d_vrai)
 1613:                     {
 1614:                         if (fwrite("\n", 1, 1, (*descripteur).descripteur_c)
 1615:                                 != 1)
 1616:                         {
 1617:                             (*s_etat_processus).erreur_systeme =
 1618:                                     d_es_erreur_fichier;
 1619:                             return;
 1620:                         }
 1621:                     }
 1622: 
 1623:                     l_element_courant = (*l_element_courant).suivant;
 1624:                     l_element_courant_format = (*l_element_courant_format)
 1625:                             .suivant;
 1626:                 }
 1627: 
 1628:                 if ((l_element_courant_format != NULL) ||
 1629:                         (l_element_courant != NULL))
 1630:                 {
 1631:                     liberation(s_etat_processus, s_objet_argument_2);
 1632:                     liberation(s_etat_processus, s_objet_argument_1);
 1633: 
 1634:                     (*s_etat_processus).erreur_execution =
 1635:                             d_ex_erreur_format_fichier;
 1636:                     return;
 1637:                 }
 1638:             }
 1639:             else
 1640:             {
 1641:                 liberation(s_etat_processus, s_objet_argument_1);
 1642:                 liberation(s_etat_processus, s_objet_argument_2);
 1643: 
 1644:                 (*s_etat_processus).erreur_execution =
 1645:                         d_ex_erreur_type_fichier;
 1646:                 return;
 1647:             }
 1648:         }
 1649:     }
 1650:     else if (((*s_objet_argument_2).type == LST) &&
 1651:             ((*s_objet_argument_1).type == SCK))
 1652:     {
 1653:         /*
 1654:          * Vérification de l'autorisation d'écriture
 1655:          */
 1656: 
 1657:         if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1658:                 .protection == 'R')
 1659:         {
 1660:             liberation(s_etat_processus, s_objet_argument_2);
 1661:             liberation(s_etat_processus, s_objet_argument_1);
 1662: 
 1663:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
 1664:             return;
 1665:         }
 1666: 
 1667:         if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
 1668:         {
 1669:             /*
 1670:              * Sockets formatées
 1671:              */
 1672: 
 1673:             if ((chaine = formateur_fichier(s_etat_processus,
 1674:                     s_objet_argument_2, (*((struct_socket *)
 1675:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
 1676:                     &longueur_effective, &recursivite, d_faux)) == NULL)
 1677:             {
 1678:                 liberation(s_etat_processus, s_objet_argument_2);
 1679:                 liberation(s_etat_processus, s_objet_argument_1);
 1680: 
 1681:                 return;
 1682:             }
 1683:         }
 1684:         else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
 1685:                 == 'Y')
 1686:         {
 1687:             /*
 1688:              * Sockets non formatées
 1689:              */
 1690: 
 1691:             if ((chaine = formateur_fichier(s_etat_processus,
 1692:                     s_objet_argument_2, (*((struct_socket *)
 1693:                     (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
 1694:                     &longueur_effective, &recursivite, d_faux)) == NULL)
 1695:             {
 1696:                 liberation(s_etat_processus, s_objet_argument_2);
 1697:                 liberation(s_etat_processus, s_objet_argument_1);
 1698: 
 1699:                 return;
 1700:             }
 1701:         }
 1702:         else
 1703:         {
 1704:             /*
 1705:              *  Sockets de type FLOW
 1706:              */
 1707: 
 1708:             if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
 1709:                     .donnee)).type != CHN)
 1710:             {
 1711:                 liberation(s_etat_processus, s_objet_argument_2);
 1712:                 liberation(s_etat_processus, s_objet_argument_1);
 1713: 
 1714:                 (*s_etat_processus).erreur_execution =
 1715:                         d_ex_erreur_type_argument;
 1716:                 return;
 1717:             }
 1718: 
 1719:             if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 1720:                     (*((*((struct_liste_chainee *) (*s_objet_argument_2)
 1721:                     .objet)).donnee)).objet, &longueur_effective)) == 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: 
 1730:         if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
 1731:                 "STREAM") == 0) || (strcmp((*((struct_socket *)
 1732:                 (*s_objet_argument_1).objet)).type,
 1733:                 "SEQUENTIAL DATAGRAM") == 0))
 1734:         { // Sockets connectées
 1735: 
 1736:             action.sa_handler = SIG_IGN;
 1737:             action.sa_flags = SA_ONSTACK;
 1738: 
 1739:             if (sigaction(SIGPIPE, &action, &registre) != 0)
 1740:             {
 1741:                 (*s_etat_processus).erreur_systeme = d_es_signal;
 1742:                 return;
 1743:             }
 1744: 
 1745: #           ifndef SEMAPHORES_NOMMES
 1746:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1747: #           else
 1748:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1749: #           endif
 1750:             {
 1751:                 if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1752:                 {
 1753:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1754:                     return;
 1755:                 }
 1756: 
 1757:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1758:                 return;
 1759:             }
 1760: 
 1761:             if (send((*((struct_socket *) (*s_objet_argument_1).objet))
 1762:                     .socket, chaine, (size_t) longueur_effective, 0) < 0)
 1763:             {
 1764:                 ios = errno;
 1765: 
 1766:                 if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1767:                 {
 1768:                     (*s_etat_processus).erreur_systeme = d_es_signal;
 1769:                     return;
 1770:                 }
 1771: 
 1772: #               ifndef SEMAPHORES_NOMMES
 1773:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1774: #               else
 1775:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1776: #               endif
 1777:                 {
 1778:                     if (errno != EINTR)
 1779:                     {
 1780:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1781:                         return;
 1782:                     }
 1783:                 }
 1784: 
 1785:                 if ((ios == EPIPE) || (ios == ECONNRESET))
 1786:                 {
 1787:                     (*s_etat_processus).erreur_execution =
 1788:                             d_ex_erreur_acces_fichier;
 1789:                     return;
 1790:                 }
 1791: 
 1792:                 (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1793:                 return;
 1794:             }
 1795: 
 1796: #           ifndef SEMAPHORES_NOMMES
 1797:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1798: #           else
 1799:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1800: #           endif
 1801:             {
 1802:                 if (errno != EINTR)
 1803:                 {
 1804:                     if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1805:                     {
 1806:                         (*s_etat_processus).erreur_systeme = d_es_signal;
 1807:                         return;
 1808:                     }
 1809: 
 1810:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1811:                     return;
 1812:                 }
 1813:             }
 1814: 
 1815:             if (sigaction(SIGPIPE, &registre, NULL) != 0)
 1816:             {
 1817:                 (*s_etat_processus).erreur_systeme = d_es_signal;
 1818:                 return;
 1819:             }
 1820:         }
 1821:         else
 1822:         { // Sockets non connectées
 1823: 
 1824:             /*
 1825:              * Vérification de l'adresse distante
 1826:              */
 1827: 
 1828:             if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
 1829:                     .adresse_distante, "") == 0)
 1830:             {
 1831:                 liberation(s_etat_processus, s_objet_argument_1);
 1832:                 liberation(s_etat_processus, s_objet_argument_2);
 1833: 
 1834:                 (*s_etat_processus).erreur_execution =
 1835:                         d_ex_erreur_acces_fichier;
 1836:                 return;
 1837:             }
 1838: 
 1839:             /*
 1840:              * Création de l'adresse logique
 1841:              */
 1842: 
 1843:             if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1844:                     .domaine == PF_UNIX)
 1845:             {
 1846:                 adresse_unix.sun_family = AF_UNIX;
 1847:                 strncpy(adresse_unix.sun_path, (*((struct_socket *)
 1848:                         (*s_objet_argument_1).objet)).adresse_distante,
 1849:                         UNIX_PATH_MAX);
 1850:                 adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
 1851:                         d_code_fin_chaine;
 1852: 
 1853: #               ifndef SEMAPHORES_NOMMES
 1854:                     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 1855: #               else
 1856:                     if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1857: #               endif
 1858:                 {
 1859:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1860:                     return;
 1861:                 }
 1862: 
 1863:                 if (sendto((*((struct_socket *)
 1864:                         (*s_objet_argument_1).objet)).socket, chaine,
 1865:                         (size_t) longueur_effective, 0, (struct sockaddr *)
 1866:                         &adresse_unix, sizeof(adresse_unix)) < 0)
 1867:                 {
 1868:                     ios = errno;
 1869: 
 1870: #                   ifndef SEMAPHORES_NOMMES
 1871:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 1872:                                 != 0)
 1873: #                   else
 1874:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1875: #                   endif
 1876:                     {
 1877:                         if (errno != EINTR)
 1878:                         {
 1879:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1880:                             return;
 1881:                         }
 1882:                     }
 1883: 
 1884:                     if ((ios == EPIPE) || (ios == ECONNRESET))
 1885:                     {
 1886:                         (*s_etat_processus).erreur_execution =
 1887:                                 d_ex_erreur_acces_fichier;
 1888:                         return;
 1889:                     }
 1890: 
 1891:                     if (ios == EMSGSIZE)
 1892:                     {
 1893:                         (*s_etat_processus).erreur_execution =
 1894:                                 d_ex_taille_message;
 1895:                         return;
 1896:                     }
 1897: 
 1898:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
 1899:                     return;
 1900:                 }
 1901: 
 1902: #               ifndef SEMAPHORES_NOMMES
 1903:                     while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 1904: #               else
 1905:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1906: #               endif
 1907:                 {
 1908:                     if (errno != EINTR)
 1909:                     {
 1910:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1911:                         return;
 1912:                     }
 1913:                 }
 1914:             }
 1915:             else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 1916:                     .domaine == PF_INET)
 1917:             {
 1918:                 if (sscanf((*((struct_socket *)
 1919:                         (*s_objet_argument_1).objet))
 1920:                         .adresse_distante, "%d.%d.%d.%d(%d)",
 1921:                         &(adresse[0]), &(adresse[1]), &(adresse[2]),
 1922:                         &(adresse[3]), &port) == 5)
 1923:                 { // Adresse IPv4
 1924:                     calcul_adresse = 0;
 1925:                     for(i = 0; i < 4; calcul_adresse =
 1926:                             (256 * calcul_adresse) +
 1927:                             ((unsigned char) adresse[i++]));
 1928: 
 1929:                     memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
 1930:                     adresse_ipv4.sin_family = AF_INET;
 1931:                     adresse_ipv4.sin_port = htons((uint16_t) port);
 1932:                     adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
 1933: 
 1934: #                   ifndef SEMAPHORES_NOMMES
 1935:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 1936:                                 != 0)
 1937: #                   else
 1938:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 1939: #                   endif
 1940:                     {
 1941:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 1942:                         return;
 1943:                     }
 1944: 
 1945:                     if (sendto((*((struct_socket *)
 1946:                             (*s_objet_argument_1).objet)).socket, chaine,
 1947:                             (size_t) longueur_effective, 0, (struct sockaddr *)
 1948:                             &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
 1949:                     {
 1950:                         ios = errno;
 1951: 
 1952: #                       ifndef SEMAPHORES_NOMMES
 1953:                             while(sem_wait(&((*s_etat_processus)
 1954:                                     .semaphore_fork)) != 0)
 1955: #                       else
 1956:                             while(sem_wait((*s_etat_processus)
 1957:                                     .semaphore_fork) != 0)
 1958: #                       endif
 1959:                         {
 1960:                             if (errno != EINTR)
 1961:                             {
 1962:                                 (*s_etat_processus).erreur_systeme =
 1963:                                         d_es_processus;
 1964:                                 return;
 1965:                             }
 1966:                         }
 1967: 
 1968:                         if ((ios == EPIPE) || (ios == ECONNRESET))
 1969:                         {
 1970:                             (*s_etat_processus).erreur_execution =
 1971:                                     d_ex_erreur_acces_fichier;
 1972:                             return;
 1973:                         }
 1974: 
 1975:                         if (ios == EMSGSIZE)
 1976:                         {
 1977:                             (*s_etat_processus).erreur_execution =
 1978:                                     d_ex_taille_message;
 1979:                             return;
 1980:                         }
 1981: 
 1982:                         (*s_etat_processus).erreur_systeme =
 1983:                                 d_es_erreur_fichier;
 1984:                         return;
 1985:                     }
 1986: 
 1987: #                   ifndef SEMAPHORES_NOMMES
 1988:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 1989:                                 != 0)
 1990: #                   else
 1991:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 1992: #                   endif
 1993:                     {
 1994:                         if (errno != EINTR)
 1995:                         {
 1996:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 1997:                             return;
 1998:                         }
 1999:                     }
 2000:                 }
 2001:                 else
 2002:                 {
 2003:                     liberation(s_etat_processus, s_objet_argument_1);
 2004:                     liberation(s_etat_processus, s_objet_argument_2);
 2005: 
 2006:                     (*s_etat_processus).erreur_execution =
 2007:                             d_ex_erreur_parametre_fichier;
 2008:                     return;
 2009:                 }
 2010:             }
 2011:             else if ((*((struct_socket *) (*s_objet_argument_1).objet))
 2012:                     .domaine == PF_INET6)
 2013:             {
 2014:                 if (sscanf((*((struct_socket *) (*s_objet_argument_1)
 2015:                         .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
 2016:                         "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
 2017:                         &(adresse[0]), &(adresse[1]), &(adresse[2]),
 2018:                         &(adresse[3]), &(adresse[4]), &(adresse[5]),
 2019:                         &(adresse[6]), &(adresse[7]), &(adresse[8]),
 2020:                         &(adresse[9]), &(adresse[10]), &(adresse[11]),
 2021:                         &(adresse[12]), &(adresse[13]), &(adresse[14]),
 2022:                         &(adresse[15]), &port)== 17)
 2023:                 { // Adresse IPv6
 2024: #                   ifdef IPV6
 2025:                     memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
 2026:                     adresse_ipv6.sin6_family = AF_INET6;
 2027:                     adresse_ipv6.sin6_port = htons((uint16_t) port);
 2028: 
 2029:                     for(i = 0; i < 16;
 2030:                             adresse_ipv6.sin6_addr.s6_addr[i] =
 2031:                             (unsigned char) adresse[i], i++);
 2032: 
 2033: #                   ifndef SEMAPHORES_NOMMES
 2034:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 2035:                                 != 0)
 2036: #                   else
 2037:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2038: #                   endif
 2039:                     {
 2040:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2041:                         return;
 2042:                     }
 2043: 
 2044:                     if (sendto((*((struct_socket *)
 2045:                             (*s_objet_argument_1).objet)).socket, chaine,
 2046:                             (size_t) longueur_effective, 0, (struct sockaddr *)
 2047:                             &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
 2048:                     {
 2049:                         ios = errno;
 2050: 
 2051: #                       ifndef SEMAPHORES_NOMMES
 2052:                             while(sem_wait(&((*s_etat_processus)
 2053:                                     .semaphore_fork)) != 0)
 2054: #                       else
 2055:                             while(sem_wait((*s_etat_processus)
 2056:                                     .semaphore_fork) != 0)
 2057: #                       endif
 2058:                         {
 2059:                             if (errno != EINTR)
 2060:                             {
 2061:                                 (*s_etat_processus).erreur_systeme =
 2062:                                         d_es_processus;
 2063:                                 return;
 2064:                             }
 2065:                         }
 2066: 
 2067:                         if ((ios == EPIPE) || (ios == ECONNRESET))
 2068:                         {
 2069:                             (*s_etat_processus).erreur_execution =
 2070:                                     d_ex_erreur_acces_fichier;
 2071:                             return;
 2072:                         }
 2073: 
 2074:                         if (ios == EMSGSIZE)
 2075:                         {
 2076:                             (*s_etat_processus).erreur_execution =
 2077:                                     d_ex_taille_message;
 2078:                             return;
 2079:                         }
 2080: 
 2081:                         (*s_etat_processus).erreur_systeme =
 2082:                                 d_es_erreur_fichier;
 2083:                         return;
 2084:                     }
 2085: 
 2086: #                   ifndef SEMAPHORES_NOMMES
 2087:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 2088:                                 != 0)
 2089: #                   else
 2090:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2091: #                   endif
 2092:                     {
 2093:                         if (errno != EINTR)
 2094:                         {
 2095:                             (*s_etat_processus).erreur_systeme =
 2096:                                     d_es_processus;
 2097:                             return;
 2098:                         }
 2099:                     }
 2100: #                   else
 2101:                     if ((*s_etat_processus).langue == 'F')
 2102:                     {
 2103:                         printf("+++Attention : Support du protocole"
 2104:                                 " IPv6 indisponible\n");
 2105:                     }
 2106:                     else
 2107:                     {
 2108:                         printf("+++Warning : IPv6 support "
 2109:                                 "unavailable\n");
 2110:                     }
 2111: #                   endif
 2112:                 }
 2113:                 else
 2114:                 {
 2115:                     liberation(s_etat_processus, s_objet_argument_1);
 2116:                     liberation(s_etat_processus, s_objet_argument_2);
 2117: 
 2118:                     (*s_etat_processus).erreur_execution =
 2119:                             d_ex_erreur_parametre_fichier;
 2120:                     return;
 2121:                 }
 2122:             }
 2123:             else 
 2124:             {
 2125:                 liberation(s_etat_processus, s_objet_argument_1);
 2126:                 liberation(s_etat_processus, s_objet_argument_2);
 2127: 
 2128:                 (*s_etat_processus).erreur_execution =
 2129:                         d_ex_erreur_parametre_fichier;
 2130:                 return;
 2131:             }
 2132:         }
 2133: 
 2134:         free(chaine);
 2135:     }
 2136:     else
 2137:     {
 2138:         liberation(s_etat_processus, s_objet_argument_2);
 2139:         liberation(s_etat_processus, s_objet_argument_1);
 2140: 
 2141:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2142:         return;
 2143:     }
 2144: 
 2145:     liberation(s_etat_processus, s_objet_argument_2);
 2146:     liberation(s_etat_processus, s_objet_argument_1);
 2147: 
 2148:     return;
 2149: }
 2150: 
 2151: 
 2152: /*
 2153: ================================================================================
 2154:   Fonction 'wflock'
 2155: ================================================================================
 2156:   Entrées : pointeur sur une structure struct_processus
 2157: --------------------------------------------------------------------------------
 2158:   Sorties :
 2159: --------------------------------------------------------------------------------
 2160:   Effets de bord : néant
 2161: ================================================================================
 2162: */
 2163: 
 2164: void
 2165: instruction_wflock(struct_processus *s_etat_processus)
 2166: {
 2167:     logical1                    drapeau;
 2168: 
 2169:     struct flock                lock;
 2170: 
 2171:     struct timespec             attente;
 2172: 
 2173:     struct_descripteur_fichier  *descripteur;
 2174: 
 2175:     struct_objet                *s_objet_argument_1;
 2176:     struct_objet                *s_objet_argument_2;
 2177: 
 2178:     unsigned char               *chaine;
 2179:     unsigned char               registre_instruction_valide;
 2180: 
 2181:     attente.tv_sec = 0;
 2182:     attente.tv_nsec = GRANULARITE_us * 1000;
 2183: 
 2184:     (*s_etat_processus).erreur_execution = d_ex;
 2185: 
 2186:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2187:     {
 2188:         printf("\n  WFLOCK ");
 2189:         
 2190:         if ((*s_etat_processus).langue == 'F')
 2191:         {
 2192:             printf("(attente du positionnement d'un verrou sur un fichier)"
 2193:                     "\n\n");
 2194:         }
 2195:         else
 2196:         {
 2197:             printf("(wait for file lock)\n\n");
 2198:         }
 2199: 
 2200:         printf("    2: %s\n", d_FCH);
 2201:         printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
 2202: 
 2203:         return;
 2204:     }
 2205:     else if ((*s_etat_processus).test_instruction == 'Y')
 2206:     {
 2207:         (*s_etat_processus).nombre_arguments = -1;
 2208:         return;
 2209:     }
 2210: 
 2211:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2212:     {
 2213:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
 2214:         {
 2215:             return;
 2216:         }
 2217:     }
 2218: 
 2219:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2220:             &s_objet_argument_1) == d_erreur)
 2221:     {
 2222:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2223:         return;
 2224:     }
 2225: 
 2226:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2227:             &s_objet_argument_2) == d_erreur)
 2228:     {
 2229:         liberation(s_etat_processus, s_objet_argument_1);
 2230: 
 2231:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2232:         return;
 2233:     }
 2234: 
 2235:     if (((*s_objet_argument_2).type == FCH) &&
 2236:             ((*s_objet_argument_1).type == CHN))
 2237:     {
 2238:         drapeau = d_faux;
 2239: 
 2240:         do
 2241:         {
 2242:             if ((chaine = conversion_majuscule(s_etat_processus,
 2243:                     (unsigned char *) (*s_objet_argument_1).objet)) == NULL)
 2244:             {
 2245:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2246:                 return;
 2247:             }
 2248: 
 2249:             if (strcmp(chaine, "WRITE") == 0)
 2250:             {
 2251:                 lock.l_type = F_WRLCK;
 2252:             }
 2253:             else if (strcmp(chaine, "READ") == 0)
 2254:             {
 2255:                 lock.l_type = F_RDLCK;
 2256:             }
 2257:             else if (strcmp(chaine, "NONE") == 0)
 2258:             {
 2259:                 lock.l_type = F_UNLCK;
 2260:             }
 2261:             else
 2262:             {
 2263:                 free(chaine);
 2264: 
 2265:                 liberation(s_etat_processus, s_objet_argument_1);
 2266:                 liberation(s_etat_processus, s_objet_argument_2);
 2267: 
 2268:                 (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
 2269:                 return;
 2270:             }
 2271: 
 2272:             free(chaine);
 2273: 
 2274:             lock.l_whence = SEEK_SET;
 2275:             lock.l_start = 0;
 2276:             lock.l_len = 0;
 2277:             lock.l_pid = getpid();
 2278: 
 2279:             if ((descripteur = descripteur_fichier(s_etat_processus,
 2280:                     (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
 2281:             {
 2282:                 return;
 2283:             }
 2284: 
 2285:             if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
 2286:                     == -1)
 2287:             {
 2288:                 liberation(s_etat_processus, s_objet_argument_1);
 2289:                 liberation(s_etat_processus, s_objet_argument_2);
 2290: 
 2291:                 (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
 2292:                 return;
 2293:             }
 2294: 
 2295: #           ifndef SEMAPHORES_NOMMES
 2296:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 2297: #           else
 2298:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2299: #           endif
 2300:             {
 2301:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 2302:                 return;
 2303:             }
 2304: 
 2305: #           ifndef SEMAPHORES_NOMMES
 2306:                 while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 2307: #           else
 2308:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2309: #           endif
 2310:             {
 2311:                 if (errno != EINTR)
 2312:                 {
 2313:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2314:                     return;
 2315:                 }
 2316:             }
 2317: 
 2318:             if (lock.l_type == F_UNLCK)
 2319:             {
 2320:                 drapeau = d_vrai;
 2321:             }
 2322:             else
 2323:             {
 2324:                 if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
 2325:                         != 0)
 2326:                 {
 2327:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2328:                     return;
 2329:                 }
 2330: 
 2331:                 if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 2332:                 {
 2333:                     affectation_interruptions_logicielles(s_etat_processus);
 2334:                 }
 2335: 
 2336:                 if (pthread_mutex_unlock(&(*s_etat_processus)
 2337:                         .mutex_interruptions) != 0)
 2338:                 {
 2339:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2340:                     return;
 2341:                 }
 2342: 
 2343:                 if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 2344:                 {
 2345:                     registre_instruction_valide =
 2346:                             (*s_etat_processus).instruction_valide;
 2347:                     traitement_interruptions_logicielles(
 2348:                             s_etat_processus);
 2349:                     (*s_etat_processus).instruction_valide =
 2350:                             registre_instruction_valide;
 2351:                 }
 2352: 
 2353:                 nanosleep(&attente, NULL);
 2354:                 scrutation_injection(s_etat_processus);
 2355: 
 2356:                 INCR_GRANULARITE(attente.tv_nsec);
 2357:             }
 2358:         } while((drapeau == d_faux) && ((*s_etat_processus)
 2359:                 .var_volatile_requete_arret != -1));
 2360:     }
 2361:     else
 2362:     {
 2363:         liberation(s_etat_processus, s_objet_argument_1);
 2364:         liberation(s_etat_processus, s_objet_argument_2);
 2365: 
 2366:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2367:         return;
 2368:     }
 2369: 
 2370:     return;
 2371: }
 2372: 
 2373: 
 2374: /*
 2375: ================================================================================
 2376:   Fonction 'wfproc'
 2377: ================================================================================
 2378:   Entrées : pointeur sur une structure struct_processus
 2379: --------------------------------------------------------------------------------
 2380:   Sorties :
 2381: --------------------------------------------------------------------------------
 2382:   Effets de bord : néant
 2383: ================================================================================
 2384: */
 2385: 
 2386: void
 2387: instruction_wfproc(struct_processus *s_etat_processus)
 2388: {
 2389:     logical1                    drapeau_fin;
 2390: 
 2391:     struct_liste_chainee        *l_element_courant;
 2392: 
 2393:     struct_objet                *s_objet_argument;
 2394: 
 2395:     struct timespec             attente;
 2396: 
 2397:     unsigned char               registre_instruction_valide;
 2398: 
 2399:     (*s_etat_processus).erreur_execution = d_ex;
 2400: 
 2401:     attente.tv_sec = 0;
 2402:     attente.tv_nsec = GRANULARITE_us * 1000;
 2403: 
 2404:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2405:     {
 2406:         printf("\n  WFPROC ");
 2407: 
 2408:         if ((*s_etat_processus).langue == 'F')
 2409:         {
 2410:             printf("(attente de la fin d'un processus fils)\n\n");
 2411:         }
 2412:         else
 2413:         {
 2414:             printf("(wait for child process end)\n\n");
 2415:         }
 2416: 
 2417:         printf("    1: %s\n", d_PRC);
 2418: 
 2419:         return;
 2420:     }
 2421:     else if ((*s_etat_processus).test_instruction == 'Y')
 2422:     {
 2423:         (*s_etat_processus).nombre_arguments = -1;
 2424:         return;
 2425:     }
 2426: 
 2427:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2428:     {
 2429:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2430:         {
 2431:             return;
 2432:         }
 2433:     }
 2434: 
 2435:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2436:             &s_objet_argument) == d_erreur)
 2437:     {
 2438:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2439:         return;
 2440:     }
 2441: 
 2442:     if ((*s_objet_argument).type == PRC)
 2443:     {
 2444:         drapeau_fin = d_faux;
 2445: 
 2446:         if ((*s_etat_processus).profilage == d_vrai)
 2447:         {
 2448:             profilage(s_etat_processus, "Interprocess or interthread "
 2449:                     "communications (WFPROC)");
 2450: 
 2451:             if ((*s_etat_processus).erreur_systeme != d_es)
 2452:             {
 2453:                 return;
 2454:             }
 2455:         }
 2456: 
 2457:         if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
 2458:                 != 0)
 2459:         {
 2460:             if ((*s_etat_processus).profilage == d_vrai)
 2461:             {
 2462:                 profilage(s_etat_processus, NULL);
 2463:             }
 2464: 
 2465:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2466:             return;
 2467:         }
 2468: 
 2469:         while(drapeau_fin == d_faux)
 2470:         {
 2471:             l_element_courant = (struct_liste_chainee *)
 2472:                     (*s_etat_processus).l_base_pile_processus;
 2473: 
 2474:             while(l_element_courant != NULL)
 2475:             {
 2476:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2477:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2478:                 {
 2479:                     if ((*(*((struct_processus_fils *)
 2480:                             (*s_objet_argument).objet)).thread)
 2481:                             .processus_detache == d_vrai)
 2482:                     {
 2483:                         if ((*(*((struct_processus_fils *)
 2484:                                 (*(*l_element_courant)
 2485:                                 .donnee).objet)).thread).pid ==
 2486:                                 (*(*((struct_processus_fils *)
 2487:                                 (*s_objet_argument).objet)).thread).pid)
 2488:                         {
 2489:                             break;
 2490:                         }
 2491:                     }
 2492:                 }
 2493:                 else
 2494:                 {
 2495:                     if ((*(*((struct_processus_fils *)
 2496:                             (*s_objet_argument).objet)).thread)
 2497:                             .processus_detache == d_faux)
 2498:                     {
 2499:                         if ((pthread_equal((*(*((struct_processus_fils *)
 2500:                                 (*(*l_element_courant).donnee).objet)).thread)
 2501:                                 .tid, (*(*((struct_processus_fils *)
 2502:                                 (*s_objet_argument).objet)).thread).tid) != 0)
 2503:                                 && ((*(*((struct_processus_fils *)
 2504:                                 (*(*l_element_courant).donnee).objet)).thread)
 2505:                                 .pid == (*(*((struct_processus_fils *)
 2506:                                 (*s_objet_argument).objet)).thread).pid))
 2507:                         {
 2508:                             break;
 2509:                         }
 2510:                     }
 2511:                 }
 2512: 
 2513:                 l_element_courant = (*l_element_courant).suivant;
 2514:             }
 2515: 
 2516:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2517:             {
 2518:                 if ((*s_etat_processus).profilage == d_vrai)
 2519:                 {
 2520:                     profilage(s_etat_processus, NULL);
 2521:                 }
 2522: 
 2523:                 if (pthread_mutex_unlock(&((*s_etat_processus)
 2524:                         .mutex_pile_processus)) != 0)
 2525:                 {
 2526:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2527:                     return;
 2528:                 }
 2529: 
 2530:                 liberation(s_etat_processus, s_objet_argument);
 2531:                 return;
 2532:             }
 2533: 
 2534:             if (l_element_courant == NULL)
 2535:             {
 2536:                 /*
 2537:                  * Si l_element_courant vaut NULL, le processus n'existe plus.
 2538:                  */
 2539: 
 2540:                 drapeau_fin = d_vrai;
 2541:             }
 2542:             else
 2543:             {
 2544:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2545:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2546:                 {
 2547:                     if (envoi_signal_processus((*(*((struct_processus_fils *)
 2548:                             (*(*l_element_courant).donnee).objet)).thread).pid,
 2549:                             rpl_signull, d_faux) != 0)
 2550:                     {
 2551:                         drapeau_fin = d_vrai;
 2552:                     }
 2553:                     else
 2554:                     {
 2555:                         drapeau_fin = d_faux;
 2556:                     }
 2557:                 }
 2558:                 else
 2559:                 {
 2560:                     if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2561:                             (*(*l_element_courant).donnee).objet)).thread)
 2562:                             .mutex)) != 0)
 2563:                     {
 2564:                         if ((*s_etat_processus).profilage == d_vrai)
 2565:                         {
 2566:                             profilage(s_etat_processus, NULL);
 2567:                         }
 2568: 
 2569:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2570:                         return;
 2571:                     }
 2572: 
 2573:                     if ((*(*((struct_processus_fils *)
 2574:                             (*(*l_element_courant).donnee).objet)).thread)
 2575:                             .thread_actif == d_faux)
 2576:                     {
 2577:                         drapeau_fin = d_vrai;
 2578:                     }
 2579:                     else
 2580:                     {
 2581:                         drapeau_fin = d_faux;
 2582:                     }
 2583: 
 2584:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2585:                             (*(*l_element_courant).donnee).objet)).thread)
 2586:                             .mutex)) != 0)
 2587:                     {
 2588:                         if ((*s_etat_processus).profilage == d_vrai)
 2589:                         {
 2590:                             profilage(s_etat_processus, NULL);
 2591:                         }
 2592: 
 2593:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2594:                         return;
 2595:                     }
 2596:                 }
 2597: 
 2598:                 if (drapeau_fin == d_faux)
 2599:                 {
 2600:                     /*
 2601:                      * Le processus n'est pas terminé
 2602:                      */
 2603: 
 2604:                     if (pthread_mutex_lock(&((*s_etat_processus)
 2605:                             .mutex_interruptions)) != 0)
 2606:                     {
 2607:                         pthread_mutex_unlock(&((*s_etat_processus)
 2608:                                 .mutex_pile_processus));
 2609: 
 2610:                         if ((*s_etat_processus).profilage == d_vrai)
 2611:                         {
 2612:                             profilage(s_etat_processus, NULL);
 2613:                         }
 2614: 
 2615:                         (*s_etat_processus).erreur_systeme =
 2616:                                 d_es_processus;
 2617:                         return;
 2618:                     }
 2619: 
 2620:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2621:                             != 0)
 2622:                     {
 2623:                         affectation_interruptions_logicielles(s_etat_processus);
 2624:                     }
 2625: 
 2626:                     if (pthread_mutex_unlock(&((*s_etat_processus)
 2627:                             .mutex_interruptions)) != 0)
 2628:                     {
 2629:                         pthread_mutex_unlock(&((*s_etat_processus)
 2630:                                 .mutex_pile_processus));
 2631: 
 2632:                         if ((*s_etat_processus).profilage == d_vrai)
 2633:                         {
 2634:                             profilage(s_etat_processus, NULL);
 2635:                         }
 2636: 
 2637:                         (*s_etat_processus).erreur_systeme =
 2638:                                 d_es_processus;
 2639:                         return;
 2640:                     }
 2641: 
 2642:                     if (pthread_mutex_unlock(&((*s_etat_processus)
 2643:                             .mutex_pile_processus)) != 0)
 2644:                     {
 2645:                         if ((*s_etat_processus).profilage == d_vrai)
 2646:                         {
 2647:                             profilage(s_etat_processus, NULL);
 2648:                         }
 2649: 
 2650:                         (*s_etat_processus).erreur_systeme =
 2651:                                 d_es_processus;
 2652:                         return;
 2653:                     }
 2654: 
 2655:                     if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 2656:                     {
 2657:                         registre_instruction_valide =
 2658:                                 (*s_etat_processus).instruction_valide;
 2659:                         traitement_interruptions_logicielles(
 2660:                                 s_etat_processus);
 2661:                         (*s_etat_processus).instruction_valide =
 2662:                                 registre_instruction_valide;
 2663:                     }
 2664: 
 2665: #                   ifndef SEMAPHORES_NOMMES
 2666:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 2667:                                 != 0)
 2668: #                   else
 2669:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2670: #                   endif
 2671:                     {
 2672:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2673:                         return;
 2674:                     }
 2675: 
 2676:                     nanosleep(&attente, NULL);
 2677: 
 2678: #                   ifndef SEMAPHORES_NOMMES
 2679:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 2680:                                 != 0)
 2681: #                   else
 2682:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2683: #                   endif
 2684:                     {
 2685:                         if (errno != EINTR)
 2686:                         {
 2687:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2688:                             return;
 2689:                         }
 2690:                     }
 2691: 
 2692:                     scrutation_injection(s_etat_processus);
 2693: 
 2694:                     if (pthread_mutex_lock(&((*s_etat_processus)
 2695:                             .mutex_pile_processus)) != 0)
 2696:                     {
 2697:                         if ((*s_etat_processus).profilage == d_vrai)
 2698:                         {
 2699:                             profilage(s_etat_processus, NULL);
 2700:                         }
 2701: 
 2702:                         (*s_etat_processus).erreur_systeme =
 2703:                                 d_es_processus;
 2704:                         return;
 2705:                     }
 2706:                 }
 2707:             }
 2708: 
 2709:             INCR_GRANULARITE(attente.tv_nsec);
 2710:         }
 2711: 
 2712:         if ((*s_etat_processus).profilage == d_vrai)
 2713:         {
 2714:             profilage(s_etat_processus, NULL);
 2715:         }
 2716: 
 2717:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
 2718:                 != 0)
 2719:         {
 2720:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2721:             return;
 2722:         }
 2723:     }
 2724:     else
 2725:     {
 2726:         liberation(s_etat_processus, s_objet_argument);
 2727: 
 2728:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2729:         return;
 2730:     }
 2731: 
 2732:     liberation(s_etat_processus, s_objet_argument);
 2733: 
 2734:     return;
 2735: }
 2736: 
 2737: 
 2738: /*
 2739: ================================================================================
 2740:   Fonction 'wfdata'
 2741: ================================================================================
 2742:   Entrées : pointeur sur une structure struct_processus
 2743: --------------------------------------------------------------------------------
 2744:   Sorties :
 2745: --------------------------------------------------------------------------------
 2746:   Effets de bord : néant
 2747: ================================================================================
 2748: */
 2749: 
 2750: void
 2751: instruction_wfdata(struct_processus *s_etat_processus)
 2752: {
 2753:     logical1                    drapeau_fin;
 2754: 
 2755:     struct_liste_chainee        *l_element_courant;
 2756: 
 2757:     struct_objet                *s_objet_argument;
 2758: 
 2759:     struct timespec             attente;
 2760: 
 2761:     unsigned char               registre_instruction_valide;
 2762: 
 2763:     (*s_etat_processus).erreur_execution = d_ex;
 2764: 
 2765:     attente.tv_sec = 0;
 2766:     attente.tv_nsec = GRANULARITE_us * 1000;
 2767: 
 2768:     if ((*s_etat_processus).affichage_arguments == 'Y')
 2769:     {
 2770:         printf("\n  WFDATA ");
 2771: 
 2772:         if ((*s_etat_processus).langue == 'F')
 2773:         {
 2774:             printf("(attente de données d'un processus fils)\n\n");
 2775:         }
 2776:         else
 2777:         {
 2778:             printf("(wait for data from child process)\n\n");
 2779:         }
 2780: 
 2781:         printf("    1: %s\n", d_PRC);
 2782: 
 2783:         return;
 2784:     }
 2785:     else if ((*s_etat_processus).test_instruction == 'Y')
 2786:     {
 2787:         (*s_etat_processus).nombre_arguments = -1;
 2788:         return;
 2789:     }
 2790: 
 2791:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 2792:     {
 2793:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 2794:         {
 2795:             return;
 2796:         }
 2797:     }
 2798: 
 2799:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2800:             &s_objet_argument) == d_erreur)
 2801:     {
 2802:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 2803:         return;
 2804:     }
 2805: 
 2806:     if ((*s_objet_argument).type == PRC)
 2807:     {
 2808:         drapeau_fin = d_faux;
 2809: 
 2810:         if ((*s_etat_processus).profilage == d_vrai)
 2811:         {
 2812:             profilage(s_etat_processus, "Interprocess or interthread "
 2813:                     "communications (WFDATA)");
 2814: 
 2815:             if ((*s_etat_processus).erreur_systeme != d_es)
 2816:             {
 2817:                 return;
 2818:             }
 2819:         }
 2820: 
 2821:         if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
 2822:                 != 0)
 2823:         {
 2824:             if ((*s_etat_processus).profilage == d_vrai)
 2825:             {
 2826:                 profilage(s_etat_processus, NULL);
 2827:             }
 2828: 
 2829:             (*s_etat_processus).erreur_systeme = d_es_processus;
 2830:             return;
 2831:         }
 2832: 
 2833:         while(drapeau_fin == d_faux)
 2834:         {
 2835:             l_element_courant = (struct_liste_chainee *)
 2836:                     (*s_etat_processus).l_base_pile_processus;
 2837: 
 2838:             while(l_element_courant != NULL)
 2839:             {
 2840:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2841:                         .donnee).objet)).thread).processus_detache == d_vrai)
 2842:                 {
 2843:                     if (((*(*((struct_processus_fils *) (*(*l_element_courant)
 2844:                             .donnee).objet)).thread).pid ==
 2845:                             (*(*((struct_processus_fils *)
 2846:                             (*s_objet_argument).objet)).thread).pid)
 2847:                             && ((*(*((struct_processus_fils *)
 2848:                             (*s_objet_argument).objet)).thread)
 2849:                             .processus_detache == d_vrai))
 2850:                     {
 2851:                         break;
 2852:                     }
 2853:                 }
 2854:                 else
 2855:                 {
 2856:                     if ((pthread_equal((*(*((struct_processus_fils *)
 2857:                             (*(*l_element_courant).donnee).objet)).thread).tid,
 2858:                             (*(*((struct_processus_fils *) (*s_objet_argument)
 2859:                             .objet)).thread).tid) != 0) &&
 2860:                             ((*(*((struct_processus_fils *)
 2861:                             (*(*l_element_courant).donnee).objet)).thread).pid
 2862:                             == (*(*((struct_processus_fils *)
 2863:                             (*s_objet_argument).objet)).thread).pid) &&
 2864:                             ((*(*((struct_processus_fils *)
 2865:                             (*s_objet_argument).objet)).thread)
 2866:                             .processus_detache == d_faux))
 2867:                     {
 2868:                         break;
 2869:                     }
 2870:                 }
 2871: 
 2872:                 l_element_courant = (*l_element_courant).suivant;
 2873:             }
 2874: 
 2875:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2876:             {
 2877:                 if ((*s_etat_processus).profilage == d_vrai)
 2878:                 {
 2879:                     profilage(s_etat_processus, NULL);
 2880:                 }
 2881: 
 2882:                 if (pthread_mutex_unlock(&((*s_etat_processus)
 2883:                         .mutex_pile_processus)) != 0)
 2884:                 {
 2885:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2886:                     return;
 2887:                 }
 2888: 
 2889:                 liberation(s_etat_processus, s_objet_argument);
 2890:                 return;
 2891:             }
 2892: 
 2893:             if (l_element_courant != NULL)
 2894:             {
 2895:                 if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
 2896:                         (*(*l_element_courant).donnee).objet)).thread).mutex))
 2897:                         != 0)
 2898:                 {
 2899:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 2900:                     return;
 2901:                 }
 2902: 
 2903:                 if ((*(*((struct_processus_fils *) (*(*l_element_courant)
 2904:                         .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
 2905:                 {
 2906:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2907:                             (*(*l_element_courant).donnee).objet)).thread)
 2908:                             .mutex)) != 0)
 2909:                     {
 2910:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2911:                         return;
 2912:                     }
 2913: 
 2914:                     drapeau_fin = d_vrai;
 2915:                 }
 2916:                 else
 2917:                 {
 2918:                     if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
 2919:                             (*(*l_element_courant).donnee).objet)).thread)
 2920:                             .mutex)) != 0)
 2921:                     {
 2922:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2923:                         return;
 2924:                     }
 2925: 
 2926:                     if (pthread_mutex_unlock(&((*s_etat_processus)
 2927:                             .mutex_pile_processus)) != 0)
 2928:                     {
 2929:                         if ((*s_etat_processus).profilage == d_vrai)
 2930:                         {
 2931:                             profilage(s_etat_processus, NULL);
 2932:                         }
 2933: 
 2934:                         (*s_etat_processus).erreur_systeme =
 2935:                                 d_es_processus;
 2936:                         return;
 2937:                     }
 2938: 
 2939: #                   ifndef SEMAPHORES_NOMMES
 2940:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 2941:                                 != 0)
 2942: #                   else
 2943:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 2944: #                   endif
 2945:                     {
 2946:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2947:                         return;
 2948:                     }
 2949: 
 2950:                     nanosleep(&attente, NULL);
 2951: 
 2952: #                   ifndef SEMAPHORES_NOMMES
 2953:                         while(sem_wait(&((*s_etat_processus).semaphore_fork))
 2954:                                 != 0)
 2955: #                   else
 2956:                         while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 2957: #                   endif
 2958:                     {
 2959:                         if (errno != EINTR)
 2960:                         {
 2961:                             (*s_etat_processus).erreur_systeme = d_es_processus;
 2962:                             return;
 2963:                         }
 2964:                     }
 2965: 
 2966:                     scrutation_injection(s_etat_processus);
 2967: 
 2968:                     if (pthread_mutex_lock(&(*s_etat_processus)
 2969:                             .mutex_interruptions) != 0)
 2970:                     {
 2971:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2972:                         return;
 2973:                     }
 2974: 
 2975:                     if ((*s_etat_processus).nombre_interruptions_non_affectees
 2976:                             != 0)
 2977:                     {
 2978:                         affectation_interruptions_logicielles(s_etat_processus);
 2979:                     }
 2980: 
 2981:                     if (pthread_mutex_unlock(&(*s_etat_processus)
 2982:                             .mutex_interruptions) != 0)
 2983:                     {
 2984:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 2985:                         return;
 2986:                     }
 2987: 
 2988:                     if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 2989:                     {
 2990:                         registre_instruction_valide =
 2991:                                 (*s_etat_processus).instruction_valide;
 2992:                         traitement_interruptions_logicielles(s_etat_processus);
 2993:                         (*s_etat_processus).instruction_valide =
 2994:                                 registre_instruction_valide;
 2995:                     }
 2996: 
 2997:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 2998:                     {
 2999:                         if ((*s_etat_processus).profilage == d_vrai)
 3000:                         {
 3001:                             profilage(s_etat_processus, NULL);
 3002:                         }
 3003: 
 3004:                         return;
 3005:                     }
 3006: 
 3007:                     if (pthread_mutex_lock(&((*s_etat_processus)
 3008:                             .mutex_pile_processus)) != 0)
 3009:                     {
 3010:                         if ((*s_etat_processus).profilage == d_vrai)
 3011:                         {
 3012:                             profilage(s_etat_processus, NULL);
 3013:                         }
 3014: 
 3015:                         (*s_etat_processus).erreur_systeme =
 3016:                                 d_es_processus;
 3017:                         return;
 3018:                     }
 3019:                 }
 3020:             }
 3021:             else
 3022:             {
 3023:                 drapeau_fin = d_vrai;
 3024:                 (*s_etat_processus).erreur_execution = d_ex_processus;
 3025:             }
 3026: 
 3027:             INCR_GRANULARITE(attente.tv_nsec);
 3028:         }
 3029: 
 3030:         if ((*s_etat_processus).profilage == d_vrai)
 3031:         {
 3032:             profilage(s_etat_processus, NULL);
 3033:         }
 3034: 
 3035:         if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
 3036:                 != 0)
 3037:         {
 3038:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3039:             return;
 3040:         }
 3041:     }
 3042:     else
 3043:     {
 3044:         liberation(s_etat_processus, s_objet_argument);
 3045: 
 3046:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3047:         return;
 3048:     }
 3049: 
 3050:     liberation(s_etat_processus, s_objet_argument);
 3051: 
 3052:     return;
 3053: }
 3054: 
 3055: 
 3056: /*
 3057: ================================================================================
 3058:   Fonction 'wfsock'
 3059: ================================================================================
 3060:   Entrées : pointeur sur une structure struct_processus
 3061: --------------------------------------------------------------------------------
 3062:   Sorties :
 3063: --------------------------------------------------------------------------------
 3064:   Effets de bord : néant
 3065: ================================================================================
 3066: */
 3067: 
 3068: static inline logical1
 3069: options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket)
 3070: {
 3071:     int                         drapeau;
 3072: 
 3073:     if (((*s_socket).options & (1 << d_BROADCAST)) != 0)
 3074:     {
 3075:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau,
 3076:                 sizeof(drapeau)) != 0)
 3077:         {
 3078:             return(d_erreur);
 3079:         }
 3080:     }
 3081: 
 3082:     if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0)
 3083:     {
 3084:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau,
 3085:                 sizeof(drapeau)) != 0)
 3086:         {
 3087:             return(d_erreur);
 3088:         }
 3089:     }
 3090: 
 3091:     if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0)
 3092:     {
 3093:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau,
 3094:                 sizeof(drapeau)) != 0)
 3095:         {
 3096:             return(d_erreur);
 3097:         }
 3098:     }
 3099: 
 3100: #   ifdef SO_PRIORITY
 3101:     if (((*s_socket).options & (1 << d_PRIORITY)) != 0)
 3102:     {
 3103:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY,
 3104:                 &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0)
 3105:         {
 3106:             return(d_erreur);
 3107:         }
 3108:     }
 3109: #   endif
 3110: 
 3111:     // Les deux options suivantes ne peuvent être positionnées simultanément.
 3112: 
 3113:     if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0)
 3114:     {
 3115:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF,
 3116:                 &((*s_socket).buffer_reception),
 3117:                 sizeof((*s_socket).buffer_reception)) != 0)
 3118:         {
 3119:             return(d_erreur);
 3120:         }
 3121:     }
 3122: 
 3123: #   ifdef SO_RCVBUFFORCE
 3124:     if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0)
 3125:     {
 3126:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE,
 3127:                 &((*s_socket).buffer_reception),
 3128:                 sizeof((*s_socket).buffer_reception)) != 0)
 3129:         {
 3130:             return(d_erreur);
 3131:         }
 3132:     }
 3133: #   endif
 3134: 
 3135:     // Même remarque
 3136: 
 3137:     if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0)
 3138:     {
 3139:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF,
 3140:                 &((*s_socket).buffer_emission),
 3141:                 sizeof((*s_socket).buffer_emission)) != 0)
 3142:         {
 3143:             return(d_erreur);
 3144:         }
 3145:     }
 3146: 
 3147: #   ifdef SO_SNDBUFFORCE
 3148:     if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0)
 3149:     {
 3150:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE,
 3151:                 &((*s_socket).buffer_emission),
 3152:                 sizeof((*s_socket).buffer_emission)) != 0)
 3153:         {
 3154:             return(d_erreur);
 3155:         }
 3156:     }
 3157: #   endif
 3158: 
 3159:     if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0)
 3160:     {
 3161:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO,
 3162:                 &((*s_socket).timeout_emission),
 3163:                 sizeof((*s_socket).timeout_emission)) != 0)
 3164:         {
 3165:             return(d_erreur);
 3166:         }
 3167:     }
 3168: 
 3169:     if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0)
 3170:     {
 3171:         if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO,
 3172:                 &((*s_socket).timeout_emission),
 3173:                 sizeof((*s_socket).timeout_emission)) != 0)
 3174:         {
 3175:             return(d_erreur);
 3176:         }
 3177:     }
 3178: 
 3179:     return(d_absence_erreur);;
 3180: }
 3181: 
 3182: 
 3183: void
 3184: instruction_wfsock(struct_processus *s_etat_processus)
 3185: {
 3186:     int                     erreur;
 3187: 
 3188:     logical1                drapeau;
 3189: 
 3190:     socklen_t               longueur;
 3191: 
 3192:     struct_liste_chainee    *l_element_courant;
 3193: 
 3194:     struct_objet            *s_objet_argument;
 3195:     struct_objet            *s_objet_resultat;
 3196: 
 3197:     struct pollfd           s_poll;
 3198: 
 3199:     struct sockaddr_in      adresse_ipv4;
 3200: #   ifdef IPV6
 3201:     struct sockaddr_in6     adresse_ipv6;
 3202: #   endif
 3203: 
 3204:     unsigned long           i;
 3205: 
 3206:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3207:     {
 3208:         printf("\n  WFSOCK ");
 3209: 
 3210:         if ((*s_etat_processus).langue == 'F')
 3211:         {
 3212:             printf("(attente d'une connexion sur une socket)\n\n");
 3213:         }
 3214:         else
 3215:         {
 3216:             printf("(wait for connection on a socket)\n\n");
 3217:         }
 3218: 
 3219:         printf("    1: %s\n", d_SCK);
 3220:         printf("->  2: %s\n", d_SCK);
 3221:         printf("    1: %s\n", d_SCK);
 3222: 
 3223:         return;
 3224:     }
 3225:     else if ((*s_etat_processus).test_instruction == 'Y')
 3226:     {
 3227:         (*s_etat_processus).nombre_arguments = -1;
 3228:         return;
 3229:     }
 3230: 
 3231:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3232:     {
 3233:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 3234:         {
 3235:             return;
 3236:         }
 3237:     }
 3238: 
 3239:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3240:             &s_objet_argument) == d_erreur)
 3241:     {
 3242:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 3243:         return;
 3244:     }
 3245: 
 3246:     if ((*s_objet_argument).type == SCK)
 3247:     {
 3248:         if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
 3249:                 "STREAM") != 0) && (strcmp((*((struct_socket *)
 3250:                 (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
 3251:         {
 3252:             // Mode non connecté : l'attente se fait sur un poll()
 3253: 
 3254:             if ((s_objet_resultat = copie_objet(s_etat_processus,
 3255:                     s_objet_argument, 'P')) == NULL)
 3256:             {
 3257:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 3258:                 return;
 3259:             }
 3260: 
 3261:             s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
 3262:             s_poll.events = POLLIN;
 3263:             s_poll.revents = 0;
 3264: 
 3265:             do
 3266:             {
 3267:                 drapeau = d_vrai;
 3268: 
 3269: #               ifndef SEMAPHORES_NOMMES
 3270:                 if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3271: #               else
 3272:                 if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3273: #               endif
 3274:                 {
 3275:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 3276:                     return;
 3277:                 }
 3278: 
 3279:                 if (poll(&s_poll, 1, -1) < 0)
 3280:                 {
 3281:                     erreur = errno;
 3282: 
 3283: #                   ifndef SEMAPHORES_NOMMES
 3284:                     while(sem_wait(&((*s_etat_processus)
 3285:                             .semaphore_fork)) != 0)
 3286: #                   else
 3287:                     while(sem_wait((*s_etat_processus).semaphore_fork)
 3288:                             != 0)
 3289: #                   endif
 3290: 
 3291:                     if (erreur != EINTR)
 3292:                     {
 3293:                         liberation(s_etat_processus, s_objet_argument);
 3294:                         liberation(s_etat_processus, s_objet_resultat);
 3295: 
 3296:                         (*s_etat_processus).erreur_execution =
 3297:                                 d_ex_erreur_acces_fichier;
 3298:                         return;
 3299:                     }
 3300: 
 3301:                     scrutation_injection(s_etat_processus);
 3302: 
 3303:                     if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3304:                     {
 3305:                         drapeau = d_vrai;
 3306:                     }
 3307:                     else
 3308:                     {
 3309:                         drapeau = d_faux;
 3310:                     }
 3311:                 }
 3312:                 else
 3313:                 {
 3314: #                   ifndef SEMAPHORES_NOMMES
 3315:                         while(sem_wait(&((*s_etat_processus)
 3316:                                 .semaphore_fork)) != 0)
 3317: #                   else
 3318:                         while(sem_wait((*s_etat_processus).semaphore_fork)
 3319:                                 != 0)
 3320: #                   endif
 3321:                     {
 3322:                         if (errno != EINTR)
 3323:                         {
 3324:                             (*s_etat_processus).erreur_systeme =
 3325:                                     d_es_processus;
 3326:                             return;
 3327:                         }
 3328:                     }
 3329:                 }
 3330:             } while(drapeau == d_faux);
 3331: 
 3332:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3333:                     s_objet_argument) == d_erreur)
 3334:             {
 3335:                 return;
 3336:             }
 3337: 
 3338:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3339:                     s_objet_resultat) == d_erreur)
 3340:             {
 3341:                 return;
 3342:             }
 3343:         }
 3344:         else
 3345:         {
 3346:             // Mode connecté
 3347: 
 3348:             if ((s_objet_resultat = copie_objet(s_etat_processus,
 3349:                     s_objet_argument, 'O')) == NULL)
 3350:             {
 3351:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 3352:                 return;
 3353:             }
 3354: 
 3355:             (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
 3356:             (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
 3357:                     = 'N';
 3358: 
 3359:             if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
 3360:                     PF_INET)
 3361:             {
 3362:                 longueur = sizeof(adresse_ipv4);
 3363: 
 3364:                 do
 3365:                 {
 3366:                     drapeau = d_vrai;
 3367: 
 3368: #                   ifndef SEMAPHORES_NOMMES
 3369:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3370:                                 != 0)
 3371: #                   else
 3372:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3373: #                   endif
 3374:                     {
 3375:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3376:                         return;
 3377:                     }
 3378: 
 3379:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3380:                             .socket = accept((*((struct_socket *)
 3381:                             (*s_objet_argument).objet)).socket,
 3382:                             (struct sockaddr *) &adresse_ipv4, &longueur))
 3383:                             < 0)
 3384:                     {
 3385:                         erreur = errno;
 3386: 
 3387: #                       ifndef SEMAPHORES_NOMMES
 3388:                             while(sem_wait(&((*s_etat_processus)
 3389:                                     .semaphore_fork)) != 0)
 3390: #                       else
 3391:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3392:                                     != 0)
 3393: #                       endif
 3394:                         {
 3395:                             if (errno != EINTR)
 3396:                             {
 3397:                                 (*s_etat_processus).erreur_systeme =
 3398:                                         d_es_processus;
 3399:                                 return;
 3400:                             }
 3401:                         }
 3402: 
 3403:                         if (erreur != EINTR)
 3404:                         {
 3405:                             liberation(s_etat_processus, s_objet_argument);
 3406:                             liberation(s_etat_processus, s_objet_resultat);
 3407: 
 3408:                             (*s_etat_processus).erreur_execution =
 3409:                                     d_ex_erreur_acces_fichier;
 3410:                             return;
 3411:                         }
 3412: 
 3413:                         scrutation_injection(s_etat_processus);
 3414: 
 3415:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3416:                         {
 3417:                             drapeau = d_vrai;
 3418:                         }
 3419:                         else
 3420:                         {
 3421:                             drapeau = d_faux;
 3422:                         }
 3423:                     }
 3424:                     else
 3425:                     {
 3426: #                       ifndef SEMAPHORES_NOMMES
 3427:                             while(sem_wait(&((*s_etat_processus)
 3428:                                     .semaphore_fork)) != 0)
 3429: #                       else
 3430:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3431:                                     != 0)
 3432: #                       endif
 3433:                         {
 3434:                             if (errno != EINTR)
 3435:                             {
 3436:                                 (*s_etat_processus).erreur_systeme =
 3437:                                         d_es_processus;
 3438:                                 return;
 3439:                             }
 3440:                         }
 3441: 
 3442:                         if (options_sockets(s_etat_processus,
 3443:                                 (*s_objet_resultat).objet) != d_absence_erreur)
 3444:                         {
 3445:                             liberation(s_etat_processus, s_objet_argument);
 3446:                             liberation(s_etat_processus, s_objet_resultat);
 3447: 
 3448:                             (*s_etat_processus).erreur_execution =
 3449:                                     d_ex_erreur_parametre_fichier;
 3450:                             return;
 3451:                         }
 3452:                     }
 3453:                 } while(drapeau == d_faux);
 3454: 
 3455:                 if (((*((struct_socket *) (*s_objet_resultat).objet))
 3456:                         .adresse_distante = malloc(22 *
 3457:                         sizeof(unsigned char))) == NULL)
 3458:                 {
 3459:                     (*s_etat_processus).erreur_systeme =
 3460:                             d_es_allocation_memoire;
 3461:                     return;
 3462:                 }
 3463: 
 3464:                 sprintf((*((struct_socket *) (*s_objet_resultat).objet))
 3465:                         .adresse_distante, "%d.%d.%d.%d(%d)",
 3466:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
 3467:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
 3468:                         (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
 3469:                         ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
 3470:                         ntohs(adresse_ipv4.sin_port));
 3471:             }
 3472:             else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
 3473:                     PF_INET6)
 3474:             {
 3475: #           ifdef IPV6
 3476:                 longueur = sizeof(adresse_ipv6);
 3477: 
 3478:                 do
 3479:                 {
 3480:                     drapeau = d_vrai;
 3481: 
 3482: #                   ifndef SEMAPHORES_NOMMES
 3483:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3484:                                 != 0)
 3485: #                   else
 3486:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3487: #                   endif
 3488:                     {
 3489:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3490:                         return;
 3491:                     }
 3492: 
 3493:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3494:                             .socket = accept((*((struct_socket *)
 3495:                             (*s_objet_argument).objet)).socket,
 3496:                             (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
 3497:                     {
 3498:                         erreur = errno;
 3499: 
 3500: #                       ifndef SEMAPHORES_NOMMES
 3501:                             while(sem_wait(&((*s_etat_processus)
 3502:                                     .semaphore_fork)) != 0)
 3503: #                       else
 3504:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3505:                                     != 0)
 3506: #                       endif
 3507:                         {
 3508:                             if (errno != EINTR)
 3509:                             {
 3510:                                 (*s_etat_processus).erreur_systeme =
 3511:                                         d_es_processus;
 3512:                                 return;
 3513:                             }
 3514:                         }
 3515: 
 3516:                         if (erreur != EINTR)
 3517:                         {
 3518:                             liberation(s_etat_processus, s_objet_argument);
 3519:                             liberation(s_etat_processus, s_objet_resultat);
 3520: 
 3521:                             (*s_etat_processus).erreur_execution =
 3522:                                     d_ex_erreur_acces_fichier;
 3523:                             return;
 3524:                         }
 3525: 
 3526:                         scrutation_injection(s_etat_processus);
 3527: 
 3528:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3529:                         {
 3530:                             drapeau = d_vrai;
 3531:                         }
 3532:                         else
 3533:                         {
 3534:                             drapeau = d_faux;
 3535:                         }
 3536:                     }
 3537:                     else
 3538:                     {
 3539: #                       ifndef SEMAPHORES_NOMMES
 3540:                             while(sem_wait(&((*s_etat_processus)
 3541:                                     .semaphore_fork)) != 0)
 3542: #                       else
 3543:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3544:                                     != 0)
 3545: #                       endif
 3546:                         {
 3547:                             if (errno != EINTR)
 3548:                             {
 3549:                                 (*s_etat_processus).erreur_systeme =
 3550:                                         d_es_processus;
 3551:                                 return;
 3552:                             }
 3553:                         }
 3554: 
 3555:                         if (options_sockets(s_etat_processus,
 3556:                                 (*s_objet_resultat).objet) != d_absence_erreur)
 3557:                         {
 3558:                             liberation(s_etat_processus, s_objet_argument);
 3559:                             liberation(s_etat_processus, s_objet_resultat);
 3560: 
 3561:                             (*s_etat_processus).erreur_execution =
 3562:                                     d_ex_erreur_parametre_fichier;
 3563:                             return;
 3564:                         }
 3565:                     }
 3566:                 } while(drapeau == d_faux);
 3567: 
 3568:                 if (((*((struct_socket *) (*s_objet_resultat).objet))
 3569:                         .adresse_distante = malloc(55 *
 3570:                         sizeof(unsigned char))) == NULL)
 3571:                 {
 3572:                     (*s_etat_processus).erreur_systeme =
 3573:                             d_es_allocation_memoire;
 3574:                     return;
 3575:                 }
 3576: 
 3577:                 (*((struct_socket *) (*s_objet_resultat).objet))
 3578:                         .adresse_distante = d_code_fin_chaine;
 3579: 
 3580:                 for(i = 0; i < 16; i++)
 3581:                 {
 3582:                     sprintf((*((struct_socket *) (*s_objet_resultat)
 3583:                             .objet)).adresse_distante, (i == 0) ? "%s%X"
 3584:                             : "%s:%X", (*((struct_socket *) (*s_objet_resultat)
 3585:                             .objet)).adresse_distante,
 3586:                             adresse_ipv6.sin6_addr.s6_addr[i]);
 3587:                 }
 3588: 
 3589:                 sprintf((*((struct_socket *) (*s_objet_resultat)
 3590:                         .objet)).adresse_distante, "%s(%u)",
 3591:                         (*((struct_socket *) (*s_objet_resultat)
 3592:                         .objet)).adresse_distante,
 3593:                         ntohs(adresse_ipv6.sin6_port));
 3594: #           else
 3595:                 if ((*s_etat_processus).langue == 'F')
 3596:                 {
 3597:                     printf("+++Attention : Support du protocole"
 3598:                             " IPv6 indisponible\n");
 3599:                 }
 3600:                 else
 3601:                 {
 3602:                     printf("+++Warning : IPv6 support "
 3603:                             "unavailable\n");
 3604:                 }
 3605: #           endif
 3606:             }
 3607:             else
 3608:             {
 3609:                 longueur = 0;
 3610: 
 3611:                 do
 3612:                 {
 3613:                     drapeau = d_vrai;
 3614: 
 3615: #                   ifndef SEMAPHORES_NOMMES
 3616:                         if (sem_post(&((*s_etat_processus).semaphore_fork))
 3617:                                 != 0)
 3618: #                   else
 3619:                         if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3620: #                   endif
 3621:                     {
 3622:                         (*s_etat_processus).erreur_systeme = d_es_processus;
 3623:                         return;
 3624:                     }
 3625: 
 3626:                     if (((*((struct_socket *) (*s_objet_resultat).objet))
 3627:                             .socket = accept((*((struct_socket *)
 3628:                             (*s_objet_argument).objet)).socket, NULL,
 3629:                             &longueur)) < 0)
 3630:                     {
 3631:                         erreur = errno;
 3632: 
 3633: #                       ifndef SEMAPHORES_NOMMES
 3634:                             while(sem_wait(&((*s_etat_processus)
 3635:                                     .semaphore_fork)) != 0)
 3636: #                       else
 3637:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3638:                                     != 0)
 3639: #                       endif
 3640:                         {
 3641:                             if (errno != EINTR)
 3642:                             {
 3643:                                 (*s_etat_processus).erreur_systeme =
 3644:                                         d_es_processus;
 3645:                                 return;
 3646:                             }
 3647:                         }
 3648: 
 3649:                         if (erreur != EINTR)
 3650:                         {
 3651:                             liberation(s_etat_processus, s_objet_argument);
 3652:                             liberation(s_etat_processus, s_objet_resultat);
 3653: 
 3654:                             (*s_etat_processus).erreur_execution =
 3655:                                     d_ex_erreur_acces_fichier;
 3656:                             return;
 3657:                         }
 3658: 
 3659:                         scrutation_injection(s_etat_processus);
 3660: 
 3661:                         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3662:                         {
 3663:                             drapeau = d_vrai;
 3664:                         }
 3665:                         else
 3666:                         {
 3667:                             drapeau = d_faux;
 3668:                         }
 3669:                     }
 3670:                     else
 3671:                     {
 3672: #                       ifndef SEMAPHORES_NOMMES
 3673:                             while(sem_wait(&((*s_etat_processus)
 3674:                                     .semaphore_fork)) != 0)
 3675: #                       else
 3676:                             while(sem_wait((*s_etat_processus).semaphore_fork)
 3677:                                     != 0)
 3678: #                       endif
 3679:                         {
 3680:                             if (errno != EINTR)
 3681:                             {
 3682:                                 (*s_etat_processus).erreur_systeme =
 3683:                                         d_es_processus;
 3684:                                 return;
 3685:                             }
 3686:                         }
 3687: 
 3688:                         if (options_sockets(s_etat_processus,
 3689:                                 (*s_objet_resultat).objet) != d_absence_erreur)
 3690:                         {
 3691:                             liberation(s_etat_processus, s_objet_argument);
 3692:                             liberation(s_etat_processus, s_objet_resultat);
 3693: 
 3694:                             (*s_etat_processus).erreur_execution =
 3695:                                     d_ex_erreur_parametre_fichier;
 3696:                             return;
 3697:                         }
 3698:                     }
 3699:                 } while(drapeau == d_faux);
 3700:             }
 3701: 
 3702:             // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
 3703:             // que de EINTR sachant qu'une requête d'arrêt est en court de
 3704:             // traitement.
 3705: 
 3706:             if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
 3707:             {
 3708:                 l_element_courant = (*s_etat_processus).s_sockets;
 3709: 
 3710:                 if (l_element_courant == NULL)
 3711:                 {
 3712:                     if (((*s_etat_processus).s_sockets =
 3713:                             allocation_maillon(s_etat_processus)) == NULL)
 3714:                     {
 3715:                         (*s_etat_processus).erreur_systeme =
 3716:                                 d_es_allocation_memoire;
 3717:                         return;
 3718:                     }
 3719: 
 3720:                     (*(*s_etat_processus).s_sockets).suivant = NULL;
 3721:                     l_element_courant = (*s_etat_processus).s_sockets;
 3722:                 }
 3723:                 else
 3724:                 {
 3725:                     /*
 3726:                      * Ajout d'un élément à la fin de la liste chaînée
 3727:                      */
 3728: 
 3729:                     while((*l_element_courant).suivant != NULL)
 3730:                     {
 3731:                         l_element_courant = (*l_element_courant).suivant;
 3732:                     }
 3733: 
 3734:                     if (((*l_element_courant).suivant =
 3735:                             allocation_maillon(s_etat_processus)) == NULL)
 3736:                     {
 3737:                         (*s_etat_processus).erreur_systeme =
 3738:                                 d_es_allocation_memoire;
 3739:                         return;
 3740:                     }
 3741: 
 3742:                     l_element_courant = (*l_element_courant).suivant;
 3743:                     (*l_element_courant).suivant = NULL;
 3744:                 }
 3745: 
 3746:                 if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
 3747:                         s_objet_resultat, 'O')) == NULL)
 3748:                 {
 3749:                     (*s_etat_processus).erreur_systeme =
 3750:                             d_es_allocation_memoire;
 3751:                     return;
 3752:                 }
 3753:             }
 3754: 
 3755:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3756:                     s_objet_argument) == d_erreur)
 3757:             {
 3758:                 return;
 3759:             }
 3760: 
 3761:             if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3762:                     s_objet_resultat) == d_erreur)
 3763:             {
 3764:                 return;
 3765:             }
 3766:         }
 3767:     }
 3768:     else
 3769:     {
 3770:         liberation(s_etat_processus, s_objet_argument);
 3771: 
 3772:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3773:         return;
 3774:     }
 3775: 
 3776:     return;
 3777: }
 3778: 
 3779: 
 3780: /*
 3781: ================================================================================
 3782:   Fonction 'wfswi'
 3783: ================================================================================
 3784:   Entrées : pointeur sur une structure struct_processus
 3785: --------------------------------------------------------------------------------
 3786:   Sorties :
 3787: --------------------------------------------------------------------------------
 3788:   Effets de bord : néant
 3789: ================================================================================
 3790: */
 3791: 
 3792: void
 3793: instruction_wfswi(struct_processus *s_etat_processus)
 3794: {
 3795:     integer8                    interruption;
 3796: 
 3797:     logical1                    drapeau_fin;
 3798: 
 3799:     struct_objet                *s_objet_argument;
 3800: 
 3801:     struct timespec             attente;
 3802: 
 3803:     (*s_etat_processus).erreur_execution = d_ex;
 3804: 
 3805:     attente.tv_sec = 0;
 3806:     attente.tv_nsec = GRANULARITE_us * 1000;
 3807: 
 3808:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3809:     {
 3810:         printf("\n  WFSWI ");
 3811: 
 3812:         if ((*s_etat_processus).langue == 'F')
 3813:         {
 3814:             printf("(attente d'une interruption)\n\n");
 3815:         }
 3816:         else
 3817:         {
 3818:             printf("(wait for interrupt)\n\n");
 3819:         }
 3820: 
 3821:         printf("    1: %s\n", d_INT);
 3822: 
 3823:         return;
 3824:     }
 3825:     else if ((*s_etat_processus).test_instruction == 'Y')
 3826:     {
 3827:         (*s_etat_processus).nombre_arguments = -1;
 3828:         return;
 3829:     }
 3830: 
 3831:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3832:     {
 3833:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 3834:         {
 3835:             return;
 3836:         }
 3837:     }
 3838: 
 3839:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 3840:             &s_objet_argument) == d_erreur)
 3841:     {
 3842:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 3843:         return;
 3844:     }
 3845: 
 3846:     if ((*s_objet_argument).type == INT)
 3847:     {
 3848:         drapeau_fin = d_faux;
 3849: 
 3850:         interruption = (*((integer8 *) (*s_objet_argument).objet));
 3851: 
 3852:         if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
 3853:         {
 3854:             liberation(s_etat_processus, s_objet_argument);
 3855: 
 3856:             (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
 3857:             return;
 3858:         }
 3859: 
 3860:         while(drapeau_fin == d_faux)
 3861:         {
 3862:             if ((*s_etat_processus).var_volatile_requete_arret != 0)
 3863:             {
 3864:                 liberation(s_etat_processus, s_objet_argument);
 3865:                 return;
 3866:             }
 3867: 
 3868:             if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
 3869:                     != 0)
 3870:             {
 3871:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3872:                 return;
 3873:             }
 3874: 
 3875:             if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 3876:             {
 3877:                 affectation_interruptions_logicielles(s_etat_processus);
 3878:             }
 3879: 
 3880:             if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions)
 3881:                     != 0)
 3882:             {
 3883:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 3884:                 return;
 3885:             }
 3886: 
 3887:             if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
 3888:             {
 3889:                 drapeau_fin = d_vrai;
 3890:             }
 3891:             else
 3892:             {
 3893:                 nanosleep(&attente, NULL);
 3894:                 scrutation_injection(s_etat_processus);
 3895:                 INCR_GRANULARITE(attente.tv_nsec);
 3896:             }
 3897:         }
 3898:     }
 3899:     else
 3900:     {
 3901:         liberation(s_etat_processus, s_objet_argument);
 3902: 
 3903:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 3904:         return;
 3905:     }
 3906: 
 3907:     liberation(s_etat_processus, s_objet_argument);
 3908: 
 3909:     return;
 3910: }
 3911: 
 3912: 
 3913: /*
 3914: ================================================================================
 3915:   Fonction 'wfpoke'
 3916: ================================================================================
 3917:   Entrées : pointeur sur une structure struct_processus
 3918: --------------------------------------------------------------------------------
 3919:   Sorties :
 3920: --------------------------------------------------------------------------------
 3921:   Effets de bord : néant
 3922: ================================================================================
 3923: */
 3924: 
 3925: void
 3926: instruction_wfpoke(struct_processus *s_etat_processus)
 3927: {
 3928:     struct timespec             attente;
 3929: 
 3930:     unsigned char               registre_instruction_valide;
 3931: 
 3932:     (*s_etat_processus).erreur_execution = d_ex;
 3933: 
 3934:     attente.tv_sec = 0;
 3935:     attente.tv_nsec = GRANULARITE_us * 1000;
 3936: 
 3937:     if ((*s_etat_processus).affichage_arguments == 'Y')
 3938:     {
 3939:         printf("\n  WFPOKE ");
 3940: 
 3941:         if ((*s_etat_processus).langue == 'F')
 3942:         {
 3943:             printf("(attente de données en provenance du processus père)\n\n");
 3944:             printf("  Aucun argument\n");
 3945:         }
 3946:         else
 3947:         {
 3948:             printf("(wait for data from parent process)\n\n");
 3949:             printf("  No argument\n");
 3950:         }
 3951: 
 3952:         return;
 3953:     }
 3954:     else if ((*s_etat_processus).test_instruction == 'Y')
 3955:     {
 3956:         (*s_etat_processus).nombre_arguments = -1;
 3957:         return;
 3958:     }
 3959: 
 3960:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 3961:     {
 3962:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 3963:         {
 3964:             return;
 3965:         }
 3966:     }
 3967: 
 3968:     if ((*s_etat_processus).presence_pipes == d_faux)
 3969:     {
 3970:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 3971:         return;
 3972:     }
 3973: 
 3974:     if ((*s_etat_processus).nombre_objets_injectes > 0)
 3975:     {
 3976:         return;
 3977:     }
 3978: 
 3979:     if ((*s_etat_processus).profilage == d_vrai)
 3980:     {
 3981:         profilage(s_etat_processus, "Interprocess or interthread "
 3982:                 "communications (WFPOKE)");
 3983: 
 3984:         if ((*s_etat_processus).erreur_systeme != d_es)
 3985:         {
 3986:             return;
 3987:         }
 3988:     }
 3989: 
 3990:     do
 3991:     {
 3992: #       ifndef SEMAPHORES_NOMMES
 3993:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 3994: #       else
 3995:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 3996: #       endif
 3997:         {
 3998:             (*s_etat_processus).erreur_systeme = d_es_processus;
 3999:             return;
 4000:         }
 4001: 
 4002:         nanosleep(&attente, NULL);
 4003: 
 4004: #       ifndef SEMAPHORES_NOMMES
 4005:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 4006: #       else
 4007:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 4008: #       endif
 4009:         {
 4010:             if (errno != EINTR)
 4011:             {
 4012:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 4013:                 return;
 4014:             }
 4015:         }
 4016: 
 4017:         scrutation_injection(s_etat_processus);
 4018: 
 4019:         if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
 4020:         {
 4021:             (*s_etat_processus).erreur_systeme = d_es_processus;
 4022:             return;
 4023:         }
 4024: 
 4025:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 4026:         {
 4027:             affectation_interruptions_logicielles(s_etat_processus);
 4028:         }
 4029: 
 4030:         if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
 4031:         {
 4032:             (*s_etat_processus).erreur_systeme = d_es_processus;
 4033:             return;
 4034:         }
 4035: 
 4036:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 4037:         {
 4038:             registre_instruction_valide =
 4039:                     (*s_etat_processus).instruction_valide;
 4040:             traitement_interruptions_logicielles(s_etat_processus);
 4041:             (*s_etat_processus).instruction_valide =
 4042:                     registre_instruction_valide;
 4043:         }
 4044: 
 4045:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 4046:         {
 4047:             if ((*s_etat_processus).profilage == d_vrai)
 4048:             {
 4049:                 profilage(s_etat_processus, NULL);
 4050:             }
 4051: 
 4052:             return;
 4053:         }
 4054: 
 4055:         INCR_GRANULARITE(attente.tv_nsec);
 4056:     } while((*s_etat_processus).nombre_objets_injectes == 0);
 4057: 
 4058:     return;
 4059: }
 4060: 
 4061: 
 4062: /*
 4063: ================================================================================
 4064:   Fonction 'wfack'
 4065: ================================================================================
 4066:   Entrées : pointeur sur une structure struct_processus
 4067: --------------------------------------------------------------------------------
 4068:   Sorties :
 4069: --------------------------------------------------------------------------------
 4070:   Effets de bord : néant
 4071: ================================================================================
 4072: */
 4073: 
 4074: void
 4075: instruction_wfack(struct_processus *s_etat_processus)
 4076: {
 4077:     struct timespec             attente;
 4078: 
 4079:     unsigned char               registre_instruction_valide;
 4080: 
 4081:     (*s_etat_processus).erreur_execution = d_ex;
 4082: 
 4083:     attente.tv_sec = 0;
 4084:     attente.tv_nsec = GRANULARITE_us * 1000;
 4085: 
 4086:     if ((*s_etat_processus).affichage_arguments == 'Y')
 4087:     {
 4088:         printf("\n  WFACK ");
 4089: 
 4090:         if ((*s_etat_processus).langue == 'F')
 4091:         {
 4092:             printf("(attente des acquittements de lecture)\n\n");
 4093:             printf("  Aucun argument\n");
 4094:         }
 4095:         else
 4096:         {
 4097:             printf("(wait for reading of data acknowledgement)\n\n");
 4098:             printf("  No argument\n");
 4099:         }
 4100: 
 4101:         return;
 4102:     }
 4103:     else if ((*s_etat_processus).test_instruction == 'Y')
 4104:     {
 4105:         (*s_etat_processus).nombre_arguments = -1;
 4106:         return;
 4107:     }
 4108: 
 4109:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 4110:     {
 4111:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
 4112:         {
 4113:             return;
 4114:         }
 4115:     }
 4116: 
 4117:     if ((*s_etat_processus).presence_pipes == d_faux)
 4118:     {
 4119:         (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
 4120:         return;
 4121:     }
 4122: 
 4123:     if ((*s_etat_processus).profilage == d_vrai)
 4124:     {
 4125:         profilage(s_etat_processus, "Interprocess or interthread communications"
 4126:                 " (WFACK)");
 4127: 
 4128:         if ((*s_etat_processus).erreur_systeme != d_es)
 4129:         {
 4130:             return;
 4131:         }
 4132:     }
 4133: 
 4134:     while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
 4135:     {
 4136:         scrutation_injection(s_etat_processus);
 4137: 
 4138:         if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
 4139:         {
 4140:             (*s_etat_processus).erreur_systeme = d_es_processus;
 4141:             return;
 4142:         }
 4143: 
 4144:         if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
 4145:         {
 4146:             affectation_interruptions_logicielles(s_etat_processus);
 4147:         }
 4148: 
 4149:         if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
 4150:         {
 4151:             (*s_etat_processus).erreur_systeme = d_es_processus;
 4152:             return;
 4153:         }
 4154: 
 4155:         if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
 4156:         {
 4157:             registre_instruction_valide =
 4158:                     (*s_etat_processus).instruction_valide;
 4159:             traitement_interruptions_logicielles(s_etat_processus);
 4160:             (*s_etat_processus).instruction_valide =
 4161:                     registre_instruction_valide;
 4162:         }
 4163: 
 4164:         if ((*s_etat_processus).var_volatile_requete_arret != 0)
 4165:         {
 4166:             if ((*s_etat_processus).profilage == d_vrai)
 4167:             {
 4168:                 profilage(s_etat_processus, NULL);
 4169:             }
 4170: 
 4171:             return;
 4172:         }
 4173: 
 4174: #       ifndef SEMAPHORES_NOMMES
 4175:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
 4176: #       else
 4177:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
 4178: #       endif
 4179:         {
 4180:             (*s_etat_processus).erreur_systeme = d_es_processus;
 4181:             return;
 4182:         }
 4183: 
 4184:         nanosleep(&attente, NULL);
 4185:         INCR_GRANULARITE(attente.tv_nsec);
 4186: 
 4187: #       ifndef SEMAPHORES_NOMMES
 4188:             while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
 4189: #       else
 4190:             while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
 4191: #       endif
 4192:         {
 4193:             if (errno != EINTR)
 4194:             {
 4195:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 4196:                 return;
 4197:             }
 4198:         }
 4199:     }
 4200: 
 4201:     if ((*s_etat_processus).profilage == d_vrai)
 4202:     {
 4203:         profilage(s_etat_processus, NULL);
 4204:     }
 4205: 
 4206:     return;
 4207: }
 4208: 
 4209: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>