| 1 |
%% |
| 2 |
%% This is file `ifplatform.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% ifplatform.dtx (with options: `package') |
| 8 |
%% ________________________________________________________ |
| 9 |
%% Copyright (C) 2007-2017 Will Robertson & Johannes Gro^^c3^^9fe |
| 10 |
%% License information appended. |
| 11 |
\ProvidesPackage{ifplatform} |
| 12 |
[2017/10/13 v0.4a Testing for the operating system] |
| 13 |
\RequirePackage{shellesc,pdftexcmds,catchfile,ifluatex} |
| 14 |
\newif\ifshellescape |
| 15 |
\newif\ifwindows |
| 16 |
\newif\ifmacosx |
| 17 |
\newif\iflinux |
| 18 |
\newif\ifcygwin |
| 19 |
\newcommand\windowsname{Windows} |
| 20 |
\newcommand\notwindowsname{*NIX} |
| 21 |
\newcommand\linuxname{Linux} |
| 22 |
\newcommand\macosxname{Mac\,OS\,X} |
| 23 |
\newcommand\cygwinname{Cygwin} |
| 24 |
\newcommand\unknownplatform{[Unknown]} |
| 25 |
\edef\ip@file{\jobname.w18} |
| 26 |
\newif\if@ip@nix@ |
| 27 |
\ifnum\pdf@shellescape=1\relax |
| 28 |
\shellescapetrue |
| 29 |
\else |
| 30 |
\ifluatex\else |
| 31 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 32 |
shell escape is disabled, |
| 33 |
so I can only detect \@backslashchar ifwindows% |
| 34 |
} |
| 35 |
\fi |
| 36 |
\fi |
| 37 |
\def\ip@cantdecide{% |
| 38 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 39 |
I can't tell if this is Windows or *nix; |
| 40 |
you appear to be both% |
| 41 |
}% |
| 42 |
} |
| 43 |
\ifluatex |
| 44 |
\csname\directlua{ |
| 45 |
if os.type == "unix" then |
| 46 |
tex.sprint("@ip@nix@true") |
| 47 |
elseif os.type == "windows" then |
| 48 |
tex.sprint("windowstrue") |
| 49 |
end |
| 50 |
}\endcsname |
| 51 |
\else |
| 52 |
\IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true} |
| 53 |
\IfFileExists{/dev/null}{\windowsfalse}{\windowstrue} |
| 54 |
\edef\ip@windows@echo@test{echo \string# > "\ip@file"} |
| 55 |
\def\ip@backupplan{% |
| 56 |
\IfFileExists{\ip@file}{% |
| 57 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 58 |
Please delete the file "\ip@file" and try again% |
| 59 |
}% |
| 60 |
\ip@cantdecide |
| 61 |
}{% |
| 62 |
\ShellEscape{\ip@windows@echo@test}% |
| 63 |
\IfFileExists{\ip@file}{% |
| 64 |
\ShellEscape{del "\ip@file"}% |
| 65 |
\windowstrue |
| 66 |
}{% |
| 67 |
\@ip@nix@true |
| 68 |
}% |
| 69 |
}% |
| 70 |
} |
| 71 |
\ifwindows |
| 72 |
\if@ip@nix@ |
| 73 |
\PackageWarningNoLine{ifplatform}{^^J \space\space\space |
| 74 |
I can't tell if this is Windows or *nix; |
| 75 |
you appear to be neither% |
| 76 |
} |
| 77 |
\fi |
| 78 |
\else |
| 79 |
\if@ip@nix@\else |
| 80 |
\ifshellescape |
| 81 |
\ip@backupplan |
| 82 |
\else |
| 83 |
\ip@cantdecide |
| 84 |
\fi |
| 85 |
\fi |
| 86 |
\fi |
| 87 |
\fi |
| 88 |
\def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6} |
| 89 |
\if@ip@nix@\ifshellescape |
| 90 |
\ifwindows\else |
| 91 |
\ShellEscape{uname -s > "\ip@file"} |
| 92 |
\CatchFileDef\@tempa{\ip@file}{} |
| 93 |
\ShellEscape{rm -- "\ip@file"} |
| 94 |
\edef\@tempa{\expandafter\zap@space\@tempa\@empty} |
| 95 |
\def\@tempb{Linux} |
| 96 |
\ifx\@tempa\@tempb |
| 97 |
\linuxtrue |
| 98 |
\else |
| 99 |
\def\@tempb{Darwin} |
| 100 |
\ifx\@tempa\@tempb |
| 101 |
\macosxtrue |
| 102 |
\else |
| 103 |
\def\@tempb{CYGWIN} |
| 104 |
\edef\@tempc{\expandafter\ip@only@six\@tempa------\@nil} |
| 105 |
\ifx\@tempb\@tempc |
| 106 |
\cygwintrue |
| 107 |
\else |
| 108 |
\edef\unknownplatform{\@tempa} |
| 109 |
\fi |
| 110 |
\fi |
| 111 |
\fi |
| 112 |
\fi |
| 113 |
\fi\fi |
| 114 |
\edef\platformname{% |
| 115 |
\ifwindows |
| 116 |
\noexpand\windowsname |
| 117 |
\else |
| 118 |
\ifshellescape |
| 119 |
\iflinux |
| 120 |
\noexpand\linuxname |
| 121 |
\else |
| 122 |
\ifmacosx |
| 123 |
\noexpand\macosxname |
| 124 |
\else |
| 125 |
\ifcygwin |
| 126 |
\noexpand\cygwinname |
| 127 |
\else |
| 128 |
\noexpand\unknownplatform |
| 129 |
\fi |
| 130 |
\fi |
| 131 |
\fi |
| 132 |
\else |
| 133 |
\noexpand\notwindowsname |
| 134 |
\fi |
| 135 |
\fi |
| 136 |
} |
| 137 |
%% Copyright (C) 2007-2017 by Will Robertson & Johannes Gro^^c3^^9fe |
| 138 |
%% |
| 139 |
%% Distributable under the LaTeX Project Public License, |
| 140 |
%% version 1.3c or higher (your choice). The latest version of |
| 141 |
%% this license is at: http://www.latex-project.org/lppl.txt |
| 142 |
%% |
| 143 |
%% This work is "author-maintained" by Will Robertson. |
| 144 |
%% |
| 145 |
%% This work consists of the file ifplatform.dtx |
| 146 |
%% and the derived files ifplatform.pdf, |
| 147 |
%% ifplatform.sty, and |
| 148 |
%% ifplatform.ins. |
| 149 |
%% |
| 150 |
%% End of file `ifplatform.sty'. |