aplat

Documents structurés pour Unix
git clone git://git.asteride.xyz/~ldp/aplat.git
Journaux | Fichiers | Références | LISEZ-MOI | LICENCE

commit 7b68f319a9f67774c31c712db03dc05034a1b45a
parent 7adb4583ed29e8b6011da89788b468893fad3e17
Auteur: Selve <selve@asteride.xyz>
Date:   Tue, 23 Jan 2024 12:05:07 -0500

correction d'un problème avec les blocs

À la fin d'un bloc était appelée inconditionnellement la fonction tp_bloc_rec(),
qui supprime tous les caractères d'un tampon jusqu'à la première nouvelle ligne
trouvée, inclusivement. Il ne faut pas appeler cette fonction lorsqu'un bloc est
vide, par contre, car elle supprimera trop de caractères. Un test a été ajouté
pour n'appeler cette fonction que si le bloc n'est pas vide.

Diffstat:
Maplat.c | 7++++++-
Mtampon.c | 9+++++++++
Mtampon.h | 1+
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/aplat.c b/aplat.c @@ -352,10 +352,13 @@ bloc(FILE *f, struct tampon *tp) { int c; int npar; + int ncar; assert(f != NULL); assert(tp != NULL); + ncar = tp_ncar(tp); + while ((c = getc(f)) != EOF) { switch (c) { case '\n': @@ -375,7 +378,9 @@ bloc(FILE *f, struct tampon *tp) ungetc(c, f); if (npar == NGUI) { if (c != '!') { - tp_bloc_rec(tp); + /* si le bloc n'est pas vide */ + if (ncar != tp_ncar(tp)) + tp_bloc_rec(tp); return c; } } diff --git a/tampon.c b/tampon.c @@ -107,3 +107,12 @@ tp_etq_rec(struct tampon *tp) assert(tp->pc - tp->tp > 0); return ETQ_SEP_REL; } + +/* obtenir le pointeur vers le prochain caractère */ +int +tp_ncar(struct tampon *tp) +{ + INVARIANTS_TP(tp); + + return tp->pc - tp->tp - 1; +} diff --git a/tampon.h b/tampon.h @@ -17,5 +17,6 @@ int tp_ecr(char c, struct tampon *); void tp_eff(struct tampon *); void tp_bloc_rec(struct tampon *); int tp_etq_rec(struct tampon *); +int tp_ncar(struct tampon *); #endif