-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmydef_page.def
129 lines (111 loc) · 3.79 KB
/
mydef_page.def
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
include: version.def
page: mydef_page
output_dir: script
type:
#Usage: perl createpages.pl def_file
use MyDef;
my $def_file
my %config;
my $default_module=$MyDef::var->{module}
$call parse_arg
$if $def_file eq "-pipe"
#-- reads from STDIN
#-- dump to STDOUT
MyDef::pipe_page($config{module})
$else
$config{def_file}=$def_file
MyDef::init(%config);
my $module=$MyDef::var->{module}
$if $config{"debug-import"}
$MyDef::parseutil::debug={import=>1}
MyDef::import_data($def_file)
$call @load_arg_macros
$if $config{find}
$call find_subcode
$elif $config{dump}
$call dump_source
$elif $config{"debug-import"}
# done
$else
$call compile_pages
# ----------------------------------------
subcode: parse_arg
$foreach $a in @ARGV
$if $a =~ /^-m(\w+)/
$config{module} = $1
$elif $a =~/^-o(\S+)/
$config{output_dir} = $1
$elif $a =~/^-f(\S+)/
$config{find} = $1
$elif $a =~/^-(dump|debug.*)/
$config{$1} = 1
$elif $a=~/\.def$/
$if $def_file
die "Multiple def source files not supported\n"
$if -f $a
$def_file=$a
$else
die "$a is not a regular file\n"
$elif $a eq "-pipe"
$def_file="-pipe"
$call @check_arg_version, $a
$if !$def_file
die "Please supply data definition file.";
subcode: load_arg_macros
$foreach $a in @ARGV
$if $a=~/-M(\w+)=(.*)/
$MyDef::def->{macros}->{$1} =$2
# ----------------------------------------
subcode: compile_pages
my $pages=$MyDef::def->{pages}
my $pagelist=$MyDef::def->{pagelist}
my ($n_skip, $n_create)
$foreach $t in @$pagelist
my $p=$pages->{$t}
$if $p->{subpage}
next
my $t_module=$default_module
$if $p->{module}
$t_module=$p->{module}
$if $t_module and ($t_module ne $module)
# $print "skip page $t: module mismatch [page:$t_module][config:$module]"
$n_skip++
next
$n_create++
MyDef::createpage($t);
$if $n_create==0
$print skiped $n_skip pages (due to module mismatch), use -m to overide default module.
# ----------------------------------------
subcode: find_subcode
my $def=$MyDef::def
my $name=$config{find}
$if $def->{codes}->{$name}
my $code=$def->{codes}->{$name}
$call dump_code
$elif $def->{macros}->{$name}
$print macro: $name: $def->{macros}->{$name}
$else
$print name: $name not found.
subcode: dump_code
my $type=$code->{type}
my $param=join ", ", @{$code->{params}}
my $source=$code->{source}
my $indent=1
print $type, "code: $name($param)\n"
$foreach $l in @$source
$if $l=~/^SOURCE_INDENT/
$indent++
$elif $l=~/^SOURCE_DEDENT/
$indent--
$else
print " "x$indent, $l, "\n"
# ------------------------------------
subcode: dump_source
my $def=$MyDef::def
$foreach %{$def->{pages}}
$print page: $k
$if $v->{codes}
$while my ($k2, $v2) = each %{$v->{codes}}
$print " $v2->{type}code: $k2\n"
$foreach %{$def->{codes}}
$print $v->{type}code: $k