| 1 |
package Ifeffit::FindFile; # -*- cperl -*- |
| 2 |
###################################################################### |
| 3 |
## Ifeffit::FindFile: Crude, object oriented file location database |
| 4 |
## |
| 5 |
## Athena, Artemis, Hephaestus copyright (c) 2001-2006, 2008 Bruce Ravel |
| 6 |
## [email protected] |
| 7 |
## http://cars9.uchicago.edu/~ravel/ |
| 8 |
## |
| 9 |
## Ifeffit is copyright (c) 1992-2006 Matt Newville |
| 10 |
## [email protected] |
| 11 |
## http://cars9.uchicago.edu/ifeffit/ |
| 12 |
## |
| 13 |
## The latest version of horae can always be found at |
| 14 |
## http://cars9.uchicago.edu/~ravel/software/exafs |
| 15 |
## |
| 16 |
## ------------------------------------------------------------------- |
| 17 |
## All rights reserved. This program is free software; you can |
| 18 |
## redistribute it and/or modify it provided that the above notice |
| 19 |
## of copyright, these terms of use, and the disclaimer of |
| 20 |
## warranty below appear in the source code and documentation, and |
| 21 |
## that none of the names of Argonne National Laboratory, The |
| 22 |
## Naval Research Laboratory, The University of Chicago, |
| 23 |
## University of Washington, or the authors appear in advertising |
| 24 |
## or endorsement of works derived from this software without |
| 25 |
## specific prior written permission from all parties. |
| 26 |
## |
| 27 |
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 28 |
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 29 |
## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 30 |
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 31 |
## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 32 |
## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 33 |
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 34 |
## OTHER DEALINGS IN THIS SOFTWARE. |
| 35 |
## ------------------------------------------------------------------- |
| 36 |
###################################################################### |
| 37 |
|
| 38 |
use strict; |
| 39 |
use vars qw($VERSION $cvs_info $module_version @ISA @EXPORT @EXPORT_OK @buffer); |
| 40 |
use constant ETOK=>0.262468292; |
| 41 |
use Carp qw(confess cluck); |
| 42 |
use File::Basename; |
| 43 |
use File::Copy; |
| 44 |
use File::Path; |
| 45 |
|
| 46 |
use constant ENV_HOME => $ENV{HOME} || ""; |
| 47 |
use constant ENV_IFEFFIT_DIR => $ENV{IFEFFIT_DIR} || ""; |
| 48 |
use constant PLOP => "plop"; |
| 49 |
|
| 50 |
require Exporter; |
| 51 |
|
| 52 |
@ISA = qw(Exporter AutoLoader); |
| 53 |
@EXPORT_OK = qw(); |
| 54 |
|
| 55 |
sub identify_self { |
| 56 |
my @caller = caller; |
| 57 |
use File::Basename qw(dirname); |
| 58 |
return dirname($caller[1]); |
| 59 |
}; |
| 60 |
use vars qw($thisdir $is_windows $is_darwin $xray); |
| 61 |
$thisdir = identify_self(); |
| 62 |
$is_windows = ((lc($^O) eq 'mswin32') or (lc($^O) eq 'cygwin')); |
| 63 |
$is_darwin = (lc($^O) eq 'darwin'); |
| 64 |
($xray = $thisdir) =~ s{Ifeffit$}{Xray}; |
| 65 |
|
| 66 |
## attempt to find some adequate userspace on WINDOWS |
| 67 |
my $WIN_HOME = ENV_IFEFFIT_DIR; |
| 68 |
if ($is_windows) { |
| 69 |
if (-e $ENV{USERPROFILE}) { |
| 70 |
$WIN_HOME = File::Spec->catfile($ENV{USERPROFILE}, "Application Data"); |
| 71 |
mkpath($WIN_HOME) if not -e $WIN_HOME; |
| 72 |
} elsif (-e $ENV{HOMEPATH}) { |
| 73 |
$WIN_HOME = $ENV{HOMEPATH}; |
| 74 |
} elsif (-e $ENV{HOME}) { |
| 75 |
$WIN_HOME = $ENV{HOME}; |
| 76 |
}; |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
my %_unix = |
| 81 |
( |
| 82 |
hephaestus => |
| 83 |
{ |
| 84 |
horae => File::Spec->catfile(ENV_HOME, ".horae"), |
| 85 |
hephaestus => File::Spec->catfile($thisdir, "lib", "hephaestus"), |
| 86 |
par => PLOP, |
| 87 |
rc_personal => File::Spec->catfile(ENV_HOME, ".horae", "hephaestus.ini"), |
| 88 |
rc_system => File::Spec->catfile($thisdir, "lib", "hephaestus", "hephaestus.ini"), |
| 89 |
data => File::Spec->catfile(ENV_HOME, ".horae", "hephaestus.data"), |
| 90 |
}, |
| 91 |
|
| 92 |
athena => |
| 93 |
{ |
| 94 |
horae => File::Spec->catfile(ENV_HOME, ".horae"), |
| 95 |
rc_dummy => File::Spec->catfile(ENV_HOME, ".horae", "athenarc.dummy"), |
| 96 |
rc_personal => File::Spec->catfile(ENV_HOME, ".horae", "athenarc"), |
| 97 |
version_marker => File::Spec->catfile(ENV_HOME, ".horae", "athena.0.8.022"), |
| 98 |
mru => File::Spec->catfile(ENV_HOME, ".horae", "athena.mru"), |
| 99 |
system_mee => File::Spec->catfile($thisdir, "lib", "athena", "athena.mee"), |
| 100 |
mee => File::Spec->catfile(ENV_HOME, ".horae", "athena.mee"), |
| 101 |
plotstyles => File::Spec->catfile(ENV_HOME, ".horae", "athena.plst"), |
| 102 |
plugins => File::Spec->catfile(ENV_HOME, ".horae", "athena.plugins"), |
| 103 |
demos => File::Spec->catfile($thisdir, "lib", "demos"), |
| 104 |
poddir => File::Spec->catfile($thisdir, "lib", "athena.doc"), |
| 105 |
aug => File::Spec->catfile($thisdir, "lib", "aug"), |
| 106 |
augpod => File::Spec->catfile($thisdir, "lib", "aug", "pod"), |
| 107 |
aughtml => File::Spec->catfile($thisdir, "lib", "aug", "html"), |
| 108 |
logo => File::Spec->catfile($thisdir, "lib", "athena", "athena-logo.gif"), |
| 109 |
rc_sys => File::Spec->catfile($thisdir, "lib", "athena", "athenarc"), |
| 110 |
hints => File::Spec->catfile($thisdir, "lib", "athena", "athena.hints"), |
| 111 |
xbm => File::Spec->catfile($thisdir, "lib", "athena", "athena_icon.xbm"), |
| 112 |
xpm => File::Spec->catfile($thisdir, "lib", "athena", "athena_icon.gif"), |
| 113 |
config => File::Spec->catfile($thisdir, "lib", "athena", "athena.config"), |
| 114 |
plugininc => $thisdir, |
| 115 |
pluginiff => $thisdir, |
| 116 |
userplugininc => File::Spec->catfile(ENV_HOME, ".horae"), |
| 117 |
userfiletypedir => File::Spec->catfile(ENV_HOME, ".horae", "Ifeffit", "Plugins", "Filetype", "Athena"), |
| 118 |
par => PLOP, |
| 119 |
oldrc => File::Spec->catfile(ENV_HOME, ".athenarc"), |
| 120 |
oldmru => File::Spec->catfile(ENV_HOME, ".athena.mru"), |
| 121 |
temp_lcf => File::Spec->catfile(ENV_HOME, ".horae", "stash", "...marked.lcf.csv"), |
| 122 |
}, |
| 123 |
|
| 124 |
artemis => |
| 125 |
{ |
| 126 |
horae => File::Spec->catfile(ENV_HOME, ".horae"), |
| 127 |
tmp => File::Spec->catfile(ENV_HOME, ".horae", "stash", "tmp"), |
| 128 |
rc_dummy => File::Spec->catfile(ENV_HOME, ".horae", "artemisrc.dummy"), |
| 129 |
rc_personal => File::Spec->catfile(ENV_HOME, ".horae", "artemisrc"), |
| 130 |
version_marker => File::Spec->catfile(ENV_HOME, ".horae", "artemis.0.6.007"), |
| 131 |
mru => File::Spec->catfile(ENV_HOME, ".horae", "artemis.mru"), |
| 132 |
doc => File::Spec->catfile($thisdir, "lib", "artemis.doc"), |
| 133 |
logo => File::Spec->catfile($thisdir, "lib", "artemis", "artemis-logo.gif"), |
| 134 |
rc_sys => File::Spec->catfile($thisdir, "lib", "artemis", "artemisrc"), |
| 135 |
hints => File::Spec->catfile($thisdir, "lib", "artemis", "artemis.hints"), |
| 136 |
xbm => File::Spec->catfile($thisdir, "lib", "artemis", "artemis_icon.xbm"), |
| 137 |
xpm => File::Spec->catfile($thisdir, "lib", "artemis", "artemis_icon.gif"), |
| 138 |
config => File::Spec->catfile($thisdir, "lib", "artemis", "artemis.config"), |
| 139 |
readme => File::Spec->catfile($thisdir, "lib", "artemis", "artemis_project.readme"), |
| 140 |
par => PLOP, |
| 141 |
oldrc => File::Spec->catfile(ENV_HOME, ".artemisrc"), |
| 142 |
oldmru => File::Spec->catfile(ENV_HOME, ".artemis.mru"), |
| 143 |
}, |
| 144 |
|
| 145 |
atoms => |
| 146 |
{ |
| 147 |
atp_personal => File::Spec->catfile(ENV_HOME, ".horae", "atp"), |
| 148 |
atp_sys => File::Spec->catfile($xray, "atp"), |
| 149 |
xray_lib => File::Spec->catfile($xray, "lib"), |
| 150 |
space_group_db => File::Spec->catfile($xray, "space_groups.db"), |
| 151 |
}, |
| 152 |
|
| 153 |
other => |
| 154 |
{ |
| 155 |
horae => File::Spec->catfile(ENV_HOME, ".horae"), |
| 156 |
atp_personal => File::Spec->catfile(ENV_HOME, ".horae", "atp"), |
| 157 |
downloads => File::Spec->catfile(ENV_HOME, ".horae", "downloads"), |
| 158 |
stash => File::Spec->catfile(ENV_HOME, ".horae", "stash"), |
| 159 |
formula_dat => PLOP, |
| 160 |
absorption => PLOP, |
| 161 |
scattering => PLOP, |
| 162 |
cromann_db => PLOP, |
| 163 |
waaskirf_db => PLOP, |
| 164 |
}, |
| 165 |
); |
| 166 |
|
| 167 |
my %_windows = |
| 168 |
( |
| 169 |
hephaestus => |
| 170 |
{ |
| 171 |
horae => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "hephaestus"), |
| 172 |
hephaestus => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "hephaestus"), |
| 173 |
par => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "par", "hephaestus"), |
| 174 |
rc_personal => File::Spec->catfile($WIN_HOME, "horae", "hephaestus.ini"), |
| 175 |
rc_system => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "hephaestus", "hephaestus.ini"), |
| 176 |
data => File::Spec->catfile($WIN_HOME, "horae", "hephaestus.data"), |
| 177 |
}, |
| 178 |
|
| 179 |
athena => |
| 180 |
{ |
| 181 |
horae => File::Spec->catfile($WIN_HOME, "horae"), |
| 182 |
demos => File::Spec->catfile(ENV_IFEFFIT_DIR, "examples", "Athena", "demos"), |
| 183 |
poddir => File::Spec->catfile(ENV_IFEFFIT_DIR, "doc", "athena"), |
| 184 |
aug => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "aug"), |
| 185 |
augpod => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "aug", "pod"), |
| 186 |
aughtml => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "aug", "html"), |
| 187 |
rc_sys => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athenarcw"), |
| 188 |
logo => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena-logo.gif"), |
| 189 |
config => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena.config"), |
| 190 |
hints => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena.hints"), |
| 191 |
xbm => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena_icon.xbm"), |
| 192 |
xpm => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena_icon.gif"), |
| 193 |
plugininc => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl"), |
| 194 |
pluginiff => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Ifeffit"), |
| 195 |
par => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "par", "athena"), |
| 196 |
rc_dummy => File::Spec->catfile($WIN_HOME, "horae", "athenarc.dummy"), |
| 197 |
rc_personal => File::Spec->catfile($WIN_HOME, "horae", "athena.ini"), |
| 198 |
version_marker => File::Spec->catfile($WIN_HOME, "horae", "athena.0.8.022"), |
| 199 |
mru => File::Spec->catfile($WIN_HOME, "horae", "athena.mru"), |
| 200 |
system_mee => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "athena", "athena.mee"), |
| 201 |
mee => File::Spec->catfile($WIN_HOME, "horae", "athena.mee"), |
| 202 |
plotstyles => File::Spec->catfile($WIN_HOME, "horae", "athena.plst"), |
| 203 |
plugins => File::Spec->catfile($WIN_HOME, "horae", "athena.plugins"), |
| 204 |
userplugininc => File::Spec->catfile($WIN_HOME, "horae"), |
| 205 |
userfiletypedir => File::Spec->catfile($WIN_HOME, "horae", "Ifeffit", "Plugins", "Filetype", "Athena"), |
| 206 |
oldrc => File::Spec->catfile(ENV_IFEFFIT_DIR, "athena.ini"), |
| 207 |
oldmru => File::Spec->catfile(ENV_IFEFFIT_DIR, "athena.mru"), |
| 208 |
temp_lcf => File::Spec->catfile($WIN_HOME, "horae", "stash", "...marked.lcf.csv"), |
| 209 |
}, |
| 210 |
|
| 211 |
artemis => |
| 212 |
{ |
| 213 |
horae => File::Spec->catfile($WIN_HOME, "horae"), |
| 214 |
doc => File::Spec->catfile(ENV_IFEFFIT_DIR, "doc", "artemis"), |
| 215 |
rc_sys => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemisrcw"), |
| 216 |
logo => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis-logo.gif"), |
| 217 |
hints => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis.hints"), |
| 218 |
xbm => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis_icon.xbm"), |
| 219 |
xpm => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis_icon.gif"), |
| 220 |
config => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis.config"), |
| 221 |
readme => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "artemis", "artemis_project.readme"), |
| 222 |
par => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "par", "artemis"), |
| 223 |
tmp => File::Spec->catfile($WIN_HOME, "horae", "stash", "tmp"), |
| 224 |
rc_dummy => File::Spec->catfile($WIN_HOME, "horae", "artemisrc.dummy"), |
| 225 |
rc_personal => File::Spec->catfile($WIN_HOME, "horae", "artemis.ini"), |
| 226 |
version_marker => File::Spec->catfile($WIN_HOME, "horae", "artemis.0.6.007"), |
| 227 |
mru => File::Spec->catfile($WIN_HOME, "horae", "artemis.mru"), |
| 228 |
oldrc => File::Spec->catfile(ENV_IFEFFIT_DIR, "artemis.ini"), |
| 229 |
oldmru => File::Spec->catfile(ENV_IFEFFIT_DIR, "artemis.mru"), |
| 230 |
}, |
| 231 |
|
| 232 |
atoms => |
| 233 |
{ |
| 234 |
atp_personal => File::Spec->catfile($WIN_HOME, "horae", "atp"), |
| 235 |
atp_sys => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "atp"), |
| 236 |
xray_lib => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "lib"), |
| 237 |
space_group_db => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "space_groups.db") |
| 238 |
}, |
| 239 |
|
| 240 |
other => |
| 241 |
{ |
| 242 |
horae => File::Spec->catfile($WIN_HOME, "horae"), |
| 243 |
atp_personal => File::Spec->catfile($WIN_HOME, "horae", "atp"), |
| 244 |
downloads => File::Spec->catfile($WIN_HOME, "horae", "downloads"), |
| 245 |
stash => File::Spec->catfile($WIN_HOME, "horae", "stash"), |
| 246 |
formula_dat => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "chemistry", "formula.dat"), |
| 247 |
absorption => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "Absorption"), |
| 248 |
scattering => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "Scattering"), |
| 249 |
cromann_db => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "cromamm.db"), |
| 250 |
waaskirf_db => File::Spec->catfile(ENV_IFEFFIT_DIR, "share", "perl", "Xray", "waaskirf.db"), |
| 251 |
}, |
| 252 |
); |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
sub find { |
| 257 |
my ($self, $program, $which) = (shift, shift, shift); |
| 258 |
my $location; |
| 259 |
if ($is_windows) { |
| 260 |
$location = $_windows{$program}{$which}; |
| 261 |
## } elsif ($is_darwin) { |
| 262 |
## $location = $_unix{$program}{$which}; |
| 263 |
} else { |
| 264 |
$location = $_unix{$program}{$which}; |
| 265 |
}; |
| 266 |
return ($location eq PLOP) ? q{} : $location; |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
1; |
| 272 |
__END__ |