summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/getfiledate/getfiledate.sty
blob: 6e9faf2c3c8a600f49b303aac4c6fff82532c566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
% This is file getfiledate.sty, version 1.2.                               %
%                                                                          %
% This package fetches and formats the date of last modification of any    %
% existing file. It is based on an idea by Heiko Oberdiek (2009).          %
%                                                                          %
% This work may be distributed and/or modified under the conditions        %
% of the LaTeX Project Public License, either version 1.3 of this          %
% license or any later version. The latest version of this license         %
% is in http://www.latex-project.org/lppl.txt and version 1.3 or later     %
% is part of all distributions of LaTeX version 2005/12/01 or later.       %
%                                                                          %
% Copyright (c) 2009 Ahmed Musa (a.musa@rocketmail.com).                   %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

\ProvidesPackage{getfiledate}
  [2009/11/23 v1.2 Get date of last modification of existing file]
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\RequirePackage{etextools}[2009/09/30]
\RequirePackage{ltxnew}
\RequirePackage{xkeyval}
\@ifpackageloaded{xcolor}{}{\RequirePackage[table]{xcolor}}
\RequirePackage{amssymb}
\RequirePackage{boxedminipage}
\new\long\def\gfd@err#1#2{\PackageError{getfiledate}{#1}{#2}}
\new\long\def\gfd@warn#1{\PackageWarningNoLine{getfiledate}{#1}}
\new\let\gfd@alignright\relax
\new\let\gfd@alignleft\relax
\new\dimen\gfd@width@tmp\gfd@width@tmp=\z@\relax
\providecommand*\space{ }
\define@boolkeys[gfd]{getfiledate}[gfd@]{boxed,putprefix,notime}[true]
\define@cmdkey[gfd]{getfiledate}[gfd@]{prefix}[%
  The date of last modification of file]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{postfix}[was]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{file}[nofile.tex]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{width}[\hsize]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{marker}[]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{markercolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{filenamecolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{datecolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{inlinespace}[1em]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{head}[\baselineskip]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{foot}[\baselineskip]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framesep}[3pt]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framerule}[0.4pt]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{separator}[\textbullet]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framecolor}[black]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{sepcolor}[black]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{separator}[\textbullet]{}
\define@choicekey*+[gfd]{getfiledate}{align}[\gfd@val\gfd@nr]%
{center,right,left,justified}[justified]{%
  \ifcase\gfd@nr\relax
    \def\gfd@alignright{\hfil}%
    \def\gfd@alignleft{\hfil}%
  \or
    \def\gfd@alignright{\hfill}%
    \let\gfd@alignleft\relax
  \or
    \let\gfd@alignright\relax
    \def\gfd@alignleft{\hfill}%
  \or
    \let\gfd@alignright\relax
    \let\gfd@alignleft\relax
  \fi
}{%
  \gfd@err{Inadmissible value '#1' for align}
}
\DeclareOptionX*{\gfd@warn{Unknown option '\CurrentOption' ignored}}
\ExecuteOptionsX[gfd]<getfiledate>[notime,boxed]{%
  align=center,head,foot,prefix,postfix,marker,markercolor,
  filenamecolor,datecolor,inlinespace,file,width,framesep,
  framerule,framecolor,sepcolor,separator,putprefix
}
\ProcessOptionsX*[gfd]<getfiledate>\relax
\begingroup
\ifcsdef{pdffilemoddate}{}{%
  \AfterGroup{%
    \gfd@err{Missing command \string\pdffilemoddate}{%
      Use pdfTeX 1.30.0 or later version}
    \endinput
  }
}
\endgroup
\newcommand\getfiledate[2][]{%
  \setkeys[gfd]{getfiledate}{#1}%
  \setkeys[gfd]{getfiledate}{file={#2}}%
  \par\vspace{\gfd@head}%
  \begingroup
  \gfd@alignright
  \mbox{%
  \ifgfd@boxed
    \let\gfd@marker\@empty
    \def\gfd@inlinespace{\z@}%
    \fboxsep=\gfd@framesep\relax
    \fboxrule=\gfd@framerule\relax
    \gfd@width@tmp=\dimexpr\gfd@width+2\fboxsep+2\fboxrule\relax
    \color{\gfd@framecolor}%
    \begin{boxedminipage}{\gfd@width@tmp}%
      \normalcolor\gfd@tempa{\gfd@file}\relax
    \end{boxedminipage}%
  \else
    \noindent\gfd@tempa{\gfd@file}%
  \fi
  }%
  \gfd@alignleft
  \endgroup
  \par\vspace{\gfd@foot}%
}
\def\gfd@tempa#1{%
  \IfFileExists{#1}{%
    \expandafter\expandafter\expandafter
    \gfd@tempb\expandafter\@gobbletwo\pdffilemoddate{#1}
    D:00000000000000\@nil{#1}%
  }{\gfd@err{File '#1' does not exist or wrong path}{%
    Please enter correct filename and path}}
}
\newcommand\gfd@tempb[8]{\gfd@tempc{#1#2#3#4}{#5#6}{#7#8}}
\newcommand\gfd@tempc[9]{\gfd@tempd{#1}{#2}{#3}{#4#5}{#6#7}{#8#9}}
\def\gfd@tempd#1#2#3#4#5#6#7\@nil#8{%
  \parbox{\gfd@width}{%
    \removelastskip\noindent
    \ifbool{gfd@putprefix}{\gfd@prefix@a{#8}}{}\ignorespaces
    \textcolor{\gfd@datecolor}{#1-#2-#3}%
    \ifbool{gfd@notime}{}{%
      \space\textcolor{\gfd@sepcolor}{\gfd@separator}\space%
      \textcolor{\gfd@datecolor}{#4:#5:#6}\ignorespaces
    }.%
  }%
  \removelastskip
}
\def\gfd@prefix@a#1{%
  \ifcsempty{gfd@marker}{}{\gfd@marker@a}%
  \gfd@prefix\space\textcolor{\gfd@filenamecolor}{#1}\space\gfd@postfix\space%
}
\def\gfd@marker@a{%
  \textcolor{\gfd@markercolor}{\gfd@marker}%
  \leavevmode\hskip\gfd@inlinespace plus\z@ minus\z@\relax
}

\endinput