File:  [local] / rpl / src / interface_readline.c
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:50 2020 UTC (4 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_32, HEAD
Modification du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.32
    4:   Copyright (C) 1989-2020 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Procédure permettant d'accéder à la structure s_etat_processus sous
   29:   la forme d'une variable globale par fil d'exécution.
   30: ================================================================================
   31:   Entrées :
   32: --------------------------------------------------------------------------------
   33:   Sorties : erreur le cas échéant
   34: --------------------------------------------------------------------------------
   35:   Effets de bord : néant
   36: ================================================================================
   37: */
   38: 
   39: static pthread_key_t        k_etat_processus;
   40: 
   41: 
   42: int
   43: initialisation_etat_processus_readline()
   44: {
   45:     return(pthread_key_create(&k_etat_processus, NULL));
   46: }
   47: 
   48: int
   49: liberation_etat_processus_readline()
   50: {
   51:     return(pthread_key_delete(k_etat_processus));
   52: }
   53: 
   54: int
   55: association_etat_processus_readline(struct_processus *s_etat_processus)
   56: {
   57:     return(pthread_setspecific(k_etat_processus, s_etat_processus));
   58: }
   59: 
   60: 
   61: /*
   62: ================================================================================
   63:   Procédure de d'analyse syntaxique du source pour readline
   64: ================================================================================
   65:   Entrées :
   66: --------------------------------------------------------------------------------
   67:   Sorties :
   68:     - rl_done à 0 ou à 1.
   69: --------------------------------------------------------------------------------
   70:   Effets de bord :
   71: ================================================================================
   72: */
   73: 
   74: static char                 *ligne = NULL;
   75: static unsigned int         niveau = 0;
   76: 
   77: int
   78: readline_analyse_syntaxique(int count, int key)
   79: {
   80:     char                        prompt[] = "+ %03d> ";
   81:     char                        prompt2[8];
   82:     char                        *registre;
   83: 
   84:     integer8                    tampon_position_courante;
   85: 
   86:     struct_processus            *s_etat_processus;
   87: 
   88:     unsigned char               *tampon_definitions_chainees;
   89:     unsigned char               *tampon_instruction_courante;
   90: 
   91:     s_etat_processus = pthread_getspecific(k_etat_processus);
   92: 
   93:     if ((*rl_line_buffer) == d_code_fin_chaine)
   94:     {
   95:         if (ligne == NULL)
   96:         {
   97:             rl_done = 1;
   98:         }
   99:         else
  100:         {
  101:             rl_done = 0;
  102:         }
  103:     }
  104:     else
  105:     {
  106:         if (ligne == NULL)
  107:         {
  108:             if ((ligne = sys_malloc((strlen(rl_line_buffer) + 1)
  109:                     * sizeof(char))) == NULL)
  110:             {
  111:                 rl_done = 1;
  112:                 return(0);
  113:             }
  114: 
  115:             strcpy(ligne, rl_line_buffer);
  116:         }
  117:         else
  118:         {
  119:             registre = ligne;
  120: 
  121:             if ((ligne = sys_malloc((strlen(registre)
  122:                     + strlen(rl_line_buffer) + 2) * sizeof(char))) == NULL)
  123:             {
  124:                 rl_done = 1;
  125:                 return(0);
  126:             }
  127: 
  128:             sprintf(ligne, "%s %s", registre, rl_line_buffer);
  129:         }
  130: 
  131:         rl_replace_line("", 1);
  132: 
  133:         tampon_definitions_chainees = (*s_etat_processus).definitions_chainees;
  134:         tampon_instruction_courante = (*s_etat_processus).instruction_courante;
  135:         tampon_position_courante = (*s_etat_processus).position_courante;
  136: 
  137:         (*s_etat_processus).definitions_chainees = ligne;
  138:         (*s_etat_processus).debug = d_faux;
  139:         (*s_etat_processus).erreur_systeme = d_es;
  140:         (*s_etat_processus).erreur_execution = d_ex;
  141: 
  142:         if (analyse_syntaxique(s_etat_processus) == d_absence_erreur)
  143:         {
  144:             rl_done = 1;
  145:         }
  146:         else
  147:         {
  148:             if ((*s_etat_processus).erreur_systeme != d_es)
  149:             {
  150:                 rl_done = 1;
  151:             }
  152:             else
  153:             {
  154:                 rl_done = 0;
  155:                 rl_crlf();
  156: 
  157:                 sprintf(prompt2, prompt, ++niveau);
  158: 
  159:                 rl_expand_prompt(prompt2);
  160:                 rl_on_new_line();
  161:             }
  162:         }
  163: 
  164:         (*s_etat_processus).definitions_chainees = tampon_definitions_chainees;
  165:         (*s_etat_processus).instruction_courante = tampon_instruction_courante;
  166:         (*s_etat_processus).position_courante = tampon_position_courante;
  167:         (*s_etat_processus).erreur_execution = d_ex;
  168:     }
  169: 
  170:     if (rl_done != 0)
  171:     {
  172:         uprintf("\n");
  173: 
  174:         if (ligne != NULL)
  175:         {
  176:             rl_replace_line(ligne, 1);
  177: 
  178:             sys_free(ligne);
  179:             ligne = NULL;
  180:         }
  181: 
  182:         niveau = 0;
  183:     }
  184: 
  185:     return(0);
  186: }
  187: 
  188: int
  189: readline_effacement(int count, int key)
  190: {
  191:     rl_done = 0;
  192:     rl_replace_line("", 1);
  193: 
  194:     sys_free(ligne);
  195:     ligne = NULL;
  196:     niveau = 0;
  197: 
  198:     uprintf("^G\n");
  199:     rl_expand_prompt("RPL/2> ");
  200:     rl_on_new_line();
  201:     return(0);
  202: }
  203: 
  204: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>