File:  [local] / rpl / src / instructions_w1.c
Revision 1.24: download - view: text, annotated - select for diffs - revision graph
Sun Aug 15 14:46:25 2010 UTC (13 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Patches pour OpenBSD.

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

CVSweb interface <joel.bertrand@systella.fr>