Annotation of rpl/src/instructions_r7.c, revision 1.16
1.1 bertrand 1: /*
2: ================================================================================
1.15 bertrand 3: RPL/2 (R) version 4.1.13
1.14 bertrand 4: Copyright (C) 1989-2013 Dr. BERTRAND Joël
1.1 bertrand 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 'restart'
29: ================================================================================
30: Entrées : pointeur sur une structure struct_processus
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_restart(struct_processus *s_etat_processus)
40: {
41: struct timespec attente;
42:
43: (*s_etat_processus).erreur_execution = d_ex;
44:
45: if ((*s_etat_processus).affichage_arguments == 'Y')
46: {
47: printf("\n RESTART ");
48:
49: if ((*s_etat_processus).langue == 'F')
50: {
51: printf("(réinitialisation du programme)\n\n");
52: printf(" Aucun argument\n");
53: }
54: else
55: {
56: printf("(program reinitialization)\n\n");
57: printf(" No argument\n");
58: }
59:
60: return;
61: }
62: else if ((*s_etat_processus).test_instruction == 'Y')
63: {
64: (*s_etat_processus).nombre_arguments = -1;
65: return;
66: }
67:
68: if (test_cfsf(s_etat_processus, 31) == d_vrai)
69: {
70: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
71: {
72: return;
73: }
74: }
75:
76: envoi_signal_processus((*s_etat_processus).pid_processus_pere,
77: rpl_sigabort);
78: (*s_etat_processus).requete_arret = 'Y';
79:
80: attente.tv_sec = 0;
81: attente.tv_nsec = GRANULARITE_us * 1000;
82:
83: while((*s_etat_processus).var_volatile_requete_arret == 0)
84: {
85: scrutation_interruptions(s_etat_processus);
86: nanosleep(&attente, NULL);
87: INCR_GRANULARITE(attente.tv_nsec);
88: }
89:
90: if ((*s_etat_processus).traitement_instruction_halt == d_vrai)
91: {
92: (*s_etat_processus).execution_pas_suivant = d_vrai;
93: }
94:
95: (*s_etat_processus).requete_redemarrage = d_vrai;
96: return;
97: }
98:
1.2 bertrand 99:
100: /*
101: ================================================================================
102: Fonction 'regex'
103: ================================================================================
104: Entrées : pointeur sur une structure struct_processus
105: --------------------------------------------------------------------------------
106: Sorties :
107: --------------------------------------------------------------------------------
108: Effets de bord : néant
109: ================================================================================
110: */
111:
112: void
113: instruction_regex(struct_processus *s_etat_processus)
114: {
115: regex_t expression;
116:
117: struct_liste_chainee *l_element_courant_ecriture;
118: struct_liste_chainee *l_element_courant_lecture;
119:
120: struct_objet *s_objet_argument_1;
121: struct_objet *s_objet_argument_2;
122: struct_objet *s_objet_resultat;
123:
124: (*s_etat_processus).erreur_execution = d_ex;
125:
126: if ((*s_etat_processus).affichage_arguments == 'Y')
127: {
128: printf("\n REGEX ");
129:
130: if ((*s_etat_processus).langue == 'F')
131: {
132: printf("(expression régulière)\n\n");
133: }
134: else
135: {
136: printf("(regular expression)\n\n");
137: }
138:
1.16 ! bertrand 139: printf(" 1: %s\n", d_LST);
! 140: printf(" 1: %s\n", d_CHN);
1.2 bertrand 141: printf("-> 1: %s\n\n", d_LST);
142:
1.16 ! bertrand 143: printf(" 2: %s\n", d_CHN);
1.2 bertrand 144: printf(" 1: %s\n", d_CHN);
145: printf("-> 1: %s (0 or -1)\n", d_INT);
146:
147: return;
148: }
149: else if ((*s_etat_processus).test_instruction == 'Y')
150: {
151: (*s_etat_processus).nombre_arguments = 2;
152: return;
153: }
154:
155: if (test_cfsf(s_etat_processus, 31) == d_vrai)
156: {
157: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
158: {
159: return;
160: }
161: }
162:
163: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
164: &s_objet_argument_1) == d_erreur)
165: {
166: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
167: return;
168: }
169:
170: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
171: &s_objet_argument_2) == d_erreur)
172: {
173: liberation(s_etat_processus, s_objet_argument_1);
174:
175: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
176: return;
177: }
178:
179: if (((*s_objet_argument_1).type == CHN) &&
180: ((*s_objet_argument_2).type == CHN))
181: {
182: // Renvoie 0 ou -1
183:
184: if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
185: REG_EXTENDED | REG_NOSUB) != 0)
186: {
187: liberation(s_etat_processus, s_objet_argument_1);
188: liberation(s_etat_processus, s_objet_argument_2);
189:
190: (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
191: return;
192: }
193:
194: if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
195: {
196: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
197: return;
198: }
199:
1.4 bertrand 200: if (regexec(&expression, (const char *) (*s_objet_argument_2).objet,
1.2 bertrand 201: 0, NULL, 0) == 0)
202: {
203: (*((integer8 *) (*s_objet_resultat).objet)) = -1;
204: }
205: else // REG_NOMATCH
206: {
207: (*((integer8 *) (*s_objet_resultat).objet)) = 0;
208: }
209:
210: regfree(&expression);
211: }
212: else if (((*s_objet_argument_1).type == CHN) &&
213: ((*s_objet_argument_2).type == LST))
214: {
215: // Renvoie une liste de chaînes qui correspondent
216:
217: if (regcomp(&expression, (const char *) (*s_objet_argument_1).objet,
218: REG_EXTENDED | REG_NOSUB) != 0)
219: {
220: liberation(s_etat_processus, s_objet_argument_1);
221: liberation(s_etat_processus, s_objet_argument_2);
222:
223: (*s_etat_processus).erreur_execution = d_ex_expression_reguliere;
224: return;
225: }
226:
227: if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
228: {
229: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
230: return;
231: }
232:
233: l_element_courant_lecture = (*s_objet_argument_2).objet;
234: l_element_courant_ecriture = NULL;
235:
236: while(l_element_courant_lecture != NULL)
237: {
238: if ((*(*l_element_courant_lecture).donnee).type != CHN)
239: {
1.3 bertrand 240: regfree(&expression);
1.2 bertrand 241: liberation(s_etat_processus, s_objet_argument_1);
242: liberation(s_etat_processus, s_objet_argument_2);
243: liberation(s_etat_processus, s_objet_resultat);
244:
245: (*s_etat_processus).erreur_execution =
246: d_ex_erreur_type_argument;
247: return;
248: }
249:
250: if (regexec(&expression, (const char *)
251: (*(*l_element_courant_lecture).donnee).objet,
252: 0, NULL, 0) == 0)
253: {
254: if (l_element_courant_ecriture == NULL)
255: {
256: if (((*s_objet_resultat).objet =
257: allocation_maillon(s_etat_processus)) == NULL)
258: {
259: (*s_etat_processus).erreur_systeme =
260: d_es_allocation_memoire;
261: return;
262: }
263:
264: l_element_courant_ecriture = (*s_objet_resultat).objet;
265:
266: if (((*l_element_courant_ecriture).donnee =
267: copie_objet(s_etat_processus,
268: (*l_element_courant_lecture).donnee, 'P'))
269: == NULL)
270: {
271: (*s_etat_processus).erreur_systeme =
272: d_es_allocation_memoire;
273: return;
274: }
275:
276: (*l_element_courant_ecriture).suivant = NULL;
277: }
278: else
279: {
280: if (((*l_element_courant_ecriture).suivant =
281: allocation_maillon(s_etat_processus)) == NULL)
282: {
283: (*s_etat_processus).erreur_systeme =
284: d_es_allocation_memoire;
285: return;
286: }
287:
288: l_element_courant_ecriture =
289: (*l_element_courant_ecriture).suivant;
290:
291: if (((*l_element_courant_ecriture).donnee =
292: copie_objet(s_etat_processus,
293: (*l_element_courant_lecture).donnee, 'P'))
294: == NULL)
295: {
296: (*s_etat_processus).erreur_systeme =
297: d_es_allocation_memoire;
298: return;
299: }
300:
301: (*l_element_courant_ecriture).suivant = NULL;
302: }
303: }
304:
305: l_element_courant_lecture = (*l_element_courant_lecture).suivant;
306: }
307:
308: regfree(&expression);
309: }
310: else
311: {
312: liberation(s_etat_processus, s_objet_argument_1);
313: liberation(s_etat_processus, s_objet_argument_2);
314:
315: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
316: return;
317: }
318:
319: liberation(s_etat_processus, s_objet_argument_1);
320: liberation(s_etat_processus, s_objet_argument_2);
321:
322: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
323: s_objet_resultat) == d_erreur)
324: {
325: return;
326: }
327:
328: return;
329: }
330:
1.1 bertrand 331: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>