/* ================================================================================ RPL/2 (R) version 4.1.12 Copyright (C) 1989-2013 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" /* ================================================================================ Fonction 'srev' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_srev(struct_processus *s_etat_processus) { struct_objet *s_objet_argument; struct_objet *s_objet_resultat; unsigned char *ptr_e; unsigned char *ptr_l; unsigned int i; unsigned int saut; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n SREV "); if ((*s_etat_processus).langue == 'F') { printf("(inversion d'une chaîne)\n\n"); } else { printf("(string inversion)\n\n"); } printf(" 1: %s\n", d_CHN); printf("-> 1: %s\n", d_CHN); return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = 0; return; } if (test_cfsf(s_etat_processus, 31) == d_vrai) { if (empilement_pile_last(s_etat_processus, 1) == d_erreur) { return; } } if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), &s_objet_argument) == d_erreur) { (*s_etat_processus).erreur_execution = d_ex_manque_argument; return; } if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*s_objet_resultat).objet = malloc((strlen((unsigned char *) (*s_objet_argument).objet) + 1) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } ptr_l = (unsigned char *) (*s_objet_argument).objet; ptr_e = ((unsigned char *) (*s_objet_resultat).objet) + strlen((unsigned char *) (*s_objet_argument).objet); (*ptr_e) = d_code_fin_chaine; while((*ptr_l) != d_code_fin_chaine) { if ((*ptr_l) == '\\') { // On n'inverse pas une séquence d'échappement. // Les séquences d'échappement valides sont : // '\\', '\"', '\b', '\n', '\t' et '\x??'. switch(*(ptr_l + 1)) { case '\\': case '"': case 'b': case 'n': case 't': { saut = 2; break; } case 'x': { saut = 4; break; } default: { saut = 0; break; } } for(i = 0; i < saut; i++) { if (*(ptr_l + i) == d_code_fin_chaine) { saut = i; break; } (*((ptr_e - saut) + i)) = (*(ptr_l + i)); } ptr_e -= saut; ptr_l += saut; } else { ptr_e--; (*ptr_e) = (*ptr_l); ptr_l++; } } liberation(s_etat_processus, s_objet_argument); if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) { return; } return; } // vim: ts=4