commit 7bebb321f2aceb3536b3f693bf3edc644b125f04
parent f93b9b8fb1cf00e4bce186f1f80d0c0cd7c4d17b
Auteur: Selve <selve@asteride.xyz>
Date: Wed, 14 Feb 2024 17:45:46 -0500
ajout de l'utilitaire assembler
Il sert à fusionner plusieurs documents aplat en un seul. Il s'appelait avant
empaqt.
Diffstat:
3 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
*.o
*.core
abattre
+assembler
diff --git a/Makefile b/Makefile
@@ -9,16 +9,21 @@ COPTS = -Wall -Wextra -Werror -Wpedantic --std=c89 ${COPTS_SPCL}
.c.o:
${CC} ${COPTS} -c "$<"
-all: abattre
+all: abattre assembler
abattre: abattre.o meta.o tampon.o
${CC} ${COPTS} -o "$@" abattre.o meta.o tampon.o
-install: abattre
+assembler: assembler.o
+ ${CC} ${COPTS} -o "$@" assembler.o
+
+install: abattre assembler
install -m 755 abattre ${BIN_DOS}/abattre
+ install -m 755 abattre ${BIN_DOS}/assembler
uninstall:
- rm -f ${PREFIX}/abattre
+ rm -f ${BIN_DOS}/abattre
+ rm -f ${BIN_DOS}/assembler
clean:
- rm -f abattre *.o
+ rm -f abattre assembler *.o
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;
+}