| 1 |
13 |
louismarie |
#include "formateur.h"
|
| 2 |
|
|
|
| 3 |
|
|
/* Autres modules utilises */
|
| 4 |
|
|
|
| 5 |
|
|
#include <debogueur.h>
|
| 6 |
|
|
#include <dialogue.h>
|
| 7 |
|
|
|
| 8 |
|
|
/* Modules de la bibliotheque standard */
|
| 9 |
|
|
|
| 10 |
|
|
#include <stdlib.h>
|
| 11 |
|
|
#include <stdio.h>
|
| 12 |
|
|
#include <string.h>
|
| 13 |
|
|
#include <ctype.h>
|
| 14 |
|
|
|
| 15 |
|
|
/*********************************************************************************************/
|
| 16 |
|
|
/* COMPOSITION DES ENSEMBLES DE CARACTERES */
|
| 17 |
|
|
/* Tout autre caractere rencontre dans la source sera inconnu et renverra une erreur lors de */
|
| 18 |
|
|
/* sa lecture. */
|
| 19 |
|
|
/*********************************************************************************************/
|
| 20 |
|
|
|
| 21 |
|
|
|
| 22 |
|
|
/* D‰finition de constantes pour la taille de chaque ensemble existant. */
|
| 23 |
|
|
int taille_ensemble[NBR_ENS] = {taille_lettre, taille_chiffre, taille_prefixe,
|
| 24 |
|
|
taille_sep_explicite, taille_sep_invisible, taille_commentaire};
|
| 25 |
|
|
|
| 26 |
|
|
/* D‰finition des ensembles */
|
| 27 |
|
|
|
| 28 |
|
|
int ens_lettre[taille_lettre] =
|
| 29 |
|
|
{
|
| 30 |
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
|
| 31 |
|
|
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
| 32 |
|
|
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
|
| 33 |
|
|
'Z', '_', '.', '?', '$'
|
| 34 |
|
|
};
|
| 35 |
|
|
|
| 36 |
|
|
int ens_chiffre[taille_chiffre] =
|
| 37 |
|
|
{
|
| 38 |
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a',
|
| 39 |
|
|
'b', 'c', 'd', 'e', 'f'
|
| 40 |
|
|
};
|
| 41 |
|
|
|
| 42 |
|
|
int ens_prefixe[taille_prefixe] =
|
| 43 |
|
|
{
|
| 44 |
|
|
'@', '%', '&', '+', '-', '\''
|
| 45 |
|
|
};
|
| 46 |
|
|
|
| 47 |
|
|
int ens_sep_explicite[taille_sep_explicite] =
|
| 48 |
|
|
{
|
| 49 |
|
|
ACF, ACO, NL, DP, PF, PO, PS, MS, DIR, VIR, EOF
|
| 50 |
|
|
};
|
| 51 |
|
|
|
| 52 |
|
|
int ens_sep_invisible[taille_sep_invisible] =
|
| 53 |
|
|
{
|
| 54 |
|
|
'\t', ' ', '\r'
|
| 55 |
|
|
};
|
| 56 |
|
|
|
| 57 |
|
|
int ens_commentaire[taille_commentaire] =
|
| 58 |
|
|
{
|
| 59 |
|
|
';', '\n'
|
| 60 |
|
|
};
|
| 61 |
|
|
|
| 62 |
|
|
/* D‰finition du tableau regroupant tous les ensembles qui est export‰. */
|
| 63 |
|
|
int *ensemble[NBR_ENS] = {ens_lettre, ens_chiffre, ens_prefixe,
|
| 64 |
|
|
ens_sep_explicite, ens_sep_invisible, ens_commentaire};
|
| 65 |
|
|
|
| 66 |
|
|
/* D‰finition de la table des correspondances des caractˆres d'‰chappement. */
|
| 67 |
|
|
char car_ech[] = "nt\\";
|
| 68 |
|
|
char seq_ech[] = "\n\t\\";
|
| 69 |
|
|
|
| 70 |
|
|
|
| 71 |
|
|
/*********************************************************************************************/
|
| 72 |
|
|
/* MACROS DE TRAVAIL SUR LES ENSEMBLES */
|
| 73 |
|
|
/* Pour ne pas avoir utiliser de r‰f‰rence directe aux ensembles de caractˆres, on y accˆde */
|
| 74 |
|
|
/* au travers de macros d‰finies ici. En cas de changement, le code des autres modules */
|
| 75 |
|
|
/* n'aura donc pas € Štre modifi‰. */
|
| 76 |
|
|
/*********************************************************************************************/
|
| 77 |
|
|
|
| 78 |
|
|
/* G‰nˆre le masque caract‰ristique de l'ensemble */
|
| 79 |
|
|
#define MASK_ENSEMBLE(ensbl) (1<<ensbl)
|
| 80 |
|
|
|
| 81 |
|
|
/* Caractˆres d'encadrement des caractˆres. */
|
| 82 |
|
|
#define CAR_ENC (ensemble[prefixe][5])
|
| 83 |
|
|
|
| 84 |
|
|
/* D‰finit les caractˆres de d‰but et de fin de commentaire. */
|
| 85 |
|
|
#define DEBUT_COM (ensemble[commentaire][0])
|
| 86 |
|
|
#define FIN_COM (ensemble[commentaire][1])
|
| 87 |
|
|
|
| 88 |
|
|
/* Cette macro sp‰cifie si le caractˆre de fin de commentaire fait partie du commentaire ou */
|
| 89 |
|
|
/* si il doit Štre pris en compte. A 1, celui-ci est ignor‰. */
|
| 90 |
|
|
#define IGNORE_FIN_COMMENT 0
|
| 91 |
|
|
|
| 92 |
|
|
/* Macro de conversion chiffre (1..9, a..f, A..F) vers sa valeur num‰rique. */
|
| 93 |
|
|
/* En cas de caractˆre invalide, on retourne 0. */
|
| 94 |
|
|
#define CAR_TO_NUM(car) (\
|
| 95 |
|
|
((car >= '0') && (car <= '9')) ? (car - '0') :\
|
| 96 |
|
|
((car >= 'a') && (car <= 'f')) ? (10 + car - 'a') :\
|
| 97 |
|
|
((car >= 'A') && (car <= 'F')) ? (10 + car - 'A') :\
|
| 98 |
|
|
0)
|
| 99 |
|
|
|
| 100 |
|
|
/* Macro de d‰finition des bases des entiers en fonction de leur pr‰fixe. */
|
| 101 |
|
|
#define VAL_BASE(prefixe) (\
|
| 102 |
|
|
(prefixe == '\'') ? 0 :\
|
| 103 |
|
|
(prefixe == '@') ? 16 :\
|
| 104 |
|
|
(prefixe == '%') ? 2 :\
|
| 105 |
|
|
(prefixe == '&') ? 8 :\
|
| 106 |
|
|
10\
|
| 107 |
|
|
)
|
| 108 |
|
|
|
| 109 |
|
|
/* Macro de d‰finition du signe des entiers en fonction de leur pr‰fixe. */
|
| 110 |
|
|
#define SGN_INIT(prefixe) (\
|
| 111 |
|
|
(prefixe == '-') ? -1 :\
|
| 112 |
|
|
1\
|
| 113 |
|
|
)
|
| 114 |
|
|
|
| 115 |
|
|
|
| 116 |
|
|
/*********************************************************************************************/
|
| 117 |
|
|
/* FONCTIONS DE TRAVAIL SUR LES ENSEMBLES */
|
| 118 |
|
|
/* Fonctions publi‰es pour simplifier le traitement des ensembles. */
|
| 119 |
|
|
/*********************************************************************************************/
|
| 120 |
|
|
|
| 121 |
|
|
char type_car(int c)
|
| 122 |
|
|
/* Cette fonction recherche dans tous les ensembles le caractˆre c et positionne un bit pour */
|
| 123 |
|
|
/* chaque ensemble auquel il appartient. */
|
| 124 |
|
|
{
|
| 125 |
|
|
char type=0;
|
| 126 |
|
|
int i, j, flag;
|
| 127 |
|
|
|
| 128 |
|
|
for(i=0; i<NBR_ENS; i++)
|
| 129 |
|
|
{
|
| 130 |
|
|
flag =0;
|
| 131 |
|
|
for (j=0; (j<taille_ensemble[i]) && !flag; j++)
|
| 132 |
|
|
flag = (c == ensemble[i][j]);
|
| 133 |
|
|
if (flag) type |= MASK_ENSEMBLE(i);
|
| 134 |
|
|
}
|
| 135 |
|
|
return type;
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
/*********************************************************************************************/
|
| 140 |
|
|
/* */
|
| 141 |
|
|
/* POINT D'ENTREE PRINCIPAL DU MODULE */
|
| 142 |
|
|
/* */
|
| 143 |
|
|
/* type_lexeme * get_lexeme(FILE * f) */
|
| 144 |
|
|
/* */
|
| 145 |
|
|
/* Cette fonction lit les lexˆmes dans le fichier pass‰ en paramˆtre. En cas d'erreur, le */
|
| 146 |
|
|
/* valeur NULL est retourn‰e. */
|
| 147 |
|
|
/* */
|
| 148 |
|
|
/*********************************************************************************************/
|
| 149 |
|
|
|
| 150 |
|
|
type_lexeme * get_lexeme(FILE * f)
|
| 151 |
|
|
{
|
| 152 |
|
|
/* Macro de lecture de caractˆre avec typage et traitement de l'erreur fatale */
|
| 153 |
|
|
#define LIT_CAR {\
|
| 154 |
|
|
if ( (car=fgetc(f) )==EOF && !( feof(f)) )\
|
| 155 |
|
|
DIALOGUE("formateur(get_lexeme)",0, F_ERR_LECT);\
|
| 156 |
|
|
typ=type_car(car);\
|
| 157 |
|
|
}
|
| 158 |
|
|
|
| 159 |
|
|
/* Macro de lecture du premier caractˆre significatif dans le fichier. Il est € noter que ce */
|
| 160 |
|
|
/* caractˆre n'est pas n‰cessairement valide. */
|
| 161 |
|
|
#define LIT_SIGNIFICATIF {do LIT_CAR\
|
| 162 |
|
|
while((!(typ & ~MASK_ENSEMBLE(sep_invisible))) && typ);\
|
| 163 |
|
|
}
|
| 164 |
|
|
|
| 165 |
|
|
int car, typ;
|
| 166 |
|
|
type_lexeme * ptr_lex;
|
| 167 |
|
|
|
| 168 |
|
|
if (f==NULL) DIALOGUE("formateur(get_lexeme)",0, F_FLUX_NULL);
|
| 169 |
|
|
|
| 170 |
|
|
LIT_SIGNIFICATIF;
|
| 171 |
|
|
|
| 172 |
|
|
if (!typ)
|
| 173 |
|
|
{
|
| 174 |
|
|
err_code=S_CAR_INVALID;
|
| 175 |
|
|
return NULL;
|
| 176 |
|
|
}
|
| 177 |
|
|
|
| 178 |
|
|
if (typ & MASK_ENSEMBLE(lettre))
|
| 179 |
|
|
{ /* Lire lexeme ALPHA */
|
| 180 |
|
|
char memo_string[MAX_LONG_ALPHA];
|
| 181 |
|
|
int i=0;
|
| 182 |
|
|
do /* Epuiser les car alphanum‰riques. */
|
| 183 |
|
|
{
|
| 184 |
|
|
if (i==MAX_LONG_ALPHA-1)
|
| 185 |
|
|
{
|
| 186 |
|
|
err_code=S_ALPHA_LONG;
|
| 187 |
|
|
return NULL;
|
| 188 |
|
|
}
|
| 189 |
|
|
memo_string[i++]=car;
|
| 190 |
|
|
LIT_CAR;
|
| 191 |
|
|
}
|
| 192 |
|
|
while(typ & (MASK_ENSEMBLE(lettre) | MASK_ENSEMBLE(chiffre)));
|
| 193 |
|
|
|
| 194 |
|
|
/* v‰rifie que le dernier caractˆre ‰tait un s‰parateur ou d‰but commentaire */
|
| 195 |
|
|
if ((typ & (MASK_ENSEMBLE(sep_explicite) | MASK_ENSEMBLE(sep_invisible)))
|
| 196 |
|
|
|| (car == DEBUT_COM))
|
| 197 |
|
|
{
|
| 198 |
|
|
/* On remet le dernier caractˆre qui n'est pas du type alpha. */
|
| 199 |
|
|
ungetc(car, f);
|
| 200 |
|
|
memo_string[i]='\0';
|
| 201 |
|
|
ALLOC_LEX(ptr_lex);
|
| 202 |
|
|
if (ptr_lex==NULL) DIALOGUE("formateur(get_lexeme)", 0, F_ERR_MEM);
|
| 203 |
|
|
ptr_lex->type=POS_MPV(ALPHA);
|
| 204 |
|
|
(ptr_lex->valeur).alpha=(char*) malloc(i+1);
|
| 205 |
|
|
strcpy((ptr_lex->valeur).alpha, memo_string);
|
| 206 |
|
|
return ptr_lex;
|
| 207 |
|
|
}
|
| 208 |
|
|
else
|
| 209 |
|
|
{
|
| 210 |
|
|
err_code=S_ALPHA_INVALID;
|
| 211 |
|
|
return NULL;
|
| 212 |
|
|
}
|
| 213 |
|
|
}
|
| 214 |
|
|
|
| 215 |
|
|
|
| 216 |
|
|
if (typ & (MASK_ENSEMBLE(chiffre) | MASK_ENSEMBLE(prefixe)))
|
| 217 |
|
|
{ /* Caractere numerique (‰ventuellement pr‰fixe, signe, etc.) */
|
| 218 |
|
|
int val, sgn, base, car_in, typ_in, err_sel = 0;
|
| 219 |
|
|
|
| 220 |
|
|
/* On m‰morise la valeur et le type du caractˆre en entr‰e pour le cas o· ce */
|
| 221 |
|
|
/* choix ne serait pas le bon. */
|
| 222 |
|
|
car_in = car;
|
| 223 |
|
|
typ_in = typ;
|
| 224 |
|
|
|
| 225 |
|
|
val = CAR_TO_NUM(car); /* Initialisation de la valeur de l'entier. */
|
| 226 |
|
|
sgn = SGN_INIT(car); /* initialistaion du signe de l'entier. */
|
| 227 |
|
|
base = VAL_BASE(car); /* initialisation de la base d'aprˆs le pr‰fixe. */
|
| 228 |
|
|
|
| 229 |
|
|
if (car==CAR_ENC) /* Cas d'un entier de type caractˆre. */
|
| 230 |
|
|
{
|
| 231 |
|
|
long pos=ftell(f);
|
| 232 |
|
|
char * car_trouve;
|
| 233 |
|
|
int err_ech=0;
|
| 234 |
|
|
LIT_CAR;
|
| 235 |
|
|
if (car=='\\') /* D‰but de s‰quence d'‰chappement. */
|
| 236 |
|
|
{
|
| 237 |
|
|
LIT_CAR;
|
| 238 |
|
|
if ((car_trouve=strchr(car_ech, car))!=NULL)
|
| 239 |
|
|
car=*(seq_ech+(car_trouve-car_ech));
|
| 240 |
|
|
else err_ech=1;
|
| 241 |
|
|
}
|
| 242 |
|
|
val=car;
|
| 243 |
|
|
LIT_CAR;
|
| 244 |
|
|
if (err_ech || car!=CAR_ENC)
|
| 245 |
|
|
{
|
| 246 |
|
|
err_sel=1;
|
| 247 |
|
|
car=car_in;
|
| 248 |
|
|
typ=typ_in;
|
| 249 |
|
|
fseek(f,pos-ftell(f),SEEK_CUR);
|
| 250 |
|
|
}
|
| 251 |
|
|
else
|
| 252 |
|
|
{
|
| 253 |
|
|
ALLOC_LEX(ptr_lex);
|
| 254 |
|
|
if (ptr_lex==NULL) DIALOGUE("formateur(get_lexeme)", 0, F_ERR_MEM);
|
| 255 |
|
|
ptr_lex->type=POS_MPV(NUM);
|
| 256 |
|
|
(ptr_lex->valeur).num=val;
|
| 257 |
|
|
return ptr_lex;
|
| 258 |
|
|
}
|
| 259 |
|
|
}
|
| 260 |
|
|
|
| 261 |
|
|
if (typ & MASK_ENSEMBLE(prefixe))
|
| 262 |
|
|
{ /* Si on a affaire € un pr‰fixe, le chargement du premier chiffre est */
|
| 263 |
|
|
/* obligatoire mais il peut Štre s‰par‰ du chiffre par des s‰parateurs */
|
| 264 |
|
|
/* invisibles. */
|
| 265 |
|
|
LIT_SIGNIFICATIF;
|
| 266 |
|
|
val = CAR_TO_NUM(car);
|
| 267 |
|
|
if (!((typ & MASK_ENSEMBLE(chiffre)) && (val < base)))
|
| 268 |
|
|
{ /* Erreur de format ou de s‰lection, caractˆre n'est pas un pr‰fixe */
|
| 269 |
|
|
ungetc(car, f);
|
| 270 |
|
|
car = car_in;
|
| 271 |
|
|
typ = typ_in;
|
| 272 |
|
|
err_sel = 1;
|
| 273 |
|
|
}
|
| 274 |
|
|
}
|
| 275 |
|
|
|
| 276 |
|
|
if (!err_sel) /* Uniquement s'il n'y a pas eu d'erreur de s‰lection. */
|
| 277 |
|
|
{
|
| 278 |
|
|
LIT_CAR;
|
| 279 |
|
|
while (typ & MASK_ENSEMBLE(chiffre))
|
| 280 |
|
|
{
|
| 281 |
|
|
int chiffre_val = CAR_TO_NUM(car);
|
| 282 |
|
|
if (chiffre_val >= base)
|
| 283 |
|
|
{
|
| 284 |
|
|
err_code=S_INT_INVALID;
|
| 285 |
|
|
return NULL; /* chiffre valide ? */
|
| 286 |
|
|
}
|
| 287 |
|
|
val *= base;
|
| 288 |
|
|
val += chiffre_val;
|
| 289 |
|
|
LIT_CAR;
|
| 290 |
|
|
}
|
| 291 |
|
|
|
| 292 |
|
|
/* Si le dernier caractˆre ‰tait un s‰parateur ou d‰but commentaire. */
|
| 293 |
|
|
if ((typ & (MASK_ENSEMBLE(sep_explicite)|MASK_ENSEMBLE(sep_invisible)))
|
| 294 |
|
|
|| (car == DEBUT_COM))
|
| 295 |
|
|
{
|
| 296 |
|
|
ungetc(car, f);
|
| 297 |
|
|
ALLOC_LEX(ptr_lex);
|
| 298 |
|
|
if (ptr_lex==NULL) DIALOGUE("formateur(get_lexeme)", 0, F_ERR_MEM);
|
| 299 |
|
|
ptr_lex->type=POS_MPV(NUM);
|
| 300 |
|
|
(ptr_lex->valeur).num=val*sgn;
|
| 301 |
|
|
return ptr_lex;
|
| 302 |
|
|
}
|
| 303 |
|
|
else
|
| 304 |
|
|
{
|
| 305 |
|
|
err_code=S_INT_INVALID;
|
| 306 |
|
|
return NULL;
|
| 307 |
|
|
}
|
| 308 |
|
|
}
|
| 309 |
|
|
}
|
| 310 |
|
|
|
| 311 |
|
|
|
| 312 |
|
|
if (typ & MASK_ENSEMBLE(sep_explicite))
|
| 313 |
|
|
{ /* Lire lexeme operateur. */
|
| 314 |
|
|
ALLOC_LEX(ptr_lex);
|
| 315 |
|
|
if (ptr_lex==NULL) DIALOGUE("formateur(get_lexeme)", 0, F_ERR_MEM);
|
| 316 |
|
|
ptr_lex->type=POS_MPV(OP);
|
| 317 |
|
|
(ptr_lex->valeur).op=car;
|
| 318 |
|
|
return ptr_lex;
|
| 319 |
|
|
}
|
| 320 |
|
|
|
| 321 |
|
|
|
| 322 |
|
|
if (car == DEBUT_COM)
|
| 323 |
|
|
{ /* Epuiser le commentaire. */
|
| 324 |
|
|
do
|
| 325 |
|
|
{
|
| 326 |
|
|
LIT_CAR;
|
| 327 |
|
|
}
|
| 328 |
|
|
while(car!=FIN_COM && car!=EOF);
|
| 329 |
|
|
if (!IGNORE_FIN_COMMENT) ungetc(car, f);
|
| 330 |
|
|
return get_lexeme(f);
|
| 331 |
|
|
}
|
| 332 |
|
|
|
| 333 |
|
|
/* Le caractˆre rencontr‰ n'‰tait pas dans le bon contexte, erreur. */
|
| 334 |
|
|
err_code=S_ERR_FORMAT;
|
| 335 |
|
|
return NULL;
|
| 336 |
|
|
}
|
| 337 |
|
|
|
| 338 |
|
|
|
| 339 |
|
|
/* Renvoie 1 si l est compatible avec filtre */
|
| 340 |
|
|
int filtre_lexeme(type_lexeme * l, type_lexeme * filtre, int casse)
|
| 341 |
|
|
{
|
| 342 |
|
|
int (* compare)();
|
| 343 |
|
|
int v_comp=0;
|
| 344 |
|
|
|
| 345 |
|
|
compare = casse ? (void *) &strcmp : (void *) &strcasecmp;
|
| 346 |
|
|
|
| 347 |
|
|
/* Si les lexˆmes n'ont pas le mŠme type de base le filtre ne passe pas. */
|
| 348 |
|
|
if (BASE_TYPE(l) != BASE_TYPE(filtre)) return 0;
|
| 349 |
|
|
/* Si l n'est pas du mŠme sous type que filtre le filtre ne passe pas. */
|
| 350 |
|
|
if (SOUS_TYPE(filtre)!=0 && SOUS_TYPE(l)!=SOUS_TYPE(filtre)) return 0;
|
| 351 |
|
|
|
| 352 |
|
|
if (!LIT_MPV(l->type) || !LIT_MPV(filtre->type)) v_comp=0;
|
| 353 |
|
|
else switch (BASE_TYPE(l))
|
| 354 |
|
|
{
|
| 355 |
|
|
case ALPHA : if ((*compare) (l->valeur.alpha,
|
| 356 |
|
|
filtre->valeur.alpha))
|
| 357 |
|
|
v_comp=0;
|
| 358 |
|
|
else v_comp=1;
|
| 359 |
|
|
break;
|
| 360 |
|
|
case NUM : if (l->valeur.num != filtre->valeur.num)
|
| 361 |
|
|
v_comp=0;
|
| 362 |
|
|
else v_comp=1;
|
| 363 |
|
|
break;
|
| 364 |
|
|
case OP : if (l->valeur.op != filtre->valeur.op)
|
| 365 |
|
|
v_comp=0;
|
| 366 |
|
|
else v_comp=1;
|
| 367 |
|
|
break;
|
| 368 |
|
|
default : v_comp=0;
|
| 369 |
|
|
break;
|
| 370 |
|
|
}
|
| 371 |
|
|
|
| 372 |
|
|
/* Si les deux lexˆmes n'ont pas la mŠme valeur le filtre ne passe pas. */
|
| 373 |
|
|
if (LIT_MPV(filtre->type) && (!LIT_MPV(l->type) || !v_comp)) return 0;
|
| 374 |
|
|
return 1;
|
| 375 |
|
|
}
|
| 376 |
|
|
|
| 377 |
|
|
/* Renvoie 1 si les 2 lexˆmes sont ‰gaux */
|
| 378 |
|
|
int id_lexeme(type_lexeme * l1, type_lexeme * l2, int casse)
|
| 379 |
|
|
{
|
| 380 |
|
|
int (* compare)();
|
| 381 |
|
|
|
| 382 |
|
|
if (l1->type != l2->type) return 0; /* Lexˆmes de type, sstype ou bit de val diff. */
|
| 383 |
|
|
if (!LIT_MPV(l1->type) && !LIT_MPV(l2->type)) return 1; /* Aucun lexˆme n'a de val. */
|
| 384 |
|
|
|
| 385 |
|
|
compare = casse ? (void *) &strcmp : (void *) &strcasecmp;
|
| 386 |
|
|
|
| 387 |
|
|
switch BASE_TYPE(l1)
|
| 388 |
|
|
{
|
| 389 |
|
|
case ALPHA : if (!(*compare)(l1->valeur.alpha, l2->valeur.alpha))
|
| 390 |
|
|
return 1;
|
| 391 |
|
|
break;
|
| 392 |
|
|
case NUM : if (l1->valeur.num == l2->valeur.num)
|
| 393 |
|
|
return 1;
|
| 394 |
|
|
break;
|
| 395 |
|
|
case OP : if (l1->valeur.op == l2->valeur.op)
|
| 396 |
|
|
return 1;
|
| 397 |
|
|
break;
|
| 398 |
|
|
default : return 0;
|
| 399 |
|
|
break;
|
| 400 |
|
|
}
|
| 401 |
|
|
return 0;
|
| 402 |
|
|
}
|
| 403 |
|
|
|
| 404 |
|
|
|
| 405 |
|
|
/*********************************************************************************************/
|
| 406 |
|
|
/* */
|
| 407 |
|
|
/* POINT D'ENTREE SECONDAIRE DU MODULE */
|
| 408 |
|
|
/* */
|
| 409 |
|
|
/* void print_lexeme(type_lexeme * l) */
|
| 410 |
|
|
/* */
|
| 411 |
|
|
/* Cette fonction affiche un lexˆme € l'‰cran avec formatage suivant son type et la pr‰sence */
|
| 412 |
|
|
/* ‰ventuelle d'une valeur. */
|
| 413 |
|
|
/* */
|
| 414 |
|
|
/*********************************************************************************************/
|
| 415 |
|
|
|
| 416 |
|
|
int fprint_lexeme(FILE * f, type_lexeme * l)
|
| 417 |
|
|
{
|
| 418 |
|
|
#define ALPHA_VAL (l->valeur.alpha)
|
| 419 |
|
|
#define NUM_VAL (l->valeur.num)
|
| 420 |
|
|
#define OP_VAL (l->valeur.op)
|
| 421 |
|
|
long int pos=ftell(f);
|
| 422 |
|
|
|
| 423 |
|
|
switch (BASE_TYPE(l))
|
| 424 |
|
|
{
|
| 425 |
|
|
case ALPHA : if (LIT_MPV(l->type)) fprintf(f, "%s", ALPHA_VAL);
|
| 426 |
|
|
break;
|
| 427 |
|
|
case NUM : if (LIT_MPV(l->type)) fprintf(f, "%d", NUM_VAL);
|
| 428 |
|
|
break;
|
| 429 |
|
|
case OP : if (LIT_MPV(l->type)) fprintf(f, "%c", OP_VAL);
|
| 430 |
|
|
break;
|
| 431 |
|
|
}
|
| 432 |
|
|
return ftell(f)-pos;
|
| 433 |
|
|
}
|
| 434 |
|
|
|
| 435 |
|
|
/*********************************************************************************************
|
| 436 |
|
|
* *
|
| 437 |
|
|
* POINT D'ENTREE SECONDAIRE DU MODULE *
|
| 438 |
|
|
* *
|
| 439 |
|
|
* int strcasecmp(const char *, const char *) *
|
| 440 |
|
|
* *
|
| 441 |
|
|
* Redefinit cette fonction car elle n'est pas posix. *
|
| 442 |
|
|
* *
|
| 443 |
|
|
* Renvoie un nombre (<, =, >) € z‰ro si s1 est (<, =, >) € s2. *
|
| 444 |
|
|
* *
|
| 445 |
|
|
*********************************************************************************************/
|
| 446 |
|
|
|
| 447 |
|
|
int strcasecmp(char * s1, char * s2)
|
| 448 |
|
|
{
|
| 449 |
|
|
for(; tolower(*s1)==tolower(*s2); s1++, s2++)
|
| 450 |
|
|
if (*s1=='\0') return 0;
|
| 451 |
|
|
return (*s1-*s2);
|
| 452 |
|
|
}
|
| 453 |
|
|
|