Annotation of rpl/src/instructions_d4.c, revision 1.18.2.1

1.1       bertrand    1: /*
                      2: ================================================================================
1.18.2.1! bertrand    3:   RPL/2 (R) version 4.0.22
1.17      bertrand    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1       bertrand    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: 
1.13      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   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: {
1.6       bertrand   41:    const char                  *queue;
                     42: 
1.1       bertrand   43:    file                        *fichier;
                     44: 
1.6       bertrand   45:    integer8                    lecture_i64;
                     46: 
1.1       bertrand   47:    logical1                    erreur;
                     48:    logical1                    existence;
                     49:    logical1                    ouverture;
                     50: 
1.6       bertrand   51:    sqlite3_stmt                *ppStmt;
                     52: 
                     53:    struct_descripteur_fichier  *descripteur;
                     54: 
1.1       bertrand   55:    struct_objet                *s_objet_argument;
1.6       bertrand   56:    struct_objet                *s_objet_indice;
1.1       bertrand   57: 
                     58:    struct flock                lock;
                     59: 
                     60:    struct stat                 requete;
                     61: 
1.6       bertrand   62:    unsigned char               *commande;
1.5       bertrand   63:    unsigned char               *nom;
1.6       bertrand   64:    unsigned char               *utf8;
1.5       bertrand   65: 
1.1       bertrand   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:        {
1.6       bertrand   76:            printf("(effacement d'un fichier ou d'un enregistrement)\n\n");
1.1       bertrand   77:        }
                     78:        else
                     79:        {
1.6       bertrand   80:            printf("(delete file or record)\n\n");
1.1       bertrand   81:        }
                     82: 
1.6       bertrand   83:        printf("    1: %s\n\n", d_CHN);
1.1       bertrand   84: 
1.6       bertrand   85:        printf("    2: %s, %s\n", d_CHN, d_INT);
                     86:        printf("    1: %s\n", d_FCH);
1.1       bertrand   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:    {
1.6       bertrand   97:        if ((*s_etat_processus).l_base_pile == NULL)
1.1       bertrand   98:        {
1.6       bertrand   99:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1       bertrand  100:            return;
                    101:        }
1.6       bertrand  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:        }
1.1       bertrand  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:    {
1.5       bertrand  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)
1.1       bertrand  137:        {
                    138:            liberation(s_etat_processus, s_objet_argument);
1.5       bertrand  139:            free(nom);
1.1       bertrand  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:        {
1.5       bertrand  148:            if ((fichier = fopen(nom, "r+")) == NULL)
1.1       bertrand  149:            {
                    150:                liberation(s_etat_processus, s_objet_argument);
1.5       bertrand  151:                free(nom);
1.1       bertrand  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:            {
1.5       bertrand  166:                free(nom);
                    167: 
1.1       bertrand  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);
1.5       bertrand  187:                free(nom);
1.1       bertrand  188: 
                    189:                (*s_etat_processus).erreur_execution =
                    190:                        d_ex_erreur_acces_fichier;
                    191:                return;
                    192:            }
                    193: 
1.5       bertrand  194:            erreur = caracteristiques_fichier(s_etat_processus, nom,
1.1       bertrand  195:                    &existence, &ouverture, &unite);
                    196: 
                    197:            if ((erreur != d_absence_erreur) || (ouverture == d_vrai))
                    198:            {
                    199:                liberation(s_etat_processus, s_objet_argument);
1.5       bertrand  200:                free(nom);
1.1       bertrand  201: 
                    202:                (*s_etat_processus).erreur_execution =
                    203:                        d_ex_erreur_acces_fichier;
                    204:                return;
                    205:            }
                    206: 
1.5       bertrand  207:            if (destruction_fichier(nom) == d_erreur)
1.1       bertrand  208:            {
                    209:                liberation(s_etat_processus, s_objet_argument);
1.5       bertrand  210:                free(nom);
1.1       bertrand  211: 
                    212:                (*s_etat_processus).erreur_execution =
                    213:                        d_ex_erreur_acces_fichier;
                    214:                return;
                    215:            }
                    216:        }
                    217:        else // Socket
                    218:        {
1.5       bertrand  219:            if (unlink(nom) != 0)
1.1       bertrand  220:            {
                    221:                liberation(s_etat_processus, s_objet_argument);
1.5       bertrand  222:                free(nom);
1.1       bertrand  223: 
                    224:                (*s_etat_processus).erreur_execution =
                    225:                        d_ex_erreur_acces_fichier;
                    226:                return;
                    227:            }
                    228:        }
1.5       bertrand  229: 
                    230:        free(nom);
1.1       bertrand  231:    }
1.6       bertrand  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:    }
1.1       bertrand  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                    presence_variable;
                    670:    logical1                    matrice_entiere;
                    671: 
                    672:    long                        i;
                    673: 
                    674:    struct_objet                *s_objet_statistique;
                    675: 
                    676:    unsigned char               *nom_fichier;
                    677: 
                    678:    unsigned long               j;
                    679: 
                    680:    struct_fichier_graphique    *l_fichier_courant;
                    681:    struct_fichier_graphique    *l_fichier_precedent;
                    682: 
                    683:    (*s_etat_processus).erreur_execution = d_ex;
                    684: 
                    685:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    686:    {
                    687:        printf("\n  DRWS ");
                    688: 
                    689:        if ((*s_etat_processus).langue == 'F')
                    690:        {
                    691:            printf("(affiche une série statistique)\n\n");
                    692:            printf("  Aucun argument\n");
                    693:        }
                    694:        else
                    695:        {
                    696:            printf("(draw statistical data)\n\n");
                    697:            printf("  No argument\n");
                    698:        }
                    699: 
                    700:        return;
                    701:    }
                    702:    else if ((*s_etat_processus).test_instruction == 'Y')
                    703:    {
                    704:        (*s_etat_processus).nombre_arguments = -1;
                    705:        return;
                    706:    }
                    707: 
                    708:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    709:    {
                    710:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                    711:        {
                    712:            return;
                    713:        }
                    714:    }
                    715: 
                    716:    /*
                    717:     * Vérification de la présence de la matrice statistique
                    718:     */
                    719: 
                    720:    if (recherche_variable(s_etat_processus, ds_sdat) == d_faux)
                    721:    {
                    722:        /*
                    723:         * Aucune variable ds_sdat n'existe.
                    724:         */
                    725: 
                    726:        (*s_etat_processus).erreur_execution = d_ex_absence_observations;
                    727:        (*s_etat_processus).erreur_systeme = d_es;
                    728: 
                    729:        return;
                    730:    }
                    731: 
                    732:    i = (*s_etat_processus).position_variable_courante;
                    733:    presence_variable = d_faux;
                    734: 
                    735:    while(i >= 0)
                    736:    {
                    737:        if ((strcmp((*s_etat_processus).s_liste_variables[i].nom,
                    738:                ds_sdat) == 0) && ((*s_etat_processus)
                    739:                .s_liste_variables[i].niveau == 1))
                    740:        {
                    741:            presence_variable = d_vrai;
                    742:            break;
                    743:        }
                    744: 
                    745:        i--;
                    746:    }
                    747: 
                    748:    if (presence_variable == d_faux)
                    749:    {
                    750:        (*s_etat_processus).erreur_execution = d_ex_absence_observations;
                    751:        return;
                    752:    }
                    753: 
                    754:    if ((s_objet_statistique = (*s_etat_processus).s_liste_variables[i].objet)
                    755:            == NULL)
                    756:    {
                    757:        (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
                    758:        return;
                    759:    }
                    760: 
                    761:    if ((*s_objet_statistique).type == MIN)
                    762:    {
                    763:        matrice_entiere = d_vrai;
                    764:    }
                    765:    else if ((*s_objet_statistique).type == MRL)
                    766:    {
                    767:        matrice_entiere = d_faux;
                    768:    }
                    769:    else
                    770:    {
                    771:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    772:        return;
                    773:    }
                    774: 
                    775:    /*
                    776:     * Création du fichier graphique temporaire
                    777:     */
                    778: 
                    779:    if ((nom_fichier = creation_nom_fichier(s_etat_processus,
                    780:            (*s_etat_processus).chemin_fichiers_temporaires)) == NULL)
                    781:    {
                    782:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    783:        return;
                    784:    }
                    785: 
                    786:    if ((fichier = fopen(nom_fichier, "w+")) == NULL)
                    787:    {
                    788:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    789:        return;
                    790:    }
                    791: 
                    792:    switch((*((struct_matrice *) (*s_objet_statistique).objet)).nombre_colonnes)
                    793:    {
                    794: 
                    795:    /*
                    796:     * Une seule colonne
                    797:     */
                    798: 
                    799:        case 1 :
                    800:        {
                    801:            dimensions = 2;
                    802: 
                    803:            for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
                    804:                    .nombre_lignes; j++)
                    805:            {
                    806:                if (matrice_entiere == d_vrai)
                    807:                {
                    808:                    if (fprintf(fichier, "%f %f\n", (double) j, (double)
                    809:                            ((integer8 **) (*((struct_matrice *)
                    810:                            (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
                    811:                    {
                    812:                        (*s_etat_processus).erreur_systeme =
                    813:                                d_es_erreur_fichier;
                    814:                        return;
                    815:                    }
                    816:                }
                    817:                else
                    818:                {
                    819:                    if (fprintf(fichier, "%f %f\n", (double) j, (double)
                    820:                            ((real8 **) (*((struct_matrice *)
                    821:                            (*s_objet_statistique).objet)).tableau)[j][0]) < 0)
                    822:                    {
                    823:                        (*s_etat_processus).erreur_systeme =
                    824:                                d_es_erreur_fichier;
                    825:                        return;
                    826:                    }
                    827:                }
                    828:            }
                    829: 
                    830:            break;
                    831:        }
                    832: 
                    833:    /*
                    834:     * Deux colonnes ou plus
                    835:     */
                    836: 
                    837:        default :
                    838:        {
                    839:            dimensions = 2;
                    840: 
                    841:            if (((*s_etat_processus).colonne_statistique_1 < 1) ||
                    842:                    ((*s_etat_processus).colonne_statistique_2 < 1) ||
                    843:                    ((*s_etat_processus).colonne_statistique_1 > (signed long)
                    844:                    (*((struct_matrice *) (*s_objet_statistique).objet))
                    845:                    .nombre_colonnes) ||
                    846:                    ((*s_etat_processus).colonne_statistique_2 > (signed long)
                    847:                    (*((struct_matrice *) (*s_objet_statistique).objet))
                    848:                    .nombre_colonnes))
                    849:            {
                    850:                if (fclose(fichier) != 0)
                    851:                {
                    852:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    853:                    return;
                    854:                }
                    855: 
                    856:                if (destruction_fichier(nom_fichier) == d_erreur)
                    857:                {
                    858:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    859:                    return;
                    860:                }
                    861: 
                    862:                free(nom_fichier);
                    863: 
                    864:                (*s_etat_processus).erreur_execution =
                    865:                        d_ex_observations_inexistantes;
                    866:                return;
                    867:            }
                    868: 
                    869:            for(j = 0; j < (*((struct_matrice *) (*s_objet_statistique).objet))
                    870:                    .nombre_lignes; j++)
                    871:            {
                    872:                if (matrice_entiere == d_vrai)
                    873:                {
                    874:                    if (fprintf(fichier, "%f %f\n", (double) ((integer8 **)
                    875:                            (*((struct_matrice *) (*s_objet_statistique).objet))
                    876:                            .tableau)[j][(*s_etat_processus)
                    877:                            .colonne_statistique_1 - 1], (double) ((integer8 **)
                    878:                            (*((struct_matrice *) (*s_objet_statistique).objet))
                    879:                            .tableau)[j][(*s_etat_processus)
                    880:                            .colonne_statistique_2 - 1]) < 0)
                    881:                    {
                    882:                        (*s_etat_processus).erreur_systeme =
                    883:                                d_es_erreur_fichier;
                    884:                        return;
                    885:                    }
                    886:                }
                    887:                else
                    888:                {
                    889:                    if (fprintf(fichier, "%f %f\n", (double) ((real8 **)
                    890:                            (*((struct_matrice *) (*s_objet_statistique).objet))
                    891:                            .tableau)[j][(*s_etat_processus)
                    892:                            .colonne_statistique_1 - 1], (double) ((real8 **)
                    893:                            (*((struct_matrice *) (*s_objet_statistique).objet))
                    894:                            .tableau)[j][(*s_etat_processus)
                    895:                            .colonne_statistique_2 - 1]) < 0)
                    896:                    {
                    897:                        (*s_etat_processus).erreur_systeme =
                    898:                                d_es_erreur_fichier;
                    899:                        return;
                    900:                    }
                    901:                }
                    902:            }
                    903: 
                    904:            break;
                    905:        }
                    906:    }
                    907: 
                    908:    /*
                    909:     * Fermeture du fichier graphique
                    910:     */
                    911: 
                    912:    if (fclose(fichier) != 0)
                    913:    {
                    914:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    915:        return;
                    916:    }
                    917: 
                    918:    /*
                    919:     * Chaînage du fichier temporaire à la liste des fichiers graphiques
                    920:     */
                    921: 
                    922:    l_fichier_courant = (*s_etat_processus).fichiers_graphiques;
                    923: 
                    924:    if (l_fichier_courant == NULL)
                    925:    {
                    926:        if (((*s_etat_processus).fichiers_graphiques = malloc(
                    927:                sizeof(struct_fichier_graphique))) == NULL)
                    928:        {
                    929:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    930:            return;
                    931:        }
                    932: 
                    933:        (*(*s_etat_processus).fichiers_graphiques).suivant = NULL;
                    934:        (*(*s_etat_processus).fichiers_graphiques).nom = nom_fichier;
                    935:        (*(*s_etat_processus).fichiers_graphiques).legende = NULL;
                    936:        (*(*s_etat_processus).fichiers_graphiques).dimensions = dimensions;
                    937:        (*(*s_etat_processus).fichiers_graphiques).presence_axes = d_faux;
                    938:        (*(*s_etat_processus).fichiers_graphiques).systeme_axes =
                    939:                (*s_etat_processus).systeme_axes;
                    940:        strcpy((*(*s_etat_processus).fichiers_graphiques).type,
                    941:                (*s_etat_processus).type_trace_sigma);
                    942:    }
                    943:    else
                    944:    {
                    945:        while(l_fichier_courant != NULL)
                    946:        {
                    947:            if ((*l_fichier_courant).dimensions != dimensions)
                    948:            {
                    949:                (*s_etat_processus).erreur_execution =
                    950:                        d_ex_dimensions_differentes;
                    951:                return;
                    952:            }
                    953: 
                    954:            l_fichier_precedent = l_fichier_courant;
                    955:            l_fichier_courant = (*l_fichier_courant).suivant;
                    956:        }
                    957: 
                    958:        l_fichier_courant = l_fichier_precedent;
                    959: 
                    960:        if (((*l_fichier_courant).suivant = malloc(
                    961:                sizeof(struct_fichier_graphique))) == NULL)
                    962:        {
                    963:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    964:            return;
                    965:        }
                    966: 
                    967:        l_fichier_courant = (*l_fichier_courant).suivant;
                    968: 
                    969:        (*l_fichier_courant).suivant = NULL;
                    970:        (*l_fichier_courant).nom = nom_fichier;
                    971:        (*l_fichier_courant).legende = NULL;
                    972:        (*l_fichier_courant).dimensions = dimensions;
                    973:        (*l_fichier_courant).presence_axes = d_faux;
                    974:        (*l_fichier_courant).systeme_axes = (*s_etat_processus).systeme_axes;
                    975:        strcpy((*l_fichier_courant).type, (*s_etat_processus).type_trace_sigma);
                    976:    }
                    977: 
                    978:    /*
                    979:     * Affichage du graphique
                    980:     */
                    981: 
                    982:    appel_gnuplot(s_etat_processus, 'N');
                    983:    (*s_etat_processus).erreur_execution = d_ex;
                    984:    (*s_etat_processus).exception = d_ep;
                    985: 
                    986:    return;
                    987: }
                    988: 
                    989: 
                    990: /*
                    991: ================================================================================
                    992:   Fonction 'decr'
                    993: ================================================================================
                    994:   Entrées :
                    995: --------------------------------------------------------------------------------
                    996:   Sorties :
                    997: --------------------------------------------------------------------------------
                    998:   Effets de bord : néant
                    999: ================================================================================
                   1000: */
                   1001: 
                   1002: void
                   1003: instruction_decr(struct_processus *s_etat_processus)
                   1004: {
                   1005:    logical1                    variable_partagee;
                   1006: 
                   1007:    struct_objet                *s_copie_argument;
                   1008:    struct_objet                *s_objet_argument;
                   1009: 
                   1010:    (*s_etat_processus).erreur_execution = d_ex;
                   1011: 
                   1012:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1013:    {
                   1014:        printf("\n  DECR ");
                   1015: 
                   1016:        if ((*s_etat_processus).langue == 'F')
                   1017:        {
                   1018:            printf("(décrémentation)\n\n");
                   1019:        }
                   1020:        else
                   1021:        {
                   1022:            printf("(decrementation)\n\n");
                   1023:        }
                   1024: 
                   1025:        printf("    1: %s\n", d_INT);
                   1026:        printf("->  1: %s\n\n", d_INT);
                   1027: 
                   1028:        printf("    1: %s\n", d_NOM);
                   1029: 
                   1030:        return;
                   1031:    }
                   1032:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1033:    {
                   1034:        (*s_etat_processus).nombre_arguments = -1;
                   1035:        return;
                   1036:    }
                   1037: 
                   1038:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1039:    {
                   1040:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1041:        {
                   1042:            return;
                   1043:        }
                   1044:    }
                   1045: 
                   1046:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1047:            &s_objet_argument) == d_erreur)
                   1048:    {
                   1049:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1050:        return;
                   1051:    }
                   1052: 
                   1053:    if ((*s_objet_argument).type == INT)
                   1054:    {
                   1055:        if ((s_copie_argument = copie_objet(s_etat_processus,
                   1056:                s_objet_argument, 'O')) == NULL)
                   1057:        {
                   1058:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1059:            return;
                   1060:        }
                   1061: 
                   1062:        liberation(s_etat_processus, s_objet_argument);
                   1063:        s_objet_argument = s_copie_argument;
                   1064: 
                   1065:        (*((integer8 *) (*s_objet_argument).objet))--;
                   1066: 
                   1067:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1068:                s_objet_argument) == d_erreur)
                   1069:        {
                   1070:            return;
                   1071:        }
                   1072:    }
                   1073:    else if ((*s_objet_argument).type == NOM)
                   1074:    {
                   1075:        if (recherche_variable(s_etat_processus, (*((struct_nom *)
                   1076:                (*s_objet_argument).objet)).nom) == d_faux)
                   1077:        {
                   1078:            (*s_etat_processus).erreur_systeme = d_es;
                   1079:            (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
                   1080: 
                   1081:            return;
                   1082:        }
                   1083: 
                   1084:        liberation(s_etat_processus, s_objet_argument);
                   1085: 
                   1086:        if ((*s_etat_processus).s_liste_variables
                   1087:                [(*s_etat_processus).position_variable_courante]
                   1088:                .variable_verrouillee == d_vrai)
                   1089:        {
                   1090:            (*s_etat_processus).erreur_execution =
                   1091:                    d_ex_variable_verrouillee;
                   1092:            return;
                   1093:        }
                   1094: 
                   1095:        if ((*s_etat_processus).s_liste_variables
                   1096:                [(*s_etat_processus).position_variable_courante].objet
                   1097:                == NULL)
                   1098:        {
                   1099:            if (pthread_mutex_lock(&((*(*s_etat_processus)
                   1100:                    .s_liste_variables_partagees).mutex)) != 0)
                   1101:            {
                   1102:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1103:                return;
                   1104:            }
                   1105: 
                   1106:            if (recherche_variable_partagee(s_etat_processus,
                   1107:                    (*s_etat_processus).s_liste_variables
                   1108:                    [(*s_etat_processus).position_variable_courante].nom,
                   1109:                    (*s_etat_processus).s_liste_variables
                   1110:                    [(*s_etat_processus).position_variable_courante]
                   1111:                    .variable_partagee, (*s_etat_processus).s_liste_variables
                   1112:                    [(*s_etat_processus).position_variable_courante]
                   1113:                    .origine) == d_faux)
                   1114:            {
                   1115:                (*s_etat_processus).erreur_systeme = d_es;
                   1116:                (*s_etat_processus).erreur_execution =
                   1117:                        d_ex_variable_non_definie;
                   1118: 
                   1119:                return;
                   1120:            }
                   1121: 
                   1122:            s_objet_argument = (*(*s_etat_processus)
                   1123:                    .s_liste_variables_partagees).table
                   1124:                    [(*(*s_etat_processus).s_liste_variables_partagees)
                   1125:                    .position_variable].objet;
                   1126:            variable_partagee = d_vrai;
                   1127:        }
                   1128:        else
                   1129:        {
                   1130:            s_objet_argument = (*s_etat_processus).s_liste_variables
                   1131:                    [(*s_etat_processus).position_variable_courante].objet;
                   1132:            variable_partagee = d_faux;
                   1133:        }
                   1134: 
                   1135:        if ((s_copie_argument = copie_objet(s_etat_processus,
                   1136:                s_objet_argument, 'O')) == NULL)
                   1137:        {
                   1138:            if (variable_partagee == d_vrai)
                   1139:            {
                   1140:                if (pthread_mutex_unlock(&((*(*s_etat_processus)
                   1141:                        .s_liste_variables_partagees).mutex)) != 0)
                   1142:                {
                   1143:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1144:                    return;
                   1145:                }
                   1146:            }
                   1147: 
                   1148:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1149:            return;
                   1150:        }
                   1151: 
                   1152:        liberation(s_etat_processus, s_objet_argument);
                   1153: 
                   1154:        if (variable_partagee == d_vrai)
                   1155:        {
                   1156:            (*s_etat_processus).s_liste_variables[(*s_etat_processus)
                   1157:                    .position_variable_courante].objet = NULL;
                   1158:            (*(*s_etat_processus)
                   1159:                    .s_liste_variables_partagees).table
                   1160:                    [(*(*s_etat_processus).s_liste_variables_partagees)
                   1161:                    .position_variable].objet = s_copie_argument;
                   1162:        }
                   1163:        else
                   1164:        {
                   1165:            (*s_etat_processus).s_liste_variables[(*s_etat_processus)
                   1166:                    .position_variable_courante].objet = s_copie_argument;
                   1167:        }
                   1168: 
                   1169:        if ((*s_copie_argument).type == INT)
                   1170:        {
                   1171:            (*((integer8 *) (*s_copie_argument).objet))--;
                   1172: 
                   1173:            if (variable_partagee == d_vrai)
                   1174:            {
                   1175:                if (pthread_mutex_unlock(&((*(*s_etat_processus)
                   1176:                        .s_liste_variables_partagees).mutex)) != 0)
                   1177:                {
                   1178:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1179:                    return;
                   1180:                }
                   1181:            }
                   1182:        }
                   1183:        else
                   1184:        {
                   1185:            if (variable_partagee == d_vrai)
                   1186:            {
                   1187:                if (pthread_mutex_unlock(&((*(*s_etat_processus)
                   1188:                        .s_liste_variables_partagees).mutex)) != 0)
                   1189:                {
                   1190:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1191:                    return;
                   1192:                }
                   1193:            }
                   1194: 
                   1195:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1196:            return;
                   1197:        }
                   1198:    }
                   1199:    else
                   1200:    {
                   1201:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1202: 
                   1203:        liberation(s_etat_processus, s_objet_argument);
                   1204:        return;
                   1205:    }
                   1206: 
                   1207:    return;
                   1208: }
                   1209: 
                   1210: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>