aplat

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

commit 196256e646e275b450597c03d8f8f559641a8152
parent 90838739814c6b4ac4f390285087c13e83d6c275
Auteur: ldp <ldp@asteride.xyz>
Date:   Tue,  6 Aug 2024 19:55:13 -0400

ajout de assembler

Diffstat:
M.gitignore | 3++-
MMakefile | 11+++++++++--
Aassembler.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,4 +2,5 @@ *.core *.mo aplat -accumuler +assembler +assurer diff --git a/Makefile b/Makefile @@ -32,11 +32,14 @@ LANG_MAN != ls "${DOS_MAN}" .po.mo: msgfmt -o "$@" "$<" -all: aplat assurer traductions +all: aplat assembler assurer traductions aplat: aplat.o tampon.o general.o ${CC} ${COPTS} ${LDOPTS} -o "$@" aplat.o tampon.o general.o ${LIBS} +assembler: assembler.o + ${CC} ${COPTS} ${LDOPTS} -o "$@" assembler.o ${LIBS} + assurer: assurer.o general.o ${CC} ${COPTS} ${LDOPTS} -o "$@" assurer.o general.o ${LIBS} @@ -54,6 +57,10 @@ inst_aplat: mkdir -p "${BIN_DOS}" install -m 755 aplat "${BIN_DOS}"/aplat +inst_assembler: + mkdir -p "${BIN_DOS}" + install -m 755 assembler "${BIN_DOS}"/assembler + inst_trad: for F in ${FCH_MO} ; \ do \ @@ -73,7 +80,7 @@ inst_man: cp "${DOS_MAN}/$$L/plat.5" "${MAN_DOS}/$$L/man5" ; \ done -install: all inst_aplat inst_trad inst_man +install: all inst_aplat inst_assembler inst_trad inst_man uninstall: rm -f ${BIN_DOS}/aplat diff --git a/assembler.c b/assembler.c @@ -0,0 +1,81 @@ +#include <assert.h> +#include <limits.h> +#include <stdio.h> + +static int inclure(FILE *); +static int lire_chemin(FILE *, char *); +static int copier_fichier(char *); + +char *nom_prog; + +int +main(int argc, char **argv) +{ + (void)argc; + + if ((nom_prog = argv[0]) == NULL || nom_prog[0] == '\0') + nom_prog = "assembler"; + + return inclure(stdin); +} + + +static int +inclure(FILE *f) +{ + int res; + char chemin[PATH_MAX+1]; + + assert(f != NULL); + + printf("(pqt\n"); + while ((res = lire_chemin(f, chemin)) > 0) { + printf("(fch (@:nom %s)\n", chemin); + if (copier_fichier(chemin) < 0) + return -1; + printf(")\n"); + } + printf(")\n"); + + return res; +} + +static int +lire_chemin(FILE *f, char *chemin) +{ + int c; + long n; + + assert(f != NULL); + assert(chemin != NULL); + + for (n = 0; (c = getc(f)) != '\n' && c != EOF; n++) { + if (n == PATH_MAX) { + fprintf(stderr, "%s: chemin trop long\n", nom_prog); + return -1; + } + *chemin++ = c; + } + if (c == EOF) + return 0; + *chemin = '\0'; + + return 1; +} + +static int +copier_fichier(char *chemin) { + int c; + FILE *f; + + if ((f = fopen(chemin, "r")) == NULL) { + fprintf(stderr, "%s: impossible d'ouvrir %s\n", + nom_prog, chemin); + return -1; + } + + while ((c = getc(f)) != EOF) + putc(c, stdout); + + return 0; +}