1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.36
4: Copyright (C) 1989-2025 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: Fonction 'srev'
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_srev(struct_processus *s_etat_processus)
40: {
41: struct_objet *s_objet_argument;
42: struct_objet *s_objet_resultat;
43:
44: unsigned char *ptr_e;
45: unsigned char *ptr_l;
46:
47: unsigned int i;
48: unsigned int saut;
49:
50: if ((*s_etat_processus).affichage_arguments == 'Y')
51: {
52: printf("\n SREV ");
53:
54: if ((*s_etat_processus).langue == 'F')
55: {
56: printf("(inversion d'une chaîne)\n\n");
57: }
58: else
59: {
60: printf("(string inversion)\n\n");
61: }
62:
63: printf(" 1: %s\n", d_CHN);
64: printf("-> 1: %s\n", d_CHN);
65:
66: return;
67: }
68: else if ((*s_etat_processus).test_instruction == 'Y')
69: {
70: (*s_etat_processus).nombre_arguments = 0;
71: return;
72: }
73:
74: if (test_cfsf(s_etat_processus, 31) == d_vrai)
75: {
76: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
77: {
78: return;
79: }
80: }
81:
82: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
83: &s_objet_argument) == d_erreur)
84: {
85: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
86: return;
87: }
88:
89: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
90: {
91: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
92: return;
93: }
94:
95: if (((*s_objet_resultat).objet = malloc((strlen((unsigned char *)
96: (*s_objet_argument).objet) + 1) * sizeof(unsigned char))) == NULL)
97: {
98: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
99: return;
100: }
101:
102: ptr_l = (unsigned char *) (*s_objet_argument).objet;
103: ptr_e = ((unsigned char *) (*s_objet_resultat).objet) +
104: strlen((unsigned char *) (*s_objet_argument).objet);
105: (*ptr_e) = d_code_fin_chaine;
106:
107: while((*ptr_l) != d_code_fin_chaine)
108: {
109: if ((*ptr_l) == '\\')
110: {
111: // On n'inverse pas une séquence d'échappement.
112: // Les séquences d'échappement valides sont :
113: // '\\', '\"', '\b', '\n', '\t' et '\x??'.
114:
115: switch(*(ptr_l + 1))
116: {
117: case '\\':
118: case '"':
119: case 'b':
120: case 'n':
121: case 't':
122: {
123: saut = 2;
124: break;
125: }
126:
127: case 'x':
128: {
129: saut = 4;
130: break;
131: }
132:
133: default:
134: {
135: saut = 0;
136: break;
137: }
138: }
139:
140: for(i = 0; i < saut; i++)
141: {
142: if (*(ptr_l + i) == d_code_fin_chaine)
143: {
144: saut = i;
145: break;
146: }
147:
148: (*((ptr_e - saut) + i)) = (*(ptr_l + i));
149: }
150:
151: ptr_e -= saut;
152: ptr_l += saut;
153: }
154: else
155: {
156: ptr_e--;
157: (*ptr_e) = (*ptr_l);
158: ptr_l++;
159: }
160: }
161:
162: liberation(s_etat_processus, s_objet_argument);
163:
164: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
165: s_objet_resultat) == d_erreur)
166: {
167: return;
168: }
169:
170: return;
171: }
172:
173: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>