depre

Afficher la date et l'heure hexadécimale
git clone git://git.asteride.xyz/~ldp/depre.git
Journaux | Fichiers | Références | LISEZ-MOI | LICENCE

commit 9a5a30c3d27fbf9df40bebaa0f711ec240f0b2e2
parent d9e9e6a8c4dc0efa3c001d98e820bb61d872c138
Auteur: ldp <ldp@asteride.xyz>
Date:   Wed,  7 Aug 2024 16:27:44 -0400

changement du nom du programme

Diffstat:
MMakefile | 14+++++++-------
Ddax.c | 98-------------------------------------------------------------------------------
Adepre.c | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 105 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ PREFIX = /usr/local BIN_DOS = ${PREFIX}/bin CC = cc -COPTS_SPCL = -O2 +COPTS_SPCL = -O2 -NDEBUG COPTS = -Wall -Wextra -Werror -Wpedantic -Wno-implicit-fallthrough \ -std=c89 ${COPTS_SPCL} @@ -10,17 +10,17 @@ COPTS = -Wall -Wextra -Werror -Wpedantic -Wno-implicit-fallthrough \ .c.o: ${CC} ${COPTS} -c "$<" -all: dax +all: depre -dax: dax.o - ${CC} ${COPTS} -o "$@" dax.o +depre: depre.o + ${CC} ${COPTS} -o "$@" depre.o install: all mkdir -p "${BIN_DOS}" - install -m 755 dax "${BIN_DOS}"/dax + install -m 755 depre "${BIN_DOS}"/depre uninstall: - rm -f ${BIN_DOS}/dax + rm -f ${BIN_DOS}/depre clean: - rm -f dax *.o *.core + rm -f depre *.o *.core diff --git a/dax.c b/dax.c @@ -1,98 +0,0 @@ -/* dax, affiche la date et l'heure hexadécimale - * par ldp <ldp@asteride.xyz> - * Ce programme est distribué sous la licence libre GPLv3 - */ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <unistd.h> - -/* nombre de secondes entre l'époque Unix et l'époque dax */ -#define NSECS (11138 * 60 * 60 * 24 + 3600 * 4) - -static void utilisation(FILE *f); -static int ccvt(char *cc, time_t *rep); - -char *nom_prog; - -int -main(int argc, char **argv) -{ - int opt; - time_t secondes; - unsigned int jours; - - if ((nom_prog = argv[0]) == NULL || nom_prog[0] == '\0') - nom_prog = "dax"; - - secondes = time(NULL); - - opterr = 0; - while ((opt = getopt(argc, argv, "r:h")) != -1) { - switch (opt) { - case 'r': - if (ccvt(optarg, &secondes) < 0) - goto erreur; - break; - case 'h': - utilisation(stdout); - return 0; - default: - goto erreur; - } - } - - if (argc - optind != 0) - goto erreur; - - /* nombre de secondes écoulées depuis l'époque dax */ - secondes = secondes - NSECS; - if (secondes < 0) - goto erreur; - /* nombre de jours complets écoulés */ - jours = secondes / 86400; - /* nombre de secondes écoulées aujourd'hui */ - secondes -= jours * 86400; - - /* afficher la date d'aujourd'hui */ - printf("%x.%llx\n", jours, secondes * (16 * 16 * 16) / 86400); - - return 0; - -erreur: - utilisation(stderr); - return 1; -} - -static void -utilisation(FILE *f) -{ - fprintf(f, "Utilisation: %s [-r secondes] [-h]\n", nom_prog); -} - -static int -ccvt(char *cc, time_t *rep) -{ - int signe; - - assert(cc != NULL); - - *rep = 0; - signe = 1; - if (*cc == '-') { - signe = -1; - cc++; - } - - for (;*cc != '\0'; cc++) { - if (*cc < '0' || *cc > '9') - return -1; - *rep = *rep * 10 + *cc - '0'; - } - - *rep *= signe; - - return 0; -} diff --git a/depre.c b/depre.c @@ -0,0 +1,99 @@ +/* depre, afficher la date et l'heure selon la représentation hexadécimale du + * temps dêpre + * par ldp <ldp@asteride.xyz> + * Ce programme est distribué sous la licence libre GPLv3 + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + +/* nombre de secondes entre l'époque Unix et l'époque depre */ +#define NSECS (11138 * 60 * 60 * 24 + 3600 * 4) + +static void utilisation(FILE *f); +static int ccvt(char *cc, time_t *rep); + +char *nom_prog; + +int +main(int argc, char **argv) +{ + int opt; + time_t secondes; + unsigned int jours; + + if ((nom_prog = argv[0]) == NULL || nom_prog[0] == '\0') + nom_prog = "depre"; + + secondes = time(NULL); + + opterr = 0; + while ((opt = getopt(argc, argv, "s:h")) != -1) { + switch (opt) { + case 's': + if (ccvt(optarg, &secondes) < 0) + goto erreur; + break; + case 'h': + utilisation(stdout); + return 0; + default: + goto erreur; + } + } + + if (argc - optind != 0) + goto erreur; + + /* nombre de secondes écoulées depuis l'époque depre */ + secondes = secondes - NSECS; + if (secondes < 0) + goto erreur; + /* nombre de jours complets écoulés */ + jours = secondes / 86400; + /* nombre de secondes écoulées aujourd'hui */ + secondes -= jours * 86400; + + /* afficher la date d'aujourd'hui */ + printf("%x.%llx\n", jours, secondes * (16 * 16 * 16) / 86400); + + return 0; + +erreur: + utilisation(stderr); + return 1; +} + +static void +utilisation(FILE *f) +{ + fprintf(f, "Utilisation: %s [-r secondes] [-h]\n", nom_prog); +} + +static int +ccvt(char *cc, time_t *rep) +{ + int signe; + + assert(cc != NULL); + + *rep = 0; + signe = 1; + if (*cc == '-') { + signe = -1; + cc++; + } + + for (;*cc != '\0'; cc++) { + if (*cc < '0' || *cc > '9') + return -1; + *rep = *rep * 10 + *cc - '0'; + } + + *rep *= signe; + + return 0; +}