line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mac::Glue::Common; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
5
|
use vars qw($SERIALIZER); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
5
|
|
|
|
|
|
|
# for MacPerl, use Storable for PPC and FreezeThaw for CFM68K; |
6
|
|
|
|
|
|
|
# won't work with plain 68K build; Storable for other platforms |
7
|
1
|
0
|
|
1
|
|
24
|
$SERIALIZER = $^O eq 'MacOS' |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
8
|
|
|
|
|
|
|
? $MacPerl::Architecture eq 'MacPPC' |
9
|
|
|
|
|
|
|
? 'Storable' |
10
|
|
|
|
|
|
|
: $MacPerl::Architecture eq 'MacCFM68K' |
11
|
|
|
|
|
|
|
? 'FreezeThaw' |
12
|
|
|
|
|
|
|
: die("Must be using CFM68K or PPC build of MacPerl: $MacPerl::Architecture") |
13
|
|
|
|
|
|
|
: 'Storable'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
18
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
107
|
|
19
|
1
|
|
|
1
|
|
755
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
889
|
|
|
1
|
|
|
|
|
87
|
|
20
|
1
|
|
|
1
|
|
3756
|
use Getopt::Std; |
|
1
|
|
|
|
|
56
|
|
|
1
|
|
|
|
|
56
|
|
21
|
1
|
|
|
1
|
|
804
|
use MacPerl; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Mac::AETE::App; |
23
|
|
|
|
|
|
|
use Mac::AETE::Dialect; |
24
|
|
|
|
|
|
|
use Mac::AETE::Format::Glue; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use base 'Exporter'; |
27
|
|
|
|
|
|
|
use vars qw( |
28
|
|
|
|
|
|
|
@EXPORT $REVISION $VERSION $MACGLUEDIR |
29
|
|
|
|
|
|
|
$PROGNAME $PROGVERSION $PROGDESC $PROGOPTS |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
@EXPORT = qw(glue is_osax is_dialect opts $MACGLUEDIR); |
33
|
|
|
|
|
|
|
($REVISION) = ' $Revision: 1.6 $ ' =~ /\$Revision:\s+([^\s]+)/; |
34
|
|
|
|
|
|
|
$VERSION = '1.02'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$PROGNAME ||= basename($0); |
37
|
|
|
|
|
|
|
$PROGVERSION ||= $VERSION; |
38
|
|
|
|
|
|
|
$PROGDESC ||= ''; |
39
|
|
|
|
|
|
|
$PROGOPTS ||= ''; |
40
|
|
|
|
|
|
|
$MACGLUEDIR = $ENV{MACGLUEDIR}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ($^O eq 'MacOS') { |
43
|
|
|
|
|
|
|
$MACGLUEDIR ||= "$ENV{MACPERL}site_perl:Mac:Glue:glues:"; |
44
|
|
|
|
|
|
|
$MACGLUEDIR .= ':' unless $MACGLUEDIR =~ /:$/; |
45
|
|
|
|
|
|
|
} elsif (!$MACGLUEDIR) { |
46
|
|
|
|
|
|
|
my $dir = dirname $INC{'Mac/Glue/Common.pm'}; |
47
|
|
|
|
|
|
|
unless (file_name_is_absolute($dir)) { |
48
|
|
|
|
|
|
|
require Cwd; |
49
|
|
|
|
|
|
|
$dir = catdir(Cwd::cwd(), $dir); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
$MACGLUEDIR = catdir($dir, 'glues'); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# in case old code uses it ... |
55
|
|
|
|
|
|
|
$ENV{MACGLUEDIR} = $MACGLUEDIR; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub glue { |
58
|
|
|
|
|
|
|
my($opts, $files, $type) = @_; |
59
|
|
|
|
|
|
|
$type ||= 'app'; |
60
|
|
|
|
|
|
|
my($delete, %files); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
local $MacPerl::Target = '' if $^O ne 'MacOS'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my @dirs = $MACGLUEDIR; |
65
|
|
|
|
|
|
|
my $class = 'Mac::AETE::App'; |
66
|
|
|
|
|
|
|
if ($type eq 'dialect') { |
67
|
|
|
|
|
|
|
push @dirs, 'dialects'; |
68
|
|
|
|
|
|
|
$class = 'Mac::AETE::Dialect'; |
69
|
|
|
|
|
|
|
} elsif ($type eq 'addition') { |
70
|
|
|
|
|
|
|
push @dirs, 'additions'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if (ref $files eq 'ARRAY') { # convert to hash |
74
|
|
|
|
|
|
|
%files = map { ($_, $_) } @$files; |
75
|
|
|
|
|
|
|
} else { |
76
|
|
|
|
|
|
|
%files = %$files; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
foreach my $drop (sort { lc basename($a) cmp lc basename($b) } keys %files) { |
80
|
|
|
|
|
|
|
$drop = readlink $drop while -l $drop; |
81
|
|
|
|
|
|
|
print "Making glue for '$drop'\n"; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# initialize |
84
|
|
|
|
|
|
|
(my $ddrop = $drop) =~ s|[/:]$||; # is dir/package ? |
85
|
|
|
|
|
|
|
my($file, $dir) = fileparse($ddrop, ''); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if ($type eq 'dialect') { |
88
|
|
|
|
|
|
|
unless (is_dialect($files{$drop})) { |
89
|
|
|
|
|
|
|
warn "$file does not appear to be a dialect (skipped)\n"; |
90
|
|
|
|
|
|
|
next; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
$file =~ s/\s+Dialect$//; |
93
|
|
|
|
|
|
|
} elsif ($type eq 'addition') { |
94
|
|
|
|
|
|
|
unless (is_osax($files{$drop}, $file)) { |
95
|
|
|
|
|
|
|
warn "$file does not appear to be an addition (skipped)\n"; |
96
|
|
|
|
|
|
|
if ($file =~ /\.app$/) { |
97
|
|
|
|
|
|
|
(my $path = $files{$drop}) =~ s|^(.+$drop).*$|$1|; |
98
|
|
|
|
|
|
|
(my $gluemac = $0) =~ s/scriptadds$/mac/; |
99
|
|
|
|
|
|
|
warn " Try: $gluemac '$path'\n"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
next; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $fixed = Mac::AETE::Format::Glue::fixname($file); |
106
|
|
|
|
|
|
|
$fixed =~ s/_(?:app|rsrc|osax)$//; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if ($type eq 'app' && ! $opts->{I}) { |
109
|
|
|
|
|
|
|
$fixed = MacPerl::Ask("What is the glue name?", $fixed); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if (!$fixed) { |
113
|
|
|
|
|
|
|
warn "No name given for $file (skipped)\n"; |
114
|
|
|
|
|
|
|
next; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $output = catfile(@dirs, $fixed); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if (-e $output && ! $opts->{I}) { |
120
|
|
|
|
|
|
|
if (! defined $delete) { |
121
|
|
|
|
|
|
|
$delete = MacPerl::Answer( |
122
|
|
|
|
|
|
|
'Overwrite existing glues if they exist?', |
123
|
|
|
|
|
|
|
qw(OK No Cancel) |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
exit if $delete == 0; |
126
|
|
|
|
|
|
|
$delete = 0 if $delete == 2; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
next unless my $aete = $class->new($files{$drop}); |
131
|
|
|
|
|
|
|
my $conv = Mac::AETE::Format::Glue->new($output, !$delete); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$aete->set_format($conv); |
134
|
|
|
|
|
|
|
$aete->read; |
135
|
|
|
|
|
|
|
$aete->write; |
136
|
|
|
|
|
|
|
$conv->finish; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $name = $file; |
139
|
|
|
|
|
|
|
$name .= ", v$aete->{VERSION}" if $aete->{VERSION}; |
140
|
|
|
|
|
|
|
print "Created and installed \u$type glue for '$name' ($fixed)\n"; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub is_osax { |
145
|
|
|
|
|
|
|
my($osax, $file) = @_; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
return unless -f $osax; |
148
|
|
|
|
|
|
|
# Mac OS X doesn't use file type/creator for this |
149
|
|
|
|
|
|
|
if ($^O ne 'MacOS') { |
150
|
|
|
|
|
|
|
return if $file !~ /\.osax$/; |
151
|
|
|
|
|
|
|
} else { |
152
|
|
|
|
|
|
|
my $type = MacPerl::GetFileInfo($osax); |
153
|
|
|
|
|
|
|
return if !$type || $type ne 'osax'; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub is_dialect { |
160
|
|
|
|
|
|
|
my $dlct = shift; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
return unless -f $dlct; |
163
|
|
|
|
|
|
|
# Mac OS X doesn't use file type/creator for this |
164
|
|
|
|
|
|
|
return 1 if $^O ne 'MacOS'; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my($creator, $type) = MacPerl::GetFileInfo($dlct); |
167
|
|
|
|
|
|
|
return if !$type || !$creator || $creator ne 'ascr' || |
168
|
|
|
|
|
|
|
($type ne 'shlb' && $type ne 'dlct' && $type ne 'thng'); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
return 1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub opts { |
174
|
|
|
|
|
|
|
my %opts; |
175
|
|
|
|
|
|
|
my $opts = $PROGOPTS . 'hvI'; |
176
|
|
|
|
|
|
|
usage('Options used incorrectly') unless getopts($opts, \%opts); |
177
|
|
|
|
|
|
|
usage() if $opts{'h'}; |
178
|
|
|
|
|
|
|
version() if $opts{'v'}; |
179
|
|
|
|
|
|
|
return \%opts; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub usage { |
183
|
|
|
|
|
|
|
print "*** $_[0]\n" if $_[0]; |
184
|
|
|
|
|
|
|
# Remember to doublecheck these match getopts()! |
185
|
|
|
|
|
|
|
print <
|
186
|
|
|
|
|
|
|
Usage: $PROGNAME [OPTIONS] PATHS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$PROGDESC |
189
|
|
|
|
|
|
|
-h Help (this message) |
190
|
|
|
|
|
|
|
-v Version |
191
|
|
|
|
|
|
|
-I Do not prompt, use defaults |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
EOT |
194
|
|
|
|
|
|
|
exit; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub version { |
199
|
|
|
|
|
|
|
print <
|
200
|
|
|
|
|
|
|
$PROGNAME $PROGVERSION |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Copyright (c) 1998-2003 Chris Nandor. All rights reserved. This program |
203
|
|
|
|
|
|
|
is free software; you can redistribute it and/or modify it under the same |
204
|
|
|
|
|
|
|
terms as Perl itself. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
EOT |
207
|
|
|
|
|
|
|
exit; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
__END__ |