File:  [local] / rpl / src / instructions_d4.c
Revision 1.59: download - view: text, annotated - select for diffs - revision graph
Mon Jan 5 15:32:17 2015 UTC (9 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
En route vers la 4.1.20.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.20
    4:   Copyright (C) 1989-2015 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(&commande, "select count(*) from data where "
  314:                         "id = %lld", (*((integer8 *) (*s_objet_indice).objet)))
  315:                         < 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(&commande, "delete from data where id = %lld",
  381:                         (*((integer8 *) (*s_objet_indice).objet))) < 0)
  382:                 {
  383:                     (*s_etat_processus).erreur_systeme =
  384:                             d_es_allocation_memoire;
  385:                     return;
  386:                 }
  387: 
  388:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  389:                         commande, (int) strlen(commande), &ppStmt, &queue)
  390:                         != SQLITE_OK)
  391:                 {
  392:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  393:                     return;
  394:                 }
  395: 
  396:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  397:                 {
  398:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  399:                     return;
  400:                 }
  401: 
  402:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  403:                 {
  404:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  405:                     return;
  406:                 }
  407: 
  408:                 free(commande);
  409:                 liberation(s_etat_processus, s_objet_indice);
  410:             }
  411:             else
  412:             {
  413:                 BUG(((*descripteur).type == 'C'), uprintf("Bad filtype !\n"));
  414: 
  415:                 if (depilement(s_etat_processus, &((*s_etat_processus)
  416:                         .l_base_pile), &s_objet_indice) == d_erreur)
  417:                 {
  418:                     (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  419:                     return;
  420:                 }
  421: 
  422:                 if ((*s_objet_indice).type != CHN)
  423:                 {
  424:                     liberation(s_etat_processus, s_objet_argument);
  425:                     liberation(s_etat_processus, s_objet_indice);
  426: 
  427:                     (*s_etat_processus).erreur_execution =
  428:                             d_ex_erreur_type_argument;
  429:                     return;
  430:                 }
  431: 
  432:                 // Récupération de l'identifiant de la clef
  433: 
  434:                 if ((utf8 = transliteration(s_etat_processus,
  435:                         (unsigned char *) (*s_objet_indice).objet, d_locale,
  436:                         "UTF-8")) == NULL)
  437:                 {
  438:                     liberation(s_etat_processus, s_objet_argument);
  439:                     liberation(s_etat_processus, s_objet_indice);
  440: 
  441:                     return;
  442:                 }
  443: 
  444:                 if (alsprintf(&commande, "select id from key where key = "
  445:                         "'{ \"%s\" }'", utf8) < 0)
  446:                 {
  447:                     (*s_etat_processus).erreur_systeme =
  448:                             d_es_allocation_memoire;
  449:                     return;
  450:                 }
  451: 
  452:                 free(utf8);
  453: 
  454:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  455:                         commande, (int) strlen(commande), &ppStmt, &queue)
  456:                         != SQLITE_OK)
  457:                 {
  458:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  459:                     return;
  460:                 }
  461: 
  462:                 attente.tv_sec = 0;
  463:                 attente.tv_nsec = GRANULARITE_us * 1000;
  464: 
  465:                 do
  466:                 {
  467:                     ios = sqlite3_step(ppStmt);
  468: 
  469:                     switch(ios)
  470:                     {
  471:                         case SQLITE_ROW:
  472:                         {
  473:                             // Correspondance
  474:                             break;
  475:                         }
  476: 
  477:                         case SQLITE_DONE:
  478:                         {
  479:                             // Aucune correspondance
  480:                             if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  481:                             {
  482:                                 (*s_etat_processus).erreur_systeme =
  483:                                         d_es_erreur_fichier;
  484:                                 return;
  485:                             }
  486: 
  487:                             free(commande);
  488: 
  489:                             liberation(s_etat_processus, s_objet_argument);
  490:                             liberation(s_etat_processus, s_objet_indice);
  491: 
  492:                             (*s_etat_processus).erreur_execution =
  493:                                     d_ex_enregistrement_inexistant;
  494:                             return;
  495:                         }
  496: 
  497:                         case SQLITE_LOCKED:
  498:                         case SQLITE_BUSY:
  499:                         {
  500:                             nanosleep(&attente, NULL);
  501:                             INCR_GRANULARITE(attente.tv_nsec);
  502:                             break;
  503:                         }
  504: 
  505:                         default:
  506:                         {
  507:                             (*s_etat_processus).erreur_systeme =
  508:                                     d_es_erreur_fichier;
  509:                             return;
  510:                         }
  511:                     }
  512:                 } while(ios != SQLITE_ROW);
  513: 
  514:                 if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
  515:                 {
  516:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  517:                     return;
  518:                 }
  519: 
  520:                 lecture_i64 = sqlite3_column_int64(ppStmt, 0);
  521: 
  522:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  523:                 {
  524:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  525:                     return;
  526:                 }
  527: 
  528:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  529:                 {
  530:                     (*s_etat_processus).erreur_systeme =
  531:                             d_es_erreur_fichier;
  532:                     return;
  533:                 }
  534: 
  535:                 free(commande);
  536: 
  537:                 if (alsprintf(&commande, "delete from data where key_id = %lld",
  538:                         lecture_i64) < 0)
  539:                 {
  540:                     (*s_etat_processus).erreur_systeme =
  541:                             d_es_allocation_memoire;
  542:                     return;
  543:                 }
  544: 
  545:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  546:                         commande, (int) strlen(commande), &ppStmt, &queue)
  547:                         != SQLITE_OK)
  548:                 {
  549:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  550:                     return;
  551:                 }
  552: 
  553:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  554:                 {
  555:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  556:                     return;
  557:                 }
  558: 
  559:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  560:                 {
  561:                     (*s_etat_processus).erreur_systeme =
  562:                             d_es_erreur_fichier;
  563:                     return;
  564:                 }
  565: 
  566:                 free(commande);
  567: 
  568:                 if (alsprintf(&commande, "delete from key where id = %lld",
  569:                         lecture_i64) < 0)
  570:                 {
  571:                     (*s_etat_processus).erreur_systeme =
  572:                             d_es_allocation_memoire;
  573:                     return;
  574:                 }
  575: 
  576:                 if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
  577:                         commande, (int) strlen(commande), &ppStmt, &queue)
  578:                         != SQLITE_OK)
  579:                 {
  580:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  581:                     return;
  582:                 }
  583: 
  584:                 if (sqlite3_step(ppStmt) != SQLITE_DONE)
  585:                 {
  586:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  587:                     return;
  588:                 }
  589: 
  590:                 if (sqlite3_finalize(ppStmt) != SQLITE_OK)
  591:                 {
  592:                     (*s_etat_processus).erreur_systeme =
  593:                             d_es_erreur_fichier;
  594:                     return;
  595:                 }
  596: 
  597:                 free(commande);
  598:                 liberation(s_etat_processus, s_objet_indice);
  599:             }
  600:         }
  601:         else // Fichiers non formatés
  602:         {
  603:         }
  604:     }
  605:     else
  606:     {
  607:         liberation(s_etat_processus, s_objet_argument);
  608: 
  609:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  610:         return;
  611:     }
  612: 
  613:     liberation(s_etat_processus, s_objet_argument);
  614: 
  615:     return;
  616: }
  617: 
  618: 
  619: /*
  620: ================================================================================
  621:   Fonction 'date'
  622: ================================================================================
  623:   Entrées : pointeur sur une structure struct_processus
  624: --------------------------------------------------------------------------------
  625:   Sorties :
  626: --------------------------------------------------------------------------------
  627:   Effets de bord : néant
  628: ================================================================================
  629: */
  630: 
  631: void
  632: instruction_date(struct_processus *s_etat_processus)
  633: {
  634:     struct_objet            *s_objet;
  635: 
  636:     struct timeval          horodatage;
  637: 
  638:     (*s_etat_processus).erreur_execution = d_ex;
  639: 
  640:     if ((*s_etat_processus).affichage_arguments == 'Y')
  641:     {
  642:         printf("\n  DATE ");
  643: 
  644:         if ((*s_etat_processus).langue == 'F')
  645:         {
  646:             printf("(information sur la date et l'heure)\n\n");
  647:         }
  648:         else
  649:         {
  650:             printf("(date and time)\n\n");
  651:         }
  652: 
  653:         printf("->  1: %s\n", d_LST);
  654: 
  655:         return;
  656:     }
  657:     else if ((*s_etat_processus).test_instruction == 'Y')
  658:     {
  659:         (*s_etat_processus).nombre_arguments = -1;
  660:         return;
  661:     }
  662: 
  663:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  664:     {
  665:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  666:         {
  667:             return;
  668:         }
  669:     }
  670: 
  671:     gettimeofday(&horodatage, NULL);
  672: 
  673:     if ((s_objet = formateur_date(s_etat_processus, &horodatage)) == NULL)
  674:     {
  675:         return;
  676:     }
  677: 
  678:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  679:             s_objet) == d_erreur)
  680:     {
  681:         return;
  682:     }
  683: 
  684:     return;
  685: }
  686: 
  687: 
  688: /*
  689: ================================================================================
  690:   Fonction 'drws'
  691: ================================================================================
  692:   Entrées : pointeur sur une structure struct_processus
  693: --------------------------------------------------------------------------------
  694:   Sorties :
  695: --------------------------------------------------------------------------------
  696:   Effets de bord : néant
  697: ================================================================================
  698: */
  699: 
  700: void
  701: instruction_drws(struct_processus *s_etat_processus)
  702: {
  703:     file                        *fichier;
  704: 
  705:     int                         dimensions;
  706: 
  707:     logical1                    matrice_entiere;
  708: 
  709:     struct_objet                *s_objet_statistique;
  710: 
  711:     unsigned char               *nom_fichier;
  712: 
  713:     integer8                    j;
  714: 
  715:     struct_fichier_graphique    *l_fichier_courant;
  716:     struct_fichier_graphique    *l_fichier_precedent;
  717: 
  718:     (*s_etat_processus).erreur_execution = d_ex;
  719: 
  720:     if ((*s_etat_processus).affichage_arguments == 'Y')
  721:     {
  722:         printf("\n  DRWS ");
  723: 
  724:         if ((*s_etat_processus).langue == 'F')
  725:         {
  726:             printf("(affiche une série statistique)\n\n");
  727:             printf("  Aucun argument\n");
  728:         }
  729:         else
  730:         {
  731:             printf("(draw statistical data)\n\n");
  732:             printf("  No argument\n");
  733:         }
  734: 
  735:         return;
  736:     }
  737:     else if ((*s_etat_processus).test_instruction == 'Y')
  738:     {
  739:         (*s_etat_processus).nombre_arguments = -1;
  740:         return;
  741:     }
  742: 
  743:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  744:     {
  745:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  746:         {
  747:             return;
  748:         }
  749:     }
  750: 
  751:     /*
  752:      * Vérification de la présence de la matrice statistique
  753:      */
  754: 
  755:     if (recherche_variable_globale(s_etat_processus, ds_sdat) == d_faux)
  756:     {
  757:         /*
  758:          * Aucune variable ds_sdat n'existe.
  759:          */
  760: 
  761:         if ((*s_etat_processus).erreur_execution == d_ex)
  762:         {
  763:             (*s_etat_processus).erreur_execution = d_ex_absence_observations;
  764:         }
  765: 
  766:         (*s_etat_processus).erreur_systeme = d_es;
  767: 
  768:         return;
  769:     }
  770: 
  771:     s_objet_statistique = (*(*s_etat_processus).pointeur_variable_courante)
  772:             .objet;
  773: 
  774:     if ((*s_objet_statistique).type == MIN)
  775:     {
  776:         matrice_entiere = d_vrai;
  777:     }
  778:     else if ((*s_objet_statistique).type == MRL)
  779:     {
  780:         matrice_entiere = d_faux;
  781:     }
  782:     else
  783:     {
  784:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  785:         return;
  786:     }
  787: 
  788:     /*
  789:      * Création du fichier graphique temporaire
  790:      */
  791: 
  792:     if ((nom_fichier = creation_nom_fichier(s_etat_processus,
  793:             (*s_etat_processus).chemin_fichiers_temporaires)) == NULL)
  794:     {
  795:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  796:         return;
  797:     }
  798: 
  799:     if ((fichier = fopen(nom_fichier, "w+")) == NULL)
  800:     {
  801:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  802:         return;
  803:     }
  804: 
  805:     switch((*((struct_matrice *) (*s_objet_statistique).objet)).nombre_colonnes)
  806:     {
  807: 
  808:     /*
  809:      * Une seule colonne
  810:      */
  811: 
  812:         case 1 :
  813:         {
  814:             dimensions = 2;
  815: 
  816:             for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
  817:                     .nombre_lignes; j++)
  818:             {
  819:                 if (matrice_entiere == d_vrai)
  820:                 {
  821:                     if (fprintf(fichier, "%f %f\n", (double) j, (double)
  822:                             ((integer8 **) (*((struct_matrice *)
  823:                             (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
  824:                     {
  825:                         (*s_etat_processus).erreur_systeme =
  826:                                 d_es_erreur_fichier;
  827:                         return;
  828:                     }
  829:                 }
  830:                 else
  831:                 {
  832:                     if (fprintf(fichier, "%f %f\n", (double) j, (double)
  833:                             ((real8 **) (*((struct_matrice *)
  834:                             (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
  835:                     {
  836:                         (*s_etat_processus).erreur_systeme =
  837:                                 d_es_erreur_fichier;
  838:                         return;
  839:                     }
  840:                 }
  841:             }
  842: 
  843:             break;
  844:         }
  845: 
  846:     /*
  847:      * Deux colonnes ou plus
  848:      */
  849: 
  850:         default :
  851:         {
  852:             dimensions = 2;
  853: 
  854:             if (((*s_etat_processus).colonne_statistique_1 < 1) ||
  855:                     ((*s_etat_processus).colonne_statistique_2 < 1) ||
  856:                     ((*s_etat_processus).colonne_statistique_1 >
  857:                     (*((struct_matrice *) (*s_objet_statistique).objet))
  858:                     .nombre_colonnes) ||
  859:                     ((*s_etat_processus).colonne_statistique_2 >
  860:                     (*((struct_matrice *) (*s_objet_statistique).objet))
  861:                     .nombre_colonnes))
  862:             {
  863:                 if (fclose(fichier) != 0)
  864:                 {
  865:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  866:                     return;
  867:                 }
  868: 
  869:                 if (destruction_fichier(nom_fichier) == d_erreur)
  870:                 {
  871:                     (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  872:                     return;
  873:                 }
  874: 
  875:                 free(nom_fichier);
  876: 
  877:                 (*s_etat_processus).erreur_execution =
  878:                         d_ex_observations_inexistantes;
  879:                 return;
  880:             }
  881: 
  882:             for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
  883:                     .nombre_lignes; j++)
  884:             {
  885:                 if (matrice_entiere == d_vrai)
  886:                 {
  887:                     if (fprintf(fichier, "%f %f\n", (double) ((integer8 **)
  888:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  889:                             .tableau)[j][(*s_etat_processus)
  890:                             .colonne_statistique_1 - 1], (double) ((integer8 **)
  891:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  892:                             .tableau)[j][(*s_etat_processus)
  893:                             .colonne_statistique_2 - 1]) < 0)
  894:                     {
  895:                         (*s_etat_processus).erreur_systeme =
  896:                                 d_es_erreur_fichier;
  897:                         return;
  898:                     }
  899:                 }
  900:                 else
  901:                 {
  902:                     if (fprintf(fichier, "%f %f\n", (double) ((real8 **)
  903:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  904:                             .tableau)[j][(*s_etat_processus)
  905:                             .colonne_statistique_1 - 1], (double) ((real8 **)
  906:                             (*((struct_matrice *) (*s_objet_statistique).objet))
  907:                             .tableau)[j][(*s_etat_processus)
  908:                             .colonne_statistique_2 - 1]) < 0)
  909:                     {
  910:                         (*s_etat_processus).erreur_systeme =
  911:                                 d_es_erreur_fichier;
  912:                         return;
  913:                     }
  914:                 }
  915:             }
  916: 
  917:             break;
  918:         }
  919:     }
  920: 
  921:     /*
  922:      * Fermeture du fichier graphique
  923:      */
  924: 
  925:     if (fclose(fichier) != 0)
  926:     {
  927:         (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
  928:         return;
  929:     }
  930: 
  931:     /*
  932:      * Chaînage du fichier temporaire à la liste des fichiers graphiques
  933:      */
  934: 
  935:     l_fichier_courant = (*s_etat_processus).fichiers_graphiques;
  936: 
  937:     if (l_fichier_courant == NULL)
  938:     {
  939:         if (((*s_etat_processus).fichiers_graphiques = malloc(
  940:                 sizeof(struct_fichier_graphique))) == NULL)
  941:         {
  942:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  943:             return;
  944:         }
  945: 
  946:         (*(*s_etat_processus).fichiers_graphiques).suivant = NULL;
  947:         (*(*s_etat_processus).fichiers_graphiques).nom = nom_fichier;
  948:         (*(*s_etat_processus).fichiers_graphiques).legende = NULL;
  949:         (*(*s_etat_processus).fichiers_graphiques).dimensions = dimensions;
  950:         (*(*s_etat_processus).fichiers_graphiques).presence_axes = d_faux;
  951:         (*(*s_etat_processus).fichiers_graphiques).systeme_axes =
  952:                 (*s_etat_processus).systeme_axes;
  953:         strcpy((*(*s_etat_processus).fichiers_graphiques).type,
  954:                 (*s_etat_processus).type_trace_sigma);
  955:     }
  956:     else
  957:     {
  958:         while(l_fichier_courant != NULL)
  959:         {
  960:             if ((*l_fichier_courant).dimensions != dimensions)
  961:             {
  962:                 (*s_etat_processus).erreur_execution =
  963:                         d_ex_dimensions_differentes;
  964:                 return;
  965:             }
  966: 
  967:             l_fichier_precedent = l_fichier_courant;
  968:             l_fichier_courant = (*l_fichier_courant).suivant;
  969:         }
  970: 
  971:         l_fichier_courant = l_fichier_precedent;
  972: 
  973:         if (((*l_fichier_courant).suivant = malloc(
  974:                 sizeof(struct_fichier_graphique))) == NULL)
  975:         {
  976:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  977:             return;
  978:         }
  979: 
  980:         l_fichier_courant = (*l_fichier_courant).suivant;
  981: 
  982:         (*l_fichier_courant).suivant = NULL;
  983:         (*l_fichier_courant).nom = nom_fichier;
  984:         (*l_fichier_courant).legende = NULL;
  985:         (*l_fichier_courant).dimensions = dimensions;
  986:         (*l_fichier_courant).presence_axes = d_faux;
  987:         (*l_fichier_courant).systeme_axes = (*s_etat_processus).systeme_axes;
  988:         strcpy((*l_fichier_courant).type, (*s_etat_processus).type_trace_sigma);
  989:     }
  990: 
  991:     /*
  992:      * Affichage du graphique
  993:      */
  994: 
  995:     appel_gnuplot(s_etat_processus, 'N');
  996:     (*s_etat_processus).erreur_execution = d_ex;
  997:     (*s_etat_processus).exception = d_ep;
  998: 
  999:     return;
 1000: }
 1001: 
 1002: 
 1003: /*
 1004: ================================================================================
 1005:   Fonction 'decr'
 1006: ================================================================================
 1007:   Entrées :
 1008: --------------------------------------------------------------------------------
 1009:   Sorties :
 1010: --------------------------------------------------------------------------------
 1011:   Effets de bord : néant
 1012: ================================================================================
 1013: */
 1014: 
 1015: void
 1016: instruction_decr(struct_processus *s_etat_processus)
 1017: {
 1018:     logical1                    variable_partagee;
 1019: 
 1020:     struct_objet                *s_copie_argument;
 1021:     struct_objet                *s_objet_argument;
 1022: 
 1023:     (*s_etat_processus).erreur_execution = d_ex;
 1024: 
 1025:     if ((*s_etat_processus).affichage_arguments == 'Y')
 1026:     {
 1027:         printf("\n  DECR ");
 1028: 
 1029:         if ((*s_etat_processus).langue == 'F')
 1030:         {
 1031:             printf("(décrémentation)\n\n");
 1032:         }
 1033:         else
 1034:         {
 1035:             printf("(decrementation)\n\n");
 1036:         }
 1037: 
 1038:         printf("    1: %s\n", d_INT);
 1039:         printf("->  1: %s\n\n", d_INT);
 1040: 
 1041:         printf("    1: %s\n", d_NOM);
 1042: 
 1043:         return;
 1044:     }
 1045:     else if ((*s_etat_processus).test_instruction == 'Y')
 1046:     {
 1047:         (*s_etat_processus).nombre_arguments = -1;
 1048:         return;
 1049:     }
 1050: 
 1051:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
 1052:     {
 1053:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
 1054:         {
 1055:             return;
 1056:         }
 1057:     }
 1058: 
 1059:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1060:             &s_objet_argument) == d_erreur)
 1061:     {
 1062:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1063:         return;
 1064:     }
 1065: 
 1066:     if ((*s_objet_argument).type == INT)
 1067:     {
 1068:         if ((s_copie_argument = copie_objet(s_etat_processus,
 1069:                 s_objet_argument, 'O')) == NULL)
 1070:         {
 1071:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1072:             return;
 1073:         }
 1074: 
 1075:         liberation(s_etat_processus, s_objet_argument);
 1076:         s_objet_argument = s_copie_argument;
 1077: 
 1078:         (*((integer8 *) (*s_objet_argument).objet))--;
 1079: 
 1080:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1081:                 s_objet_argument) == d_erreur)
 1082:         {
 1083:             return;
 1084:         }
 1085:     }
 1086:     else if ((*s_objet_argument).type == NOM)
 1087:     {
 1088:         if (recherche_variable(s_etat_processus, (*((struct_nom *)
 1089:                 (*s_objet_argument).objet)).nom) == d_faux)
 1090:         {
 1091:             (*s_etat_processus).erreur_systeme = d_es;
 1092:             (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
 1093: 
 1094:             return;
 1095:         }
 1096: 
 1097:         liberation(s_etat_processus, s_objet_argument);
 1098: 
 1099:         if ((*(*s_etat_processus).pointeur_variable_courante)
 1100:                 .variable_verrouillee == d_vrai)
 1101:         {
 1102:             (*s_etat_processus).erreur_execution =
 1103:                     d_ex_variable_verrouillee;
 1104:             return;
 1105:         }
 1106: 
 1107:         if ((*(*s_etat_processus).pointeur_variable_courante).objet
 1108:                 == NULL)
 1109:         {
 1110:             if (recherche_variable_partagee(s_etat_processus,
 1111:                     (*(*s_etat_processus).pointeur_variable_courante).nom,
 1112:                     (*(*s_etat_processus).pointeur_variable_courante)
 1113:                     .variable_partagee, (*(*s_etat_processus)
 1114:                     .pointeur_variable_courante).origine) == NULL)
 1115:             {
 1116:                 (*s_etat_processus).erreur_systeme = d_es;
 1117:                 (*s_etat_processus).erreur_execution =
 1118:                         d_ex_variable_non_definie;
 1119: 
 1120:                 return;
 1121:             }
 1122: 
 1123:             s_objet_argument = (*(*s_etat_processus)
 1124:                     .pointeur_variable_partagee_courante).objet;
 1125:             variable_partagee = d_vrai;
 1126:         }
 1127:         else
 1128:         {
 1129:             s_objet_argument = (*(*s_etat_processus).pointeur_variable_courante)
 1130:                     .objet;
 1131:             variable_partagee = d_faux;
 1132:         }
 1133: 
 1134:         if ((s_copie_argument = copie_objet(s_etat_processus,
 1135:                 s_objet_argument, 'O')) == NULL)
 1136:         {
 1137:             if (variable_partagee == d_vrai)
 1138:             {
 1139:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1140:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1141:                 {
 1142:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1143:                     return;
 1144:                 }
 1145:             }
 1146: 
 1147:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1148:             return;
 1149:         }
 1150: 
 1151:         liberation(s_etat_processus, s_objet_argument);
 1152: 
 1153:         if (variable_partagee == d_vrai)
 1154:         {
 1155:             (*(*s_etat_processus).pointeur_variable_courante).objet = NULL;
 1156:             (*(*s_etat_processus).pointeur_variable_partagee_courante).objet =
 1157:                     s_copie_argument;
 1158:         }
 1159:         else
 1160:         {
 1161:             (*(*s_etat_processus).pointeur_variable_courante).objet =
 1162:                     s_copie_argument;
 1163:         }
 1164: 
 1165:         if ((*s_copie_argument).type == INT)
 1166:         {
 1167:             (*((integer8 *) (*s_copie_argument).objet))--;
 1168: 
 1169:             if (variable_partagee == d_vrai)
 1170:             {
 1171:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1172:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1173:                 {
 1174:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1175:                     return;
 1176:                 }
 1177:             }
 1178:         }
 1179:         else
 1180:         {
 1181:             if (variable_partagee == d_vrai)
 1182:             {
 1183:                 if (pthread_mutex_unlock(&((*(*s_etat_processus)
 1184:                         .pointeur_variable_partagee_courante).mutex)) != 0)
 1185:                 {
 1186:                     (*s_etat_processus).erreur_systeme = d_es_processus;
 1187:                     return;
 1188:                 }
 1189:             }
 1190: 
 1191:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1192:             return;
 1193:         }
 1194:     }
 1195:     else
 1196:     {
 1197:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1198: 
 1199:         liberation(s_etat_processus, s_objet_argument);
 1200:         return;
 1201:     }
 1202: 
 1203:     return;
 1204: }
 1205: 
 1206: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>