blob: 8d48229e717eb21c0c78923d97ec2e14cddc111f (
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
|
%%
%% This is file `ifplatform.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ifplatform.dtx (with options: `package')
%% ________________________________________________________
%% Copyright (C) 2007-2017 Will Robertson & Johannes Gro^^c3^^9fe
%% License information appended.
\ProvidesPackage{ifplatform}
[2017/10/13 v0.4a Testing for the operating system]
\RequirePackage{shellesc,pdftexcmds,catchfile,ifluatex}
\newif\ifshellescape
\newif\ifwindows
\newif\ifmacosx
\newif\iflinux
\newif\ifcygwin
\newcommand\windowsname{Windows}
\newcommand\notwindowsname{*NIX}
\newcommand\linuxname{Linux}
\newcommand\macosxname{Mac\,OS\,X}
\newcommand\cygwinname{Cygwin}
\newcommand\unknownplatform{[Unknown]}
\edef\ip@file{\jobname.w18}
\newif\if@ip@nix@
\ifnum\pdf@shellescape=1\relax
\shellescapetrue
\else
\ifluatex\else
\PackageWarningNoLine{ifplatform}{^^J \space\space\space
shell escape is disabled,
so I can only detect \@backslashchar ifwindows%
}
\fi
\fi
\def\ip@cantdecide{%
\PackageWarningNoLine{ifplatform}{^^J \space\space\space
I can't tell if this is Windows or *nix;
you appear to be both%
}%
}
\ifluatex
\csname\directlua{
if os.type == "unix" then
tex.sprint("@ip@nix@true")
elseif os.type == "windows" then
tex.sprint("windowstrue")
end
}\endcsname
\else
\IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true}
\IfFileExists{/dev/null}{\windowsfalse}{\windowstrue}
\edef\ip@windows@echo@test{echo \string# > "\ip@file"}
\def\ip@backupplan{%
\IfFileExists{\ip@file}{%
\PackageWarningNoLine{ifplatform}{^^J \space\space\space
Please delete the file "\ip@file" and try again%
}%
\ip@cantdecide
}{%
\ShellEscape{\ip@windows@echo@test}%
\IfFileExists{\ip@file}{%
\ShellEscape{del "\ip@file"}%
\windowstrue
}{%
\@ip@nix@true
}%
}%
}
\ifwindows
\if@ip@nix@
\PackageWarningNoLine{ifplatform}{^^J \space\space\space
I can't tell if this is Windows or *nix;
you appear to be neither%
}
\fi
\else
\if@ip@nix@\else
\ifshellescape
\ip@backupplan
\else
\ip@cantdecide
\fi
\fi
\fi
\fi
\def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6}
\if@ip@nix@\ifshellescape
\ifwindows\else
\ShellEscape{uname -s > "\ip@file"}
\CatchFileDef\@tempa{\ip@file}{}
\ShellEscape{rm -- "\ip@file"}
\edef\@tempa{\expandafter\zap@space\@tempa\@empty}
\def\@tempb{Linux}
\ifx\@tempa\@tempb
\linuxtrue
\else
\def\@tempb{Darwin}
\ifx\@tempa\@tempb
\macosxtrue
\else
\def\@tempb{CYGWIN}
\edef\@tempc{\expandafter\ip@only@six\@tempa------\@nil}
\ifx\@tempb\@tempc
\cygwintrue
\else
\edef\unknownplatform{\@tempa}
\fi
\fi
\fi
\fi
\fi\fi
\edef\platformname{%
\ifwindows
\noexpand\windowsname
\else
\ifshellescape
\iflinux
\noexpand\linuxname
\else
\ifmacosx
\noexpand\macosxname
\else
\ifcygwin
\noexpand\cygwinname
\else
\noexpand\unknownplatform
\fi
\fi
\fi
\else
\noexpand\notwindowsname
\fi
\fi
}
%% Copyright (C) 2007-2017 by Will Robertson & Johannes Gro^^c3^^9fe
%%
%% 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 "author-maintained" by Will Robertson.
%%
%% This work consists of the file ifplatform.dtx
%% and the derived files ifplatform.pdf,
%% ifplatform.sty, and
%% ifplatform.ins.
%%
%% End of file `ifplatform.sty'.
|