summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3experimental/l3sys-shell/l3sys-shell.sty
blob: 0145cdc39d643d308cf90bd70d6646e1475c4974 (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
%%
%% This is file `l3sys-shell.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3sys-shell.dtx  (with options: `package')
%% 
%% Copyright (C) 2018,2019 The LaTeX3 Project
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "l3experimental bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: l3sys-shell.dtx
\RequirePackage{expl3}
\ProvidesExplPackage{l3sys-shell}{2019-09-19}{}
  {L3 Experimental system shell functions}
\cs_new:Npn \__sys_path_to_win:n #1
  {
    \exp_after:wN \__sys_path_to_win:w \tl_to_str:n {#1} ~ \q_stop
  }
\cs_new:Npn \__sys_path_to_win:w #1 ~ #2 \q_stop
  {
    \__sys_path_to_win:N #1 \q_nil
    \tl_if_empty:nF {#2}
      {
        \c_space_tl
        \__sys_path_to_win:w #2 \q_stop
      }
  }
\cs_new:Npn \__sys_path_to_win:N #1
  {
    \quark_if_nil:NF #1
      {
        \token_if_eq_meaning:NNTF #1 /
          { \c_backslash_str }
          {#1}
         \__sys_path_to_win:N
      }
  }
\cs_new_protected:Npx \sys_shell_cp:nn #1#2
  {
    \sys_if_shell_unrestricted:T
      {
        \sys_shell_now:x
          {
            \sys_if_platform_unix:T
              {
                cp~-f~ \exp_not:N \tl_to_str:n {#1} ~
                  \exp_not:N \tl_to_str:n {#2}
              }
            \sys_if_platform_windows:T
              {
                copy~/y~ \exp_not:N \__sys_path_to_win:n {#1} ~
                  \exp_not:N \__sys_path_to_win:n {#2}
              }
          }
      }
  }
\cs_new_protected:Npx \sys_shell_mkdir:n #1
  {
    \sys_if_shell_unrestricted:T
      {
        \sys_shell_now:x
          {
            \sys_if_platform_unix:T
              { mkdir~-p~ \exp_not:N \tl_to_str:n {#1} }
            \sys_if_platform_windows:T
              {
                if~not~exist~
                  \exp_not:N \__sys_path_to_win:n { #1 / nul } ~
                  mkdir~ \exp_not:N \__sys_path_to_win:n {#1}
              }
          }
      }
  }
\cs_new_protected:Npx \sys_shell_mv:nn #1#2
  {
    \sys_if_shell_unrestricted:T
      {
        \sys_shell_now:x
          {
            \sys_if_platform_unix:T
              {
                mv~ \exp_not:N \tl_to_str:n {#1} ~
                  \exp_not:N \tl_to_str:n {#2}
              }
            \sys_if_platform_windows:T
              {
                copy~/y~ \exp_not:N \__sys_path_to_win:n {#1} ~
                  \exp_not:N \__sys_path_to_win:n {#2}
                  \token_to_str:N & \token_to_str:N &
                  del~/f~/q~\exp_not:N \__sys_path_to_win:n {#1}
              }
          }
      }
  }
\cs_new_protected:Npx \sys_shell_rm:n #1
  {
    \sys_if_shell_unrestricted:T
      {
        \sys_shell_now:x
          {
            \sys_if_platform_unix:T
              { rm~-f~ \exp_not:N \tl_to_str:n {#1}  }
            \sys_if_platform_windows:T
              { del~/f~/q~ \exp_not:N \__sys_path_to_win:n {#1} }
          }
      }
  }
\cs_new_protected:Npx \sys_shell_rmdir:n #1
  {
    \sys_if_shell_unrestricted:T
      {
        \sys_shell_mkdir:n {#1}
        \sys_shell_now:x
          {
            \sys_if_platform_unix:T
              { rm~-rf~ \exp_not:N \tl_to_str:n {#1} }
            \sys_if_platform_windows:T
              { rmdir~/s~/q~ \exp_not:N \__sys_path_to_win:n {#1} }
          }
      }
  }
\tl_new:N \l__sys_tmp_tl
\cs_new_protected:Npx \sys_shell_get_pwd:N #1
  {
    \sys_if_shell_unrestricted:T
      {
        \exp_not:N \sys_shell_get:nnN
          {
            \sys_if_platform_unix:T { pwd }
            \sys_if_platform_windows:T { cd }
          }
          {
            \char_set_catcode_other:N \exp_not:N \\
            \char_set_catcode_other:N \exp_not:N \#
            \char_set_catcode_other:N \exp_not:N \~
            \char_set_catcode_other:N \exp_not:N \%
            \char_set_catcode_space:N \exp_not:N \ %
            \tex_endlinechar:D -1 \scan_stop:
          }
        \exp_not:N \l__sys_tmp_tl
        \str_set:NV #1 \exp_not:N \l__sys_tmp_tl
      }
  }
\cs_new_protected:Npx \sys_shell_split_ls:nN #1#2
  {
    \sys_if_shell_unrestricted:T
      {
        \exp_not:N \sys_shell_get:nnN
          {
            \sys_if_platform_unix:T { ls~-1~ #1 }
            \sys_if_platform_windows:T { dir~/b~ #1 }
          }
          {
            \ExplSyntaxOff
            \char_set_catcode_other:N \exp_not:N \\
            \char_set_catcode_other:N \exp_not:N \#
            \char_set_catcode_other:N \exp_not:N \~
            \char_set_catcode_other:N \exp_not:N \%
            \char_set_catcode_other:n { 13 }
          }
          \exp_not:N \l__sys_tmp_tl
        \str_set:NV \exp_not:N \l__sys_tmp_tl \exp_not:N \l__sys_tmp_tl
        \seq_set_split:NnV #2 { \char_generate:nn { `\^^M } { 12 } }
          \exp_not:N \l__sys_tmp_tl
        \seq_pop_right:NN #2 \exp_not:N \l__sys_tmp_tl
      }
  }
%% 
%%
%% End of file `l3sys-shell.sty'.