logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Add-the-d-option-to-specify-the-.Dd-date.patch (4900B)


  1. From 5b40a091f4d31fa6d21a84536f5998135faf6dfa Mon Sep 17 00:00:00 2001
  2. From: schwarze <schwarze>
  3. Date: Tue, 13 Nov 2018 08:45:29 +0000
  4. Subject: [PATCH] Add the -d option to specify the .Dd date, and fall back to
  5. the mtime before resorting to the current time. Patch from Michael Forney
  6. <mforney at mforney dot org> with minimal tweaks by me.
  7. Upstream: Yes, main.c@1.72 util.c@1.35
  8. While here, fix the date format, "%F" is wrong for mdoc(7).
  9. Change it to "%B %e, %Y" which isn't perfect due to the
  10. spurious blank before single-digit day numbers, but closer.
  11. ---
  12. extern.h | 1 +
  13. main.c | 35 ++++++++++++++++++++++++++---------
  14. texi2mdoc.1 | 14 +++++++++++++-
  15. util.c | 1 -
  16. 4 files changed, 40 insertions(+), 11 deletions(-)
  17. diff --git a/extern.h b/extern.h
  18. index f713e0b..643edde 100644
  19. --- a/extern.h
  20. +++ b/extern.h
  21. @@ -365,6 +365,7 @@ struct texi {
  22. size_t dirsz; /* number of texi directories */
  23. char *title; /* title of document */
  24. char *subtitle; /* subtitle of document */
  25. + char *date; /* date of document */
  26. int secoffs; /* see sectioner() */
  27. char **indexs; /* @defindex indices */
  28. size_t indexsz; /* entries in indexs */
  29. diff --git a/main.c b/main.c
  30. index d343727..308fe5e 100644
  31. --- a/main.c
  32. +++ b/main.c
  33. @@ -17,6 +17,9 @@
  34. #if defined(__linux__) || defined(__MINT__)
  35. # define _GNU_SOURCE /* memmem */
  36. #endif
  37. +
  38. +#include <sys/stat.h>
  39. +
  40. #include <assert.h>
  41. #include <ctype.h>
  42. #include <getopt.h>
  43. @@ -1587,8 +1590,6 @@ static void
  44. dotop(struct texi *p, enum texicmd cmd, size_t *pos)
  45. {
  46. const char *cp;
  47. - time_t t;
  48. - char date[32];
  49. if (--p->ign)
  50. texierr(p, "@top command while ignoring");
  51. @@ -1598,13 +1599,11 @@ dotop(struct texi *p, enum texicmd cmd, size_t *pos)
  52. * We use the title set with @settitle for the `Nd' description
  53. * and the source document filename (the first one as invoked on
  54. * the command line) for the title.
  55. - * The date is set to the current date.
  56. + * The date is set to the modification time of the input.
  57. */
  58. - t = time(NULL);
  59. - strftime(date, sizeof(date), "%F", localtime(&t));
  60. teximacroopen(p, "Dd");
  61. - texiputchars(p, date);
  62. + texiputchars(p, p->date);
  63. teximacroclose(p);
  64. teximacroopen(p, "Dt");
  65. for (cp = p->title; '\0' != *cp; cp++)
  66. @@ -1864,9 +1863,12 @@ int
  67. main(int argc, char *argv[])
  68. {
  69. struct texi texi;
  70. - int c;
  71. + char date[32];
  72. + struct stat st;
  73. char *dirpath, *dir, *ccp;
  74. const char *progname, *Idir, *cp;
  75. + time_t t;
  76. + int c;
  77. progname = strrchr(argv[0], '/');
  78. if (progname == NULL)
  79. @@ -1878,8 +1880,11 @@ main(int argc, char *argv[])
  80. texi.ign = 1;
  81. Idir = NULL;
  82. - while (-1 != (c = getopt(argc, argv, "I:")))
  83. + while (-1 != (c = getopt(argc, argv, "d:I:")))
  84. switch (c) {
  85. + case ('d'):
  86. + texi.date = optarg;
  87. + break;
  88. case ('I'):
  89. Idir = optarg;
  90. break;
  91. @@ -1905,16 +1910,28 @@ main(int argc, char *argv[])
  92. *ccp = '\0';
  93. texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz);
  94. free(dirpath);
  95. + if (NULL == texi.date) {
  96. + t = stat(argv[0], &st) == 0 ? st.st_mtime : time(NULL);
  97. + strftime(date, sizeof(date),
  98. + "%B %e, %Y", localtime(&t));
  99. + texi.date = date;
  100. + }
  101. parsefile(&texi, argv[0], 1);
  102. } else {
  103. texi.title = strdup("Unknown Manual");
  104. texi.dirs = parsedirs(&texi, NULL, Idir, &texi.dirsz);
  105. + if (NULL == texi.date) {
  106. + t = time(NULL);
  107. + strftime(date, sizeof(date),
  108. + "%B %e, %Y", localtime(&t));
  109. + texi.date = date;
  110. + }
  111. parsestdin(&texi);
  112. }
  113. texiexit(&texi);
  114. return(EXIT_FAILURE);
  115. usage:
  116. - fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname);
  117. + fprintf(stderr, "usage: %s [-d date] [-I dirs] [file]\n", progname);
  118. return(EXIT_FAILURE);
  119. }
  120. diff --git a/texi2mdoc.1 b/texi2mdoc.1
  121. index 9f8169e..f479adc 100644
  122. --- a/texi2mdoc.1
  123. +++ b/texi2mdoc.1
  124. @@ -14,7 +14,7 @@
  125. .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  126. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  127. .\"
  128. -.Dd $Mdocdate: February 25 2015 $
  129. +.Dd $Mdocdate: November 13 2018 $
  130. .Dt TEXI2MDOC 1
  131. .Os
  132. .Sh NAME
  133. @@ -22,6 +22,7 @@
  134. .Nd convert texinfo documents to mdoc
  135. .Sh SYNOPSIS
  136. .Nm texi2mdoc
  137. +.Op Fl d Ar date
  138. .Op Fl I Ar dirs
  139. .Op Ar file
  140. .Sh DESCRIPTION
  141. @@ -39,6 +40,17 @@ By default,
  142. reads from standard input.
  143. Its arguments are as follows:
  144. .Bl -tag -width Ds
  145. +.It Fl d Ar date
  146. +Set the output document date in the
  147. +.Ic \&Dd
  148. +macro to
  149. +.Ar date ,
  150. +to be specified in the format
  151. +.Dq Ar Month Day , Year .
  152. +If unspecified,
  153. +.Nm
  154. +uses the file modification date
  155. +or the current date when reading from standard input.
  156. .It Fl I Ar dirs
  157. Colon-separated directories to search for
  158. .Li @include
  159. diff --git a/util.c b/util.c
  160. index 944872f..c6de818 100644
  161. --- a/util.c
  162. +++ b/util.c
  163. @@ -27,7 +27,6 @@
  164. #include <stdio.h>
  165. #include <stdlib.h>
  166. #include <string.h>
  167. -#include <time.h>
  168. #include <unistd.h>
  169. #include "extern.h"
  170. --
  171. 2.19.1