commit d180f19cecf115e5f90cef21ae9ae57c729b81b3
parent 8055e62c92a91be5da513e22c24a41b74a9b45c5
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date: Fri, 10 Apr 2026 18:29:14 -0400
Appliquer la mise à jour du tfm
Diffstat:
| M | att.c | | | 56 | +++++++++++++++++++++++--------------------------------- |
| M | tfd.c | | | 15 | +++++++++++---- |
| M | tfm.c | | | 53 | ++++++++++------------------------------------------- |
3 fichiers modifiés, 44 insertions(+), 80 suppressions(-)
diff --git a/att.c b/att.c
@@ -25,15 +25,15 @@ static int lire_champ(FILE *f, char *t, size_t max, size_t *noct);
static ssize_t nombre(char *t, size_t noct);
/* Ajouter un symbole à un transducteur.
- * Renvoie 0, ou -1 en cas d’erreur. Doit être utilisé un lieu de tfm_symb_id()
- * pour intercepter les symboles spéciaux comme @0@. */
-static int ajt_symb(struct tfm *tfm, char *t, size_t noct, ssize_t *id);
+ * Renvoie l’identifiant du symbole, ou -1 en cas d’erreur. Doit être utilisé
+ * un lieu de tfm_symb_id() pour intercepter les symboles spéciaux. */
+static ssize_t ajt_symb(struct tfm *tfm, char *t, size_t noct);
/* Placer le symbole du transudcteur tfm correspondant à l’identifiant id dans
* le tampon symb, de taille max.
* Doit être utilisé au lieu de tfm_symb_obt() pour intercepter les identifiants
* de symbole spéciaux. Renvoie la taille du symbole, ou -1 en cas d’erreur. */
-static ssize_t symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max);
+static ssize_t symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max);
/* Lire un fichier au format .att.
* La routine se fait peut-être une idée trop stricte du format .att et n’est
@@ -97,7 +97,7 @@ att_lire(FILE *f)
goto erreur;
case SEP_TB:
/* Sauvegarder le champ dans se. */
- if (ajt_symb(tfm, champ, noct, &se) < 0)
+ if ((se = ajt_symb(tfm, champ, noct)) < 0)
goto erreur;
}
@@ -110,7 +110,7 @@ att_lire(FILE *f)
goto erreur;
case SEP_NL:
/* Sauvegarder le champ dans ss. */
- if (ajt_symb(tfm, champ, noct, &ss) < 0)
+ if ((ss = ajt_symb(tfm, champ, noct)) < 0)
goto erreur;
}
@@ -219,42 +219,37 @@ nombre(char *t, size_t noct)
return n;
}
-static int
-ajt_symb(struct tfm *tfm, char *t, size_t noct, ssize_t *id)
+static ssize_t
+ajt_symb(struct tfm *tfm, char *t, size_t noct)
{
assert(tfm);
assert(t);
assert(noct > 0);
- assert(id);
/* Intercepter les symboles spéciaux. */
- if (noct == 3 && memcmp(t, "@0@", noct) == 0) {
- *id = TFM_SYMB_EPSILON;
- return 0;
- } else if (noct == 19 && memcmp(t, "@_IDENTITY_SYMBOL_@", noct) == 0) {
- *id = TFM_SYMB_IDENTITE;
- return 0;
- } else if (noct == 18 && memcmp(t, "@_UNKNOWN_SYMBOL_@", noct) == 0) {
- *id = TFM_SYMB_AUTRE;
- return 0;
- }
-
- if ((*id = tfm_symb_id(tfm, t, noct)) < 0)
- return -1;
-
- assert(*id >= 0);
-
- return 0;
+ if (noct == 18 && memcmp(t, "@_UNKNOWN_SYMBOL_@", noct) == 0)
+ return TFM_SYMB_AUTRE;
+ if (noct == 3 && memcmp(t, "@0@", noct) == 0)
+ return TFM_SYMB_EPSILON;
+ if (noct == 19 && memcmp(t, "@_IDENTITY_SYMBOL_@", noct) == 0)
+ return TFM_SYMB_IDENTITE;
+
+ return tfm_symb_id(tfm, t, noct);
}
static ssize_t
-symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max)
+symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max)
{
assert(tfm);
assert(symb);
assert(max > 0);
switch (id) {
+ case TFM_SYMB_AUTRE:
+ if (max < 18)
+ return -1;
+ memcpy(symb, "@_UNKNOWN_SYMBOL_@", 18);
+ return 18;
case TFM_SYMB_EPSILON:
if (max < 3)
return -1;
@@ -265,14 +260,9 @@ symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max)
return -1;
memcpy(symb, "@_IDENTITY_SYMBOL_@", 19);
return 19;
- case TFM_SYMB_AUTRE:
- if (max < 18)
- return -1;
- memcpy(symb, "@_UNKNOWN_SYMBOL_@", 18);
- return 18;
}
- assert(id >= 0);
+ assert((id & 0x01) == TFM_SNORMAL);
return tfm_symb_obt(tfm, id, symb, max);
}
diff --git a/tfd.c b/tfd.c
@@ -185,6 +185,10 @@ segmenteur(struct tfm *tfm)
if ((symbs = automate_symbs(tfm, &finaux)) == NULL)
goto erreur2;
+ /* Le premier état ne peut être final; car un symbole doit avoir une
+ * longueur supérieure à 0. */
+ assert(!symbs->etats[0].final);
+
/* Empiler le premier état. */
if ((ipile = tampex_empl((void **)&pile)) < 0)
goto erreur3;
@@ -220,7 +224,8 @@ segmenteur(struct tfm *tfm)
for (itrans = symbs->etats[ietat].trans;
ntrans--;
itrans = symbs->trans[itrans].prch) {
- assert(symbs->trans[itrans].se >= 0);
+ assert((symbs->trans[itrans].se & 0x01) ==
+ TFM_SNORMAL);
if (tfm_symb_obt(symbs, symbs->trans[itrans].se,
(char *)&c, 1) != 1)
goto erreur3;
@@ -295,7 +300,7 @@ segmenteur_base(uint16_t (**segm)[2], struct tfm *tfm, size_t ietat)
for (itrans = tfm->etats[ietat].trans,
ntrans = tfm->etats[ietat].ntrans;
ntrans--; itrans = tfm->trans[itrans].prch) {
- assert(tfm->trans[itrans].se >= 0);
+ assert((tfm->trans[itrans].se & 0x01) == TFM_SNORMAL);
if (tfm_symb_obt(tfm, tfm->trans[itrans].se, &c, 1) != 1)
return -1;
@@ -458,7 +463,7 @@ symboles_entree(struct tfm *tfm)
size_t i; /* Indice dans se. */
bool *dejala; /* Indique si l’identifiant est déjà dans se. */
size_t ietat, ntrans, itrans;
- ssize_t isymb; /* Identifiant de symbole. */
+ size_t isymb; /* Identifiant de symbole. */
assert(tfm);
@@ -477,8 +482,10 @@ symboles_entree(struct tfm *tfm)
ntrans = tfm->etats[ietat].ntrans;
ntrans--; itrans = tfm->trans[itrans].prch) {
/* Ignorer les symboles spéciaux. */
- if ((isymb = tfm->trans[itrans].se) < 0)
+ if (((isymb = tfm->trans[itrans].se) & 0x01) ==
+ TFM_SSPECIAL)
continue;
+ isymb >>= 1;
/* Ne pas ajouter le symbole s’il est déjà la. */
if (tampex_minim((void **)&dejala, isymb) < 0)
goto erreur2;
diff --git a/tfm.c b/tfm.c
@@ -30,8 +30,8 @@ static ssize_t tfm_symb_chercher(char *te, char *symb, size_t lngr);
static void trier_etat(struct tfm *tfm, size_t ietat);
/* Comparer deux transition pour les trier.
- * Renvoie -1 si t1 est inférieure t2, 0 s’ils sont égales et 1 si t2 est
- * inférieure à t1. */
+ * Renvoie -1 si t1 est supérieur t2, 0 s’ils sont égales et 1 si t2 est
+ * supérieure à t1. */
static int trans_comparer(struct tfm *tfm, size_t t1, size_t t2);
struct tfm *
@@ -94,8 +94,7 @@ tfm_ajt(struct tfm *tfm, size_t es, size_t ed, ssize_t se, ssize_t ss)
tfm->etats[es].trans = -1;
}
-
- /* Ajouter une transitions. */
+ /* Ajouter une transition. */
if ((itrans = tampex_empl((void **)&tfm->trans)) < 0)
return -1;
@@ -144,7 +143,7 @@ tfm_symb_id(struct tfm *tfm, char *symb, size_t lngr)
assert(id >= 0);
TFM_COHERENT(tfm);
- return id;
+ return (id << 1) | TFM_SNORMAL;
}
ssize_t
@@ -155,7 +154,10 @@ tfm_symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max)
TFM_COHERENT(tfm);
assert(symb);
assert(max > 0);
- assert(tampex_dedans(tfm->symbs, id));
+ assert((id & 0x01) == TFM_SNORMAL);
+ assert(tampex_dedans(tfm->symbs, id >> 1));
+
+ id >>= 1;
lngr = *(tfm->symbs + id);
@@ -171,29 +173,6 @@ tfm_symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max)
return lngr;
}
-ssize_t
-tfm_parc_symbs(struct tfm *tfm, size_t *id, char *symb, size_t max)
-{
- ssize_t lngr;
-
- TFM_COHERENT(tfm);
- assert(id);
- assert(symb);
- assert(max > 0);
-
- /* Vérifier s’il reste au moins au symbole à lire. */
- if (!tampex_dedans(tfm->symbs, *id))
- return 0;
-
- if ((lngr = tfm_symb_obt(tfm, *id, symb, max)) < 0)
- return -1;
-
- /* Préparer le prochain appel. */
- *id += lngr + 1;
-
- return lngr;
-}
-
int
tfm_mfinal(struct tfm *tfm, size_t ietat)
{
@@ -306,22 +285,10 @@ trier_etat(struct tfm *tfm, size_t ietat)
static int
trans_comparer(struct tfm *tfm, size_t t1, size_t t2)
{
- ssize_t s1;
- ssize_t s2;
-
TFM_COHERENT(tfm);
- s1 = tfm->trans[t1].se;
- s2 = tfm->trans[t2].se;
-
- /* Le symbole TFM_SYMB_AUTRE doit être placé à la fin. */
- if (s1 == TFM_SYMB_AUTRE)
- return 1;
- if (s2 == TFM_SYMB_AUTRE)
- return -1;
-
- if (s1 < s2) return -1;
- if (s1 == s2) return 0;
+ if (tfm->trans[t1].se > tfm->trans[t2].se) return -1;
+ if (tfm->trans[t1].se == tfm->trans[t2].se) return 0;
return 1;
}