/* ================================================================================ RPL/2 (R) version 4.1.14 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 'kill' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_kill(struct_processus *s_etat_processus) { (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n KILL "); if ((*s_etat_processus).langue == 'F') { printf("(abandon du processus en cours)\n\n"); printf(" Aucun argument\n"); } else { printf("(current process abort)\n\n"); printf(" No argument\n"); } return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; return; } if (test_cfsf(s_etat_processus, 31) == d_vrai) { if (empilement_pile_last(s_etat_processus, 0) == d_erreur) { return; } } (*s_etat_processus).requete_arret = 'Y'; if ((*s_etat_processus).traitement_instruction_halt == d_vrai) { (*s_etat_processus).execution_pas_suivant = d_vrai; } return; } /* ================================================================================ Fonction 'key' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_key(struct_processus *s_etat_processus) { int unite; struct_objet *s_objet_caractere; struct_objet *s_objet_drapeau; struct termios tp; tcflag_t drapeaux; unsigned char caractere; (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n KEY "); if ((*s_etat_processus).langue == 'F') { printf("(saisit une entrée au vol)\n\n"); } else { printf("(non blocking character input)\n\n"); } printf("-> 1: %s (0)\n\n", d_INT); printf("-> 2: %s\n", d_CHN); printf(" 1: %s (-1)\n", d_INT); return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; return; } if (test_cfsf(s_etat_processus, 31) == d_vrai) { if (empilement_pile_last(s_etat_processus, 0) == d_erreur) { return; } } if (tcgetattr(0, &tp) == -1) { (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } drapeaux = (ECHO | ECHOK | ICANON); tp.c_lflag &= (~drapeaux); if (tcsetattr(0, TCSANOW, &tp) == -1) { (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } if ((unite = open(ttyname(0), O_NONBLOCK|O_NOCTTY)) == -1) { tp.c_lflag |= drapeaux; if (tcsetattr(0, TCSANOW, &tp) == -1) { (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } if ((s_objet_drapeau = allocation(s_etat_processus, INT)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (read_atomic(s_etat_processus, unite, (void *) &caractere, 1) == -1) { (*((integer8 *) (*s_objet_drapeau).objet)) = 0; if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_drapeau) == d_erreur) { return; } } else { if ((s_objet_caractere = allocation(s_etat_processus, CHN)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*s_objet_caractere).objet = malloc(2 * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } ((unsigned char *) (*s_objet_caractere).objet)[0] = caractere; ((unsigned char *) (*s_objet_caractere).objet)[1] = d_code_fin_chaine; if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_caractere) == d_erreur) { return; } (*((integer8 *) (*s_objet_drapeau).objet)) = -1; if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_drapeau) == d_erreur) { return; } } if (close(unite) == -1) { tp.c_lflag |= drapeaux; if (tcsetattr(0, TCSANOW, &tp) == -1) { (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } tp.c_lflag |= drapeaux; if (tcsetattr(0, TCSANOW, &tp) == -1) { (*s_etat_processus).erreur_systeme = d_es_peripherique_stdin; return; } return; } /* ================================================================================ Fonction 'kind' ================================================================================ Entrées : structure processus -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_kind(struct_processus *s_etat_processus) { struct_objet *s_objet_argument; struct_objet *s_objet_resultat; (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n KIND "); if ((*s_etat_processus).langue == 'F') { printf("(variété d'objet)\n\n"); } else { printf("(kind of object)\n\n"); } printf(" 1: %s, %s, %s, %s, %s, %s,\n" " %s, %s, %s\n", d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX); printf("-> 1: %s\n\n", d_INT); if ((*s_etat_processus).langue == 'F') { printf(" Valeurs renvoyées : \n\n"); printf(" 0 : objet entier\n"); printf(" 1 : objet réel\n"); printf(" 2 : objet complexe\n"); } else { printf(" Returned values : \n\n"); printf(" 0 : integer object\n"); printf(" 1 : real object\n"); printf(" 2 : complex object\n"); } return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; 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, INT)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (((*s_objet_argument).type == INT) || ((*s_objet_argument).type == VIN) || ((*s_objet_argument).type == MIN)) { (*((integer8 *) (*s_objet_resultat).objet)) = 0; } else if (((*s_objet_argument).type == REL) || ((*s_objet_argument).type == VRL) || ((*s_objet_argument).type == MRL)) { (*((integer8 *) (*s_objet_resultat).objet)) = 1; } else if (((*s_objet_argument).type == CPL) || ((*s_objet_argument).type == VCX) || ((*s_objet_argument).type == MCX)) { (*((integer8 *) (*s_objet_resultat).objet)) = 2; } else { /* * Les autres types de données sont des types non numériques. */ liberation(s_etat_processus, s_objet_argument); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } liberation(s_etat_processus, s_objet_argument); return; } /* ================================================================================ Fonction 'keytitle' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_keytitle(struct_processus *s_etat_processus) { struct_objet *s_objet; (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n KEYTITLE "); if ((*s_etat_processus).langue == 'F') { printf("(titre de la légende d'un graphique)\n\n"); } else { printf("(title of graphic key)\n\n"); } printf(" 1: %s\n", d_CHN); return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; 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) == d_erreur) { (*s_etat_processus).erreur_execution = d_ex_manque_argument; return; } if ((*s_objet).type == CHN) { free((*s_etat_processus).legende); if (((*s_etat_processus).legende = malloc((strlen((unsigned char *) (*s_objet).objet) + 1) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } strcpy((*s_etat_processus).legende, (unsigned char *) (*s_objet).objet); liberation(s_etat_processus, s_objet); (*s_etat_processus).mise_a_jour_trace_requise = d_vrai; } else { liberation(s_etat_processus, s_objet); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } return; } /* ================================================================================ Fonction 'keylabel' ================================================================================ Entrées : -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void instruction_keylabel(struct_processus *s_etat_processus) { struct_fichier_graphique *l_element_courant; struct_objet *s_objet; (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') { printf("\n KEYLABEL "); if ((*s_etat_processus).langue == 'F') { printf("(label du graphique courant)\n\n"); } else { printf("(current graphic label)\n\n"); } printf(" 1: %s\n", d_CHN); return; } else if ((*s_etat_processus).test_instruction == 'Y') { (*s_etat_processus).nombre_arguments = -1; 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) == d_erreur) { (*s_etat_processus).erreur_execution = d_ex_manque_argument; return; } if ((*s_objet).type == CHN) { l_element_courant = (*s_etat_processus).fichiers_graphiques; if (l_element_courant == NULL) { liberation(s_etat_processus, s_objet); (*s_etat_processus).erreur_execution = d_ex_absence_graphique_courant; return; } while((*l_element_courant).suivant != NULL) { l_element_courant = (*l_element_courant).suivant; } if ((*l_element_courant).legende != NULL) { free((*l_element_courant).legende); } if (((*l_element_courant).legende = malloc((strlen((unsigned char *) (*s_objet).objet) + 1) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } strcpy((*l_element_courant).legende, (unsigned char *) (*s_objet).objet); liberation(s_etat_processus, s_objet); (*s_etat_processus).mise_a_jour_trace_requise = d_vrai; } else { liberation(s_etat_processus, s_objet); (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; return; } return; } // vim: ts=4