trafi

Transducteurs finis
git clone git://git.asteride.xyz/trafi.git
Journaux | Fichiers | Références

commit 668222941762ea1e06d56cb0e4b3e3739ef8ce6d
parent fb98ad5e6153231e475e88ae66f27179af554ed3
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date:   Mon, 16 Feb 2026 12:10:28 -0500

Excentrer la représentation des symboles spéciaux

Leur représentation dépend du format de fichier.

Diffstat:
Matt.c | 30++++++++++++++++++++++++++++--
Mtfm.c | 13+------------
Mtfm.h | 6+++---
3 fichiers modifiés, 32 insertions(+), 17 suppressions(-)

diff --git a/att.c b/att.c @@ -27,6 +27,12 @@ static ssize_t nombre(char *t, size_t noct); * pour intercepter les symboles spéciaux comme @0@. */ static int ajt_symb(struct tfm *tfm, char *t, size_t noct, ssize_t *id); +/* 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); + /* Préparer la lecture du fichier f. * La routine se fait peut-être une idée trop stricte du format .att et n’est * pas très flexible. */ @@ -134,12 +140,12 @@ att_ecrire(FILE *f, struct tfm *tfm) if (tampinf_obt(tfm->trans, itrans, 1, &trans) < 0) return -1; fprintf(f, "%ld\t%ld\t", ietat, trans.ed); - if ((lngr = tfm_symb_obt(tfm, trans.se, symb, + if ((lngr = symb_obt(tfm, trans.se, symb, TFM_TLL_SYMB_MAX)) < 0) return -1; fwrite(symb, 1, lngr, f); fputc('\t', f); - if ((lngr = tfm_symb_obt(tfm, trans.ss, symb, + if ((lngr = symb_obt(tfm, trans.ss, symb, TFM_TLL_SYMB_MAX)) < 0) return -1; fwrite(symb, 1, lngr, f); @@ -215,3 +221,23 @@ ajt_symb(struct tfm *tfm, char *t, size_t noct, ssize_t *id) return tfm_symb_id(tfm, t, noct, id); } + +static ssize_t +symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max) +{ + assert(tfm); + assert(symb); + assert(max > 0); + + switch (id) { + case TFM_SYMB_EPSILON: + if (max < 3) + return -1; + memcpy(symb, "@0@", 3); + return 3; + } + + assert(id >= 0); + + return tfm_symb_obt(tfm, id, symb, max); +} diff --git a/tfm.c b/tfm.c @@ -126,7 +126,7 @@ fin: } ssize_t -tfm_symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max) +tfm_symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max) { size_t lngr, i; char *ctn; @@ -137,17 +137,6 @@ tfm_symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max) ctn = tampinf_ctn(tfm->symbs); - /* Sybmoles spéciaux. */ - if (id < 0) { - switch (id) { - case TFM_SYMB_EPSILON: - if (max < 3) - return -1; - memcpy(symb, "@0@", 3); - return 3; - } - } - assert(tampinf_dedans(tfm->symbs, id)); lngr = *(unsigned char *)(ctn + id); diff --git a/tfm.h b/tfm.h @@ -71,9 +71,9 @@ int tfm_symb_id(struct tfm *tfm, char *symb, size_t lngr, ssize_t *id); /* Placer le symbole du transducteur tfm correspondant à l’identifiant id dans * le tampon symb, de taille max. - * Prend pour acquis que id est valide. Renvoie la taille du symbole, ou -1 en - * cas d’erreur. */ -ssize_t tfm_symb_obt(struct tfm *tfm, ssize_t id, char *symb, size_t max); + * Prend pour acquis que id est valide. Ne fonctionne pas pour les symboles + * spéciaux. Renvoie la taille du symbole, ou -1 en cas d’erreur. */ +ssize_t tfm_symb_obt(struct tfm *tfm, size_t id, char *symb, size_t max); /* Marquer un état comme final. * Renvoie 0, ou -1 en cas d’erreur. */