commit a8f45e469f3abf7ee4573bc11b7fc24adb6a8232
parent 2e34387ed2ba20cb72b0f8ad6e01ce44bd0bcd88
Auteur: Selve <selve@asteride.xyz>
Date: Thu, 7 Mar 2024 18:00:53 -0500
ajouts de fiches absolus
Diffstat:
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/encore.c b/encore.c
@@ -241,13 +241,15 @@ cmd_a(int argc, char **argv)
struct paquet pq;
unsigned int n;
char opt;
+ int abs;
assert(argc >= 1);
assert(argv != NULL);
- n = 1;
+ n = 1;
+ abs = 0;
- while ((opt = getopt(argc, argv, "n:h")) != -1) {
+ while ((opt = getopt(argc, argv, "n:ah")) != -1) {
switch (opt) {
case 'n':
if (cve(optarg, &n) < 0) {
@@ -258,6 +260,9 @@ cmd_a(int argc, char **argv)
return 0;
}
continue;
+ case 'a':
+ abs = 1;
+ continue;
case 'h':
utilisation(stdout, CMD_A);
return 0;
@@ -274,6 +279,12 @@ cmd_a(int argc, char **argv)
if (pq_ouvrir(argv[0], &pq) < 0)
return 1;
+ if (abs) {
+ if (n < pq.entete.nb)
+ goto err_abs;
+ n = n - pq.entete.nb;
+ }
+
if (pq_ajouter(&pq, n) < 0)
return 1;
@@ -282,6 +293,10 @@ cmd_a(int argc, char **argv)
err_util:
utilisation(stderr, CMD_A);
return 1;
+err_abs:
+ fprintf(stderr, "il y a déjà plus de %d fiches dans %s\n",
+ pq.entete.nb, pq.nom);
+ return 1;
}
static int