--- rpl/src/instructions_r3.c 2010/01/27 22:22:15 1.2 +++ rpl/src/instructions_r3.c 2012/03/01 10:14:07 1.41 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.10 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.7 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" /* @@ -741,10 +741,6 @@ instruction_rnrm(struct_processus *s_eta void instruction_rceq(struct_processus *s_etat_processus) { - logical1 presence_variable; - - long i; - struct_objet *s_objet_variable; (*s_etat_processus).erreur_execution = d_ex; @@ -787,48 +783,20 @@ instruction_rceq(struct_processus *s_eta } } - if (recherche_variable(s_etat_processus, "EQ") == d_vrai) + if (recherche_variable_globale(s_etat_processus, "EQ") == d_faux) { - i = (*s_etat_processus).position_variable_courante; - presence_variable = d_faux; - - while(i >= 0) - { - if ((strcmp((*s_etat_processus).s_liste_variables[i].nom, "EQ") - == 0) && ((*s_etat_processus).s_liste_variables[i] - .niveau == 1)) - { - presence_variable = d_vrai; - break; - } - - i--; - } - - (*s_etat_processus).position_variable_courante = i; + (*s_etat_processus).erreur_systeme = d_es; - if (presence_variable == d_faux) + if ((*s_etat_processus).erreur_execution == d_ex) { (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; - return; } - if ((*s_etat_processus).s_liste_variables[i].objet == NULL) - { - (*s_etat_processus).erreur_execution = d_ex_variable_partagee; - return; - } - } - else - { - (*s_etat_processus).erreur_systeme = d_es; - (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; return; } if ((s_objet_variable = copie_objet(s_etat_processus, - ((*s_etat_processus).s_liste_variables) - [(*s_etat_processus).position_variable_courante].objet, 'P')) + (*(*s_etat_processus).pointeur_variable_courante).objet, 'P')) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -961,20 +929,45 @@ instruction_recall(struct_processus *s_e int caractere; int ios; + logical1 drapeau_fin; + logical1 indicateur_48; + logical1 presence_chaine; + long i; long nombre_caracteres_source; struct_objet *s_objet; - struct_objet *s_objet_temporaire; + unsigned char autorisation_empilement_programme; + unsigned char *chaine; unsigned char *commande; + unsigned char *executable_candidat; + +# ifndef OS2 unsigned char *instructions = "%s/bin/rpliconv %s " "`%s/bin/rplfile " - "-m %s/share/rplfiles -i %s | awk " - "'{ print $3; }' | awk -F= '{ if " + "-m %s/share/rplfiles -i %s | " + "%s/bin/rplawk " + "'{ print $3; }' | %s/bin/rplawk -F= '{ if " "($2 != \"\") printf(\"-f %%s\", $2); }'` " "-t `locale charmap` | %s/bin/%s -o %s"; +# else + unsigned char *instructions = BOURNE_SHELL + " -c \"%s/bin/rpliconv %s " + "`%s/bin/rplfile " + "-m %s/share/rplfiles -i %s | " + "%s/bin/rplawk " + "'{ print $3; }' | %s/bin/rplawk -F= '{ if " + "($2 != \\\"\\\") printf(\\\"-f %%s\\\", " + "$2); }'` -t `" d_locale + "` | %s/bin/%s -o %s\""; +# endif + unsigned char *nom_fichier_temporaire; + unsigned char *tampon_definitions_chainees; + unsigned char *tampon_instruction_courante; + + unsigned long position_courante; (*s_etat_processus).erreur_execution = d_ex; @@ -1044,20 +1037,173 @@ instruction_recall(struct_processus *s_e return; } - if ((commande = malloc((strlen(ds_preprocesseur) + - (2 * strlen((unsigned char *) (*s_objet).objet)) + - (4 * strlen(d_exec_path)) + - strlen(nom_fichier_temporaire) + strlen(instructions) - 11) * - sizeof(unsigned char))) == NULL) + if ((*s_etat_processus).rpl_home == NULL) { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; + if ((commande = malloc((strlen(ds_preprocesseur) + + (2 * strlen((unsigned char *) (*s_objet).objet)) + + (6 * strlen(d_exec_path)) + + strlen(nom_fichier_temporaire) + strlen(instructions) - 19) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + sprintf(commande, instructions, d_exec_path, + (unsigned char *) (*s_objet).objet, + d_exec_path, d_exec_path, + (unsigned char *) (*s_objet).objet, + d_exec_path, d_exec_path, + d_exec_path, ds_preprocesseur, nom_fichier_temporaire); + + if (alsprintf(&executable_candidat, "%s/bin/rpliconv", + d_exec_path) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rpliconv") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplfile", + d_exec_path) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplfile") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplpp", + d_exec_path) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplpp") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplawk", + d_exec_path) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplawk") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); } + else + { + if ((commande = malloc((strlen(ds_preprocesseur) + + (2 * strlen((unsigned char *) (*s_objet).objet)) + + (6 * strlen((*s_etat_processus).rpl_home)) + + strlen(nom_fichier_temporaire) + strlen(instructions) - 19) + * sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + sprintf(commande, instructions, (*s_etat_processus).rpl_home, + (unsigned char *) (*s_objet).objet, + (*s_etat_processus).rpl_home, (*s_etat_processus).rpl_home, + (unsigned char *) (*s_objet).objet, + (*s_etat_processus).rpl_home, (*s_etat_processus).rpl_home, + (*s_etat_processus).rpl_home, ds_preprocesseur, + nom_fichier_temporaire); - sprintf(commande, instructions, d_exec_path, - (unsigned char *) (*s_objet).objet, - d_exec_path, d_exec_path, (unsigned char *) (*s_objet).objet, - d_exec_path, ds_preprocesseur, nom_fichier_temporaire); + if (alsprintf(&executable_candidat, "%s/bin/rpliconv", + (*s_etat_processus).rpl_home) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rpliconv") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplfile", + (*s_etat_processus).rpl_home) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplfile") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplpp", + (*s_etat_processus).rpl_home) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplpp") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + + if (alsprintf(&executable_candidat, "%s/bin/rplawk", + d_exec_path) < 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (controle_integrite(s_etat_processus, executable_candidat, + "rplawk") != d_vrai) + { + (*s_etat_processus).erreur_systeme = d_es_somme_controle; + return; + } + + free(executable_candidat); + } if ((pipe = popen(commande, "r")) == NULL) { @@ -1116,13 +1262,7 @@ instruction_recall(struct_processus *s_e return; } - if ((s_objet_temporaire = allocation(s_etat_processus, CHN)) == NULL) - { - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; - } - - if (((*s_objet_temporaire).objet = malloc((nombre_caracteres_source + 1) + if ((chaine = malloc((nombre_caracteres_source + 1) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1132,35 +1272,67 @@ instruction_recall(struct_processus *s_e rewind(pipe); i = 0; - while((caractere = getc(pipe)) != EOF) + drapeau_fin = d_faux; + presence_chaine = d_faux; + + while(drapeau_fin == d_faux) { - if ((caractere == d_code_retour_chariot) || - (caractere == d_code_tabulation)) + if ((caractere = getc(pipe)) != EOF) { - do + if ((caractere == d_code_retour_chariot) || + (caractere == d_code_tabulation) || + ((caractere == d_code_espace) && + (presence_chaine == d_faux))) { - caractere = getc(pipe); - } while(((caractere == d_code_retour_chariot) || - (caractere == d_code_tabulation)) && - (caractere != EOF)); + do + { + caractere = getc(pipe); + } while(((caractere == d_code_retour_chariot) || + (caractere == d_code_tabulation) || + ((caractere == d_code_espace) && + (presence_chaine == d_faux))) && + (caractere != EOF)); - if (caractere != EOF) + if (caractere != EOF) + { + chaine[i++] = d_code_espace; + } + else + { + drapeau_fin = d_vrai; + } + } + + if ((chaine[i] = caractere) == '\"') + { + if (i > 0) + { + if (chaine[i - 1] != '\\') + { + presence_chaine = (presence_chaine == d_faux) + ? d_vrai : d_faux; + } + } + + i++; + } + else { - ((unsigned char *) (*s_objet_temporaire).objet)[i++] = - d_code_espace; + i++; } } - - ((unsigned char *) (*s_objet_temporaire).objet)[i++] = - caractere; + else + { + drapeau_fin = d_vrai; + } } - if (caractere == EOF) + if ((caractere == EOF) && (i > 0)) { i--; } - ((unsigned char *) (*s_objet_temporaire).objet)[i] = d_code_fin_chaine; + chaine[i] = d_code_fin_chaine; if (fclose(pipe) != 0) { @@ -1168,14 +1340,157 @@ instruction_recall(struct_processus *s_e return; } - if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - s_objet_temporaire) == d_erreur) + indicateur_48 = test_cfsf(s_etat_processus, 48); + cf(s_etat_processus, 48); + + tampon_definitions_chainees = (*s_etat_processus).definitions_chainees; + tampon_instruction_courante = (*s_etat_processus).instruction_courante; + position_courante = (*s_etat_processus).position_courante; + autorisation_empilement_programme = (*s_etat_processus) + .autorisation_empilement_programme; + + (*s_etat_processus).instruction_courante = NULL; + + if (((*s_etat_processus).definitions_chainees = transliteration( + s_etat_processus, chaine, "UTF-8", d_locale)) == NULL) + { + if (indicateur_48 == d_vrai) + { + sf(s_etat_processus, 48); + } + else + { + cf(s_etat_processus, 48); + } + + if (destruction_fichier(nom_fichier_temporaire) == d_erreur) + { + (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; + return; + } + + free(nom_fichier_temporaire); + free((*s_etat_processus).instruction_courante); + free(chaine); + + (*s_etat_processus).position_courante = position_courante; + (*s_etat_processus).instruction_courante = + tampon_instruction_courante; + (*s_etat_processus).definitions_chainees = + tampon_definitions_chainees; + (*s_etat_processus).autorisation_empilement_programme = + autorisation_empilement_programme; + + liberation(s_etat_processus, s_objet); + return; + } + + (*s_etat_processus).autorisation_empilement_programme = 'Y'; + (*s_etat_processus).position_courante = 0; + + if (analyse_syntaxique(s_etat_processus) == d_erreur) + { + if (indicateur_48 == d_vrai) + { + sf(s_etat_processus, 48); + } + else + { + cf(s_etat_processus, 48); + } + + if (destruction_fichier(nom_fichier_temporaire) == d_erreur) + { + (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; + return; + } + + free(nom_fichier_temporaire); + free((*s_etat_processus).instruction_courante); + free((*s_etat_processus).definitions_chainees); + free(chaine); + + (*s_etat_processus).position_courante = position_courante; + (*s_etat_processus).instruction_courante = + tampon_instruction_courante; + (*s_etat_processus).definitions_chainees = + tampon_definitions_chainees; + (*s_etat_processus).autorisation_empilement_programme = + autorisation_empilement_programme; + + liberation(s_etat_processus, s_objet); + return; + } + + (*s_etat_processus).position_courante = 0; + + if (recherche_instruction_suivante(s_etat_processus) != + d_absence_erreur) { + if (indicateur_48 == d_vrai) + { + sf(s_etat_processus, 48); + } + else + { + cf(s_etat_processus, 48); + } + + if (destruction_fichier(nom_fichier_temporaire) == d_erreur) + { + (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; + return; + } + free(nom_fichier_temporaire); + free((*s_etat_processus).instruction_courante); + free((*s_etat_processus).definitions_chainees); + free(chaine); + + (*s_etat_processus).position_courante = position_courante; + (*s_etat_processus).instruction_courante = + tampon_instruction_courante; + (*s_etat_processus).definitions_chainees = + tampon_definitions_chainees; + (*s_etat_processus).autorisation_empilement_programme = + autorisation_empilement_programme; + + liberation(s_etat_processus, s_objet); return; } - instruction_str_fleche(s_etat_processus); + recherche_type(s_etat_processus); + + while((*s_etat_processus).definitions_chainees + [(*s_etat_processus).position_courante] != d_code_fin_chaine) + { + if ((*s_etat_processus).definitions_chainees + [(*s_etat_processus).position_courante++] != d_code_espace) + { + (*s_etat_processus).erreur_execution = d_ex_syntaxe; + } + } + + free((*s_etat_processus).instruction_courante); + free((*s_etat_processus).definitions_chainees); + free(chaine); + + (*s_etat_processus).position_courante = position_courante; + (*s_etat_processus).instruction_courante = + tampon_instruction_courante; + (*s_etat_processus).definitions_chainees = + tampon_definitions_chainees; + (*s_etat_processus).autorisation_empilement_programme = + autorisation_empilement_programme; + + if (indicateur_48 == d_vrai) + { + sf(s_etat_processus, 48); + } + else + { + cf(s_etat_processus, 48); + } if (destruction_fichier(nom_fichier_temporaire) == d_erreur) { @@ -1295,10 +1610,6 @@ instruction_rcws(struct_processus *s_eta void instruction_rcls(struct_processus *s_etat_processus) { - logical1 presence_variable; - - long i; - struct_objet *s_objet_variable; (*s_etat_processus).erreur_execution = d_ex; @@ -1339,48 +1650,20 @@ instruction_rcls(struct_processus *s_eta } } - if (recherche_variable(s_etat_processus, ds_sdat) == d_vrai) + if (recherche_variable_globale(s_etat_processus, ds_sdat) == d_faux) { - i = (*s_etat_processus).position_variable_courante; - presence_variable = d_faux; - - while(i >= 0) - { - if ((strcmp((*s_etat_processus).s_liste_variables[i].nom, ds_sdat) - == 0) && ((*s_etat_processus).s_liste_variables[i] - .niveau == 1)) - { - presence_variable = d_vrai; - break; - } - - i--; - } - - (*s_etat_processus).position_variable_courante = i; + (*s_etat_processus).erreur_systeme = d_es; - if (presence_variable == d_faux) + if ((*s_etat_processus).erreur_execution == d_ex) { (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; - return; } - if ((*s_etat_processus).s_liste_variables[i].objet == NULL) - { - (*s_etat_processus).erreur_execution = d_ex_variable_partagee; - return; - } - } - else - { - (*s_etat_processus).erreur_systeme = d_es; - (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; return; } if ((s_objet_variable = copie_objet(s_etat_processus, - ((*s_etat_processus).s_liste_variables) - [(*s_etat_processus).position_variable_courante].objet, 'O')) + (*(*s_etat_processus).pointeur_variable_courante).objet, 'O')) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;