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

1.1       bertrand    1: /*
                      2: ================================================================================
1.70      bertrand    3:   RPL/2 (R) version 4.1.32
1.72      bertrand    4:   Copyright (C) 1989-2020 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");
1.73    ! bertrand  797:        printf("  |[ ]|   : enregistrement ;\n");
1.1       bertrand  798:        printf("  \" \"     : chaîne de caractères ;\n");
                    799:        printf("  { }     : liste ;\n");
                    800:        printf("  /* */   : commentaire ;\n");
                    801:        printf("  //      : commentaire allant jusqu'à la fin de la ligne."
                    802:                "\n\n");
                    803:        printf("Fonctions classées par usage :\n");
                    804:        printf("(les instructions écrites en majuscules sont insensibles à "
                    805:                "la casse)\n\n");
                    806:    }
                    807:    else
                    808:    {
                    809:        printf("Delimiters :\n\n");
                    810:        printf("  none    : scalar, integer or real number ;\n");
                    811:        printf("  ( )     : complex number ;\n");
                    812:        printf("  #       : binary integer ;\n");
                    813:        printf("  << >>   : user-defined function, or equation expressed in "
                    814:                "RPN ;\n");
                    815:        printf("  ' '     : algebraic equation or variable name ;\n");
                    816:        printf("  [ ]     : scalar vector ;\n");
                    817:        printf("  [[ ]]   : scalar matrix ;\n");
                    818:        printf("  <[ ]>   : table ;\n");
1.73    ! bertrand  819:        printf("  |[ ]|   : record ;\n");
1.1       bertrand  820:        printf("  \" \"     : character string ;\n");
                    821:        printf("  { }     : list ;\n");
                    822:        printf("  /* */   : comment ;\n");
                    823:        printf("  //      : comment running to the end of the line.\n\n");
                    824:        printf("Functions ordre by usage :\n");
                    825:        printf("(instructions written in upper case are case-unsensitive)\n\n");
                    826:    }
                    827: 
                    828:    ptr = usages;
                    829:    *ligne = d_code_fin_chaine;
                    830: 
                    831:    while(*ptr != (unsigned char *) NULL)
                    832:    {
                    833:        if (strcmp((*ptr), USAGES_RC) == 0)
                    834:        {
                    835:            printf("    %s\n\n", ligne);
                    836:            *ligne = d_code_fin_chaine;
                    837:        }
                    838:        else if (strcmp((*ptr), USAGES_TITRE) == 0)
                    839:        {
                    840:            ptr++;
                    841: 
                    842:            if ((*s_etat_processus).langue == 'F')
                    843:            {
                    844:                ptr++;
                    845:                printf("  %s\n", *ptr);
                    846:            }
                    847:            else
                    848:            {
                    849:                printf("  %s\n", *ptr);
                    850:                ptr++;
                    851:            }
                    852:        }
                    853:        else if ((strlen(ligne) + strlen(*ptr) + 2) > 76)
                    854:        {
                    855:            printf("    %s\n", ligne);
                    856:            *ligne = d_code_fin_chaine;
                    857:            strcat(ligne, *ptr);
                    858: 
                    859:            if (*(ptr + 1) != NULL)
                    860:            {
                    861:                strcat(ligne, ", ");
                    862:            }
                    863:        }
                    864:        else
                    865:        {
                    866:            strcat(ligne, *ptr);
                    867: 
                    868:            if (*(ptr + 1) != NULL)
                    869:            {
                    870:                strcat(ligne, ", ");
                    871:            }
                    872:        }
                    873: 
                    874:        ptr++;
                    875:    }
                    876: 
                    877:    if (strlen(ligne) != 0)
                    878:    {
                    879:        printf("    %s\n", ligne);
                    880:    }
                    881: 
                    882:    printf("\n");
                    883: 
                    884:    if ((*s_etat_processus).langue == 'F')
                    885:    {
                    886:        printf("Processus asynchrones :\n");
1.35      bertrand  887:        printf("  CTRL+c : interruption de l'instruction en cours ;\n");
                    888:        printf("  CTRL+d : en mode interactif, provoque un ABORT\n");
                    889:        printf("  CTRL+g : en mode interactif, provoque l'annulation de la "
                    890:                "commande en cours ;\n");
                    891:        printf("  CTRL+z : en cours d'exécution, provoque un HALT "
1.1       bertrand  892:                "asynchrone.\n\n");
                    893: 
                    894:        printf("Drapeaux (valeurs par défaut) :\n");
                    895:        printf("  1 à 30  : drapeaux banalisés (désarmés)\n");
                    896:        printf("  31      : pile LAST active (armé en mode interactif, "
                    897:                "désarmé sinon)\n");
                    898:        printf("  32      : impression automatique (désarmé)\n");
                    899:        printf("  33      : retour à la ligne automatique invalidé "
                    900:                "(désarmé)\n");
1.18      bertrand  901:        printf("  34      : évaluation des caractères de contrôle (armé)\n");
1.1       bertrand  902:        printf("  35      : évaluation symbolique des constantes (armé)\n");
                    903:        printf("  36      : évaluation symbolique des fonctions (armé)\n");
                    904:        printf("  37 à 42 : taille des entiers binaires, bit de poids faible "
                    905:                "en tête (armés)\n");
                    906:        printf("  43 à 44 : base de numérotation binaire (désarmés)\n");
                    907:        printf("  45      : affichage multiligne (armé)\n");
1.71      bertrand  908:        printf("  46      : simplification automatique des expression "
                    909:                "(désarmé)\n");
                    910:        printf("  47      : réservé (désarmé)\n");
1.1       bertrand  911:        printf("  48      : virgule comme séparateur décimal (désarmé)\n");
                    912:        printf("  49 à 50 : format des nombres (désarmés)\n");
                    913:        printf("  51      : tonalité désactivée (désarmé)\n");
                    914:        printf("  52      : mise à jour automatique des graphiques désactivée "
                    915:                "(désarmé)\n");
                    916:        printf("  53 à 56 : nombre de chiffres décimaux, bit de poids fort "
                    917:                "en tête (désarmés)\n");
                    918:        printf("  57 à 59 : réservés (désarmés)\n");
                    919:        printf("  60      : radian et non degré comme unité angulaire "
                    920:                "(armé)\n");
                    921:        printf("  61 à 64 : réservés (désarmés)\n");
                    922:    }
                    923:    else
                    924:    {
                    925:        printf("Hot keys :\n");
1.35      bertrand  926:        printf("  CTRL+c : interruption ;\n");
                    927:        printf("  CTRL+d : in interactive mode only sends ABORT on empty "
                    928:                "command line ;\n");
                    929:        printf("  CTRL+g : in interactive mode only, nullifies current "
                    930:                "command line ;\n");
                    931:        printf("  CTRL+z : HALT.\n\n");
1.1       bertrand  932: 
                    933:        printf("Flags (default values) :\n");
1.17      bertrand  934:        printf("  1 to 30  : user flags (cleared)\n");
                    935:        printf("  31       : LAST stack enabled (set in interactive mode, "
1.1       bertrand  936:                "cleared if not)\n");
1.17      bertrand  937:        printf("  32       : automatic printing (cleared)\n");
                    938:        printf("  33       : automatic carriage return disabled "
1.1       bertrand  939:                "(cleared)\n");
1.19      bertrand  940:        printf("  34       : control characters evaluation (set)\n");
1.17      bertrand  941:        printf("  35       : constant symbolic evaluation (set)\n");
                    942:        printf("  36       : function symbolic evaluation (set)\n");
                    943:        printf("  37 to 42 : size of binary integers, while starting with "
                    944:                "less significant bit\n");
                    945:        printf("             (set)\n");
                    946:        printf("  43 to 44 : binary integer basis (cleared)\n");
                    947:        printf("  45       : multiline conversion (set)\n");
1.71      bertrand  948:        printf("  46       : expression simplification (cleared)\n");
                    949:        printf("  47       : reserved (cleared)\n");
1.17      bertrand  950:        printf("  48       : comma as decimal separator (cleared)\n");
                    951:        printf("  49 to 50 : numbers format (cleared)\n");
                    952:        printf("  51       : visual bell disabled (cleared)\n");
                    953:        printf("  52       : graphic automatic redrawing disabled "
1.1       bertrand  954:                "(cleared)\n");
1.17      bertrand  955:        printf("  53 to 56 : precision, while starting with "
1.1       bertrand  956:                "less significant bit (cleared)\n");
1.17      bertrand  957:        printf("  57 to 59 : reserved (cleared)\n");
                    958:        printf("  60       : radian mode instead of degree one (set)\n");
                    959:        printf("  61 to 64 : reserved (cleared)\n");
1.1       bertrand  960:    }
                    961: 
                    962:    printf("\n");
                    963: 
                    964:    if ((*s_etat_processus).langue == 'F')
                    965:    {
                    966:        printf("Types d'arguments :\n\n");
                    967:        printf("    %s              : entier (64 bits)\n", d_INT);
                    968:        printf("    %s                 : réel (64 bits)\n", d_REL);
                    969:        printf("    %s              : complexe (128 bits)\n", d_CPL);
                    970:        printf("    %s          : vecteur entier\n", d_VIN);
                    971:        printf("    %s             : vecteur réel\n", d_VRL);
                    972:        printf("    %s          : vecteur complexe\n", d_VCX);
                    973:        printf("    %s        : matrice entière\n", d_MIN);
                    974:        printf("    %s           : matrice réelle\n", d_MRL);
                    975:        printf("    %s        : matrice complexe\n", d_MCX);
                    976:        printf("    %s          : table\n", d_TAB);
                    977:        printf("    %s       : entier binaire\n", d_BIN);
                    978:        printf("    %s               : nom\n", d_NOM);
                    979:        printf("    %s             : chaîne de caractères\n", d_CHN);
                    980:        printf("    %s             : liste\n", d_LST);
                    981:        printf("    %s          : expression algébrique\n", d_ALG);
                    982:        printf("    %s            : expression RPN\n", d_RPN);
                    983:        printf("    %s   : descripteur de fichier\n", d_FCH);
                    984:        printf("    %s : socket\n", d_SCK);
                    985:        printf("    %s           : descripteur de bibliothèque\n", d_SLB);
                    986:        printf("    %s           : processus\n", d_PRC);
                    987:        printf("    %s        : connexion à une base de données SQL\n", d_SQL);
                    988:        printf("    %s             : mutex\n", d_MTX);
                    989:        printf("    %s  : sémaphore nommé\n", d_SPH);
1.66      bertrand  990:        printf("    %s         : enregistrement\n", d_REC);
1.1       bertrand  991:    }
                    992:    else
                    993:    {
                    994:        printf("Types :\n\n");
                    995:        printf("    %s              : integer (64 bits)\n", d_INT);
                    996:        printf("    %s                 : real (64 bits)\n", d_REL);
                    997:        printf("    %s              : complex (128 bits)\n", d_CPL);
                    998:        printf("    %s          : integer vector\n", d_VIN);
                    999:        printf("    %s             : real vector\n", d_VRL);
                   1000:        printf("    %s          : complex vector\n", d_VCX);
                   1001:        printf("    %s        : integer matrix\n", d_MIN);
                   1002:        printf("    %s           : real matrix\n", d_MRL);
                   1003:        printf("    %s        : complex matrix\n", d_MCX);
                   1004:        printf("    %s          : table\n", d_TAB);
                   1005:        printf("    %s       : binary integer\n", d_BIN);
                   1006:        printf("    %s               : name\n", d_NOM);
                   1007:        printf("    %s             : string of chars\n", d_CHN);
                   1008:        printf("    %s             : list\n", d_LST);
                   1009:        printf("    %s          : algebraic expression\n", d_ALG);
                   1010:        printf("    %s            : RPN expression\n", d_RPN);
                   1011:        printf("    %s   : file descriptor\n", d_FCH);
                   1012:        printf("    %s : socket\n", d_SCK);
                   1013:        printf("    %s           : library descriptor\n", d_SLB);
                   1014:        printf("    %s           : process\n", d_PRC);
                   1015:        printf("    %s        : connection to SQL database\n", d_SQL);
                   1016:        printf("    %s             : mutex\n", d_MTX);
                   1017:        printf("    %s  : named semaphore\n", d_SPH);
1.66      bertrand 1018:        printf("    %s         : record\n", d_REC);
1.1       bertrand 1019:    }
                   1020: 
                   1021:    /*
                   1022:     * HELP ne doit pas être récursif sous peine de boucler indéfiniment
                   1023:     * dans la fonction.
                   1024:     */
                   1025: 
                   1026:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1027:    {
                   1028:        return;
                   1029:    }
                   1030: 
                   1031:    printf("\n");
                   1032: 
                   1033:    registre = (*s_etat_processus).instruction_courante;
                   1034: 
                   1035:    flockfile(stdin);
                   1036:    flockfile(stdout);
                   1037: 
                   1038:    while((fonction = readline("HELP> ")) != NULL)
                   1039:    {
                   1040:        if (strcmp(fonction, "") == 0)
                   1041:        {
                   1042:            break;
                   1043:        }
                   1044: 
1.13      bertrand 1045:        funlockfile(stdin);
                   1046:        funlockfile(stdout);
                   1047: 
1.1       bertrand 1048:        /*
                   1049:         * Élimination des blancs précédents l'instruction
                   1050:         */
                   1051: 
                   1052:        pointeur = fonction;
                   1053: 
                   1054:        while(((*pointeur) == d_code_tabulation) ||
                   1055:                ((*pointeur) == d_code_espace))
                   1056:        {
                   1057:            pointeur++;
                   1058:        }
                   1059: 
                   1060:        (*s_etat_processus).instruction_courante = pointeur;
                   1061: 
                   1062:        /*
                   1063:         * Élimination des blancs et caractères suivant la première
                   1064:         * instruction.
                   1065:         */
                   1066: 
                   1067:        while(((*pointeur) != d_code_tabulation) &&
                   1068:                ((*pointeur) != d_code_espace) &&
                   1069:                ((*pointeur) != d_code_fin_chaine))
                   1070:        {
                   1071:            pointeur++;
                   1072:        }
                   1073: 
                   1074:        (*pointeur) = d_code_fin_chaine;
                   1075: 
                   1076:        add_history(pointeur);
                   1077:        stifle_history(ds_longueur_historique);
                   1078: 
                   1079:        (*s_etat_processus).test_instruction = 'Y';
                   1080:        analyse(s_etat_processus, NULL);
                   1081:        (*s_etat_processus).test_instruction = 'N';
                   1082: 
                   1083:        if ((*s_etat_processus).instruction_valide == 'Y')
                   1084:        {
                   1085:            (*s_etat_processus).affichage_arguments = 'Y';
                   1086:            analyse(s_etat_processus, NULL);
                   1087:            (*s_etat_processus).affichage_arguments = 'N';
                   1088: 
                   1089:            printf("\n");
                   1090:        }
                   1091:        else
                   1092:        {
                   1093:            if ((*s_etat_processus).langue == 'F')
                   1094:            {
                   1095:                printf("Fonction inconnue.\n");
                   1096:            }
                   1097:            else
                   1098:            {
                   1099:                printf("Unknown function\n");
                   1100:            }
                   1101:        }
                   1102: 
                   1103:        free(fonction);
                   1104:        flockfile(stdin);
                   1105:        flockfile(stdout);
                   1106:    }
                   1107: 
                   1108:    funlockfile(stdin);
                   1109:    funlockfile(stdout);
                   1110: 
                   1111:    if (fonction == NULL)
                   1112:    {
                   1113:        printf("\n");
                   1114:    }
                   1115: 
                   1116:    (*s_etat_processus).instruction_courante = registre;
                   1117: 
                   1118:    /*
                   1119:     * Évite l'empilement de 'HELP()' dans la pile opérationnelle dans le
                   1120:     * cas où la dernière commande entrée à l'invite "HELP> " n'existe pas.
                   1121:     */
                   1122: 
                   1123:    (*s_etat_processus).instruction_valide = 'Y';
                   1124: 
                   1125:    return;
                   1126: }
                   1127: 
                   1128: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>