Annotation of rpl/src/instructions_h1.c, revision 1.69

1.1       bertrand    1: /*
                      2: ================================================================================
1.69    ! bertrand    3:   RPL/2 (R) version 4.1.31
1.68      bertrand    4:   Copyright (C) 1989-2019 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.11      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'hex'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_hex(struct_processus *s_etat_processus)
                     40: {
                     41:    (*s_etat_processus).erreur_execution = d_ex;
                     42: 
                     43:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     44:    {
                     45:        printf("\n  HEX ");
                     46: 
                     47:        if ((*s_etat_processus).langue == 'F')
                     48:        {
                     49:            printf("(base hexadécimale)\n\n");
                     50:            printf("  Aucun argument\n");
                     51:        }
                     52:        else
                     53:        {
                     54:            printf("(hexadecimal base)\n\n");
                     55:            printf("  No argument\n");
                     56:        }
                     57: 
                     58:        return;
                     59:    }
                     60:    else if ((*s_etat_processus).test_instruction == 'Y')
                     61:    {
                     62:        (*s_etat_processus).nombre_arguments = -1;
                     63:        return;
                     64:    }
                     65: 
                     66:    sf(s_etat_processus, 43);
                     67:    sf(s_etat_processus, 44);
                     68: 
                     69:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                     70:    {
                     71:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                     72:        {
                     73:            return;
                     74:        }
                     75:    }
                     76: 
                     77:    return;
                     78: }
                     79: 
                     80: 
                     81: /*
                     82: ================================================================================
                     83:   Fonction 'HMS->'
                     84: ================================================================================
                     85:   Entrées : structure processus
                     86: --------------------------------------------------------------------------------
                     87:   Sorties :
                     88: --------------------------------------------------------------------------------
                     89:   Effets de bord : néant
                     90: ================================================================================
                     91: */
                     92: 
                     93: void
                     94: instruction_hms_fleche(struct_processus *s_etat_processus)
                     95: {
                     96:    struct_objet                    *s_copie;
                     97:    struct_objet                    *s_objet;
                     98: 
                     99:    (*s_etat_processus).erreur_execution = d_ex;
                    100: 
                    101:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    102:    {
                    103:        printf("\n  HMS-> ");
                    104: 
                    105:        if ((*s_etat_processus).langue == 'F')
                    106:        {
                    107:            printf("(conversion décimale)\n\n");
                    108:        }
                    109:        else
                    110:        {
                    111:            printf("(conversion from hours minutes seconds to decimal)\n\n");
                    112:        }
                    113: 
                    114:        printf("    1: %s\n", d_INT);
                    115:        printf("->  1: %s\n\n", d_INT);
                    116: 
                    117:        printf("    1: %s\n", d_REL);
                    118:        printf("->  1: %s\n", d_REL);
                    119: 
                    120:        return;
                    121:    }
                    122:    else if ((*s_etat_processus).test_instruction == 'Y')
                    123:    {
                    124:        (*s_etat_processus).nombre_arguments = -1;
                    125:        return;
                    126:    }
                    127: 
                    128:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    129:    {
                    130:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    131:        {
                    132:            return;
                    133:        }
                    134:    }
                    135: 
                    136:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    137:            &s_objet) == d_erreur)
                    138:    {
                    139:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    140:        return;
                    141:    }
                    142: 
                    143: /*
                    144: --------------------------------------------------------------------------------
                    145:   Argument entier
                    146: --------------------------------------------------------------------------------*/
                    147: 
                    148:    if ((*s_objet).type == INT)
                    149:    {
                    150:        /*
                    151:         * On ne fait rien...
                    152:         */
                    153:    }
                    154: 
                    155: /*
                    156: --------------------------------------------------------------------------------
                    157:   Argument réel
                    158: --------------------------------------------------------------------------------
                    159: */
                    160: 
                    161:    else if ((*s_objet).type == REL)
                    162:    {
                    163:        if ((s_copie = copie_objet(s_etat_processus, s_objet, 'O')) == NULL)
                    164:        {
                    165:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    166:            return;
                    167:        }
                    168: 
                    169:        liberation(s_etat_processus, s_objet);
                    170:        s_objet = s_copie;
                    171: 
                    172:        conversion_hms_vers_decimal((real8 *) (*s_objet).objet);
                    173:    }
                    174: 
                    175: /*
                    176: --------------------------------------------------------------------------------
                    177:   Argument invalide
                    178: --------------------------------------------------------------------------------
                    179: */
                    180: 
                    181:    else
                    182:    {
                    183:        liberation(s_etat_processus, s_objet);
                    184: 
                    185:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    186:        return;
                    187:    }
                    188: 
                    189:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    190:            s_objet) == d_erreur)
                    191:    {
                    192:        return;
                    193:    }
                    194: 
                    195:    return;
                    196: }
                    197: 
                    198: 
                    199: /*
                    200: ================================================================================
                    201:   Fonction 'HMS+'
                    202: ================================================================================
                    203:   Entrées : structure processus
                    204: --------------------------------------------------------------------------------
                    205:   Sorties :
                    206: --------------------------------------------------------------------------------
                    207:   Effets de bord : néant
                    208: ================================================================================
                    209: */
                    210: 
                    211: void
                    212: instruction_hms_plus(struct_processus *s_etat_processus)
                    213: {
                    214:    integer8                        tampon;
                    215: 
                    216:    struct_objet                    *s_objet_argument_1;
                    217:    struct_objet                    *s_objet_argument_2;
                    218:    struct_objet                    *s_objet_resultat;
                    219: 
                    220:    (*s_etat_processus).erreur_execution = d_ex;
                    221: 
                    222:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    223:    {
                    224:        printf("\n  HMS+ ");
                    225: 
                    226:        if ((*s_etat_processus).langue == 'F')
                    227:        {
                    228:            printf("(addition sexadécimale)\n\n");
                    229:        }
                    230:        else
                    231:        {
                    232:            printf("(addition in hours minutes seconds format)\n\n");
                    233:        }
                    234: 
                    235:        printf("    2: %s\n", d_INT);
                    236:        printf("    1: %s\n", d_INT);
                    237:        printf("->  1: %s, %s\n\n", d_INT, d_REL);
                    238: 
                    239:        printf("    2: %s, %s\n", d_INT, d_REL);
                    240:        printf("    1: %s, %s\n", d_INT, d_REL);
                    241:        printf("->  1: %s\n", d_REL);
                    242: 
                    243:        return;
                    244:    }
                    245:    else if ((*s_etat_processus).test_instruction == 'Y')
                    246:    {
                    247:        (*s_etat_processus).nombre_arguments = -1;
                    248:        return;
                    249:    }
                    250: 
                    251:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    252:    {
                    253:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    254:        {
                    255:            return;
                    256:        }
                    257:    }
                    258: 
                    259:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    260:            &s_objet_argument_1) == d_erreur)
                    261:    {
                    262:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    263:        return;
                    264:    }
                    265: 
                    266:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    267:            &s_objet_argument_2) == d_erreur)
                    268:    {
                    269:        liberation(s_etat_processus, s_objet_argument_1);
                    270:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    271:        return;
                    272:    }
                    273: 
                    274: /*
                    275: --------------------------------------------------------------------------------
                    276:   Arguments entiers
                    277: --------------------------------------------------------------------------------*/
                    278: 
                    279:    if (((*s_objet_argument_1).type == INT) &&
                    280:            ((*s_objet_argument_2).type == INT))
                    281:    {
                    282:        if (depassement_addition((integer8 *) (*s_objet_argument_1).objet,
                    283:                (integer8 *) (*s_objet_argument_2).objet, &tampon) ==
                    284:                d_absence_erreur)
                    285:        {
                    286:            if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    287:                    == NULL)
                    288:            {
                    289:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    290:                return;
                    291:            }
                    292: 
                    293:            (*((integer8 *) (*s_objet_resultat).objet)) = tampon;
                    294:        }
                    295:        else
                    296:        {
                    297:            if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    298:                    == NULL)
                    299:            {
                    300:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    301:                return;
                    302:            }
                    303: 
                    304:            (*((real8 *) (*s_objet_resultat).objet)) = ((real8)
                    305:                    (*((integer8 *) (*s_objet_argument_1).objet))) + ((real8)
                    306:                    (*((integer8 *) (*s_objet_argument_2).objet)));
                    307:        }
                    308:    }
                    309: 
                    310: /*
                    311: --------------------------------------------------------------------------------
                    312:   Au moins un argument réel
                    313: --------------------------------------------------------------------------------
                    314: */
                    315: 
                    316:    else if (((*s_objet_argument_1).type == REL) &&
                    317:            ((*s_objet_argument_2).type == INT))
                    318:    {
                    319:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_1).objet);
                    320: 
                    321:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    322:                == NULL)
                    323:        {
                    324:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    325:            return;
                    326:        }
                    327: 
