/
codegen_wxFileConfig.pl
executable file
·108 lines (84 loc) · 2.45 KB
/
codegen_wxFileConfig.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
#!/usr/bin/perl
use strict;
do("ini_parse_to_hash.pl");
my @array =glob("/usr/share/diskplat/disk.ini");
my $filename;
for $filename (@array)
{
my $ini_file_hash=load_ini_file($filename);
print_wxFile_config_init_header($filename);
print_function_start($filename, "void write_file( wxFileConfig &ini){\n");
gen_code($filename, $ini_file_hash, \&print_wxFileConfig_write);
gen_code($filename, $ini_file_hash, \&print_wxFileConfig_write);
print_function_end($filename, "ini.Flush();\n");
print_function_end($filename, "}\n");
print_function_start($filename, "void read_file( wxFileConfig &ini){\n");
gen_code($filename, $ini_file_hash, \&print_wxFileConfig_read);
print_function_end($filename, "}\n");
}
########################################################################
sub print_function_start($$)
{
(my $input_file, my $line)=@_;
print $line;
}
sub print_function_end($$)
{
(my $input_file, my $line)=@_;
print $line;
}
sub print_wxFile_config_init_header($)
{
(my $inifile)=@_;
use File::Basename;
my $name= basename("$inifile"); #½á¹ûÊÇ. bbb
$name=~s/\./_/g;
print<<EOF
#include <wx/fileconf.h>
#include <wx/filename.h>
#include <wx/string.h>
#include <wx/wx.h>
void write_file( wxFileConfig &ini);
void read_file( wxFileConfig &ini);
using namespace std;
int main(int argc, char *argv[])
{
wxFileConfig $name( wxEmptyString, wxEmptyString, _T("$inifile"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_NO_ESCAPE_CHARACTERS, *wxConvCurrent ) ;
write_file($name);
read_file($name);
printf("#$inifile file has created\\n");
return 0;
}
EOF
;
}
sub gen_code($$$)
{
(my $input_file, my $ini, my $func)=@_;
my $section;
foreach $section (keys(%{$ini}))
{
#print "[$section]\n";
print "\n";
my $key_value=$ini->{$section};
my $ini_key;
foreach $ini_key (sort(keys(%{$key_value})))
{
# print $ini_key."=".$key_value->{$ini_key}."\n";
my $ini_value= $key_value->{$ini_key};
#print "ini.Write(_T(\"$section/$ini_key\", _T(\"$ini_value\")\n";
#print_wxFileConfig_code($section, $ini_key, $ini_value);
$func->($section, $ini_key, $ini_value);
}
}
}
sub print_wxFileConfig_write($$$)
{
(my $section, my $ini_key, my $ini_value)=@_;
print "ini.Write(_T(\"$section/$ini_key\"), _T(\"$ini_value\"));\n";
}
sub print_wxFileConfig_read($$$)
{
(my $section, my $ini_key, my $ini_value)=@_;
print "printf(\"$section/$ini_key=%s\\n\", ini.Read(_T(\"$section/$ini_key\"), _T(\"$ini_value\")).mb_str().data());\n";
}