1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.21
4: Copyright (C) 1989-2015 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 '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:
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:
139: printf(" 2: %s\n", d_LST);
140: printf(" 1: %s\n", d_CHN);
141: printf("-> 1: %s\n\n", d_LST);
142:
143: printf(" 2: %s\n", d_CHN);
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 = -1;
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:
200: if (regexec(&expression, (const char *) (*s_objet_argument_2).objet,
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: {
240: regfree(&expression);
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:
331:
332: /*
333: ================================================================================
334: Fonction 'rgdl'
335: ================================================================================
336: Entrées : pointeur sur une structure struct_processus
337: --------------------------------------------------------------------------------
338: Sorties :
339: --------------------------------------------------------------------------------
340: Effets de bord : néant
341: ================================================================================
342: */
343:
344: void
345: instruction_rgdl(struct_processus *s_etat_processus)
346: {
347: integer8 i;
348: integer8 l;
349:
350: struct_objet *s_objet_argument_1;
351: struct_objet *s_objet_argument_2;
352: struct_objet *s_objet_argument_3;
353: struct_objet *s_objet_resultat;
354:
355: unsigned char *ptr_e;
356: unsigned char *ptr_l;
357:
358: (*s_etat_processus).erreur_execution = d_ex;
359:
360: if ((*s_etat_processus).affichage_arguments == 'Y')
361: {
362: printf("\n RGDL ");
363:
364: if ((*s_etat_processus).langue == 'F')
365: {
366: printf("(fer à droite)\n\n");
367: }
368: else
369: {
370: printf("(ragged left)\n\n");
371: }
372:
373: printf(" 3: %s\n", d_CHN);
374: printf(" 2: %s\n", d_INT);
375: printf(" 1: %s\n", d_CHN);
376: printf("-> 1: %s\n", d_CHN);
377:
378: return;
379: }
380: else if ((*s_etat_processus).test_instruction == 'Y')
381: {
382: (*s_etat_processus).nombre_arguments = -1;
383: return;
384: }
385:
386: if (test_cfsf(s_etat_processus, 31) == d_vrai)
387: {
388: if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
389: {
390: return;
391: }
392: }
393:
394: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
395: &s_objet_argument_1) == d_erreur)
396: {
397: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
398: return;
399: }
400:
401: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
402: &s_objet_argument_2) == d_erreur)
403: {
404: liberation(s_etat_processus, s_objet_argument_1);
405:
406: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
407: return;
408: }
409:
410: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
411: &s_objet_argument_3) == d_erreur)
412: {
413: liberation(s_etat_processus, s_objet_argument_1);
414: liberation(s_etat_processus, s_objet_argument_2);
415:
416: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
417: return;
418: }
419:
420: if (((*s_objet_argument_1).type == CHN) &&
421: ((*s_objet_argument_2).type == INT) &&
422: ((*s_objet_argument_3).type == CHN))
423: {
424: if ((strlen((unsigned char *) (*s_objet_argument_1).objet) != 1) ||
425: ((*((integer8 *) (*s_objet_argument_2).objet)) < 0))
426: {
427: liberation(s_etat_processus, s_objet_argument_1);
428: liberation(s_etat_processus, s_objet_argument_2);
429: liberation(s_etat_processus, s_objet_argument_3);
430:
431: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
432: return;
433: }
434:
435: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
436: {
437: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
438: return;
439: }
440:
441: if (((*s_objet_resultat).objet = malloc(((size_t) ((*((integer8 *)
442: (*s_objet_argument_2).objet)) + 1)) * sizeof(unsigned char)))
443: == NULL)
444: {
445: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
446: return;
447: }
448:
449: if (((l = (integer8) strlen((unsigned char *) (*s_objet_argument_3)
450: .objet))) >= (*((integer8 *) (*s_objet_argument_2).objet)))
451: {
452: // Recadrage simple
453:
454: ptr_e = (unsigned char *) (*s_objet_resultat).objet;
455: ptr_l = ((unsigned char *) (*s_objet_argument_3).objet)
456: + (l - (*((integer8 *) (*s_objet_argument_2).objet)));
457:
458: while((*ptr_l) != d_code_fin_chaine)
459: {
460: *ptr_e++ = *ptr_l++;
461: }
462:
463: (*ptr_e) = d_code_fin_chaine;
464: }
465: else
466: {
467: // Ajout des caractères
468:
469: ptr_e = (unsigned char *) (*s_objet_resultat).objet;
470: ptr_l = (unsigned char *) (*s_objet_argument_3).objet;
471:
472: for(i = 0; i < (*((integer8 *) (*s_objet_argument_2).objet)) - l;
473: i++)
474: {
475: *ptr_e++ = ((unsigned char *) (*s_objet_argument_1).objet)[0];
476: }
477:
478: while((*ptr_l) != d_code_fin_chaine)
479: {
480: *ptr_e++ = *ptr_l++;
481: }
482:
483: (*ptr_e) = d_code_fin_chaine;
484: }
485: }
486: else
487: {
488: liberation(s_etat_processus, s_objet_argument_1);
489: liberation(s_etat_processus, s_objet_argument_2);
490: liberation(s_etat_processus, s_objet_argument_3);
491:
492: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
493: return;
494: }
495:
496: liberation(s_etat_processus, s_objet_argument_1);
497: liberation(s_etat_processus, s_objet_argument_2);
498: liberation(s_etat_processus, s_objet_argument_3);
499:
500: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
501: s_objet_resultat) == d_erreur)
502: {
503: return;
504: }
505:
506: return;
507: }
508:
509:
510: /*
511: ================================================================================
512: Fonction 'rgdr'
513: ================================================================================
514: Entrées : pointeur sur une structure struct_processus
515: --------------------------------------------------------------------------------
516: Sorties :
517: --------------------------------------------------------------------------------
518: Effets de bord : néant
519: ================================================================================
520: */
521:
522: void
523: instruction_rgdr(struct_processus *s_etat_processus)
524: {
525: integer8 i;
526: integer8 l;
527:
528: struct_objet *s_objet_argument_1;
529: struct_objet *s_objet_argument_2;
530: struct_objet *s_objet_argument_3;
531: struct_objet *s_objet_resultat;
532:
533: unsigned char *ptr_e;
534: unsigned char *ptr_l;
535:
536: (*s_etat_processus).erreur_execution = d_ex;
537:
538: if ((*s_etat_processus).affichage_arguments == 'Y')
539: {
540: printf("\n RGDR ");
541:
542: if ((*s_etat_processus).langue == 'F')
543: {
544: printf("(fer à gauche)\n\n");
545: }
546: else
547: {
548: printf("(ragged right)\n\n");
549: }
550:
551: printf(" 3: %s\n", d_CHN);
552: printf(" 2: %s\n", d_INT);
553: printf(" 1: %s\n", d_CHN);
554: printf("-> 1: %s\n", d_CHN);
555:
556: return;
557: }
558: else if ((*s_etat_processus).test_instruction == 'Y')
559: {
560: (*s_etat_processus).nombre_arguments = -1;
561: return;
562: }
563:
564: if (test_cfsf(s_etat_processus, 31) == d_vrai)
565: {
566: if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
567: {
568: return;
569: }
570: }
571:
572: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
573: &s_objet_argument_1) == d_erreur)
574: {
575: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
576: return;
577: }
578:
579: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
580: &s_objet_argument_2) == d_erreur)
581: {
582: liberation(s_etat_processus, s_objet_argument_1);
583:
584: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
585: return;
586: }
587:
588: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
589: &s_objet_argument_3) == d_erreur)
590: {
591: liberation(s_etat_processus, s_objet_argument_1);
592: liberation(s_etat_processus, s_objet_argument_2);
593:
594: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
595: return;
596: }
597:
598: if (((*s_objet_argument_1).type == CHN) &&
599: ((*s_objet_argument_2).type == INT) &&
600: ((*s_objet_argument_3).type == CHN))
601: {
602: if ((strlen((unsigned char *) (*s_objet_argument_1).objet) != 1) ||
603: ((*((integer8 *) (*s_objet_argument_2).objet)) < 0))
604: {
605: liberation(s_etat_processus, s_objet_argument_1);
606: liberation(s_etat_processus, s_objet_argument_2);
607: liberation(s_etat_processus, s_objet_argument_3);
608:
609: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
610: return;
611: }
612:
613: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
614: {
615: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
616: return;
617: }
618:
619: if (((*s_objet_resultat).objet = malloc(((size_t) ((*((integer8 *)
620: (*s_objet_argument_2).objet)) + 1)) * sizeof(unsigned char)))
621: == NULL)
622: {
623: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
624: return;
625: }
626:
627: if (((l = (integer8) strlen((unsigned char *) (*s_objet_argument_3)
628: .objet))) >= (*((integer8 *) (*s_objet_argument_2).objet)))
629: {
630: // Recadrage simple
631:
632: ptr_e = (unsigned char *) (*s_objet_resultat).objet;
633: ptr_l = ((unsigned char *) (*s_objet_argument_3).objet);
634:
635: for(i = 0; i < (*((integer8 *) (*s_objet_argument_2).objet)); i++)
636: {
637: *ptr_e++ = *ptr_l++;
638: }
639:
640: (*ptr_e) = d_code_fin_chaine;
641: }
642: else
643: {
644: // Ajout des caractères
645:
646: ptr_e = (unsigned char *) (*s_objet_resultat).objet;
647: ptr_l = (unsigned char *) (*s_objet_argument_3).objet;
648:
649: while((*ptr_l) != d_code_fin_chaine)
650: {
651: *ptr_e++ = *ptr_l++;
652: }
653:
654: for(i = 0; i < (*((integer8 *) (*s_objet_argument_2).objet)) - l;
655: i++)
656: {
657: *ptr_e++ = ((unsigned char *) (*s_objet_argument_1).objet)[0];
658: }
659:
660: (*ptr_e) = d_code_fin_chaine;
661: }
662: }
663: else
664: {
665: liberation(s_etat_processus, s_objet_argument_1);
666: liberation(s_etat_processus, s_objet_argument_2);
667: liberation(s_etat_processus, s_objet_argument_3);
668:
669: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
670: return;
671: }
672:
673: liberation(s_etat_processus, s_objet_argument_1);
674: liberation(s_etat_processus, s_objet_argument_2);
675: liberation(s_etat_processus, s_objet_argument_3);
676:
677: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
678: s_objet_resultat) == d_erreur)
679: {
680: return;
681: }
682:
683: return;
684: }
685:
686: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>