1.46      bertrand  328:        (*((real8 *) (*s_objet_resultat).objet)) = ((real8) (*((integer8 *)
                    329:                (*s_objet_argument_2).objet))) + (*((real8 *)
1.1       bertrand  330:                (*s_objet_argument_1).objet));
                    331: 
                    332:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    333:    }
                    334:    else if (((*s_objet_argument_1).type == INT) &&
                    335:            ((*s_objet_argument_2).type == REL))
                    336:    {
                    337:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_2).objet);
                    338: 
                    339:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    340:                == NULL)
                    341:        {
                    342:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    343:            return;
                    344:        }
                    345: 
                    346:        (*((real8 *) (*s_objet_resultat).objet)) = (*((real8 *)
1.46      bertrand  347:                (*s_objet_argument_2).objet)) + ((real8) (*((integer8 *)
                    348:                (*s_objet_argument_1).objet)));
1.1       bertrand  349: 
                    350:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    351:    }
                    352:    else if (((*s_objet_argument_1).type == REL) &&
                    353:            ((*s_objet_argument_2).type == REL))
                    354:    {
                    355:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_1).objet);
                    356:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_2).objet);
                    357: 
                    358:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    359:                == NULL)
                    360:        {
                    361:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    362:            return;
                    363:        }
                    364: 
                    365:        (*((real8 *) (*s_objet_resultat).objet)) = (*((real8 *)
                    366:                (*s_objet_argument_2).objet)) + (*((real8 *)
                    367:                (*s_objet_argument_1).objet));
                    368: 
                    369:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    370:    }
                    371: 
                    372: /*
                    373: --------------------------------------------------------------------------------
                    374:   Argument invalide
                    375: --------------------------------------------------------------------------------
                    376: */
                    377: 
                    378:    else
                    379:    {
                    380:        liberation(s_etat_processus, s_objet_argument_1);
                    381:        liberation(s_etat_processus, s_objet_argument_2);
                    382: 
                    383:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    384:        return;
                    385:    }
                    386: 
                    387:    liberation(s_etat_processus, s_objet_argument_1);
                    388:    liberation(s_etat_processus, s_objet_argument_2);
                    389: 
                    390:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    391:            s_objet_resultat) == d_erreur)
                    392:    {
                    393:        return;
                    394:    }
                    395: 
                    396:    return;
                    397: }
                    398: 
                    399: 
                    400: /*
                    401: ================================================================================
                    402:   Fonction 'HMS-'
                    403: ================================================================================
                    404:   Entrées : structure processus
                    405: --------------------------------------------------------------------------------
                    406:   Sorties :
                    407: --------------------------------------------------------------------------------
                    408:   Effets de bord : néant
                    409: ================================================================================
                    410: */
                    411: 
                    412: void
                    413: instruction_hms_moins(struct_processus *s_etat_processus)
                    414: {
                    415:    integer8                        tampon;
                    416: 
                    417:    struct_objet                    *s_objet_argument_1;
                    418:    struct_objet                    *s_objet_argument_2;
                    419:    struct_objet                    *s_objet_resultat;
                    420: 
                    421:    (*s_etat_processus).erreur_execution = d_ex;
                    422: 
                    423:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    424:    {
                    425:        printf("\n  HMS- ");
                    426: 
                    427:        if ((*s_etat_processus).langue == 'F')
                    428:        {
                    429:            printf("(soustraction sexadécimale)\n\n");
                    430:        }
                    431:        else
                    432:        {
                    433:            printf("(substraction in hours minutes seconds format)\n\n");
                    434:        }
                    435: 
                    436:        printf("    2: %s\n", d_INT);
                    437:        printf("    1: %s\n", d_INT);
                    438:        printf("->  1: %s, %s\n\n", d_INT, d_REL);
                    439: 
                    440:        printf("    2: %s, %s\n", d_INT, d_REL);
                    441:        printf("    1: %s, %s\n", d_INT, d_REL);
                    442:        printf("->  1: %s\n", d_REL);
                    443: 
                    444:        return;
                    445:    }
                    446:    else if ((*s_etat_processus).test_instruction == 'Y')
                    447:    {
                    448:        (*s_etat_processus).nombre_arguments = -1;
                    449:        return;
                    450:    }
                    451: 
                    452:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    453:    {
                    454:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    455:        {
                    456:            return;
                    457:        }
                    458:    }
                    459: 
                    460:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    461:            &s_objet_argument_1) == d_erreur)
                    462:    {
                    463:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    464:        return;
                    465:    }
                    466: 
                    467:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    468:            &s_objet_argument_2) == d_erreur)
                    469:    {
                    470:        liberation(s_etat_processus, s_objet_argument_1);
                    471:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    472:        return;
                    473:    }
                    474: 
                    475: /*
                    476: --------------------------------------------------------------------------------
                    477:   Arguments entiers
                    478: --------------------------------------------------------------------------------*/
                    479: 
                    480:    if (((*s_objet_argument_1).type == INT) &&
                    481:            ((*s_objet_argument_2).type == INT))
                    482:    {
1.45      bertrand  483:        if (depassement_soustraction((integer8 *) (*s_objet_argument_2).objet,
                    484:                (integer8 *) (*s_objet_argument_1).objet, &tampon) ==
1.1       bertrand  485:                d_absence_erreur)
                    486:        {
                    487:            if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    488:                    == NULL)
                    489:            {
                    490:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    491:                return;
                    492:            }
                    493: 
                    494:            (*((integer8 *) (*s_objet_resultat).objet)) = tampon;
                    495:        }
                    496:        else
                    497:        {
                    498:            if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    499:                    == NULL)
                    500:            {
                    501:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    502:                return;
                    503:            }
                    504: 
                    505:            (*((real8 *) (*s_objet_resultat).objet)) = ((real8)
1.45      bertrand  506:                    (*((integer8 *) (*s_objet_argument_2).objet))) - ((real8)
                    507:                    (*((integer8 *) (*s_objet_argument_1).objet)));
