Debian Codegraph @

texmf-dist/doc/fonts/gfsdidot/installDidot.pl

raw
1 #!/usr/bin/perl
2 #
3 #This perl install all the mandatory files for the use
4 #of GFS Didot fonts in a texmf directory.
5 #
6 #This program has 2 parameters:
7 # 1) The name of the root directory containing the Didot
8 # distribution.
9 # 2) The name of the texmf tree root directory where the files should
10 # be installed.
11 use strict;
12 use warnings;
13 use File::Copy qw(copy);
14 use File::Path qw(make_path remove_tree);
15 use File::Spec::Functions;
16 use constant false => 0;
17 use constant true => 1;
18
19 #If this variable is set to true, the output is a little more
20 #verbose
21 my $DEBUG=false;
22
23 #Number of arguments to this program
24 my $NB_ARGS=scalar @ARGV;
25
26 #OS where the program runs
27 #MSWin32 on Windows
28 #linux on Linux
29 my $OS = $^O;
30 my $WINDOWS_OS="MSWin32";
31 my $LINUX_OS="linux";
32
33 #This constant is the name of placeholder for describing
34 #the root of a TEXMF tree.
35 my $ROOT_TEXMF="__ROOT_TEXMF__";
36 #A similar constant but for the tree of the GFS Didot distribution
37 my $ROOT_DISTRIB="__GFSDIDOT_DISTRIB__";
38 #This array contain the list of the directories which should
39 #be populated with the files of the GFS Didot distribution.
40 #inside a TEXMF tree.
41 my @TEXMF_DIDOT=(catfile($ROOT_TEXMF,"fonts","afm","GFS","Didot"),
42 catfile($ROOT_TEXMF,"doc","latex","GFS","Didot"),
43 catfile($ROOT_TEXMF,"fonts","enc","dvips","GFS","Didot"),
44 catfile($ROOT_TEXMF,"fonts","map","dvips","GFS","Didot"),
45 catfile($ROOT_TEXMF,"tex","latex","GFS","Didot"),
46 catfile($ROOT_TEXMF,"fonts","tfm","GFS","Didot"),
47 catfile($ROOT_TEXMF,"fonts","type1","GFS","Didot"),
48 catfile($ROOT_TEXMF,"fonts","source","public","GFS","Didot","vpl"),
49 catfile($ROOT_TEXMF,"fonts","vf","GFS","Didot"));
50 #List of the directories which should be copied
51 #from the GFSDidot distribution directory to the
52 #TEXMF directory. This list should match
53 #the list of the constant "@TEXMF_DIDOT".
54 my @GFSDIDOT_DISTRIB=(catfile($ROOT_DISTRIB,"afm"),
55 catfile($ROOT_DISTRIB,"doc"),
56 catfile($ROOT_DISTRIB,"enc"),
57 catfile($ROOT_DISTRIB,"map"),
58 catfile($ROOT_DISTRIB,"tex"),
59 catfile($ROOT_DISTRIB,"tfm"),
60 catfile($ROOT_DISTRIB,"type1"),
61 catfile($ROOT_DISTRIB,"vpl"),
62 catfile($ROOT_DISTRIB,"vf"));
63 #Here is the list of file names which should not be copied
64 #from source dir to destination dir.
65 #
66 #The command readdir returns all the file names including
67 #"." and ".." (current directory and upper directory) which
68 #should be excluded to avoid infinite recursion.
69 my @FILE_TO_EXCLUDE=("CVS",
70 ".",
71 "..");
72
73 #
74 #
75 #------------------------Functions-----------------------------
76 #Normally no change should be made beyond this line
77 #
78 #
79
80 #The following function will detect if the TeX used is MikTeX
81 #(the standrad TeX under Windows)
82 #
83 # The function has no parameter
84 #
85 # The function returns true if MikTeX is used under Windows
86 # and false otherwise
87 #
88 sub isMikTeX{
89 if ($OS ne $WINDOWS_OS){
90 return false;
91 }
92
93 open(my $fh, '-|', 'tex --version') or die "Can not run the command 'tex --version' $!\n";
94 while (my $line = <$fh>) {
95 if ($line =~ /.*miktex.*/i){
96 return true;
97 }
98 }
99 return false;
100 }
101
102 #The following function modify a list of directories
103 #to replace the variable part of the directory with
104 #the actual path.
105 #
106 #This function has 3 parameters:
107 # 1) A reference on an array containing the the list of directories
108 # 2) The placeholder string used for the variable part
109 # 3) Its actual value
110 #
111 #The function returns an array with all the diretory's name converted
112 #to the actual names.
113 sub realDirNames {
114 my ($dirList,$toBeReplaced,$value)=@_;
115
116 my @dirNames;
117
118 foreach my $line (@$dirList){
119 $line =~ s/$toBeReplaced/$value/;
120 #remove double slash (//) in directory names.
121 $line =~ s/\/\//\//g;
122 push(@dirNames,$line);
123 };
124
125 return @dirNames;
126 }
127
128 #The following function copy all the files from a directory
129 #to a destination directory by copying all the subdirectories.
130 #
131 #The function has 2 parameters:
132 # 1)The name of the source directory
133 # 2)The name of destination directory
134 sub copyDir {
135 my ($srcDir,$dstDir)=@_;
136
137 my $errMsg;
138 my $rc;
139
140 if ( ! -d $srcDir ){
141 die "The source directory '$srcDir' is not a directory.\n"
142 }
143 if ( ! -d $dstDir ){
144 die "The destination directory '$dstDir' is not a directory.\n"
145 }
146
147 opendir(my $dh, $srcDir) || die "Can't open $srcDir: $!";
148 while (my $currEntry=readdir $dh) {
149 $errMsg="";
150 my $fullCurrEntry=catfile($srcDir,$currEntry);
151 if ( ! -d $fullCurrEntry){
152 my $srcFile=$fullCurrEntry;
153 my $dstFile=catfile($dstDir,$currEntry);
154 $errMsg="The copy of '$srcFile' to '$dstFile'";
155 $rc=copy($srcFile,$dstFile) if ! grep {$_ eq $currEntry } @FILE_TO_EXCLUDE;
156 if ($rc){
157 print "$errMsg has suceeded.\n" if $DEBUG;
158 }
159 else{
160 print "$errMsg has failed (code: $!).\n";
161 }
162 }
163 else{
164 #Not a file, the subdirectory should be created and
165 #copied if it is not in the list of excluded files.
166 if ( ! grep {$_ eq $currEntry } @FILE_TO_EXCLUDE){
167 my $newSrcDir=$fullCurrEntry;
168 my $newDstDir=catfile($dstDir,$currEntry);
169
170 $errMsg="The creation of directory '$newDstDir'";
171 $rc=make_path($newDstDir);
172 if ($rc){
173 print "$errMsg has suceeded.\n";
174 }
175 else{
176 print "$errMsg has failed (code: $!).\n";
177 }
178 copyDir($newSrcDir,$newDstDir);
179 }
180 }
181 }
182 closedir($dh);
183 }
184
185 #
186 #---------------------------------Main program----------------------------
187 #
188
189 if ( $NB_ARGS != 2 ) {
190 print "This script installs all the necessary files for the use of the GFS Didot fonts\n";
191 print "in a texmf tree.\n";
192 print "$0 has 2 arguments:\n";
193 print " 1) The name of the directory containing the GFS Didot distribution.\n";
194 print " 2) The name of the root directory of the texmf tree where the files\n";
195 print " should be installed\n";
196 exit 1
197 }
198
199
200 my $distribDir=$ARGV[0];
201 my $texmfDir=$ARGV[1];
202
203 my @dstDirs=realDirNames(\@TEXMF_DIDOT,$ROOT_TEXMF,$texmfDir);
204 my @srcDirs=realDirNames(\@GFSDIDOT_DISTRIB,$ROOT_DISTRIB,$distribDir);
205 my $i;
206 my $errMsg;
207 my $rc;
208
209 if ((scalar @TEXMF_DIDOT) != (scalar @GFSDIDOT_DISTRIB)){
210 die "There are not the same number of source and destination directories.\n";
211 }
212
213 #Create directories in TEXMF tree
214 foreach my $line (@dstDirs){
215 if (-e $line){
216 if (-d $line){
217 remove_tree($line) or die "The directory '$line' can not be removed $!\n";
218 }
219 else{
220 unlink($line) or die "The file '$line' can not be removed $!\n";
221 }
222 };
223 make_path($line);
224 }
225 #Now copy the different source directories.
226 $i=0;
227 foreach my $dir (@srcDirs){
228 my $dstDir=$dstDirs[$i];
229
230 copyDir($dir,$dstDir);
231 print "The source directory '$dir' has been copied to the directory '$dstDir'.\n";
232 $i += 1;
233 }
234
235 my $TeXcmd;
236 #The TeX command to include the new file in TeXMF
237 if (isMikTeX()){
238 #MikTeX does not allow the command "mktexlsr" with an argument
239 $TeXcmd="mktexlsr";
240 }
241 else {
242 $TeXcmd="mktexlsr $texmfDir";
243 }
244 $rc=system($TeXcmd) ;
245 if ($rc != 0){
246 die "The command '$TeXcmd' has failed: $!\n";
247 }
248
249 if (isMikTeX()){
250 #MikTeX does not allow the command "updmap-sys" with an argument
251 #To configure the file 'updmap.cfg' on MikTeX one has to pass
252 #the command: initexmf --edit-config-file updmap
253 $TeXcmd="updmap --verbose";
254 }
255 else {
256 $TeXcmd="updmap-sys";
257 }
258 $rc=system($TeXcmd) ;
259 if ($rc != 0){
260 die "The command '$TeXcmd' has failed: $!\n";
261 }
262
263 exit 0;