| 1 |
%\iffalse |
| 2 |
%<*internal> |
| 3 |
\iffalse |
| 4 |
%</internal> |
| 5 |
%<*internal> |
| 6 |
\fi |
| 7 |
\begingroup |
| 8 |
%</internal> |
| 9 |
%<*batchfile> |
| 10 |
\input docstrip.tex |
| 11 |
\keepsilent |
| 12 |
\preamble |
| 13 |
________________________________________________________ |
| 14 |
Copyright (C) 2007-2017 Will Robertson & Johannes Große |
| 15 |
License information appended. |
| 16 |
\endpreamble |
| 17 |
\postamble |
| 18 |
Copyright (C) 2007-2017 by Will Robertson & Johannes Große |
| 19 |
|
| 20 |
Distributable under the LaTeX Project Public License, |
| 21 |
version 1.3c or higher (your choice). The latest version of |
| 22 |
this license is at: http://www.latex-project.org/lppl.txt |
| 23 |
|
| 24 |
This work is "author-maintained" by Will Robertson. |
| 25 |
|
| 26 |
This work consists of the file ifplatform.dtx |
| 27 |
and the derived files ifplatform.pdf, |
| 28 |
ifplatform.sty, and |
| 29 |
ifplatform.ins. |
| 30 |
\endpostamble |
| 31 |
\askforoverwritefalse |
| 32 |
\generate{\file{ifplatform.sty}{\from{ifplatform.dtx}{package}}} |
| 33 |
%</batchfile> |
| 34 |
%<batchfile>\endbatchfile |
| 35 |
%<*internal> |
| 36 |
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}} |
| 37 |
\nopreamble\nopostamble |
| 38 |
\endgroup |
| 39 |
\immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx} |
| 40 |
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo} |
| 41 |
%</internal> |
| 42 |
%<*driver> |
| 43 |
\documentclass{ltxdoc} |
| 44 |
\errorcontextlines=999 |
| 45 |
\EnableCrossrefs |
| 46 |
\CodelineIndex |
| 47 |
\RecordChanges |
| 48 |
%\OnlyDescription |
| 49 |
\usepackage{array,booktabs,color,enumitem,geometry,hologo,microtype} |
| 50 |
\usepackage[sc,osf]{mathpazo} |
| 51 |
\usepackage[colorlinks]{hyperref} |
| 52 |
\geometry{b5paper} |
| 53 |
\linespread{1.1} % A bit more space between lines |
| 54 |
\frenchspacing % Remove ugly extra space after punctuation |
| 55 |
\definecolor{niceblue}{rgb}{0.2,0.4,0.8} |
| 56 |
\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}} |
| 57 |
\newcommand*\pkg[1]{\textsf{#1}} |
| 58 |
\hfuzz2pt |
| 59 |
\usepackage{ifplatform}% for version info |
| 60 |
\ifwindows |
| 61 |
\typeout{ifplatform debug: using Windows.} |
| 62 |
\fi\iflinux |
| 63 |
\typeout{ifplatform debug: using Linux.} |
| 64 |
\fi\ifmacosx |
| 65 |
\typeout{ifplatform debug: using Mac OS X.} |
| 66 |
\fi\ifcygwin |
| 67 |
\typeout{ifplatform debug: using Cygwin.} |
| 68 |
\fi |
| 69 |
\begin{document} |
| 70 |
\DocInput{ifplatform.dtx} |
| 71 |
\end{document} |
| 72 |
%</driver> |
| 73 |
%\fi |
| 74 |
% |
| 75 |
% \GetFileInfo{\jobname.sty} |
| 76 |
% \CheckSum{0} |
| 77 |
% \makeatletter |
| 78 |
% |
| 79 |
% \title{The \pkg{\jobname} package} |
| 80 |
% \author{Original code by Johannes Gro\ss{}e\\ |
| 81 |
% Package by Will Robertson\\ |
| 82 |
% \color[gray]{0.5} |
| 83 |
% \texttt{http://github.com/wspr/ifplatform}} |
| 84 |
% \date{\fileversion\thanks{Thanks to Ken Brown, Joseph Wright, Zebb Prime, and others for testing this package.}\qquad \filedate} |
| 85 |
% |
| 86 |
% \maketitle |
| 87 |
% |
| 88 |
% \section{Main features and usage} |
| 89 |
% |
| 90 |
% This package provides the three following conditionals to test |
| 91 |
% which operating system is being used to run \TeX: |
| 92 |
% \begin{itemize}[nolistsep,label={}] |
| 93 |
% \item \cs{ifwindows} |
| 94 |
% \item \cs{iflinux} |
| 95 |
% \item \cs{ifmacosx} |
| 96 |
% \item \cs{ifcygwin} |
| 97 |
% \end{itemize} |
| 98 |
% If you only wish to detect \cs{ifwindows}, then it does not matter how you |
| 99 |
% load this package. Note then that use of (Linux \emph{or} \macosxname\ \emph{or} Cygwin) can |
| 100 |
% then be detected with \cs{ifwindows}\cs{else}. |
| 101 |
% |
| 102 |
% If you also wish to determine the difference between which Unix-variant |
| 103 |
% you are using (i.e., also detect \cs{iflinux}, \cs{ifmacosx}, and \cs{ifcygwin}) then shell |
| 104 |
% escape must be enabled. |
| 105 |
% This is achieved by using the |-shell-escape| command line option when |
| 106 |
% executing \LaTeX. |
| 107 |
% |
| 108 |
% If shell escape is not enabled, \cs{iflinux}, \cs{ifmacosx}, and \cs{ifcygwin} will all return \emph{false}. A warning will be printed in the console output to remind you in this case. |
| 109 |
% |
| 110 |
% \section{Auxiliary features} |
| 111 |
% |
| 112 |
% \cs{ifshellescape} is provided as a conditional to test whether |
| 113 |
% shell escape is active or not. (Note: new versions of pdf\/\TeX\ |
| 114 |
% allow you to query shell escape with \verb|\ifnum\pdfshellescape>0|\,, |
| 115 |
% and the \pkg{pdftexcmds} package provides the wrapper \cs{pdf@shellescape} |
| 116 |
% which works with \hologo{XeTeX}, \hologo{pdfTeX}, and \hologo{LuaTeX}.) |
| 117 |
% |
| 118 |
% Also, the \cmd\platformname\ command is defined to expand to a |
| 119 |
% macro that represents the operating system. Default definitions are |
| 120 |
% (respectively): |
| 121 |
% \begin{quote} |
| 122 |
% \begin{tabular}{@{}l@{\quad$\to$\quad}l} |
| 123 |
% \cmd\windowsname & `\windowsname' \\ |
| 124 |
% \cmd\notwindowsname & `\notwindowsname' (when shell escape is disabled) \\ |
| 125 |
% \cmd\linuxname & `\linuxname' \\ |
| 126 |
% \cmd\macosxname & `\macosxname' \\ |
| 127 |
% \cmd\cygwinname & `\cygwinname' \\ |
| 128 |
% \cmd\unknownplatform & \emph{whatever is returned by} |uname| \\ |
| 129 |
% \end{tabular} |
| 130 |
% \end{quote} |
| 131 |
% E.g., if \cs{ifwindows} is \emph{true} then \cs{platformname} |
| 132 |
% expands to \cs{windowsname}, which expands to `\windowsname'. |
| 133 |
% Redefine the macros above to customise |
| 134 |
% the output of \cmd\platformname. |
| 135 |
% |
| 136 |
% \begin{center}\itshape |
| 137 |
% This documentation was compiled on \platformname. |
| 138 |
% \end{center} |
| 139 |
% |
| 140 |
% \section{Other platforms} |
| 141 |
% |
| 142 |
% 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. |
| 143 |
% |
| 144 |
% For example, to test whether the AIX operating system is being used, you could use the following code: |
| 145 |
% \begin{quote} |
| 146 |
% \begin{verbatim} |
| 147 |
%\def\myplatform{aix6} |
| 148 |
%\ifx\myplatform\unknownplatform |
| 149 |
% ... AIX is being used ... |
| 150 |
%\else |
| 151 |
% ... or not ... |
| 152 |
%\fi |
| 153 |
% \end{verbatim} |
| 154 |
% \end{quote} |
| 155 |
% The \pkg{ifthen} and \pkg{xifthen} packages might be of interest to those who prefer more \LaTeX-like methods of conditional testing. |
| 156 |
% |
| 157 |
% \begin{table}[hp] |
| 158 |
% \centering |
| 159 |
% \begin{tabular}{@{}l>{\ttfamily}c@{}} |
| 160 |
% \toprule |
| 161 |
% Platform & uname \textrm{string} \\ |
| 162 |
% \midrule |
| 163 |
% FreeBSD & {FreeBSD} \\ |
| 164 |
% OpenBSD & {OpenBSD} \\ |
| 165 |
% Solaris & {SunOS} \\ |
| 166 |
% HPUX & {HP-UX} \\ |
| 167 |
% IRIX & {IRIX64} \\ |
| 168 |
% AIX & {aix6} \\ |
| 169 |
% Cray UNICOS & {sn5176} \\ |
| 170 |
% \bottomrule |
| 171 |
% \end{tabular} |
| 172 |
% \caption{List of operating systems and their \texttt{uname} strings. Adapted from % \url{http://en.wikipedia.org/wiki/Uname}.} |
| 173 |
% \label{table} |
| 174 |
% \end{table} |
| 175 |
% |
| 176 |
% \section{Limitations} |
| 177 |
% |
| 178 |
% Some technical information in case things go wrong. |
| 179 |
% \begin{itemize} |
| 180 |
% \item \pkg{ifplatform} checks for Windows by the presence or absence of the file `|nul:|'. If you have a file in your search path in *nix called `|nul:.tex|' (or without the |.tex|) then things may become confused. |
| 181 |
% |
| 182 |
% \item \pkg{ifplatform} checks for *nix by the presence or absence of the file `|/dev/null|'. If you have the file in Windows called |/dev/null.tex| (or without the extension) then things might similarly get mixed up. |
| 183 |
% |
| 184 |
% \item When both null files are detected (i.e., things aren't right with one of the two tests above), \pkg{ifplatform} uses another test to try and sort itself out. For interest, the test is: `|echo # > \jobname.w18|'. Under Windows you should end up with a text file containing an octothorpe. On *nix, the |#| will be seen as a comment char and the test will be ignored and the file will not be written. |
| 185 |
% |
| 186 |
% This `last resort' test will fail if shell escape is not enabled, or if the file |\jobname.w18| |
| 187 |
% somehow already exists, or if the behaviour of |#| isn't as reliable as I think. |
| 188 |
% |
| 189 |
% \item Note that if you're running \TeX\ binaries from Cygwin on Windows, then your platform will \emph{not} be Windows. It will appear to be a *nix system, with platform name `Cygwin'. |
| 190 |
% |
| 191 |
% \item If you ever see the error |
| 192 |
% \begin{quote}\ttfamily I can't tell if this is Windows or *nix; you |
| 193 |
% appear to be neither.\end{quote} |
| 194 |
% then I'd dearly like to know how it happened. It should |
| 195 |
% never occur, as far as I know. |
| 196 |
% (Update: in previous versions of this package, this message appeared when running under \hologo{LuaTeX}.) |
| 197 |
% \end{itemize} |
| 198 |
% Keep these points in mind and you'll never run into trouble. |
| 199 |
% I hope you won't run into trouble in any case. |
| 200 |
% |
| 201 |
% \clearpage |
| 202 |
% \StopEventually{\PrintIndex} |
| 203 |
% \section{Implementation} |
| 204 |
%\iffalse |
| 205 |
%<*package> |
| 206 |
%\fi |
| 207 |
% \begin{macrocode} |
| 208 |
\ProvidesPackage{ifplatform} |
| 209 |
[2017/10/13 v0.4a Testing for the operating system] |
| 210 |
% \end{macrocode} |
| 211 |
% Packages required: (thanks Heiko) |
| 212 |
% \begin{macrocode} |
| 213 |
\RequirePackage{shellesc,pdftexcmds,catchfile,ifluatex} |
| 214 |
% \end{macrocode} |
| 215 |
% Conditionals we provide: |
| 216 |
% \begin{macrocode} |
| 217 |
\newif\ifshellescape |
| 218 |
\newif\ifwindows |
| 219 |
\newif\ifmacosx |
| 220 |
\newif\iflinux |
| 221 |
\newif\ifcygwin |
| 222 |
% \end{macrocode} |
| 223 |
% \begin{macro}{\windowsname} |
| 224 |
% \begin{macro}{\notwindowsname} |
| 225 |
% \begin{macro}{\linuxname} |
| 226 |
% \begin{macro}{\macosxname} |
| 227 |
% \begin{macro}{\cygwinname} |
| 228 |
% \begin{macro}{\unknownplatform} |
| 229 |
% Names of operating systems: |
| 230 |
% \begin{macrocode} |
| 231 |
\newcommand\windowsname{Windows} |
| 232 |
\newcommand\notwindowsname{*NIX} |
| 233 |
\newcommand\linuxname{Linux} |
| 234 |
\newcommand\macosxname{Mac\,OS\,X} |
| 235 |
\newcommand\cygwinname{Cygwin} |
| 236 |
\newcommand\unknownplatform{[Unknown]} |
| 237 |
% \end{macrocode} |
| 238 |
% \end{macro} |
| 239 |
% \end{macro} |
| 240 |
% \end{macro} |
| 241 |
% \end{macro} |
| 242 |
% \end{macro} |
| 243 |
% \end{macro} |
| 244 |
% For internal stuff later: |
| 245 |
% \begin{macrocode} |
| 246 |
\edef\ip@file{\jobname.w18} |
| 247 |
\newif\if@ip@nix@ |
| 248 |
% \end{macrocode} |
| 249 |
% \begin{macro}{\ifshellescape} |
| 250 |
% Determine if shell escape is enabled: |
| 251 |
% \begin{macrocode} |
| 252 |
\ifnum\pdf@shellescape=1\relax |
| 253 |
\shellescapetrue |
| 254 |
\else |
| 255 |
\ifluatex\else |
| 256 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 257 |
shell escape is disabled, |
| 258 |
so I can only detect \@backslashchar ifwindows% |
| 259 |
} |
| 260 |
\fi |
| 261 |
\fi |
| 262 |
% \end{macrocode} |
| 263 |
% \end{macro} |
| 264 |
% An error message for when things go wrong: |
| 265 |
% \begin{macrocode} |
| 266 |
\def\ip@cantdecide{% |
| 267 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 268 |
I can't tell if this is Windows or *nix; |
| 269 |
you appear to be both% |
| 270 |
}% |
| 271 |
} |
| 272 |
% \end{macrocode} |
| 273 |
% Now the platform test. In Lua\TeX\ this is straightforward: |
| 274 |
% \begin{macrocode} |
| 275 |
\ifluatex |
| 276 |
\csname\directlua{ |
| 277 |
if os.type == "unix" then |
| 278 |
tex.sprint("@ip@nix@true") |
| 279 |
elseif os.type == "windows" then |
| 280 |
tex.sprint("windowstrue") |
| 281 |
end |
| 282 |
}\endcsname |
| 283 |
\else |
| 284 |
% \end{macrocode} |
| 285 |
% Otherwise we need to |
| 286 |
% test for the null files of Windows and *nix. |
| 287 |
% (This doesn't work at all in LuaTeX. Not sure why; haven't looked.) |
| 288 |
% In a normal situation, this is all we need to do: |
| 289 |
% \begin{macrocode} |
| 290 |
\IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true} |
| 291 |
\IfFileExists{/dev/null}{\windowsfalse}{\windowstrue} |
| 292 |
% \end{macrocode} |
| 293 |
% \begin{table} |
| 294 |
% \centering |
| 295 |
% \begin{tabular}{@{}llll@{}} |
| 296 |
% \toprule |
| 297 |
% File & Exists & Windows? & *nix? \\ |
| 298 |
% \midrule |
| 299 |
% \texttt{nul:} & true & Probably & Maybe \\ |
| 300 |
% & false & Definitely not & Definitely \\ |
| 301 |
% \texttt{/dev/null} & true & Maybe & Probably \\ |
| 302 |
% & false & Definitely & Definitely not \\ |
| 303 |
% \bottomrule |
| 304 |
% \end{tabular} |
| 305 |
% \caption{Possibilities for testing null files and their prospects for determining the platform.} |
| 306 |
% \label{tbl} |
| 307 |
% \end{table} |
| 308 |
% However, sometimes that's not good enough. |
| 309 |
% If things go wrong above, we still don't know which platform. Can only proceed if shell escape is on; fallback heuristic: |
| 310 |
% \begin{itemize}[nolistsep] |
| 311 |
% \item If the tmp file exists |
| 312 |
% \begin{itemize}[nolistsep] |
| 313 |
% \item Tell them to delete it and abort. |
| 314 |
% \item Otherwise: |
| 315 |
% \end{itemize} |
| 316 |
% \item Write to it with |echo| that only works on Windows |
| 317 |
% \item Then see again if it exists |
| 318 |
% \begin{itemize}[nolistsep] |
| 319 |
% \item If the tmp file exists: Windows (and delete the file) |
| 320 |
% \item Otherwise: *nix |
| 321 |
% \end{itemize} |
| 322 |
% \end{itemize} |
| 323 |
% Here's the code for the above `last resort' test: |
| 324 |
% \begin{macrocode} |
| 325 |
\edef\ip@windows@echo@test{echo \string# > "\ip@file"} |
| 326 |
\def\ip@backupplan{% |
| 327 |
\IfFileExists{\ip@file}{% |
| 328 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 329 |
Please delete the file "\ip@file" and try again% |
| 330 |
}% |
| 331 |
\ip@cantdecide |
| 332 |
}{% |
| 333 |
\ShellEscape{\ip@windows@echo@test}% |
| 334 |
\IfFileExists{\ip@file}{% |
| 335 |
\ShellEscape{del "\ip@file"}% |
| 336 |
\windowstrue |
| 337 |
}{% |
| 338 |
\@ip@nix@true |
| 339 |
}% |
| 340 |
}% |
| 341 |
} |
| 342 |
% \end{macrocode} |
| 343 |
% Now we use some odd logic to deduce what's happening in the edge cases when things go wrong: (see table~\ref{tbl}) |
| 344 |
% \begin{macrocode} |
| 345 |
\ifwindows |
| 346 |
\if@ip@nix@ |
| 347 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 348 |
I can't tell if this is Windows or *nix; |
| 349 |
you appear to be neither% |
| 350 |
} |
| 351 |
\fi |
| 352 |
\else |
| 353 |
\if@ip@nix@\else |
| 354 |
\ifshellescape |
| 355 |
\ip@backupplan |
| 356 |
\else |
| 357 |
\ip@cantdecide |
| 358 |
\fi |
| 359 |
\fi |
| 360 |
\fi |
| 361 |
\fi |
| 362 |
% \end{macrocode} |
| 363 |
% Needed below: |
| 364 |
% \begin{macrocode} |
| 365 |
\def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6} |
| 366 |
% \end{macrocode} |
| 367 |
% |
| 368 |
% \begin{macro}{\iflinux} |
| 369 |
% \begin{macro}{\ifmacosx} |
| 370 |
% \begin{macro}{\ifcygwin} |
| 371 |
% Now test for the others; directly test for Linux and Mac\,OS\,X; but what about Solaris or FreeBSD or \dots\ ? |
| 372 |
% Define \cmd\unknownplatform\ as the output of |uname| rather than enumerate the possibilities. |
| 373 |
% \begin{macrocode} |
| 374 |
\if@ip@nix@\ifshellescape |
| 375 |
\ifwindows\else |
| 376 |
\ShellEscape{uname -s > "\ip@file"} |
| 377 |
\CatchFileDef\@tempa{\ip@file}{} |
| 378 |
\ShellEscape{rm -- "\ip@file"} |
| 379 |
% \end{macrocode} |
| 380 |
% Kill a trailing space: |
| 381 |
% \begin{macrocode} |
| 382 |
\edef\@tempa{\expandafter\zap@space\@tempa\@empty} |
| 383 |
\def\@tempb{Linux} |
| 384 |
\ifx\@tempa\@tempb |
| 385 |
\linuxtrue |
| 386 |
\else |
| 387 |
\def\@tempb{Darwin} |
| 388 |
\ifx\@tempa\@tempb |
| 389 |
\macosxtrue |
| 390 |
\else |
| 391 |
\def\@tempb{CYGWIN} |
| 392 |
\edef\@tempc{\expandafter\ip@only@six\@tempa------\@nil} |
| 393 |
\ifx\@tempb\@tempc |
| 394 |
\cygwintrue |
| 395 |
\else |
| 396 |
\edef\unknownplatform{\@tempa} |
| 397 |
\fi |
| 398 |
\fi |
| 399 |
\fi |
| 400 |
\fi |
| 401 |
\fi\fi |
| 402 |
% \end{macrocode} |
| 403 |
% \end{macro} |
| 404 |
% \end{macro} |
| 405 |
% \end{macro} |
| 406 |
% |
| 407 |
% \begin{macro}{\platformname} |
| 408 |
% Defined in terms of macros so the output is user-customisable. |
| 409 |
% \begin{macrocode} |
| 410 |
\edef\platformname{% |
| 411 |
\ifwindows |
| 412 |
\noexpand\windowsname |
| 413 |
\else |
| 414 |
\ifshellescape |
| 415 |
\iflinux |
| 416 |
\noexpand\linuxname |
| 417 |
\else |
| 418 |
\ifmacosx |
| 419 |
\noexpand\macosxname |
| 420 |
\else |
| 421 |
\ifcygwin |
| 422 |
\noexpand\cygwinname |
| 423 |
\else |
| 424 |
\noexpand\unknownplatform |
| 425 |
\fi |
| 426 |
\fi |
| 427 |
\fi |
| 428 |
\else |
| 429 |
\noexpand\notwindowsname |
| 430 |
\fi |
| 431 |
\fi |
| 432 |
} |
| 433 |
% \end{macrocode} |
| 434 |
% \end{macro} |
| 435 |
%\iffalse |
| 436 |
%</package> |
| 437 |
%\fi |
| 438 |
% |
| 439 |
% \Finale |
| 440 |
% |
| 441 |
% \typeout{------------------------------------------------------} |
| 442 |
% \typeout{ To finish the installation please move the following} |
| 443 |
% \typeout{ file into a directory searched by LaTeX:} |
| 444 |
% \typeout{ \space- ifplatform.sty} |
| 445 |
% \typeout{------------------------------------------------------} |
| 446 |
% |
| 447 |
\endinput |