/* ================================================================================ RPL/2 (R) version 4.1.27 Copyright (C) 1989-2017 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl-conv.h" /* ================================================================================ Procédure permettant d'accéder à la structure s_etat_processus sous la forme d'une variable globale par fil d'exécution. ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : erreur le cas échéant -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ static pthread_key_t k_etat_processus; int initialisation_etat_processus_readline() { return(pthread_key_create(&k_etat_processus, NULL)); } int liberation_etat_processus_readline() { return(pthread_key_delete(k_etat_processus)); } int association_etat_processus_readline(struct_processus *s_etat_processus) { return(pthread_setspecific(k_etat_processus, s_etat_processus)); } /* ================================================================================ Procédure de d'analyse syntaxique du source pour readline ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : - rl_done à 0 ou à 1. -------------------------------------------------------------------------------- Effets de bord : ================================================================================ */ static char *ligne = NULL; static unsigned int niveau = 0; int readline_analyse_syntaxique(int count, int key) { char prompt[] = "+ %03d> "; char prompt2[8]; char *registre; integer8 tampon_position_courante; struct_processus *s_etat_processus; unsigned char *tampon_definitions_chainees; unsigned char *tampon_instruction_courante; s_etat_processus = pthread_getspecific(k_etat_processus); if ((*rl_line_buffer) == d_code_fin_chaine) { if (ligne == NULL) { rl_done = 1; } else { rl_done = 0; } } else { if (ligne == NULL) { if ((ligne = sys_malloc((strlen(rl_line_buffer) + 1) * sizeof(char))) == NULL) { rl_done = 1; return(0); } strcpy(ligne, rl_line_buffer); } else { registre = ligne; if ((ligne = sys_malloc((strlen(registre) + strlen(rl_line_buffer) + 2) * sizeof(char))) == NULL) { rl_done = 1; return(0); } sprintf(ligne, "%s %s", registre, rl_line_buffer); } rl_replace_line("", 1); tampon_definitions_chainees = (*s_etat_processus).definitions_chainees; tampon_instruction_courante = (*s_etat_processus).instruction_courante; tampon_position_courante = (*s_etat_processus).position_courante; (*s_etat_processus).definitions_chainees = ligne; (*s_etat_processus).debug = d_faux; (*s_etat_processus).erreur_systeme = d_es; (*s_etat_processus).erreur_execution = d_ex; if (analyse_syntaxique(s_etat_processus) == d_absence_erreur) { rl_done = 1; } else { if ((*s_etat_processus).erreur_systeme != d_es) { rl_done = 1; } else { rl_done = 0; rl_crlf(); sprintf(prompt2, prompt, ++niveau); rl_expand_prompt(prompt2); rl_on_new_line(); } } (*s_etat_processus).definitions_chainees = tampon_definitions_chainees; (*s_etat_processus).instruction_courante = tampon_instruction_courante; (*s_etat_processus).position_courante = tampon_position_courante; (*s_etat_processus).erreur_execution = d_ex; } if (rl_done != 0) { uprintf("\n"); if (ligne != NULL) { rl_replace_line(ligne, 1); sys_free(ligne); ligne = NULL; } niveau = 0; } return(0); } int readline_effacement(int count, int key) { rl_done = 0; rl_replace_line("", 1); sys_free(ligne); ligne = NULL; niveau = 0; uprintf("^G\n"); rl_expand_prompt("RPL/2> "); rl_on_new_line(); return(0); } // vim: ts=4