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 149 150 151 152 153 154 155 156
|
#!/usr/bin/perl -w
use Data::Dumper;
use File::Spec;
use IO::File;
#use diagnostics;
my $cvs_info = '$Id: language.PL,v 1.1 2000/04/02 20:52:56 bruce Exp $ ';
my $cvs_version = (split(' ', $cvs_info))[2] || "pre_release";
my $thisdir = &identify_self;
print STDOUT
"Xtal.pm language generation tool version $cvs_version for Xray::Xtal 0.30",
$/;
## the anon array contains the file extension and the index of the
## language in the database files
my %lingos = ("english" => ["en", 1],
"spanish" => ["sp", 2],
"french" => ["fr", 3],
"german" => ["ge", 4],
);
my $sep = '\|'; # field separator in database files
#gaby# my $sep = ';'; # field separator in database files
my $nl = "\013"; #''; # newline token (control-K, ascii 13)
my $header; # read the tkatomsrc header from __DATA__
$header = '# -*- mode: cperl -*-';
$header .= "$/# Xtal.pm language file generation tool, version $cvs_version$/";
while (<DATA>) {
$header .= $_;
};
my %fh = ();
## open a file for each language and write out the header
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
my $file = "xtalrc." . $ext;
$file = File::Spec -> catfile($thisdir, $file);
$fh{$ext} = IO::File -> new();
my $fh = $fh{$ext};
open $fh, ">$file" or die $!;
print $fh $header;
};
print STDOUT " Reading language data for Xtal", $/;
my $file = "xtal.dat";
#gaby# my $file = "table.xtal";
$file = File::Spec -> catfile($thisdir, $file);
open DAT, "$file" or die $!;
while (<DAT>) {
next if /^\s*$/;
my @line = split($sep, $_);
#gaby# shift @line;
foreach my $i (0 .. $#line) { # clean up white space at ends
$line[$i] =~ s/^\s+//; # of words and convert the ^K
$line[$i] =~ s|$nl|$/|g; # characters to $/
$line[$i] =~ s/\s+$//;
$line[$i] =~ s/\"/\"/;
#gaby# $line[$i] =~ s/\n$//;
};
foreach my $lang (keys %lingos) {
my $index = $lingos{$lang}->[1];
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
};
};
close DAT;
%written = ();
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
unless ($written{$lang}) {
++$written{$lang};
printf STDOUT " Writing %-7s file : %15s$/", $lang, "xtalrc.$ext";
};
my $ref;
eval "\$ref = \\\%$lang;";
my $hash_dump = Data::Dumper->Dump([$ref], [qw/Xray::Xtal::strings/]);
eval "undef \%$lang";
undef $ref;
my $fh = $fh{$ext};
print $fh $hash_dump, $/;
};
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
my $fh = $fh{$ext};
print $fh $/, "1;", $/;
close $fh;
};
sub identify_self {
my @caller = caller;
use File::Basename qw(dirname);
return dirname($caller[1]);
};
__DATA__
######################################################################
## Xtal.pm language configuration file
## copyright (c) 2000 Bruce Ravel
## ravel@phys.washington.edu
## http://feff.phys.washington.edu/~ravel/
##
## The latest version of Atoms can always be found at
## http://feff.phys.washington.edu/~ravel/software/atoms/
##
## -------------------------------------------------------------------
## All rights reserved. This program is free software; you can
## redistribute it and/or modify it under the same terms as Perl
## itself.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## Artistic License for more details.
## -------------------------------------------------------------------
######################################################################
##
## This is a language configuration file for Xtal.pm. This file is
## read after atoms starts running. The contents of this file are
## used is messages generated by Xtal.pm.
##
## To make another language file, copy this file to "xtalrc.??" where
## ?? is a two letter symbol for your language. Translate all of the
## hash values (but NOT the keys) and add an entry to the %languages
## hash in the language file for the new language. And please send
## your translation to Bruce Ravel <ravel@phys.washingon.edu> so he
## can include it with future distributions of Atoms.
##
## Some languages:
## en = English
## fr = French
## sp = Spanish
## and so on...
##
## Here is an example. Pardon my crappy language skills. Note that
## the key doesn't get translated, only the value -- that is very
## important!
##
## English:
## 'not_a_group' =>
## 'You have specified an unknown space group symbol.',
##
## Spanish:
## 'not_a_group' =>
## 'Ud ha specificado un grupo de simetria inconecido.'
##
## French:
## 'not_a_group' =>
## 'Vous avez specifie une groupe de symmetrie inconnu.'
####################################################################
## code:
|