File:  [local] / rpl / src / instructions_d4.c
Revision 1.75: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:44 2020 UTC (4 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_32, HEAD
Modification du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.32
    4:   Copyright (C) 1989-2020 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 'delete'
   29: ================================================================================
   30:   Entrées : pointeur sur une structure struct_processus
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_delete(struct_processus *s_etat_processus)
   40: {
   41:     const char                  *queue;
   42: 
   43:     file                        *fichier;
   44: 
   45:     int                         ios;
   46: 
   47:     integer8                    lecture_i64;
   48: 
   49:     logical1                    erreur;
   50:     logical1                    existence;
   51:     logical1                    ouverture;
   52: 
   53:     sqlite3_stmt                *ppStmt;
   54: 
   55:     struct_descripteur_fichier  *descripteur;
   56: 
   57:     struct_objet                *s_objet_argument;
   58:     struct_objet                *s_objet_indice;
   59: 
   60:     struct flock                lock;
   61: 
   62:     struct stat                 requete;
   63: 
   64:     struct timespec             attente;
   65: 
   66:     unsigned char               *commande;
   67:     unsigned char               *nom;
   68:     unsigned char               *utf8;
   69: 
   70:     unsigned long               unite;
   71: 
   72:     (*s_etat_processus).erreur_execution = d_ex;
   73: 
   74:     if ((*s_etat_processus).affichage_arguments == 'Y')
   75:     {
   76:         printf("\n  DELETE ");
   77: 
   78:         if ((*s_etat_processus).langue == 'F')
   79:         {
   80:             printf("(effacement d'un fichier ou d'un enregistrement)\n\n");
   81:         }
   82:         else
   83:         {
   84:             printf("(delete file or record)\n\n");
   85:         }
   86: 
   87:         printf("    1: %s\n\n", d_CHN);
   88: 
   89:         printf("    2: %s, %s\n", d_CHN, d_INT);
   90:         printf("    1: %s\n", d_FCH);
   91:         return;
   92:     }
   93:     else if ((*s_etat_processus).test_instruction == 'Y')
   94:     {
   95:         (*s_etat_processus).nombre_arguments = -1;
   96:         return;
   97:     }
   98: 
   99:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  100:     {
  101:         if ((*s_etat_processus).l_base_pile == NULL)
  102:         {
  103:             (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  104:             return;
  105:         }
  106: 
  107:         if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
  108:         {
  109:             if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  110:             {
  111:                 return;
  112:             }
  113:         }
  114:         else
  115:         {
  116:             if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  117:             {
  118:                 return;
  119:             }
  120:         }
  121:     }
  122: 
  123:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  124:             &s_objet_argument) == d_erreur)
  125:     {
  126:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  127:         return;
  128:     }
  129: 
  130:     if ((*s_objet_argument).type == CHN)
  131:     {
  132:         if ((nom = transliteration(s_etat_processus,
  133:                 (unsigned char *) (*s_objet_argument).objet,
  134:                 d_locale, "UTF-8")) == NULL)
  135:         {
  136:             liberation(s_etat_processus, s_objet_argument);
  137:             return;
  138:         }
  139: 
  140:         if (stat(nom, &requete) != 0)
  141:         {
  142:             liberation(s_etat_processus, s_objet_argument);
  143:             free(nom);
  144: 
  145:             (*s_etat_processus).erreur_execution =
  146:                     d_ex_erreur_acces_fichier;
  147:             return;
  148:         }
  149: 
  150:         if (S_ISREG(requete.st_mode)) // Fichier régulier
  151:         {
  152:             if ((fichier = fopen(nom, "r+")) == NULL)
  153:             {
  154:                 liberation(s_etat_processus, s_objet_argument);
  155:                 free(nom);
  156: 
  157:                 (*s_etat_processus).erreur_execution =
  158:                         d_ex_erreur_acces_fichier;
  159:                 return;
  160:             }
  161: 
  162:             lock.l_type = F_WRLCK;
  163:             lock.l_whence = SEEK_SET;
  164:             lock.l_start = 0;
  165:             lock.l_len = 0;
  166:             lock.l_pid = getpid();
  167: 
  168:             if (fcntl(fileno(fichier), F_GETLK, &lock) == -1)
  169:             {
  170:                 free(nom);
  171: 
  172:                 if (fclose(fichier) != 0)
  173:                 {
  174:                     liberation(s_etat_processus, s_objet_argument);
  175: 
  176:                     (*s_etat_processus).erreur_execution =
  177:                             d_ex_erreur_acces_fichier;
  178:                     return;
  179:                 }
  180: 
  181:                 liberation(s_etat_processus, s_objet_argument);
  182: 
  183:                 (*s_etat_processus).erreur_execution =
  184:                         d_ex_erreur_acces_fichier;
  185:                 return;
  186:             }
  187: 
  188:             if (lock.l_type != F_UNLCK)
  189:             {
  190:                 liberation(s_etat_processus, s_objet_argument);
  191:                 free(nom);
  192: 
  193:                 (*s_etat_processus).erreur_execution =
  194:                         d_ex_erreur_acces_fichier;
  195:                 return;
  196:             }
  197: 
  198:             erreur = caracteristiques_fichier(s_etat_processus, nom,
  199:                     &existence, &ouverture, &unite);
  200: 
  201:             if ((erreur != d_absence_erreur) || (ouverture == d_vrai))
  202:             {
  203:                 liberation(s_etat_processus, s_objet_argument);
  204:                 free(nom);
  205: 
  206:                 (*s_etat_processus).erreur_execution =
  207:                         d_ex_erreur_acces_fichier;
  208:                 return;
  209:             }
  210: 
  211:             if (destruction_fichier(nom) == d_erreur)
  212:             {
  213:                 liberation(s_etat_processus, s_objet_argument);
  214:                 free(nom);
  215: 
  216:                 (*s_etat_processus).erreur_execution =
  217:                         d_ex_erreur_acces_fichier;
  218:                 return;
  219:             }
  220:         }
  221:         else // Socket
  222:         {
  223:             if (unlink(nom) != 0)
  224:             {
  225:                 liberation(s_etat_processus, s_objet_argument);
  226:                 free(nom);
  227: 
  228:                 (*s_etat_processus).erreur_execution =
  229:                         d_ex_erreur_acces_fichier;
  230:                 return;
  231:             }
  232:         }
  233: 
  234:         free(nom);
  235:     }
  236:     else if ((*s_objet_argument).type == FCH)
  237:     {
  238:         if ((descripteur = descripteur_fichier(s_etat_processus,
  239:                 (struct_fichier *) (*s_objet_argument).objet)) == NULL)
  240:         {
  241:             return;
  242:         }
  243: 
  244:         /*
  245:          * Vérification des verrous
  246:          */
  247: 
  248:         lock.l_type = F_RDLCK;
  249:         lock.l_whence = SEEK_SET;
  250:         lock.l_start = 0;
  251:         lock.l_len = 0;
  252:         lock.l_pid = getpid();
  253: 
  254:         if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
  255:                 == -1)
  256:         {
  257:             liberation(s_etat_processus, s_objet_argument);
  258: 
  259:             (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  260:             return;
  261:         }
  262: 
  263:         if (lock.l_type != F_UNLCK)
  264:         {
  265:             liberation(s_etat_processus, s_objet_argument);
  266: 
  267:             (*s_etat_processus).erreur_execution =
  268:                     d_ex_fichier_verrouille;
  269:             return;
  270:         }
  271: 
  272:         if ((*((struct_fichier *) (*s_objet_argument).objet))
  273:                 .protection == 'R')
  274:         {
  275:             liberation(s_etat_processus, s_objet_argument);
  276: 
  277:             (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
  278:             return;
  279:         }
  280: 
  281:         if ((*((struct_fichier *) (*s_objet_argument).objet)).binaire == 'N')
  282:         {
  283:             if ((*((struct_fichier *) (*s_objet_argument).objet)).acces
  284:                     == 'S')
  285:             {
  286:                 liberation(s_etat_processus, s_objet_argument);
  287: 
  288:                 (*s_etat_processus).erreur_execution = d_ex_erreur_type_fichier;
  289:                 return;
  290:             }
  291:             else if ((*((struct_fichier *) (*s_objet_argument).objet)).acces
  292:                     == 'D')
  293:             {
  294:                 BUG(((*descripteur).type == 'C'), uprintf("Bad filtype !\n"));
  295: 
  296:                 if (depilement(s_etat_processus, &((*s_etat_processus)
  297:                         .l_base_pile), &s_objet_indice) == d_erreur)
  298:                 {
  299:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  300:                     return;
  301:                 }
  302: 
  303:                 if ((*s_objet_indice).type != INT)
  304:                 {
  305:                     liberation(s_etat_processus, s_objet_argument);
  306:                     liberation(s_etat_processus, s_objet_indice);
  307: 
  308:                     (*s_etat_processus).erreur_execution =
  309:                             d_ex_erreur_type_argument;
  310:                     return;
  311:                 }
  312: 
  313:                 if (alsprintf(s_etat_processus, &commande,
  314:                         "select count(*) from data where id = %lld",
  315:                         (*((integer8 *) (*s_objet_indice).objet))) < 0)
  316:                 {
  317:                     (*s_etat_processus).erreur_systeme =
  318:                             d_es_allocation_memoire;
  319:                     return;
  320:                 }
  321: 
  322:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  323:                         commande, (int) strlen(commande), &ppStmt, &queue)
  324:                         != SQLITE_OK)
  325:                 {
  326:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  327:                     return;
  328:                 }
  329: 
  330:                 attente.tv_sec = 0;
  331:                 attente.tv_nsec = GRANULARITE_us * 1000;
  332: 
  333:                 do
  334:                 {
  335:                     ios = sqlite3_step(ppStmt);
  336: 
  337:                     if (ios == SQLITE_ROW)
  338:                     {
  339:                         break;
  340:                     }
  341:                     else if ((ios == SQLITE_BUSY) || (ios == SQLITE_LOCKED))
  342:                     {
  343:                         nanosleep(&attente, NULL);
  344:                         INCR_GRANULARITE(attente.tv_nsec);
  345:                     }
  346:                     else
  347:                     {
  348:                         (*s_etat_processus).erreur_systeme =
  349:                                 d_es_erreur_fichier;
  350:                         return;
  351:                     }
  352:                 } while(ios != SQLITE_ROW);
  353: 
  354:                 lecture_i64 = sqlite3_column_int64(ppStmt, 0);
  355: 
  356:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  357:                 {
  358:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  359:                     return;
  360:                 }
  361: 
  362:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  363:                 {
  364:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  365:                     return;
  366:                 }
  367: 
  368:                 free(commande);
  369: 
  370:                 if (lecture_i64 == 0)
  371:                 {
  372:                     liberation(s_etat_processus, s_objet_argument);
  373:                     liberation(s_etat_processus, s_objet_indice);
  374: 
  375:                     (*s_etat_processus).erreur_execution =
  376:                             d_ex_enregistrement_inexistant;
  377:                     return;
  378:                 }
  379: 
  380:                 if (alsprintf(s_etat_processus, &commande,
  381:                         "delete from data where id = %lld",
  382:                         (*((integer8 *) (*s_objet_indice).objet))) < 0)
  383:                 {
  384:                     (*s_etat_processus).erreur_systeme =
  385:                             d_es_allocation_memoire;
  386:                     return;
  387:                 }
  388: 
  389:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  390:                         commande, (int) strlen(commande), &ppStmt, &queue)
  391:                         != SQLITE_OK)
  392:                 {
  393:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  394:                     return;
  395:                 }
  396: 
  397:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  398:                 {
  399:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  400:                     return;
  401:                 }
  402: 
  403:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  404:                 {
  405:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  406:                     return;
  407:                 }
  408: 
  409:                 free(commande);
  410:                 liberation(s_etat_processus, s_objet_indice);
  411:             }
  412:             else
  413:             {
  414:                 BUG(((*descripteur).type == 'C'), uprintf("Bad filtype !\n"));
  415: 
  416:                 if (depilement(s_etat_processus, &((*s_etat_processus)
  417:                         .l_base_pile), &s_objet_indice) == d_erreur)
  418:                 {
  419:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  420:                     return;
  421:                 }
  422: 
  423:                 if ((*s_objet_indice).type != CHN)
  424:                 {
  425:                     liberation(s_etat_processus, s_objet_argument);
  426:                     liberation(s_etat_processus, s_objet_indice);
  427: 
  428:                     (*s_etat_processus).erreur_execution =
  429:                             d_ex_erreur_type_argument;
  430:                     return;
  431:                 }
  432: 
  433:                 // Récupération de l'identifiant de la clef
  434: 
  435:                 if ((utf8 = transliteration(s_etat_processus,
  436:                         (unsigned char *) (*s_objet_indice).objet, d_locale,
  437:                         "UTF-8")) == NULL)
  438:                 {
  439:                     liberation(s_etat_processus, s_objet_argument);
  440:                     liberation(s_etat_processus, s_objet_indice);
  441: 
  442:                     return;
  443:                 }
  444: 
  445:                 if (alsprintf(s_etat_processus, &commande,
  446:                         "select id from key where key = '{ \"%s\" }'", utf8)
  447:                         < 0)
  448:                 {
  449:                     (*s_etat_processus).erreur_systeme =
  450:                             d_es_allocation_memoire;
  451:                     return;
  452:                 }
  453: 
  454:                 free(utf8);
  455: 
  456:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  457:                         commande, (int) strlen(commande), &ppStmt, &queue)
  458:                         != SQLITE_OK)
  459:                 {
  460:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  461:                     return;
  462:                 }
  463: 
  464:                 attente.tv_sec = 0;
  465:                 attente.tv_nsec = GRANULARITE_us * 1000;
  466: 
  467:                 do
  468:                 {
  469:                     ios = sqlite3_step(ppStmt);
  470: 
  471:                     switch(ios)
  472:                     {
  473:                         case SQLITE_ROW:
  474:                         {
  475:                             // Correspondance
  476:                             break;
  477:                         }
  478: 
  479:                         case SQLITE_DONE:
  480:                         {
  481:                             // Aucune correspondance
  482:                             if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  483:                             {
  484:                                 (*s_etat_processus).erreur_systeme =
  485:                                         d_es_erreur_fichier;
  486:                                 return;
  487:                             }
  488: 
  489:                             free(commande);
  490: 
  491:                             liberation(s_etat_processus, s_objet_argument);
  492:                             liberation(s_etat_processus, s_objet_indice);
  493: 
  494:                             (*s_etat_processus).erreur_execution =
  495:                                     d_ex_enregistrement_inexistant;
  496:                             return;
  497:                         }
  498: 
  499:                         case SQLITE_LOCKED:
  500:                         case SQLITE_BUSY:
  501:                         {
  502:                             nanosleep(&attente, NULL);
  503:                             INCR_GRANULARITE(attente.tv_nsec);
  504:                             break;
  505:                         }
  506: 
  507:                         default:
  508:                         {
  509:                             (*s_etat_processus).erreur_systeme =
  510:                                     d_es_erreur_fichier;
  511:                             return;
  512:                         }
  513:                     }
  514:                 } while(ios != SQLITE_ROW);
  515: 
  516:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
  517:                 {
  518:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  519:                     return;
  520:                 }
  521: 
  522:                 lecture_i64 = sqlite3_column_int64(ppStmt, 0);
  523: 
  524:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  525:                 {
  526:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  527:                     return;
  528:                 }
  529: 
  530:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  531:                 {
  532:                     (*s_etat_processus).erreur_systeme =
  533:                             d_es_erreur_fichier;
  534:                     return;
  535:                 }
  536: 
  537:                 free(commande);
  538: 
  539:                 if (alsprintf(s_etat_processus, &commande,
  540:                         "delete from data where key_id = %lld", lecture_i64)
  541:                         < 0)
  542:                 {
  543:                     (*s_etat_processus).erreur_systeme =
  544:                             d_es_allocation_memoire;
  545:                     return;
  546:                 }
  547: 
  548:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  549:                         commande, (int) strlen(commande), &ppStmt, &queue)
  550:                         != SQLITE_OK)
  551:                 {
  552:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  553:                     return;
  554:                 }
  555: 
  556:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  557:                 {
  558:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  559:                     return;
  560:                 }
  561: 
  562:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  563:                 {
  564:                     (*s_etat_processus).erreur_systeme =
  565:                             d_es_erreur_fichier;
  566:                     return;
  567:                 }
  568: 
  569:                 free(commande);
  570: 
  571:                 if (alsprintf(s_etat_processus, &commande,
  572:                         "delete from key where id = %lld", lecture_i64) < 0)
  573:                 {
  574:                     (*s_etat_processus).erreur_systeme =
  575:                             d_es_allocation_memoire;
  576:                     return;
  577:                 }
  578: 
  579:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  580:                         commande, (int) strlen(commande), &ppStmt, &queue)
  581:                         != SQLITE_OK)
  582:                 {
  583:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  584:                     return;
  585:                 }
  586: 
  587:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  588:                 {
  589:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  590:                     return;
  591:                 }
  592: 
  593:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  594:                 {
  595:                     (*s_etat_processus).erreur_systeme =
  596:                             d_es_erreur_fichier;
  597:                     return;
  598:                 }
  599: 
  600:                 free(commande);
  601:                 liberation(s_etat_processus, s_objet_indice);
  602:             }
  603:         }
  604:         else // Fichiers non formatés
  605:         {
  606:         }
  607:     }
  608:     else
  609:     {
  610:         liberation(s_etat_processus, s_objet_argument);
  611: 
  612:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  613:         return;
  614:     }
  615: 
  616:     liberation(s_etat_processus, s_objet_argument);
  617: 
  618:     return;
  619: }
  620: 
  621: 
  622: /*
  623: ================================================================================
  624:   Fonction 'date'
  625: ================================================================================
  626:   Entrées : pointeur sur une structure struct_processus
  627: --------------------------------------------------------------------------------
  628:   Sorties :
  629: --------------------------------------------------------------------------------
  630:   Effets de bord : néant
  631: ================================================================================
  632: */
  633: 
  634: void
  635: instruction_date(struct_processus *s_etat_processus)
  636: {
  637:     struct_objet            *s_objet;
  638: 
  639:     struct timeval          horodatage;
  640: 
  641:     (*s_etat_processus).erreur_execution = d_ex;
  642: 
  643:     if ((*s_etat_processus).affichage_arguments == 'Y')
  644:     {
  645:         printf("\n  DATE ");
  646: 
  647:         if ((*s_etat_processus).langue == 'F')
  648:         {
  649:             printf("(information sur la date et l'heure)\n\n");
  650:         }
  651:         else
  652:         {
  653:             printf("(date and time)\n\n");
  654:         }
  655: 
  656:         printf("->  1: %s\n", d_LST);
  657: 
  658:         return;
  659:     }
  660:     else if ((*s_etat_processus).test_instruction == 'Y')
  661:     {
  662:         (*s_etat_processus).nombre_arguments = -1;
  663:         return;
  664:     }
  665: 
  666:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  667:     {
  668:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  669:         {
  670:             return;
  671:         }
  672:     }
  673: 
  674:     gettimeofday(&horodatage, NULL);
  675: 
  676:     if ((s_objet = formateur_date(s_etat_processus, &horodatage)) == NULL)
  677:     {
  678:         return;
  679:     }
  680: 
  681:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  682:             s_objet) == d_erreur)
  683:     {
  684:         return;
  685:     }
  686: 
  687:     return;
  688: }
  689: 
  690: 
  691: /*
  692: ================================================================================
  693:   Fonction 'drws'
  694: ================================================================================
  695:   Entrées : pointeur sur une structure struct_processus
  696: --------------------------------------------------------------------------------
  697:   Sorties :
  698: --------------------------------------------------------------------------------
  699:   Effets de bord : néant
  700: ================================================================================
  701: */
  702: 
  703: void
  704: instruction_drws(struct_processus *s_etat_processus)
  705: {
  706:     file                        *fichier;
  707: 
  708:     int                         dimensions;
  709: 
  710:     logical1                    matrice_entiere;
  711: 
  712:     struct_objet                *s_objet_statistique;
  713: 
  714:     unsigned char               *nom_fichier;
  715: 
  716:     integer8                    j;
  717: 
  718:     struct_fichier_graphique    *l_fichier_courant;
  719:     struct_fichier_graphique    *l_fichier_precedent;
  720: 
  721:     (*s_etat_processus).erreur_execution = d_ex;
  722: 
  723:     if ((*s_etat_processus).affichage_arguments == 'Y')
  724:     {
  725:         printf("\n  DRWS ");
  726: 
  727:         if ((*s_etat_processus).langue == 'F')
  728:         {
  729:             printf("(affiche une série statistique)\n\n");
  730:             printf("  Aucun argument\n");
  731:         }
  732:         else
  733:         {
  734:             printf("(draw statistical data)\n\n");
  735:             printf("  No argument\n");
  736:         }
  737: 
  738:         return;
  739:     }
  740:     else if ((*s_etat_processus).test_instruction == 'Y')
  741:     {
  742:         (*s_etat_processus).nombre_arguments = -1;
  743:         return;
  744:     }
  745: 
  746:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  747:     {
  748:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  749:         {
  750:             return;
  751:         }
  752:     }
  753: 
  754:     /*
  755:      * Vérification de la présence de la matrice statistique
  756:      */
  757: 
  758:     if (recherche_variable_globale(s_etat_processus, ds_sdat) == d_faux)
  759:     {
  760:         /*
  761:          * Aucune variable ds_sdat n'existe.
  762:          */
  763: 
  764:         if ((*s_etat_processus).erreur_execution == d_ex)
  765:         {
  766:             (*s_etat_processus).erreur_execution = d_ex_absence_observations;
  767:         }
  768: 
  769:         (*s_etat_processus).erreur_systeme = d_es;
  770: 
  771:         return;
  772:     }
  773: 
  774:     s_objet_statistique = (*(*s_etat_processus).pointeur_variable_courante)
  775:             .objet;
  776: 
  777:     if ((*s_objet_statistique).type == MIN)
  778:     {
  779:         matrice_entiere = d_vrai;
  780:     }
  781:     else if ((*s_objet_statistique).type == MRL)
  782:     {
  783:         matrice_entiere = d_faux;
  784:     }
  785:     else
  786:     {
  787:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  788:         return;
  789:     }
  790: 
  791:     /*
  792:      * Création du fichier graphique temporaire
  793:      */
  794: 
  795:     if ((nom_fichier = creation_nom_fichier(s_etat_processus,
  796:             (*s_etat_processus).chemin_fichiers_temporaires)) == NULL)
  797:     {
  798:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  799:         return;
  800:     }
  801: 
  802:     if ((fichier = fopen(nom_fichier, "w+")) == NULL)
  803:     {
  804:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  805:         return;
  806:     }
  807: 
  808:     switch((*((struct_matrice *) (*s_objet_statistique).objet)).nombre_colonnes)
  809:     {
  810: 
  811:     /*
  812:      * Une seule colonne
  813:      */
  814: 
  815:         case 1 :
  816:         {
  817:             dimensions = 2;
  818: 
  819:             for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
  820:                     .nombre_lignes; j++)
  821:             {
  822:                 if (matrice_entiere == d_vrai)
  823:                 {
  824:                     if (fprintf(fichier, "%f %f\n", (double) j, (double)
  825:                             ((integer8 **) (*((struct_matrice *)
  826:                             (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
  827:                     {
  828:                         (*s_etat_processus).erreur_systeme =
  829:                                 d_es_erreur_fichier;
  830:                         return;
  831:                     }
  832:                 }
  833:                 else
  834:                 {
  835:                     if (fprintf(fichier, "%f %f\n", (double) j, (double)
  836:                             ((real8 **) (*((struct_matrice *)
  837:                             (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
  838:                     {
  839:                         (*s_etat_processus).erreur_systeme =
  840:                                 d_es_erreur_fichier;
  841:                         return;
  842:                     }
  843:                 }
  844:             }
  845: 
  846:             break;
  847:         }
  848: 
  849:     /*
  850:      * Deux colonnes ou plus
  851:      */
  852: 
  853:         default :
  854:         {
  855:             dimensions = 2;
  856: 
  857:             if (((*s_etat_processus).colonne_statistique_1 < 1) ||
  858:                     ((*s_etat_processus).colonne_statistique_2 < 1) ||
  859:                     ((*s_etat_processus).colonne_statistique_1 >
  860:                     (*((struct_matrice *) (*s_objet_statistique).objet))
  861:                     .nombre_colonnes) ||
  862:                     ((*s_etat_processus).colonne_statistique_2 >
  863:                     (*((struct_matrice *) (*s_objet_statistique).objet))
  864:                     .nombre_colonnes))
  865:             {
  866:                 if (fclose(fichier) != 0)
  867:                 {
  868:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  869:                     return;
  870:                 }
  871: 
  872:                 if (destruction_fichier(nom_fichier) == d_erreur)
  873:                 {
  874:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  875:                     return;
  876:                 }
  877: 
  878:                 free(nom_fichier);
  879: 
  880:                 (*s_etat_processus).erreur_execution =
  881:                         d_ex_observations_inexistantes;
  882:                 return;
  883:             }
  884: 
  885:             for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
  886:                     .nombre_lignes; j++)
  887:             {
  888:                 if (matrice_entiere == d_vrai)
  889:                 {
  890:                     if (fprintf(fichier, "%f %f\n", (double) ((integer8 **)
  891:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  892:                             .tableau)[j][(*s_etat_processus)
  893:                             .colonne_statistique_1 - 1], (double) ((integer8 **)
  894:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  895:                             .tableau)[j][(*s_etat_processus)
  896:                             .colonne_statistique_2 - 1]) < 0)
  897:                     {
  898:                         (*s_etat_processus).erreur_systeme =
  899:                                 d_es_erreur_fichier;
  900:                         return;
  901:                     }
  902:                 }
  903:                 else
  904:                 {
  905:                     if (fprintf(fichier, "%f %f\n", (double) ((real8 **)
  906:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  907:                             .tableau)[j][(*s_etat_processus)
  908:                             .colonne_statistique_1 - 1], (double) ((real8 **)
  909:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  910:                             .tableau)[j][(*s_etat_processus)
  911:                             .colonne_statistique_2 - 1]) < 0)
  912:                     {
  913:                         (*s_etat_processus).erreur_systeme =
  914:                                 d_es_erreur_fichier;
  915:                         return;
  916:                     }
  917:                 }
  918:             }
  919: 
  920:             break;
  921:         }
  922:     }
  923: 
  924:     /*
  925:      * Fermeture du fichier graphique
  926:      */
  927: 
  928:     if (fclose(fichier) != 0)
  929:     {
  930:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  931:         return;
  932:     }
  933: 
  934:     /*
  935:      * Chaînage du fichier temporaire à la liste des fichiers graphiques
  936:      */
  937: 
  938:     l_fichier_courant = (*s_etat_processus).fichiers_graphiques;
  939: 
  940:     if (l_fichier_courant == NULL)
  941:     {
  942:         if (((*s_etat_processus).fichiers_graphiques = malloc(
  943:                 sizeof(struct_fichier_graphique))) == NULL)
  944:         {
  945:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  946:             return;
  947:         }
  948: 
  949:         (*(*s_etat_processus).fichiers_graphiques).suivant = NULL;
  950:         (*(*s_etat_processus).fichiers_graphiques).nom = nom_fichier;
  951:         (*(*s_etat_processus).fichiers_graphiques).legende = NULL;
  952:         (*(*s_etat_processus).fichiers_graphiques).dimensions = dimensions;
  953:         (*(*s_etat_processus).fichiers_graphiques).presence_axes = d_faux;
  954:         (*(*s_etat_processus).fichiers_graphiques).systeme_axes =
  955:                 (*s_etat_processus).systeme_axes;
  956:         strcpy((*(*s_etat_processus).fichiers_graphiques).type,
  957:                 (*s_etat_processus).type_trace_sigma);
  958:     }
  959:     else
  960:     {
  961:         while(l_fichier_courant != NULL)
  962:         {
  963:             if ((*l_fichier_courant).dimensions != dimensions)
  964:             {
  965:                 (*s_etat_processus).erreur_execution =
  966:                         d_ex_dimensions_differentes;
  967:                 return;
  968:             }
  969: 
  970:             l_fichier_precedent = l_fichier_courant;
  971:             l_fichier_courant = (*l_fichier_courant).suivant;
  972:         }
  973: 
  974:         l_fichier_courant = l_fichier_precedent;
  975: 
  976:         if (((*l_fichier_courant).suivant = malloc(
  977:                 sizeof(struct_fichier_graphique))) == NULL)
  978:         {
  979:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  980:             return;
  981:         }
  982: 
  983:         l_fichier_courant = (*l_fichier_courant).suivant;
  984: 
  985:         (*l_fichier_courant).suivant = NULL;
  986:         (*l_fichier_courant).nom = nom_fichier;
  987:         (*l_fichier_courant).legende = NULL;
  988:         (*l_fichier_courant).dimensions = dimensions;
  989:         (*l_fichier_courant).presence_axes = d_faux;
  990:         (*l_fichier_courant).systeme_axes = (*s_etat_processus).systeme_axes;
  991:         strcpy((*l_fichier_courant).type, (*s_etat_processus).type_trace_sigma);
  992:     }
  993: 
  994:     /*
  995:      * Affichage du graphique
  996:      */
  997: 
  998:     appel_gnuplot(s_etat_processus, 'N');
  999:     (*s_etat_processus).erreur_execution = d_ex;
 1000:     (*s_etat_processus).exception = d_ep;
 1001: 
 1002:     return;
 1003: }
 1004: 
 1005: 
 1006: /*
 1007: ================================================================================
 1008:   Fonction 'decr'
 1009: ================================================================================
 1010:   Entrées :
 1011: --------------------------------------------------------------------------------
 1012:   Sorties :
 1013: --------------------------------------------------------------------------------
 1014:   Effets de bord : néant
 1015: ================================================================================
 1016: */
 1017: 
 1018: void
 1019: instruction_decr(struct_processus *s_etat_processus)
 1020: {
 1021:     logical1                    variable_partagee;
 1022: 
 1023:     struct_objet                *s_copie_argument;
 1024:     struct_objet                *s_objet_argument;
 1025: 
 1026:     (*s_etat_processus).erreur_execution = d_ex;
 1027: 
 1028:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1029:     {
 1030:         printf("\n  DECR ");
 1031: 
 1032:         if ((*s_etat_processus).langue == 'F')
 1033:         {
 1034:             printf("(décrémentation)\n\n");
 1035:         }
 1036:         else
 1037:         {
 1038:             printf("(decrementation)\n\n");
 1039:         }
 1040: 
 1041:         printf("    1: %s\n", d_INT);
 1042:         printf("->  1: %s\n\n", d_INT);
 1043: 
 1044:         printf("    1: %s\n", d_NOM);
 1045: 
 1046:         return;
 1047:     }
 1048:     else if ((*s_etat_processus).test_instruction == 'Y')
 1049:     {
 1050:         (*s_etat_processus).nombre_arguments = -1;
 1051:         return;
 1052:     }
 1053: 
 1054:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1055:     {
 1056:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1057:         {
 1058:             return;
 1059:         }
 1060:     }
 1061: 
 1062:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1063:             &s_objet_argument) == d_erreur)
 1064:     {
 1065:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1066:         return;
 1067:     }
 1068: 
 1069:     if ((*s_objet_argument).type == INT)
 1070:     {
 1071:         if ((s_copie_argument = copie_objet(s_etat_processus,
 1072:                 s_objet_argument, 'O')) == NULL)
 1073:         {
 1074:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1075:             return;
 1076:         }
 1077: 
 1078:         liberation(s_etat_processus, s_objet_argument);
 1079:         s_objet_argument = s_copie_argument;
 1080: 
 1081:         (*((integer8 *) (*s_objet_argument).objet))--;
 1082: 
 1083:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1084:                 s_objet_argument) == d_erreur)
 1085:         {
 1086:             return;
 1087:         }
 1088:     }
 1089:     else if ((*s_objet_argument).type == NOM)
 1090:     {
 1091:         if (recherche_variable(s_etat_processus, (*((struct_nom *)
 1092:                 (*s_objet_argument).objet)).nom) == d_faux)
 1093:         {
 1094:             (*s_etat_processus).erreur_systeme = d_es;
 1095:             (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
 1096: 
 1097:             return;
 1098:         }
 1099: 
 1100:         liberation(s_etat_processus, s_objet_argument);
 1101: 
 1102:         if ((*(*s_etat_processus).pointeur_variable_courante)
 1103:                 .variable_verrouillee == d_vrai)
 1104:         {
 1105:             (*s_etat_processus).erreur_execution =
 1106:                     d_ex_variable_verrouillee;
 1107:             return;
 1108:         }
 1109: 
 1110:         if ((*(*s_etat_processus).pointeur_variable_courante).objet
 1111:                 == NULL)
 1112:         {
 1113:             if (recherche_variable_partagee(s_etat_processus,
 1114:                     (*(*s_etat_processus).pointeur_variable_courante).nom,
 1115:                     (*(*s_etat_processus).pointeur_variable_courante)
 1116:                     .variable_partagee, (*(*s_etat_processus)
 1117:                     .pointeur_variable_courante).origine) == NULL)
 1118:             {
 1119:                 (*s_etat_processus).erreur_systeme = d_es;
 1120:                 (*s_etat_processus).erreur_execution =
 1121:                         d_ex_variable_non_definie;
 1122: 
 1123:                 return;
 1124:             }
 1125: 
 1126:             s_objet_argument = (*(*s_etat_processus)
 1127:                     .pointeur_variable_partagee_courante).objet;
 1128:             variable_partagee = d_vrai;
 1129:         }
 1130:         else
 1131:         {
 1132:             s_objet_argument = (*(*s_etat_processus).pointeur_variable_courante)
 1133:                     .objet;
 1134:             variable_partagee = d_faux;
 1135:         }
 1136: 
 1137:         if ((s_copie_argument = copie_objet(s_etat_processus,
 1138:                 s_objet_argument, 'O')) == NULL)
 1139:         {
 1140:             if (variable_partagee == d_vrai)
 1141:             {
 1142:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1143:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1144:                 {
 1145:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1146:                     return;
 1147:                 }
 1148:             }
 1149: 
 1150:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1151:             return;
 1152:         }
 1153: 
 1154:         liberation(s_etat_processus, s_objet_argument);
 1155: 
 1156:         if (variable_partagee == d_vrai)
 1157:         {
 1158:             (*(*s_etat_processus).pointeur_variable_courante).objet = NULL;
 1159:             (*(*s_etat_processus).pointeur_variable_partagee_courante).objet =
 1160:                     s_copie_argument;
 1161:         }
 1162:         else
 1163:         {
 1164:             (*(*s_etat_processus).pointeur_variable_courante).objet =
 1165:                     s_copie_argument;
 1166:         }
 1167: 
 1168:         if ((*s_copie_argument).type == INT)
 1169:         {
 1170:             (*((integer8 *) (*s_copie_argument).objet))--;
 1171: 
 1172:             if (variable_partagee == d_vrai)
 1173:             {
 1174:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1175:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1176:                 {
 1177:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1178:                     return;
 1179:                 }
 1180:             }
 1181:         }
 1182:         else
 1183:         {
 1184:             if (variable_partagee == d_vrai)
 1185:             {
 1186:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1187:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1188:                 {
 1189:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1190:                     return;
 1191:                 }
 1192:             }
 1193: 
 1194:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1195:             return;
 1196:         }
 1197:     }
 1198:     else
 1199:     {
 1200:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1201: 
 1202:         liberation(s_etat_processus, s_objet_argument);
 1203:         return;
 1204:     }
 1205: 
 1206:     return;
 1207: }
 1208: 
 1209: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>