File:  [local] / rpl / src / instructions_w1.c
Revision 1.81: download - view: text, annotated - select for diffs - revision graph
Mon Mar 25 14:42:31 2013 UTC (11 years, 1 month ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_13, HEAD
Ajout d'un cast.

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

CVSweb interface <joel.bertrand@systella.fr>