1.1       bertrand  508:        }
                    509:    }
                    510: 
                    511: /*
                    512: --------------------------------------------------------------------------------
                    513:   Au moins un argument réel
                    514: --------------------------------------------------------------------------------
                    515: */
                    516: 
                    517:    else if (((*s_objet_argument_1).type == REL) &&
                    518:            ((*s_objet_argument_2).type == INT))
                    519:    {
                    520:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_1).objet);
                    521: 
                    522:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    523:                == NULL)
                    524:        {
                    525:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    526:            return;
                    527:        }
                    528: 
1.46      bertrand  529:        (*((real8 *) (*s_objet_resultat).objet)) = ((real8) (*((integer8 *)
                    530:                (*s_objet_argument_2).objet))) - (*((real8 *)
1.1       bertrand  531:                (*s_objet_argument_1).objet));
                    532: 
                    533:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    534:    }
                    535:    else if (((*s_objet_argument_1).type == INT) &&
                    536:            ((*s_objet_argument_2).type == REL))
                    537:    {
                    538:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_2).objet);
                    539: 
                    540:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    541:                == NULL)
                    542:        {
                    543:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    544:            return;
                    545:        }
                    546: 
                    547:        (*((real8 *) (*s_objet_resultat).objet)) = (*((real8 *)
1.46      bertrand  548:                (*s_objet_argument_2).objet)) - ((real8) (*((integer8 *)
                    549:                (*s_objet_argument_1).objet)));
