From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id 045752e0 for ; Mon, 12 Nov 2018 20:00:17 -0500 (EST) Received: by mail-ot1-f67.google.com with SMTP id 81so9824919otj.2 for ; Mon, 12 Nov 2018 17:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mforney-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=kW+KkBoNTYyNhLliwwQ3LMF3hAVb3ma5F9BkK0wAEn0=; b=J0COMvZTtVcbMjmyjR7YpK3kpYPcqBU9kw8iuFs3QFjoE7LZU5u2G13coNZloReKeR SadSomyKqHT+QrXAWJiwvybpR5gstcmmkvqi6zXjNZHO4snKF+LV6v6AecUqazbk6lzw EbxGBXX57ic4g3r2AWlsaL1zZauHFDNJC/gGLbxcvX259eTxIvGGeln3fd8+FI8HYnim LXkZZSi6Dk7ucV4aWL2cky9GLBTuRKsaITGFZdIv5J6Hkss3/HVOtESs36h46/ylHS9/ ZVlcVmTDn1QmcSBsTFhsIr5FA3zOAWyAAnFjqMTV8dokIITFU0ythmpv3sFqwL/Z48+5 Jr+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=kW+KkBoNTYyNhLliwwQ3LMF3hAVb3ma5F9BkK0wAEn0=; b=IA1lgGjtXhWeb2fNOttaKrLTWbJiadl499bztrwwsVCeW2pq+mlNtSLhTUBc7QzGCB iBGkOom+rVrp1a4Ic/213Hh4lgvuHqMchNodb5eU6LJZ6zdC7t9/bSN4yYBGfU7/BI50 BEp+3mspeGB7XfOdQFve1ZgEjSTUc4WSqRFe/zSrsdIoNf8D5YxRRmenol38CI+0vioR bv22dPRMMPwFnnkLBkNctLxP4eFbR8d3KMzopAEY/4YNqQ7cF9nJAPQu78atqT163U78 6NHvPwC3IuroGZxVJoioH0eY+5acgTgIBLu681cxnjn5UEG+WmbtqTZLOWoSCvSZPw8Q JdCg== X-Gm-Message-State: AGRZ1gLWbxon1+7xSw5wExAy00IH6Fm+brHTld0ItALX/+g20guKuIQ3 sIk/oAYFRW2aitTckTXBXzf399W9tOLt7TLhk15sJdaYlSk= X-Google-Smtp-Source: AJdET5fP9ez+JnbKISUZSwbl8aX7VOcOoFQBB4cb7m5jXPP31ZihR2pJnRtAnNtts8BjaTspoMZR9EZ/40LneAjaGRE= X-Received: by 2002:a9d:3b83:: with SMTP id k3mr2042694otc.318.1542070813664; Mon, 12 Nov 2018 17:00:13 -0800 (PST) X-Mailinglist: mandoc-tech Reply-To: tech@mandoc.bsd.lv MIME-Version: 1.0 Received: by 2002:a4a:d182:0:0:0:0:0 with HTTP; Mon, 12 Nov 2018 17:00:13 -0800 (PST) X-Originating-IP: [2601:647:5180:35d7::a50] From: Michael Forney Date: Mon, 12 Nov 2018 17:00:13 -0800 Message-ID: Subject: [texi2mdoc] [PATCH] Use mtime of input file for date, and allow override from command-line To: tech@mandoc.bsd.lv Content-Type: text/plain; charset="UTF-8" Hi, I'm using texi2mdoc to generate ffmpeg manuals, and thought it would be useful to be a bit smarter about choosing the document date so that the output is reproducible. This patch changes texi2mdoc to use the mtime of the input file if given by name, falling back to the current time if reading from stdin or stat fails. In either case, the date can be given explicitly with the -d flag. Index: extern.h =================================================================== RCS file: /cvs/texi2mdoc/extern.h,v retrieving revision 1.29 diff -u -p -r1.29 extern.h --- extern.h 12 Mar 2015 10:44:34 -0000 1.29 +++ extern.h 13 Nov 2018 00:53:02 -0000 @@ -422,6 +422,7 @@ struct texi { size_t valstackpos; /* position in valstack */ char *title; /* title of document */ char *subtitle; /* subtitle of document */ + char *date; /* date of document */ int secoffs; /* see sectioner() */ struct texidex *indexs; /* index entries */ size_t indexsz; /* entries in indexs */ Index: main.c =================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.71 diff -u -p -r1.71 main.c --- main.c 19 Mar 2015 09:53:35 -0000 1.71 +++ main.c 13 Nov 2018 00:53:03 -0000 @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include "extern.h" @@ -2342,8 +2344,10 @@ main(int argc, char *argv[]) { struct texi texi; int c; - char *dirpath, *dir, *ccp; + char *dirpath, *dir, *ccp, date[32]; const char *progname, *Idir, *cp; + struct stat st; + time_t t; progname = strrchr(argv[0], '/'); if (progname == NULL) @@ -2357,11 +2361,14 @@ main(int argc, char *argv[]) texi.seenvs = -1; Idir = NULL; - while (-1 != (c = getopt(argc, argv, "C:I:"))) + while (-1 != (c = getopt(argc, argv, "C:d:I:"))) switch (c) { case ('C'): texi.chapters = optarg; break; + case ('d'): + texi.date = optarg; + break; case ('I'): Idir = optarg; break; @@ -2393,16 +2400,26 @@ main(int argc, char *argv[]) *ccp = '\0'; texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz); free(dirpath); + if (NULL == texi.date) { + t = stat(argv[0], &st) == 0 ? st.st_mtime : time(NULL); + strftime(date, sizeof(date), "%F", localtime(&t)); + texi.date = date; + } parsefile(&texi, argv[0], 1); } else { texi.title = strdup("Unknown Manual"); texi.dirs = parsedirs(&texi, NULL, Idir, &texi.dirsz); + if (NULL == texi.date) { + t = time(NULL); + strftime(date, sizeof(date), "%F", localtime(&t)); + texi.date = date; + } parsestdin(&texi); } texiexit(&texi); exit(EXIT_SUCCESS); usage: - fprintf(stderr, "usage: %s [-Cdir] [-Idirs] [file]\n", progname); + fprintf(stderr, "usage: %s [-Cdir] [-ddate] [-Idirs] [file]\n", progname); return(EXIT_FAILURE); } Index: texi2mdoc.1 =================================================================== RCS file: /cvs/texi2mdoc/texi2mdoc.1,v retrieving revision 1.15 diff -u -p -r1.15 texi2mdoc.1 --- texi2mdoc.1 12 Mar 2015 04:24:19 -0000 1.15 +++ texi2mdoc.1 13 Nov 2018 00:53:03 -0000 @@ -23,6 +23,7 @@ .Sh SYNOPSIS .Nm texi2mdoc .Op Fl C Ar dir +.Op Fl d Ar date .Op Fl I Ar dirs .Op Ar file .Sh DESCRIPTION @@ -47,6 +48,10 @@ node-level documents placed within which must exist. These are created as .Pa prefix-NNN.7 . +.It Fl d Ar date +Set the output document date to +.Ar date +instead of the modification time of the input file. .It Fl I Ar dirs Colon-separated directories to search for .Li @include Index: util.c =================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.34 diff -u -p -r1.34 util.c --- util.c 19 Mar 2015 09:53:36 -0000 1.34 +++ util.c 13 Nov 2018 00:53:03 -0000 @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "extern.h" @@ -1731,21 +1730,16 @@ texicache(struct texi *p, const char *bu * We use the title set with @settitle for the `Nd' description * and the source document filename (the first one as invoked on * the command line) for the title. - * The date is set to the current date. + * The date is set to the modification time of the input. */ void teximdocopen(struct texi *p, size_t *pos) { const char *cp; - time_t t; - char date[32]; - - t = time(NULL); - strftime(date, sizeof(date), "%F", localtime(&t)); p->seenvs = -1; teximacroopen(p, "Dd"); - texiputchars(p, date); + texiputchars(p, p->date); teximacroclose(p); teximacroopen(p, "Dt"); for (cp = p->title; '\0' != *cp; cp++) -- To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv