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
|
#!/usr/bin/env perl
# This file belongs to TLPM v2.16, TeX Live Package Manager
# Public Domain, P.Jackowski@gust.org.pl
BEGIN{$tlpm_version="2.16";$tlpm_os="i386-linux"}
# the main tlpm script
use TLPM::common;
use TLPM::constants;
use TLPM::pkg;
use TLPM::reg;
use TLPM::cmdl;
use TLPM::list;
use TLPM::incl;
use TLPM::blng;
use TLPM::inst;
use TLPM::uninst;
use TLPM::check;
use TLPM::help;
use TLPM::info;
%commands =
(
'exit' => sub {exit(0)},
'quit' => sub {exit(0)},
'list' => \&list,
'incl' => \&incl,
'blng' => \&blng,
'inst' => \&inst,
'uninst' => \&uninst,
'check' => \&check,
'info' => \&info,
'help' => \&help,
# 'Help' => \&readme,
# 'readme' => \&readme,
# 'version' => \&version,
'cmd' => \&sys
);
# interactive mode
sub prompt
{
local ($cmd_name,@cmd_args,$cmd_line);
while($true)
{
print STDOUT $tlpm_prompt;
$cmd_line = <STDIN>;
exit(0) unless defined $cmd_line; # otherwise looop after 'echo <command> | tlpm'
chomp $cmd_line;
&execute_cmd();
}
}
# batch mode
sub batch
{
local ($cmd_name,@cmd_args,$cmd_line);
local *INP;
&norm_path($batch_file);
$batch_file = &rel2abs($batch_file,$curr_dir);
open(INP,"<$batch_file") or exit $error{'wrong_inp'} -> ($batch_file);
$message -> ("Executing batch file '$batch_file'");
foreach $cmd_line (<INP>)
{
exit(0) unless defined $cmd_line;
chomp $cmd_line;
next if $cmd_line =~ /\A\s*(%|#|\z)/; # comment
print STDOUT $tlpm_prompt . $cmd_line . "\n";
&execute_cmd();
}
close INP;
}
sub execute_cmd
{
my $err;
&resolve_env($cmd_line);
&set_out($cmd_line);
&open_out();
@cmd_args = &parse_cmd($cmd_line);
return(0) unless @cmd_args; # return prompt on ENTER
$cmd_name = shift @cmd_args;
if(defined $commands{$cmd_name})
{
$err = $commands{$cmd_name} -> (@cmd_args);
}
else
{
$err = $error{'wrong_cmd'} -> ($cmd_name,'help');
}
&close_out();
return $err;
}
# the main procedure
sub main
{
my ($arg,@args);
@args = &parse_cmd(join(" ",@ARGV));
while(defined($arg = shift @args))
{
$arg eq '' and next
# or &no_opt($arg) and return $error{'wrong_cmd'} -> ($arg,'tlpm --help')
or &no_opt($arg) and do {$tl_binaries{$arg} = $true}
or &is_opt($arg,'d','directory') and do {$tl_target = shift @args;1}
or &is_opt($arg,'s','source') and do {$tl_source = shift @args;1}
or &is_opt($arg,'v','version') and return $heeelp -> ('tlpm_banner')
or &is_opt($arg,'h','help') and return &help(shift @args)
or &is_opt($arg,'H','Help','readme') and return &readme()
or &is_opt($arg,'b','batch') and do {$batch_file = shift @args;$batch_mode = 1}
# or &is_opt($arg,'q','quiet') and do {$quiet_mode = 1}
or &is_opt($arg,'D','debug') and do {$debug_mode = 1}
or &rem_opt($arg) and return $error{'wrong_opt'} -> ($arg,'tlpm --help');
}
unless(defined $tl_source){$tl_source = $ENV{'tl_source'}}# ...or remains undefined
unless(defined $tl_target){$tl_target = $ENV{'tl_target'}}
$tl_source_indeed = $false; # we need to check the source availability anyway
unless(defined %tl_binaries) # new; installing not only native binaries
{
%tl_binaries = ($tlpm_os => $true);
}
$tl_target_indeed = $false;
if($batch_mode)
{
&batch($batch_file);
}
else
{
$heeelp -> ('tlpm_banner');
$heeelp -> ('type_help');
&prompt();
}
}
#$quiet_mode = 0;
$debug_mode = 0;
$batch_mode = 0;
$batch_file = '';
&main();
# uff
|