File:  [local] / rpl / src / instructions_w1.c
Revision 1.34.2.1: download - view: text, annotated - select for diffs - revision graph
Mon Apr 11 13:02:26 2011 UTC (13 years ago) by bertrand
Branches: rpl-4_0
CVS tags: rpl-4_0_22
Diff to: branchpoint 1.34: preferred, colored
En route vers la 4.0.22.

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

CVSweb interface <joel.bertrand@systella.fr>