summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/ifplatform/ifplatform.dtx
blob: a220e684bb66a8122a5ea81165f6fcb51e9e1a0f (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
%\iffalse 
%<*internal>
\iffalse
%</internal>
%<*readme>
_____________________
The ifplatform package
v0.2       2007/11/18

This package uses -shell-escape to establish whether
the document is being processed on Windows or a *NIX
platform (Mac OS X, Linux, etc.).

Booleans provided are: 
 - ifwindows
 - iflinux
 - ifmacosx
Please request more platforms if you need them.

Finally, the \platformname macro is also provided that
expands to a string of the platform name.

Will Robertson         wspr 81 at gmail dot com
Johannes Große

Copyright 2007
Distributed under the LaTeX Project Public License
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble
  ___________________________________________________
  Copyright (C) 2007  Will Robertson & Johannes Große
  License information appended.
\endpreamble
\postamble
Copyright (C) 2007 by Will Robertson & Johannes Große

Distributable under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) 
by Will Robertson.

This work consists of the file  ifplatform.dtx
          and the derived files ifplatform.pdf,
                                ifplatform.sty, and 
                                ifplatform.ins.
\endpostamble
\askforoverwritefalse
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\generate{\file{prepare.sh}{\from{\jobname.dtx}{prepare}}}
\endgroup
%</internal>
%<*driver>
\documentclass{ltxdoc}
\errorcontextlines=999
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\usepackage{array,booktabs,color,enumitem,hyperref}
\usepackage[sc,osf]{mathpazo}
\linespread{1.1}       % A bit more space between lines
\frenchspacing         % Remove ugly extra space after punctuation
\definecolor{niceblue}{rgb}{0.2,0.4,0.8}
\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}}
\newcommand*\pkg[1]{\textsf{#1}}
\hfuzz2pt
\usepackage{ifplatform}% for version info
\begin{document}
\DocInput{ifplatform.dtx}
\end{document}
%</driver>
%\fi
%
% \GetFileInfo{\jobname.sty}
% \CheckSum{0}
% \makeatletter
%
% \title{The \pkg{\jobname} package}
% \author{Code by Johannes Gro\ss{}e\\
%         Package by Will Robertson\\
%         \color[gray]{0.5}
%         \texttt{wspr\,81\,at\,gmail\,dot\,com}}
% \date{\fileversion \qquad \filedate}
%
% \maketitle
%
% \section{About}
% This package provides the following conditionals to test
% which operating system is being used to run \TeX:
% \begin{itemize}[nolistsep,label=--]
% \item \cs{ifwindows}
% \item \cs{iflinux}
% \item \cs{ifmacosx}
% \end{itemize}
%
% \TeX\ must be invoked with the |-shell-escape| option (or equivalent) for the
% package to work. \cs{ifshellescape} is also provided to check 
% whether this is the case.
%
% Also, the \cmd\platformname\ command is defined to expand to a 
% macro that represents the operating system. Default definitions are (respectively):
%
% \begin{tabular}{@{}l@{\quad$\to$\quad}l}
% \cmd\windowsname & `Windows' \\
% \cmd\linuxname & `Linux' \\
% \cmd\macosxname & `Mac\,OS\,X' \\
% \cmd\unknownplatform & \emph{whatever is returned by} |uname| \\
% \end{tabular}
%
% \noindent Redefine these macros to customise
% the output of \cmd\platformname.
% \ifshellescape
% This documentation was compiled on \platformname.
% \fi
%
% \section{Other platforms}
%
% If greater granularity is required to differentiate between various \textsc{unix}-like operating systems, then \cmd\unknownplatform\ can be interrogated for the platform based on the output of |uname|. Table~\ref{table} lists possible outputs for a range of operating systems.
%
% For example, to test whether the AIX operating system is being used, you could use the following code:
% \begin{verbatim}
%  \def\@tempa{aix6}
%  \ifx\unknownplatform\@tempa
%    ... AIX is being used ....
%  \else
%    ... or not ...
%  \fi
% \end{verbatim}
% The \pkg{ifthen} and \pkg{xifthen} packages might be of interest to those who prefer more \LaTeX-like methods of conditional testing.
%
% \begin{table}[hp]
% \centering
% \begin{tabular}{@{}l>{\ttfamily}c@{}}
% \toprule
% Platform & uname \textrm{string} \\
% \midrule
% AIX & {aix6} \\
% Cray UNICOS & {sn5176} \\
% FreeBSD & {FreeBSD} \\
% HPUX & {HP-UX} \\
% IRIX & {IRIX64} \\
% Solaris & {SunOS} \\
% OpenBSD & {OpenBSD} \\
% \bottomrule
% \end{tabular}
% \caption{List of operating systems and their \texttt{uname} strings. Adapted from % \url{http://en.wikipedia.org/wiki/Uname}.}
% \label{table}
% \end{table}
%
% \clearpage
% \section{Implementation}
%\iffalse
%<*package>
%\fi
%    \begin{macrocode}
\ProvidesPackage{ifplatform}
  [2007/11/18 v0.2  Testing for the operating system]
%    \end{macrocode}
% Conditionals we provide:
%    \begin{macrocode}
\newif\ifshellescape
\newif\ifwindows
\newif\ifmacosx
\newif\iflinux
%    \end{macrocode}
% Names of operating systems:
%    \begin{macrocode}
\newcommand\windowsname{Windows}
\newcommand\linuxname{Linux}
\newcommand\macosxname{Mac\,OS\,X}
\newcommand\unknownplatform{[Unknown]}
%    \end{macrocode}
% Define test file name and define a hopefully unique string:
%    \begin{macrocode}
\edef\ip@file{\jobname.w18}
\edef\ip@sig{write18-test-\the\year\the\month\the\day\the\time}
\edef\ip@win{'\ip@sig'}
%    \end{macrocode}
% Macro to read in a one-line file into a temporary location:
%    \begin{macrocode}
\def\ip@read@file{%
  \newread\instream 
  \openin\instream=\ip@file
  \@tempcnta=\endlinechar
  \endlinechar=-1 
  \read\instream to\@tempa
  \endlinechar=\@tempcnta
  \closein\instream}
%    \end{macrocode}
% Use echo to (maybe) write a test file. If it succeeds, continue; else, bail.
%    \begin{macrocode}
\immediate\write18{echo \ip@win >"\ip@file"}
\IfFileExists{\ip@file}{\shellescapetrue}{\shellescapefalse\endinput}
%    \end{macrocode}
% Now read the test file into a macro:
%    \begin{macrocode}
\ip@read@file
%    \end{macrocode}
% The contents of the test file reveals several things:
% \begin{itemize}[nolistsep,label=--]
% \item test string correct with single quotes: Windows,
% \item test string correct without single quotes: Linux/Mac OS X,
% \item test string not correct: did not really write test file, so \cmd\write18\ is not enabled. (This should never happen.)
% \end{itemize}
% \begin{macro}{\ifwindows}
% First test for Windows.
%    \begin{macrocode}
\ifx\@tempa\ip@sig
  \windowsfalse
\else
  \ifx\@tempa\ip@win
    \windowstrue
  \else
    \PackageError{ifplatform}
      {There is a problem. Please delete the file \ip@file.}
      {Somehow an old file is lying around telling me the wrong things.
       \MessageBreak This should never happen. Please let us know when it does!}
  \fi
\fi
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\iflinux}
% \begin{macro}{\ifmacosx}
% Now test for the others; directly test for Linux and Mac~OS~X; but what about Solaris or FreeBSD or \dots\ ?
% Define \cmd\unknownplatform\ as the output of |uname| rather than enumerate the possibilities.
%    \begin{macrocode}
\ifwindows\else
  \immediate\write18{uname -s > "\ip@file"}
  \ip@read@file
  \def\@tempb{Linux}
  \ifx\@tempa\@tempb
    \linuxtrue
  \else
    \def\@tempb{Darwin}
    \ifx\@tempa\@tempb
      \macosxtrue
    \else
      \edef\unknownplatform{\@tempa}
    \fi
  \fi
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\platformname}
% Defined in terms of macros so the output is user-customisable.
%    \begin{macrocode}
\edef\platformname{%
  \ifwindows\noexpand\windowsname\else
  \iflinux  \noexpand\linuxname\else
  \ifmacosx \noexpand\macosxname\else
            \noexpand\unknownplatform
  \fi\fi\fi}
%    \end{macrocode}
% \end{macro}
% Clean up:
%    \begin{macrocode}
\immediate\write18{\ifwindows del \else rm -- \fi "\ip@file"}
%    \end{macrocode}
%\iffalse
%</package>
%<*prepare>
%    \begin{macrocode}
rm ifplatform.zip
mv README.txt README
zip ifplatform.zip ifplatform.dtx ifplatform.ins ifplatform.pdf README
%    \end{macrocode}
%</prepare>
%\fi
%
% \typeout{------------------------------------------------------}
% \typeout{ To finish the installation please move the following}
% \typeout{ file into a directory searched by XeTeX:}
% \typeout{ \space- ifplatform.sty}
% \typeout{------------------------------------------------------}
%
\endinput