File:  [local] / rpl / src / instructions_w1.c
Revision 1.49: download - view: text, annotated - select for diffs - revision graph
Tue Sep 20 08:56:24 2011 UTC (12 years, 7 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Fin (normalement) des patches pour SysV.

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

CVSweb interface <joel.bertrand@systella.fr>