aplat

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

commit 90838739814c6b4ac4f390285087c13e83d6c275
parent fb109e062928443dce6edec419727689f1de6869
Auteur: ldp <ldp@asteride.xyz>
Date:   Tue,  6 Aug 2024 19:40:46 -0400

restructuration du programe

Diffstat:
MMakefile | 11+++++++----
Maplat.c | 10++++------
Ageneral.c | 37+++++++++++++++++++++++++++++++++++++
Ageneral.h | 9+++++++++
Mtampon.c | 41++---------------------------------------
5 files changed, 59 insertions(+), 49 deletions(-)

diff --git a/Makefile b/Makefile @@ -14,7 +14,7 @@ DOS_MAN = man CC = cc #COPTS_SPCL = -O2 -DNDEBUG COPTS = -Wall -Wextra -Werror -Wpedantic -Wno-implicit-fallthrough \ - --std=c89 ${COPTS_SPCL} + -std=c89 ${COPTS_SPCL} CPPOPTS = -I${INC_DOS} -DI18N_DOMAINE="\"aplat\"" \ -DI18N_DOS="\"${I18N_DOS}\"" \ -DVERSION="\"${VERSION}\"" @@ -32,10 +32,13 @@ LANG_MAN != ls "${DOS_MAN}" .po.mo: msgfmt -o "$@" "$<" -all: aplat traductions +all: aplat assurer traductions -aplat: aplat.o tampon.o - ${CC} ${COPTS} ${LDOPTS} -o "$@" aplat.o tampon.o ${LIBS} +aplat: aplat.o tampon.o general.o + ${CC} ${COPTS} ${LDOPTS} -o "$@" aplat.o tampon.o general.o ${LIBS} + +assurer: assurer.o general.o + ${CC} ${COPTS} ${LDOPTS} -o "$@" assurer.o general.o ${LIBS} traductions: ${FCH_MO} diff --git a/aplat.c b/aplat.c @@ -8,13 +8,11 @@ #include <libintl.h> #include <locale.h> +#include "general.h" #include "tampon.h" #define _(c) gettext(c) -#define TP_ETQ_TLL 127 -#define TP_CTN_TLL 255 - #define JT_RIEN (-1) #define JT_OUV 0 #define JT_FRM 1 @@ -86,8 +84,8 @@ main(int argc, char **argv) goto erreur; /* initialiser les tampons */ - if (tp_init(&tp_etq, TP_ETQ_TLL) < 0 || - tp_init(&tp_ctn, TP_CTN_TLL) < 0) + if (tp_init(&tp_etq, TLL_ETQ) < 0 || + tp_init(&tp_ctn, TLL_CTN) < 0) return 1; if (aplatir(stdin) < 0) @@ -162,7 +160,7 @@ aplatir(FILE *f) fprintf(stderr, _("%s: la longueur d'une " "étiquette ne peut excéder les %d " "octets\n"), - nom_prog, TP_ETQ_TLL); + nom_prog, TLL_ETQ); return -1; } (void) afficher_ligne(&draps, &tp_etq, &tp_ctn); diff --git a/general.c b/general.c @@ -0,0 +1,37 @@ +#include <assert.h> + +/* nombre d'octets en trop */ +int +utf8_trop(char *base, char *fin) +{ + int i, n; + unsigned char c; + + assert(base); + assert(fin); + assert(base <= fin); + + if (((unsigned char) *base >> 6) == 0x2) + return -1; + + for (i = 1; ((unsigned char) *fin >> 6) == 0x2; fin--) + i++; + c = *fin; + if (c <= 0x7F) /* un octet */ + n = 1; + else if (c >= 0xF0) /* quatre octets */ + n = 4; + else if (c >= 0xE0) /* trois octets */ + n = 3; + else if (c >= 0xC2) /* deux octets */ + n = 2; + else /* séquence invalide */ + n = 0;; + + if (i < n) + return i; + else if (i == n) + return 0; + else + return n - i; +} diff --git a/general.h b/general.h @@ -0,0 +1,9 @@ +#ifndef GENERAL_H +#define GENERAL_H + +#define TLL_ETQ 127 +#define TLL_CTN 255 + +int utf8_trop(char *base, char *fin); + +#endif diff --git a/tampon.c b/tampon.c @@ -1,6 +1,7 @@ #include <assert.h> #include <stdlib.h> +#include "general.h" #include "tampon.h" #define tp_invariants(t) \ @@ -11,8 +12,6 @@ assert((t)->oc >= 0), \ assert((t)->tll >= (t)->ol)) -static int utf8_acouper(char *base, char *fin); - int tp_init(struct tampon *tp, size_t tll) { @@ -70,7 +69,7 @@ tp_terminer(struct tampon *tp) tp_invariants(tp); if (tp->ol == 0) { - if ((tp->oc = utf8_acouper(tp->tp, tp->po-1)) < 0) { + if ((tp->oc = utf8_trop(tp->tp, tp->po-1)) < 0) { tp->oc = 0; return -1; } @@ -88,39 +87,3 @@ tp_longueur(struct tampon *tp) return tp->tll - tp->ol - tp->oc; } - -/* nombre d'octets en trop */ -static int -utf8_acouper(char *base, char *fin) -{ - int i, n; - unsigned char c; - - assert(base); - assert(fin); - assert(base <= fin); - - if (((unsigned char) *base >> 6) == 0x2) - return -1; - - for (i = 1; ((unsigned char) *fin >> 6) == 0x2; fin--) - i++; - c = *fin; - if (c <= 0x7F) /* un octet */ - n = 1; - else if (c >= 0xF0) /* quatre octets */ - n = 4; - else if (c >= 0xE0) /* trois octets */ - n = 3; - else if (c >= 0xC2) /* deux octets */ - n = 2; - else /* séquence invalide */ - n = 0;; - - if (i < n) - return i; - else if (i == n) - return 0; - else - return n - i; -}