-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkathenarc.PL
executable file
·276 lines (251 loc) · 8.55 KB
/
mkathenarc.PL
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/usr/bin/perl -w
use strict;
use Text::Wrap;
use File::Copy;
#use Data::Dumper;
my %hash = ();
my $libdir = "lib/Ifeffit/lib/athena/";
my $config_file = $libdir."athena.config";
my $rc_file = $libdir."athenarc";
my $rcw_file = $libdir."athenarcw";
my $ini_file = $libdir."athena.ini";
my $pl_file = "athena_parts/rc.pl";
print "Reading configuration file: $config_file\n";
my $ret = &read_config(\%hash, $config_file);
die "config file could not be found\n" if ($ret == -1);
#print Data::Dumper->Dump([\%hash], [qw(hash)]);
open R, ">$rc_file" or die "could not open $rc_file file for writing\n";
open I, ">$ini_file" or die "could not open $ini_file file for writing\n";
open P, ">$pl_file" or die "could not open $pl_file file for writing\n";
## write the line identifying the file
print R <<EOH
##
## This is the runtime configuration file for Athena on Unix.
##
EOH
;
print I <<EOH
##
## This is the initialization file for Athena on Windows.
##
EOH
;
print P <<EOH
## -*- cperl -*-
##
## This file is part of Athena, copyright (c) 2001-2005 Bruce Ravel
##
## This section of the code initializes all configuration values.
## This file was generated from the athena.config file.
sub default_rc {
EOH
;
## write the header
foreach (<DATA>) {
print R;
print I;
};
print R "\n\n";
print I "\n\n";
## step through all the values
foreach my $s (@{$hash{order}}) {
print R wrap("# ", "# ", $hash{$s}{description});
print R "\n[$s]\n";
print I wrap("# ", "# ", $hash{$s}{description});
print I "\n[$s]\n";
foreach my $v (@{$hash{$s}{order}}) {
my $val = $hash{$s}{$v}{default};
my $win = (exists $hash{$s}{$v}{windows}) ? $hash{$s}{$v}{windows} : $val;
($val = "") if ($val eq '""');
($win = "") if ($win eq '""');
if ($hash{$s}{$v}{type} eq 'boolean') {
$val = ($val eq 'true') ? $hash{$s}{$v}{onvalue} : ($hash{$s}{$v}{offvalue}||0);
$win = ($win eq 'true') ? $hash{$s}{$v}{onvalue} : ($hash{$s}{$v}{offvalue}||0);
};
print R " $v = $val\n";
print I " $v = $win\n";
unless ($hash{$s}{$v}{type} =~ /(boolean|positive integer|real|regex)/) {
$val = '"'.$val.'"';
$win = '"'.$win.'"';
};
if ($hash{$s}{$v}{type} =~ 'regex') {
$val = "'".$val."'";
$win = "'".$win."'";
};
if ($hash{$s}{$v}{type} =~ 'boolean') {
($val = '"'.$val.'"') unless ($val =~ /[01]/);
($win = '"'.$win.'"') unless ($win =~ /[01]/);
};
if (exists $hash{$s}{$v}{windows}) {
print P " \$_[0]{$s}{$v} = (\$is_windows) ? $win : $val;\n";
} else {
print P " \$_[0]{$s}{$v} = $val;\n";
};
};
print R "\n\n";
print I "\n\n";
print P "\n\n";
};
print P <<EOH
return 1;
};
## END OF RC FILE SUBSECTION
##########################################################################################
EOH
;
## close 'em and finish up
close R;
close I;
close P;
copy($ini_file, $rcw_file);
print "Wrote $rc_file\n $rcw_file\n $ini_file\n $pl_file\n";
sub read_config {
my $rhash = $_[0];
## my $config_file = ($is_windows) ? "$ENV{IFEFFIT_DIR}\\athena.config" :
## File::Spec->catfile($Ifeffit::Group::libdir, "athena.config");
my $config_file = $_[1];
return -1 unless (-e $config_file);
$$rhash{order} = [];
my ($current_section, $current_variable) = ("", "");
open C, $config_file or die "could not open $config_file for reading\n";
while (<C>) {
next if (/^\s*$/); # blank line
next if (/^\s*\#/); # comment line
chomp;
SWITCH: {
## recognize a new section of variables
(/^section=/) and do {
my @line = split(/=/, $_);
push @{$$rhash{order}}, $line[1];
$$rhash{$line[1]} = {};
$current_section = $line[1];
last SWITCH;
};
## read the description of the current section of variables
(/^section_description/) and do {
$$rhash{$current_section}{description} = "";
my $next = <C>;
while ($next !~ /^\s*$/) {
chomp $next;
$$rhash{$current_section}{description} .= substr($next, 1);
$next = <C>;
};
$$rhash{$current_section}{description} =
substr($$rhash{$current_section}{description}, 1);
last SWITCH;
};
## recognize a new variable
(/^variable=/) and do {
my @line = split(/=/, $_);
push @{$$rhash{$current_section}{order}}, $line[1];
$$rhash{$current_section}{$line[1]} = {};
$current_variable = $line[1];
last SWITCH;
};
## read the description of the current variable
(/^description/) and do {
$$rhash{$current_section}{$current_variable}{description} = "";
my $next = <C>;
while ($next !~ /^\s*$/) {
chomp $next;
$next =~ s/^ *\./\n\n /;
$$rhash{$current_section}{$current_variable}{description} .= substr($next, 1);
$next = <C>;
};
$$rhash{$current_section}{$current_variable}{description} =
substr($$rhash{$current_section}{$current_variable}{description}, 1);
last SWITCH;
};
## the type (i.e. string, boolean, etc) of the current variable
(/^type=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{type} = $line[1];
last SWITCH;
};
## default value
(/^default=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{default} = $line[1];
last SWITCH;
};
## list values
(/^values=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{values} = $line[1];
last SWITCH;
};
## special treatment for windows
(/^windows=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{windows} = $line[1];
last SWITCH;
};
## max value for a positive integer
(/^maxint=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{maxint} = $line[1];
last SWITCH;
};
## boolean for whether a font may be variable width
(/^variable_width=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{variable_width} = $line[1];
last SWITCH;
};
## value for boolean true
(/^onvalue=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{onvalue} = $line[1];
last SWITCH;
};
## value for boolean true
(/^offvalue=/) and do {
my @line = split(/=/, $_);
$$rhash{$current_section}{$current_variable}{offvalue} = $line[1];
last SWITCH;
};
};
};
close C;
};
__DATA__
###########################################################################
## Athena is copyright (c) 2001-2005 Bruce Ravel
## bravel@anl.gov
## http://feff.phys.washington.edu/~ravel/
##
## Ifeffit is copyright (c) 1992-2005 Matt Newville
## newville@cars.uchicago.edu
## http://cars9.uchicago.edu/~newville/ifeffit/
##
## The latest version of Athena can always be found at
## http://feff.phys.washington.edu/~ravel/software/
##
## -------------------------------------------------------------------
## All rights reserved. This program is free software; you can
## redistribute it and/or modify it provided that the above notice
## of copyright, these terms of use, and the disclaimer of
## warranty below appear in the source code and documentation, and
## that none of the names of The Naval Research Laboratory, The
## University of Chicago, University of Washington, or the authors
## appear in advertising or endorsement of works derived from this
## software without specific prior written permission from all
## parties.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
## OTHER DEALINGS IN THIS SOFTWARE.
## -------------------------------------------------------------------
###########################################################################
### ***************************************************
### This file is not normally edited by hand.
### Use Athena's preferences dialog instead.
### ***************************************************
### ***************************************************
### BE VERY CAREFUL TO AVOID END OF LINE WHITESPACE
### ***************************************************