1.1       bertrand  550: 
                    551:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    552:    }
                    553:    else if (((*s_objet_argument_1).type == REL) &&
                    554:            ((*s_objet_argument_2).type == REL))
                    555:    {
                    556:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_1).objet);
                    557:        conversion_hms_vers_decimal((real8 *) (*s_objet_argument_2).objet);
                    558: 
                    559:        if ((s_objet_resultat = allocation(s_etat_processus, REL))
                    560:                == NULL)
                    561:        {
                    562:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    563:            return;
                    564:        }
                    565: 
                    566:        (*((real8 *) (*s_objet_resultat).objet)) = (*((real8 *)
                    567:                (*s_objet_argument_2).objet)) - (*((real8 *)
                    568:                (*s_objet_argument_1).objet));
                    569: 
                    570:        conversion_decimal_vers_hms((real8 *) (*s_objet_resultat).objet);
                    571:    }
                    572: 
                    573: /*
                    574: --------------------------------------------------------------------------------
                    575:   Argument invalide
                    576: --------------------------------------------------------------------------------
                    577: */
                    578: 
                    579:    else
                    580:    {
                    581:        liberation(s_etat_processus, s_objet_argument_1);
                    582:        liberation(s_etat_processus, s_objet_argument_2);
                    583: 
                    584:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    585:        return;
                    586:    }
                    587: 
                    588:    liberation(s_etat_processus, s_objet_argument_1);
                    589:    liberation(s_etat_processus, s_objet_argument_2);
                    590: 
                    591:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    592:            s_objet_resultat) == d_erreur)
                    593:    {
                    594:        return;
                    595:    }
                    596: 
                    597:    return;
                    598: }
                    599: 
                    600: 
                    601: /*
                    602: ================================================================================
                    603:   Fonction 'halt'
                    604: ================================================================================
                    605:   Entrées :
                    606: --------------------------------------------------------------------------------
                    607:   Sorties :
                    608: --------------------------------------------------------------------------------
                    609:   Effets de bord : néant
                    610: ================================================================================
                    611: */
                    612: 
                    613: void
                    614: instruction_halt(struct_processus *s_etat_processus)
                    615: {
                    616:    (*s_etat_processus).erreur_execution = d_ex;
                    617: 
                    618:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    619:    {
                    620:        printf("\n  HALT ");
                    621: 
                    622:        if ((*s_etat_processus).langue == 'F')
                    623:        {
                    624:            printf("(arrêt du programme)\n\n");
                    625:            printf("  Aucun argument\n");
                    626:        }
                    627:        else
                    628:        {
                    629:            printf("(program halt)\n\n");
                    630:            printf("  No argument\n");
                    631:        }
                    632: 
                    633:        return;
                    634:    }
                    635:    else if ((*s_etat_processus).test_instruction == 'Y')
                    636:    {
                    637:        (*s_etat_processus).nombre_arguments = -1;
                    638:        return;
                    639:    }
                    640: 
                    641:    (*s_etat_processus).debug_programme = d_vrai;
                    642: 
                    643:    return;
                    644: }
                    645: 
                    646: 
                    647: /*
                    648: ================================================================================
                    649:   Fonction 'histogram'
                    650: ================================================================================
                    651:   Entrées :
                    652: --------------------------------------------------------------------------------
                    653:   Sorties :
                    654: --------------------------------------------------------------------------------
                    655:   Effets de bord : néant
                    656: ================================================================================
                    657: */
                    658: 
                    659: void
                    660: instruction_histogram(struct_processus *s_etat_processus)
                    661: {
                    662:    (*s_etat_processus).erreur_execution = d_ex;
                    663: 
                    664:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    665:    {
                    666:        printf("\n  HISTOGRAM ");
                    667: 
                    668:        if ((*s_etat_processus).langue == 'F')
                    669:        {
                    670:            printf("(graphique statistique de type histogramme)\n\n");
                    671:            printf("  Aucun argument\n");
                    672:        }
                    673:        else
                    674:        {
                    675:            printf("(histogram statistical graphic)\n\n");
                    676:            printf("  No argument\n");
                    677:        }
                    678: 
                    679:        return;
                    680:    }
                    681:    else if ((*s_etat_processus).test_instruction == 'Y')
                    682:    {
                    683:        (*s_etat_processus).nombre_arguments = -1;
                    684:        return;
                    685:    }
                    686: 
                    687:    strcpy((*s_etat_processus).type_trace_sigma, "HISTOGRAMME");
                    688: 
                    689:    return;
                    690: }
                    691: 
                    692: 
                    693: /*
                    694: ================================================================================
                    695:   Fonction 'help'
                    696: ================================================================================
                    697:   Entrées :
                    698: --------------------------------------------------------------------------------
                    699:   Sorties :
                    700: --------------------------------------------------------------------------------
                    701:   Effets de bord : néant
                    702: ================================================================================
                    703: */
                    704: 
                    705: void
                    706: instruction_help(struct_processus *s_etat_processus)
                    707: {
                    708:    unsigned char           *fonction;
                    709:    unsigned char           ligne[80 + 1];
                    710:    unsigned char           *pointeur;
                    711:    unsigned char           **ptr;
                    712:    unsigned char           *registre;
                    713: 
                    714: #  undef COMPLETION
1.11      bertrand  715: #  include "completion-conv.h"
                    716: #  include "usages-conv.h"
1.1       bertrand  717: 
                    718:    if ((*s_etat_processus).test_instruction == 'Y')
                    719:    {
                    720:        (*s_etat_processus).nombre_arguments = -1;
                    721:        return;
                    722:    }
                    723: 
                    724:    (*s_etat_processus).erreur_execution = d_ex;
                    725: 
                    726:    printf("\n");
                    727: 
                    728:    if ((*s_etat_processus).langue == 'F')
                    729:    {
                    730:        printf("Liste alphabétique des fonctions intrinsèques :\n\n");
                    731:    }
                    732:    else
                    733:    {
                    734:        printf("Alphabetical list of intrinsic functions :\n\n");
                    735:    }
                    736: 
                    737:    ptr = commandes;
                    738:    *ligne = d_code_fin_chaine;
                    739: 
                    740:    while(*ptr != (unsigned char *) NULL)
                    741:    {
                    742:        if (strcmp((*ptr), COMPLETION_RC) == 0)
                    743:        {
                    744:            printf("%s\n\n", ligne);
                    745:            *ligne = d_code_fin_chaine;
                    746:        }
                    747:        else if ((strlen(ligne) + strlen(*ptr) + 2) > 80)
                    748:        {
                    749:            printf("%s\n", ligne);
                    750:            *ligne = d_code_fin_chaine;
                    751:            strcpy(ligne, "    ");
                    752:            strcat(ligne, *ptr);
                    753: 
                    754:            if (*(ptr + 1) != NULL)
                    755:            {
                    756:                strcat(ligne, ", ");
                    757:            }
                    758:        }
                    759:        else
                    760:        {
                    761:            if (*ligne == d_code_fin_chaine)
                    762:            {
                    763:                strcat(ligne, "  ");
                    764:            }
                    765: 
                    766:            strcat(ligne, *ptr);
                    767: 
                    768:            if (*(ptr + 1) != NULL)
                    769:            {
                    770:                strcat(ligne, ", ");
                    771:            }
                    772:        }
                    773: 
                    774:        ptr++;
                    775:    }
                    776: 
                    777:    if (strlen(ligne) != 0)
                    778:    {
                    779:        printf("%s\n", ligne);
                    780:    }
                    781: 
                    782:    printf("\n");
                    783: 
                    784:    if ((*s_etat_processus).langue == 'F')
                    785:    {
                    786:        printf("Délimiteurs :\n\n");
                    787:        printf("  aucun   : scalaire, nombre entier ou réel ;\n");
                    788:        printf("  ( )     : nombre complexe ;\n");
                    789:        printf("  #       : entier binaire ;\n");
                    790:        printf("  << >>   : fonction utilisateur ou équation en notation "
                    791:                "polonaise inversée ;\n");
                    792:        printf("  ' '     : équation en notation algébrique ou nom de "
                    793:                "variable ;\n");
                    794:        printf("  [ ]     : vecteur ;\n");
                    795:        printf("  [[ ]]   : matrice ;\n");
                    796:        printf("  <[ ]>   : table ;\n");
                    797:        printf("  \" \"     : chaîne de caractères ;\n");
                    798:        printf("  { }     : liste ;\n");
                    799:        printf("  /* */   : commentaire ;\n");
                    800:        printf("  //      : commentaire allant jusqu'à la fin de la ligne."
                    801:                "\n\n");
                    802:        printf("Fonctions classées par usage :\n");
                    803:        printf("(les instructions écrites en majuscules sont insensibles à "
                    804:                "la casse)\n\n");
                    805:    }
                    806:    else
                    807:    {
                    808:        printf("Delimiters :\n\n");
                    809:        printf("  none    : scalar, integer or real number ;\n");
                    810:        printf("  ( )     : complex number ;\n");
                    811:        printf("  #       : binary integer ;\n");
                    812:        printf("  << >>   : user-defined function, or equation expressed in "
                    813:                "RPN ;\n");
                    814:        printf("  ' '     : algebraic equation or variable name ;\n");
                    815:        printf("  [ ]     : scalar vector ;\n");
                    816:        printf("  [[ ]]   : scalar matrix ;\n");
                    817:        printf("  <[ ]>   : table ;\n");
                    818:        printf("  \" \"     : character string ;\n");
                    819:        printf("  { }     : list ;\n");
                    820:        printf("  /* */   : comment ;\n");
                    821:        printf("  //      : comment running to the end of the line.\n\n");
                    822:        printf("Functions ordre by usage :\n");
                    823:        printf("(instructions written in upper case are case-unsensitive)\n\n");
                    824:    }
                    825: 
                    826:    ptr = usages;
                    827:    *ligne = d_code_fin_chaine;
                    828: 
                    829:    while(*ptr != (unsigned char *) NULL)
                    830:    {
                    831:        if (strcmp((*ptr), USAGES_RC) == 0)
                    832:        {
                    833:            printf("    %s\n\n", ligne);
                    834:            *ligne = d_code_fin_chaine;
                    835:        }
                    836:        else if (strcmp((*ptr), USAGES_TITRE) == 0)
                    837:        {
                    838:            ptr++;
                    839: 
                    840:            if ((*s_etat_processus).langue == 'F')
                    841:            {
                    842:                ptr++;
                    843:                printf("  %s\n", *ptr);
                    844:            }
                    845:            else
                    846:            {
                    847:                printf("  %s\n", *ptr);
                    848:                ptr++;
                    849:            }
                    850:        }
                    851:        else if ((strlen(ligne) + strlen(*ptr) + 2) > 76)
                    852:        {
                    853:            printf("    %s\n", ligne);
                    854:            *ligne = d_code_fin_chaine;
                    855:            strcat(ligne, *ptr);
                    856: 
                    857:            if (*(ptr + 1) != NULL)
                    858:            {
                    859:                strcat(ligne, ", ");
                    860:            }
                    861:        }
                    862:        else
                    863:        {
                    864:            strcat(ligne, *ptr);
                    865: 
                    866:            if (*(ptr + 1) != NULL)
                    867:            {
                    868:                strcat(ligne, ", ");
                    869:            }
                    870:        }
                    871: 
                    872:        ptr++;
                    873:    }
                    874: 
                    875:    if (strlen(ligne) != 0)
                    876:    {
                    877:        printf("    %s\n", ligne);
                    878:    }
                    879: 
                    880:    printf("\n");
                    881: 
                    882:    if ((*s_etat_processus).langue == 'F')
                    883:    {
                    884:        printf("Processus asynchrones :\n");
1.35      bertrand  885:        printf("  CTRL+c : interruption de l'instruction en cours ;\n");
                    886:        printf("  CTRL+d : en mode interactif, provoque un ABORT\n");
                    887:        printf("  CTRL+g : en mode interactif, provoque l'annulation de la "
                    888:                "commande en cours ;\n");
                    889:        printf("  CTRL+z : en cours d'exécution, provoque un HALT "
1.1       bertrand  890:                "asynchrone.\n\n");
                    891: 
                    892:        printf("Drapeaux (valeurs par défaut) :\n");
                    893:        printf("  1 à 30  : drapeaux banalisés (désarmés)\n");
                    894:        printf("  31      : pile LAST active (armé en mode interactif, "
                    895:                "désarmé sinon)\n");
                    896:        printf("  32      : impression automatique (désarmé)\n");
                    897:        printf("  33      : retour à la ligne automatique invalidé "
                    898:                "(désarmé)\n");
1.18      bertrand  899:        printf("  34      : évaluation des caractères de contrôle (armé)\n");
1.1       bertrand  900:        printf("  35      : évaluation symbolique des constantes (armé)\n");
                    901:        printf("  36      : évaluation symbolique des fonctions (armé)\n");
                    902:        printf("  37 à 42 : taille des entiers binaires, bit de poids faible "
                    903:                "en tête (armés)\n");
                    904:        printf("  43 à 44 : base de numérotation binaire (désarmés)\n");
                    905:        printf("  45      : affichage multiligne (armé)\n");
                    906:        printf("  46 à 47 : réservés (désarmés)\n");
                    907:        printf("  48      : virgule comme séparateur décimal (désarmé)\n");
                    908:        printf("  49 à 50 : format des nombres (désarmés)\n");
                    909:        printf("  51      : tonalité désactivée (désarmé)\n");
                    910:        printf("  52      : mise à jour automatique des graphiques désactivée "
                    911:                "(désarmé)\n");
                    912:        printf("  53 à 56 : nombre de chiffres décimaux, bit de poids fort "
                    913:                "en tête (désarmés)\n");
                    914:        printf("  57 à 59 : réservés (désarmés)\n");
                    915:        printf("  60      : radian et non degré comme unité angulaire "
                    916:                "(armé)\n");
                    917:        printf("  61 à 64 : réservés (désarmés)\n");
                    918:    }
                    919:    else
                    920:    {
                    921:        printf("Hot keys :\n");
1.35      bertrand  922:        printf("  CTRL+c : interruption ;\n");
                    923:        printf("  CTRL+d : in interactive mode only sends ABORT on empty "
                    924:                "command line ;\n");
                    925:        printf("  CTRL+g : in interactive mode only, nullifies current "
                    926:                "command line ;\n");
                    927:        printf("  CTRL+z : HALT.\n\n");
1.1       bertrand  928: 
                    929:        printf("Flags (default values) :\n");
1.17      bertrand  930:        printf("  1 to 30  : user flags (cleared)\n");
                    931:        printf("  31       : LAST stack enabled (set in interactive mode, "
1.1       bertrand  932:                "cleared if not)\n");
1.17      bertrand  933:        printf("  32       : automatic printing (cleared)\n");
                    934:        printf("  33       : automatic carriage return disabled "
1.1       bertrand  935:                "(cleared)\n");
1.19      bertrand  936:        printf("  34       : control characters evaluation (set)\n");
1.17      bertrand  937:        printf("  35       : constant symbolic evaluation (set)\n");
                    938:        printf("  36       : function symbolic evaluation (set)\n");
                    939:        printf("  37 to 42 : size of binary integers, while starting with "
                    940:                "less significant bit\n");
                    941:        printf("             (set)\n");
                    942:        printf("  43 to 44 : binary integer basis (cleared)\n");
                    943:        printf("  45       : multiline conversion (set)\n");
                    944:        printf("  46 to 47 : reserved (cleared)\n");
                    945:        printf("  48       : comma as decimal separator (cleared)\n");
                    946:        printf("  49 to 50 : numbers format (cleared)\n");
                    947:        printf("  51       : visual bell disabled (cleared)\n");
                    948:        printf("  52       : graphic automatic redrawing disabled "
1.1       bertrand  949:                "(cleared)\n");
1.17      bertrand  950:        printf("  53 to 56 : precision, while starting with "
1.1       bertrand  951:                "less significant bit (cleared)\n");
1.17      bertrand  952:        printf("  57 to 59 : reserved (cleared)\n");
                    953:        printf("  60       : radian mode instead of degree one (set)\n");
                    954:        printf("  61 to 64 : reserved (cleared)\n");
1.1       bertrand  955:    }
                    956: 
                    957:    printf("\n");
                    958: 
                    959:    if ((*s_etat_processus).langue == 'F')
                    960:    {
                    961:        printf("Types d'arguments :\n\n");
                    962:        printf("    %s              : entier (64 bits)\n", d_INT);
                    963:        printf("    %s                 : réel (64 bits)\n", d_REL);
                    964:        printf("    %s              : complexe (128 bits)\n", d_CPL);
                    965:        printf("    %s          : vecteur entier\n", d_VIN);
                    966:        printf("    %s             : vecteur réel\n", d_VRL);
                    967:        printf("    %s          : vecteur complexe\n", d_VCX);
                    968:        printf("    %s        : matrice entière\n", d_MIN);
                    969:        printf("    %s           : matrice réelle\n", d_MRL);
                    970:        printf("    %s        : matrice complexe\n", d_MCX);
                    971:        printf("    %s          : table\n", d_TAB);
                    972:        printf("    %s       : entier binaire\n", d_BIN);
                    973:        printf("    %s               : nom\n", d_NOM);
                    974:        printf("    %s             : chaîne de caractères\n", d_CHN);
                    975:        printf("    %s             : liste\n", d_LST);
                    976:        printf("    %s          : expression algébrique\n", d_ALG);
                    977:        printf("    %s            : expression RPN\n", d_RPN);
                    978:        printf("    %s   : descripteur de fichier\n", d_FCH);
                    979:        printf("    %s : socket\n", d_SCK);
                    980:        printf("    %s           : descripteur de bibliothèque\n", d_SLB);
                    981:        printf("    %s           : processus\n", d_PRC);
                    982:        printf("    %s        : connexion à une base de données SQL\n", d_SQL);
                    983:        printf("    %s             : mutex\n", d_MTX);
                    984:        printf("    %s  : sémaphore nommé\n", d_SPH);
1.66      bertrand  985:        printf("    %s         : enregistrement\n", d_REC);
1.1       bertrand  986:    }
                    987:    else
                    988:    {
                    989:        printf("Types :\n\n");
                    990:        printf("    %s              : integer (64 bits)\n", d_INT);
                    991:        printf("    %s                 : real (64 bits)\n", d_REL);
                    992:        printf("    %s              : complex (128 bits)\n", d_CPL);
                    993:        printf("    %s          : integer vector\n", d_VIN);
                    994:        printf("    %s             : real vector\n", d_VRL);
                    995:        printf("    %s          : complex vector\n", d_VCX);
                    996:        printf("    %s        : integer matrix\n", d_MIN);
                    997:        printf("    %s           : real matrix\n", d_MRL);
                    998:        printf("    %s        : complex matrix\n", d_MCX);
                    999:        printf("    %s          : table\n", d_TAB);
                   1000:        printf("    %s       : binary integer\n", d_BIN);
                   1001:        printf("    %s               : name\n", d_NOM);
                   1002:        printf("    %s             : string of chars\n", d_CHN);
                   1003:        printf("    %s             : list\n", d_LST);
                   1004:        printf("    %s          : algebraic expression\n", d_ALG);
                   1005:        printf("    %s            : RPN expression\n", d_RPN);
                   1006:        printf("    %s   : file descriptor\n", d_FCH);
                   1007:        printf("    %s : socket\n", d_SCK);
                   1008:        printf("    %s           : library descriptor\n", d_SLB);
                   1009:        printf("    %s           : process\n", d_PRC);
                   1010:        printf("    %s        : connection to SQL database\n", d_SQL);
                   1011:        printf("    %s             : mutex\n", d_MTX);
                   1012:        printf("    %s  : named semaphore\n", d_SPH);
1.66      bertrand 1013:        printf("    %s         : record\n", d_REC);
1.1       bertrand 1014:    }
                   1015: 
                   1016:    /*
                   1017:     * HELP ne doit pas être récursif sous peine de boucler indéfiniment
                   1018:     * dans la fonction.
                   1019:     */
                   1020: 
                   1021:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1022:    {
                   1023:        return;
                   1024:    }
                   1025: 
                   1026:    printf("\n");
                   1027: 
                   1028:    registre = (*s_etat_processus).instruction_courante;
                   1029: 
                   1030:    flockfile(stdin);
                   1031:    flockfile(stdout);
                   1032: 
                   1033:    while((fonction = readline("HELP> ")) != NULL)
                   1034:    {
                   1035:        if (strcmp(fonction, "") == 0)
                   1036:        {
                   1037:            break;
                   1038:        }
                   1039: 
1.13      bertrand 1040:        funlockfile(stdin);
                   1041:        funlockfile(stdout);
                   1042: 
1.1       bertrand 1043:        /*
                   1044:         * Élimination des blancs précédents l'instruction
                   1045:         */
                   1046: 
                   1047:        pointeur = fonction;
                   1048: 
                   1049:        while(((*pointeur) == d_code_tabulation) ||
                   1050:                ((*pointeur) == d_code_espace))
                   1051:        {
                   1052:            pointeur++;
                   1053:        }
                   1054: 
                   1055:        (*s_etat_processus).instruction_courante = pointeur;
                   1056: 
                   1057:        /*
                   1058:         * Élimination des blancs et caractères suivant la première
                   1059:         * instruction.
                   1060:         */
                   1061: 
                   1062:        while(((*pointeur) != d_code_tabulation) &&
                   1063:                ((*pointeur) != d_code_espace) &&
                   1064:                ((*pointeur) != d_code_fin_chaine))
                   1065:        {
                   1066:            pointeur++;
                   1067:        }
                   1068: 
                   1069:        (*pointeur) = d_code_fin_chaine;
                   1070: 
                   1071:        add_history(pointeur);
                   1072:        stifle_history(ds_longueur_historique);
                   1073: 
                   1074:        (*s_etat_processus).test_instruction = 'Y';
                   1075:        analyse(s_etat_processus, NULL);
                   1076:        (*s_etat_processus).test_instruction = 'N';
                   1077: 
                   1078:        if ((*s_etat_processus).instruction_valide == 'Y')
                   1079:        {
                   1080:            (*s_etat_processus).affichage_arguments = 'Y';
                   1081:            analyse(s_etat_processus, NULL);
                   1082:            (*s_etat_processus).affichage_arguments = 'N';
                   1083: 
                   1084:            printf("\n");
                   1085:        }
                   1086:        else
                   1087:        {
                   1088:            if ((*s_etat_processus).langue == 'F')
                   1089:            {
                   1090:                printf("Fonction inconnue.\n");
                   1091:            }
                   1092:            else
                   1093:            {
                   1094:                printf("Unknown function\n");
                   1095:            }
                   1096:        }
                   1097: 
                   1098:        free(fonction);
                   1099:        flockfile(stdin);
                   1100:        flockfile(stdout);
                   1101:    }
                   1102: 
                   1103:    funlockfile(stdin);
                   1104:    funlockfile(stdout);
                   1105: 
                   1106:    if (fonction == NULL)
                   1107:    {
                   1108:        printf("\n");
                   1109:    }
                   1110: 
                   1111:    (*s_etat_processus).instruction_courante = registre;
                   1112: 
                   1113:    /*
                   1114:     * Évite l'empilement de 'HELP()' dans la pile opérationnelle dans le
                   1115:     * cas où la dernière commande entrée à l'invite "HELP> " n'existe pas.
                   1116:     */
                   1117: 
                   1118:    (*s_etat_processus).instruction_valide = 'Y';
                   1119: 
                   1120:    return;
                   1121: }
                   1122: 
                   1123: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>