From 6e5f6775d16e9730ccf1edbecf14da52d0ef134a Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 3 May 2001 00:20:43 +0000 Subject: Indentation --- lib/hash.c | 211 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 107 insertions(+), 104 deletions(-) (limited to 'lib/hash.c') diff --git a/lib/hash.c b/lib/hash.c index 5009611..70459e1 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -16,177 +16,180 @@ #define _(x) x #endif -/* L'ensemble de ce code source nous sert à implémenter une table de hachage qui nous sera utile - pour le stockage des variables du programme. C'est juste histoire d'aller un peu plus vite qu'une - simple liste chaînée. */ +/* + * L'ensemble de ce code source nous sert a implementer une table de hachage qui nous sera utile + * pour le stockage des variables du programme. C'est juste histoire d'aller un peu plus vite + * qu'une simple liste chainee. + */ static char *CHAINEHACHAGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; static int FonctionHachage(char *clef) { - unsigned int i; + unsigned int i; - if (!clef) { - exception(2, _("Internal error into hashing")); - } + if (!clef) { + exception(2, _("Internal error into hashing")); + } - for (i = 0; i < strlen(CHAINEHACHAGE); i++) { - if (clef[0] == CHAINEHACHAGE[i]) { - return (i); - } + for (i = 0; i < strlen(CHAINEHACHAGE); i++) { + if (clef[0] == CHAINEHACHAGE[i]) { + return (i); } - return strlen(CHAINEHACHAGE); + } + return strlen(CHAINEHACHAGE); } _Element CreerElement(char *Nom, _TypeVariable Var) { - _Element e; + _Element e; - e.NomVar = Estrdup(Nom); + e.NomVar = Estrdup(Nom); - e.Variable = Var; - return (e); + e.Variable = Var; + return (e); } static _ListeChaine InserTete(_ListeChaine l, _Element e) { - _ListeChaine aux; - unsigned int i; - - aux = (_ListeChaine) Emalloc(sizeof(struct _LstChn)); - aux->Elem.NomVar = (char *) Emalloc(sizeof(char) * (strlen(e.NomVar) + 1)); - - for (i = 0; i <= strlen(e.NomVar); i++) { - aux->Elem.NomVar[i] = e.NomVar[i]; - } - aux->Elem.Variable = e.Variable; - aux->Suivant = l; - return (aux); + _ListeChaine aux; + unsigned int i; + + aux = (_ListeChaine) Emalloc(sizeof(struct _LstChn)); + aux->Elem.NomVar = (char *) Emalloc(sizeof(char) * (strlen(e.NomVar) + 1)); + + for (i = 0; i <= strlen(e.NomVar); i++) { + aux->Elem.NomVar[i] = e.NomVar[i]; + } + aux->Elem.Variable = e.Variable; + aux->Suivant = l; + return (aux); } static int EgaliteChaine(char *ch1, char *ch2) { - unsigned int i; - - if (strlen(ch1) != strlen(ch2)) { - return (0); - } - for (i = 0; i < strlen(ch1); i++) { - if (ch1[i] != ch2[i]) { - return (0); - } + unsigned int i; + + if (strlen(ch1) != strlen(ch2)) { + return (0); + } + for (i = 0; i < strlen(ch1); i++) { + if (ch1[i] != ch2[i]) { + return (0); } - return (1); - /* return (1-strcmp(ch1,ch2)); */ + } + return (1); + /* + * return (1-strcmp(ch1,ch2)); + */ } static void Supprimer(_ListeChaine * l, char *Nom) { - _ListeChaine l_aux = NULL; - - if ((*l) != NULL) { - if (EgaliteChaine((*l)->Elem.NomVar, Nom)) { - l_aux = *l; - *l = (*l)->Suivant; - free(l_aux->Elem.NomVar); - free(l_aux); - } else { - Supprimer(&((*l)->Suivant), Nom); - } + _ListeChaine l_aux = NULL; + + if ((*l) != NULL) { + if (EgaliteChaine((*l)->Elem.NomVar, Nom)) { + l_aux = *l; + *l = (*l)->Suivant; + free(l_aux->Elem.NomVar); + free(l_aux); + } else { + Supprimer(&((*l)->Suivant), Nom); } + } } static void Detruit(_ListeChaine * l) { - _ListeChaine l_aux = NULL; - - while (*l) { - l_aux = (*l)->Suivant; - free((*l)->Elem.NomVar); - free(*l); - *l = l_aux; - } + _ListeChaine l_aux = NULL; + + while (*l) { + l_aux = (*l)->Suivant; + free((*l)->Elem.NomVar); + free(*l); + *l = l_aux; + } } char SupprimerDansTab(_TableauVariable * t, char *Nom) { - int index = FonctionHachage(Nom); - - if (0 <= index && index <= strlen(CHAINEHACHAGE)) { - Supprimer(&((*t)[index]), Nom); - } else { - return (0); - } - return (1); + int index = FonctionHachage(Nom); + + if (0 <= index && index <= strlen(CHAINEHACHAGE)) { + Supprimer(&((*t)[index]), Nom); + } else { + return (0); + } + return (1); } char InsererVarDansTab(_TableauVariable * t, _Element e) { - int index = FonctionHachage(e.NomVar); - - if (0 <= index && index <= strlen(CHAINEHACHAGE)) { - (*t)[index] = InserTete((*t)[index], e); - } else { - return (0); - } - return (1); + int index = FonctionHachage(e.NomVar); + + if (0 <= index && index <= strlen(CHAINEHACHAGE)) { + (*t)[index] = InserTete((*t)[index], e); + } else { + return (0); + } + return (1); } static _TypeVariable NomVarToVarListe(char *Nom, _ListeChaine l, char *trouve) { - *trouve = 0; - while (l != NULL) { - if (EgaliteChaine(Nom, (l->Elem).NomVar)) { - *trouve = 1; - return (l->Elem.Variable); - } - l = l->Suivant; + *trouve = 0; + while (l != NULL) { + if (EgaliteChaine(Nom, (l->Elem).NomVar)) { + *trouve = 1; + return (l->Elem.Variable); } - return (NULL); + l = l->Suivant; + } + return (NULL); } _TypeVariable NomVarToVar(char *Nom, _TableauVariable t, char *trouve) { - return (NomVarToVarListe(Nom, t[FonctionHachage(Nom)], trouve)); + return (NomVarToVarListe(Nom, t[FonctionHachage(Nom)], trouve)); } void AfficheListe(_ListeChaine l) { - while (l != NULL) { - fprintf(stderr, "%s: %s\n", l->Elem.NomVar, ply_affichage(l->Elem.Variable)); - l = l->Suivant; - } + while (l != NULL) { + fprintf(stderr, "%s: %s\n", l->Elem.NomVar, ply_affichage(l->Elem.Variable)); + l = l->Suivant; + } } void AfficheTableau(_TableauVariable t) { - unsigned int i; + unsigned int i; - for (i = 0; i < TAILLECHAINEHACHAGE; i++) { - AfficheListe(t[i]); - } + for (i = 0; i < TAILLECHAINEHACHAGE; i++) { + AfficheListe(t[i]); + } } int Initialise(_TableauVariable * t) { - unsigned int i; - + unsigned int i; - (*t) = (_TableauVariable) Emalloc(sizeof(_ListeChaine) * (strlen(CHAINEHACHAGE) + 1)); - for (i = 0; i <= strlen(CHAINEHACHAGE); i++) { - (*t)[i] = NULL; - } - return (i); + (*t) = (_TableauVariable) Emalloc(sizeof(_ListeChaine) * (strlen(CHAINEHACHAGE) + 1)); + for (i = 0; i <= strlen(CHAINEHACHAGE); i++) { + (*t)[i] = NULL; + } + return (i); } void DetruitTab(_TableauVariable * t) { - int i; + int i; - for (i = 0; i <= strlen(CHAINEHACHAGE); i++) { - Detruit(&((*t)[i])); - } + for (i = 0; i <= strlen(CHAINEHACHAGE); i++) { + Detruit(&((*t)[i])); + } - free(*t); - *t = NULL; + free(*t); + *t = NULL; } -- cgit v1.2.3