File:  [local] / rpl / src / instructions_d4.c
Revision 1.36: download - view: text, annotated - select for diffs - revision graph
Tue Jan 17 14:44:06 2012 UTC (12 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_6, HEAD
En route pour la 4.1.6.

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

CVSweb interface <joel.bertrand@systella.fr>