File:  [local] / rpl / src / instructions_w1.c
Revision 1.132: download - view: text, annotated - select for diffs - revision graph
Tue Apr 15 10:17:56 2025 UTC (2 weeks, 4 days ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Mise à jour du copyright.

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

CVSweb interface <joel.bertrand@systella.fr>