diff options
-rw-r--r-- | Master/tlpkg/tlpostcode/haranoaji-tlpost.pl | 86 |
1 files changed, 53 insertions, 33 deletions
diff --git a/Master/tlpkg/tlpostcode/haranoaji-tlpost.pl b/Master/tlpkg/tlpostcode/haranoaji-tlpost.pl index 90320bec1ee..3ede9d40dbe 100644 --- a/Master/tlpkg/tlpostcode/haranoaji-tlpost.pl +++ b/Master/tlpkg/tlpostcode/haranoaji-tlpost.pl @@ -47,7 +47,6 @@ if (win32 ()) { binmode (STDIN, ':encoding(console_in)'); binmode (STDOUT, ':encoding(console_out)'); binmode (STDERR, ':encoding(console_out)'); - print "haranoaji-tlpost\n"; require Win32::API; Win32::API->import (); @@ -55,6 +54,7 @@ if (win32 ()) { # for non-Windows, silently do nothing, to avoid tl-update-tlnet failure. exit 0; } +my $verbose = 0; # Font list: PostScript name => File name in TEXMF my %font_list = ( @@ -87,6 +87,11 @@ my @cmap_list = ( my $mode = lc (decode ('locale', $ARGV[0])); my $texdir = decode ('locale', $ARGV[1]); +unshift (@INC, "$texdir/tlpkg"); +require TeXLive::TLUtils; + +my_log ("haranoaji-tlpost\n"); + my $resourcedir = "$texdir/tlpkg/tlgs/Resource"; my $cidfontdir = "$resourcedir/CIDFont"; my $cmapdir = "$resourcedir/CMap"; @@ -100,13 +105,13 @@ if ($mode eq 'install') { die ("unknown mode: $mode\n"); } -print "\ndone.\n"; +my_log ("\ndone.\n"); exit 0; # Install sub do_install { - print "\ndo_install\n"; + my_log ("\ndo_install\n"); tlgs_check (); @@ -117,7 +122,7 @@ sub do_install { # Remove sub do_remove { - print "\ndo_remove\n"; + my_log ("\ndo_remove\n"); tlgs_check (); @@ -144,14 +149,14 @@ sub tlgs_check { # Link or copy CID font sub install_cidfont { - print "\ninstall_cidfont\n"; + my_log ("\ninstall_cidfont\n"); for my $psname (sort keys %font_list) { - print "\nFor $psname ...\n"; + my_log ("\nFor $psname ...\n"); my $fontpath_in_cidfontdir = "$cidfontdir/$psname"; if (wrapper_isfile ($fontpath_in_cidfontdir)) { - print "Already exists: ${fontpath_in_cidfontdir}\n"; + my_log ("Already exists: ${fontpath_in_cidfontdir}\n"); next; } my $fontpath_in_texmf = search_fontpath ($font_list{$psname}) or next; @@ -161,14 +166,14 @@ sub install_cidfont { # Link or copy CMap sub install_cmap { - print "\ninstall_cmap\n"; + my_log ("\ninstall_cmap\n"); foreach my $cmapname (@cmap_list) { - print "\nFor $cmapname ...\n"; + my_log ("\nFor $cmapname ...\n"); my $cmappath_in_cmapdir = "$cmapdir/$cmapname"; if (wrapper_isfile ($cmappath_in_cmapdir)) { - print "Already exists: ${cmappath_in_cmapdir}\n"; + my_log ("Already exists: ${cmappath_in_cmapdir}\n"); next; } my $cmappath_in_texmf = search_cmappath ($cmapname) or next; @@ -178,15 +183,15 @@ sub install_cmap { # Create snippet sub install_snippet { - print "\ninstall_snippet\n"; + my_log ("\ninstall_snippet\n"); for my $psname (sort keys %font_list) { - print "\nFor $psname ...\n"; + my_log ("\nFor $psname ...\n"); foreach my $cmapname (@cmap_list) { my $snippetpath = "$fontdir/$psname-$cmapname"; if (wrapper_isfile ($snippetpath)) { - print "Already exists: ${snippetpath}\n"; + my_log ("Already exists: ${snippetpath}\n"); next; } @@ -205,42 +210,42 @@ pop EOS create_file_with_contents ($snippetpath, encode ('UTF-8', $contents)); - print "Created: ${snippetpath}\n"; + my_log ("Created: ${snippetpath}\n"); } } } # Remove CID font sub remove_cidfont { - print "\nremove_cidfont\n"; + my_log ("\nremove_cidfont\n"); for my $psname (sort keys %font_list) { - print "\nFor $psname ...\n"; + my_log ("\nFor $psname ...\n"); my $fontpath_in_cidfontdir = "$cidfontdir/$psname"; if (wrapper_isfile ($fontpath_in_cidfontdir)) { wrapper_unlink ($fontpath_in_cidfontdir); - print "Removed: ${fontpath_in_cidfontdir}\n"; + my_log ("Removed: ${fontpath_in_cidfontdir}\n"); } else { - print "Not exist: ${fontpath_in_cidfontdir}\n"; + my_log ("Not exist: ${fontpath_in_cidfontdir}\n"); } } } # Remove snippet sub remove_snippet { - print "\nremove_snippet\n"; + my_log ("\nremove_snippet\n"); for my $psname (sort keys %font_list) { - print "\nFor $psname ...\n"; + my_log ("\nFor $psname ...\n"); foreach my $cmapname (@cmap_list) { my $snippetpath = "$fontdir/$psname-$cmapname"; if (wrapper_isfile ($snippetpath)) { wrapper_unlink ($snippetpath); - print "Removed: ${snippetpath}\n"; + my_log ("Removed: ${snippetpath}\n"); } else { - print "Not exist: ${snippetpath}\n"; + my_log ("Not exist: ${snippetpath}\n"); } } } @@ -249,6 +254,21 @@ sub remove_snippet { # Check Windows environment sub win32 { return ($^O=~/^MSWin(32|64)$/i); } +# Log +sub my_log { + my ($msg) = @_; + + print $msg if ($verbose); + TeXLive::TLUtils::log ($msg); +} + +# Warn +sub my_warn { + my ($msg) = @_; + + TeXLive::TLUtils::tlwarn ($msg); +} + # Search TEXMF font path sub search_fontpath { my ($filename) = @_; @@ -256,11 +276,11 @@ sub search_fontpath { my $foo = kpsewhich ($filename); if ($foo eq "") { - print "Not found font path: ${filename}\n"; + my_log ("Not found font path: ${filename}\n"); return; } - print "Font path is ${foo}.\n"; + my_log ("Font path is ${foo}.\n"); return $foo; } @@ -271,11 +291,11 @@ sub search_cmappath { my $foo = kpsewhich ("-format=cmap $cmapname"); if ($foo eq "") { - print "Not found CMap path: ${cmapname}\n"; + my_log ("Not found CMap path: ${cmapname}\n"); return; } - print "CMap path is ${foo}.\n"; + my_log ("CMap path is ${foo}.\n"); return $foo; } @@ -304,21 +324,21 @@ sub link_or_copy { my ($existingfilename, $newfilename) = @_; if (wrapper_symlink ($existingfilename, $newfilename)) { - print "Symbolic link succeeded: ${newfilename}\n"; + my_log ("Symbolic link succeeded: ${newfilename}\n"); return; } if (wrapper_hardlink ($existingfilename, $newfilename)) { - print "Hard link succeeded: ${newfilename}\n"; + my_log ("Hard link succeeded: ${newfilename}\n"); return; } if (wrapper_copy ($existingfilename, $newfilename)) { - print "Copy succeeded: ${newfilename}\n"; + my_log ("Copy succeeded: ${newfilename}\n"); return; } - print "Link/copy failed: ${newfilename}\n"; + my_warn ("Link/copy failed: ${newfilename}\n"); } # Create file with contents @@ -386,7 +406,7 @@ sub wrapper_symlink { my $msg = decode ('locale', Win32::FormatMessage (Win32::GetLastError ())); $msg =~ s/[\r\n]+\z//; - print "CreateSymbolicLinkW failed: ${msg}\n"; + my_warn ("CreateSymbolicLinkW failed: ${msg}\n"); return 0; } @@ -413,7 +433,7 @@ sub wrapper_hardlink { my $msg = decode ('locale', Win32::FormatMessage (Win32::GetLastError ())); $msg =~ s/[\r\n]+\z//; - print "CreateHardLinkW failed: ${msg}\n"; + my_warn ("CreateHardLinkW failed: ${msg}\n"); return 0; } @@ -440,7 +460,7 @@ sub wrapper_copy { my $msg = decode ('locale', Win32::FormatMessage (Win32::GetLastError ())); $msg =~ s/[\r\n]+\z//; - print "CopyFileW failed: ${msg}\n"; + my_warn ("CopyFileW failed: ${msg}\n"); return 0; } |