source: UsbWattMeter/trunk/asp_dcre/utils/genrename

Last change on this file was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

File size: 5.5 KB
Line 
1#! /usr/bin/perl
2#
3# TOPPERS Software
4# Toyohashi Open Platform for Embedded Real-Time Systems
5#
6# Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
7# Toyohashi Univ. of Technology, JAPAN
8# Copyright (C) 2005-2011 by Embedded and Real-Time Systems Laboratory
9# Graduate School of Information Science, Nagoya Univ., JAPAN
10#
11# ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
12# ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
13# •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
14# (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
15# Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
16# ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17# (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
18# —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
19ƒƒ“ƒgi—˜—p
20# ŽÒƒ}ƒjƒ…
21ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
22# ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
23# (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
24# —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
25# ‚ƁD
26# (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
27ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
28ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
29# ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
30# (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
31# •ñ‚·‚邱‚ƁD
32# (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
33# ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
34# ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
35# —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
36# –Ɛӂ·‚邱‚ƁD
37#
38# –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
39# ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
40# ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
41# ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
42# ‚̐ӔC‚𕉂í‚È‚¢D
43#
44# @(#) $Id: genrename 509 2007-08-22 23:09:56Z hiro $
45#
46
47#
48# æ“ª‚ɂ‚¯‚镶Žš—ñ
49#
50sub prefix_string {
51 local($sym) = @_;
52
53 if ($sym =~ /[a-z]/) {
54 return("_kernel_");
55 }
56 else {
57 return("_KERNEL_");
58 }
59}
60
61#
62# ƒŠƒl[ƒ€’è‹`‚𐶐¬‚·‚é
63#
64sub generate_define
65{
66 local($sym, $prefix) = @_;
67
68 print FILE "#define ",$prefix,$sym;
69 print FILE "\t" if (length($prefix.$sym) < 4);
70 print FILE "\t" if (length($prefix.$sym) < 8);
71 print FILE "\t" if (length($prefix.$sym) < 12);
72 print FILE "\t" if (length($prefix.$sym) < 16);
73 print FILE "\t" if (length($prefix.$sym) < 20);
74 print FILE "\t" if (length($prefix.$sym) < 24);
75 print FILE "\t",$prefix,prefix_string($sym),$sym,"\n";
76}
77
78#
79# ƒŠƒl[ƒ€‰ðœ‚𐶐¬‚·‚é
80#
81sub generate_undef
82{
83 local($sym, $prefix) = @_;
84
85 print FILE "#undef ",$prefix,$sym,"\n";
86}
87
88#
89# ƒCƒ“ƒNƒ‹[ƒhƒfƒBƒŒƒNƒeƒBƒu‚𐶐¬‚·‚é
90#
91sub generate_include
92{
93 local($file, $prefix) = @_;
94
95 $file =~ s/([>"])$/_$prefix.h$1/;
96 $includes .= "#include ".$file."\n";
97}
98
99#
100# ƒGƒ‰[ƒ`ƒFƒbƒN
101#
102if ($#ARGV != 0) {
103 die "Usage: genrename <prefix>\n";
104}
105
106#
107# ‰Šú‰»
108#
109@syms = ();
110$name = $ARGV[0];
111$NAME = $name; $NAME =~ y/a-z/A-Z/;
112
113$infile = $name."_rename.def";
114$header_defsym = "TOPPERS_".$NAME."_RENAME_H";
115
116#
117# ƒVƒ“ƒ{ƒ‹ƒŠƒXƒg‚ð“ǂݍž‚Þ
118#
119open(INFILE, $infile) || die "Cannot open $infile";
120while ($line = <INFILE>) {
121 chomp $line;
122 @syms = (@syms, $line);
123}
124close(INFILE);
125
126#
127# ???_rename.h ‚𐶐¬‚·‚é
128#
129$includes = "";
130$file = $name."_rename.h";
131open(FILE, "> ".$file);
132
133print FILE <<END;
134/* This file is generated from $infile by genrename. */
135
136#ifndef $header_defsym
137#define $header_defsym
138
139END
140
141foreach $sym (@syms) {
142 if ($sym =~ /^#(.*)$/) {
143 print FILE "/*\n";
144 print FILE " * ",$1,"\n";
145 print FILE " */\n";
146 }
147 elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
148 generate_include($1, "rename");
149 }
150 elsif ($sym ne "") {
151 generate_define($sym, "");
152 }
153 else {
154 print FILE "\n";
155 }
156}
157
158print FILE <<END;
159
160#ifdef TOPPERS_LABEL_ASM
161
162END
163
164foreach $sym (@syms) {
165 if ($sym =~ /^#(.*)$/) {
166 print FILE "/*\n";
167 print FILE " * ",$1,"\n";
168 print FILE " */\n";
169 }
170 elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
171 # do nothing
172 }
173 elsif ($sym ne "") {
174 generate_define($sym, "_");
175 }
176 else {
177 print FILE "\n";
178 }
179}
180
181print FILE <<END;
182
183#endif /* TOPPERS_LABEL_ASM */
184
185$includes
186#endif /* $header_defsym */
187END
188
189#
190# ???_unrename.h ‚𐶐¬‚·‚é
191#
192$includes = "";
193$file = $name."_unrename.h";
194open(FILE, "> ".$file);
195
196print FILE <<END;
197/* This file is generated from $infile by genrename. */
198
199/* This file is included only when $name\_rename.h has been included. */
200#ifdef $header_defsym
201#undef $header_defsym
202
203END
204
205foreach $sym (@syms) {
206 if ($sym =~ /^#(.*)$/) {
207 print FILE "/*\n";
208 print FILE " * ",$1,"\n";
209 print FILE " */\n";
210 }
211 elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
212 generate_include($1, "unrename");
213 }
214 elsif ($sym ne "") {
215 generate_undef($sym, "");
216 }
217 else {
218 print FILE "\n";
219 }
220}
221
222print FILE <<END;
223
224#ifdef TOPPERS_LABEL_ASM
225
226END
227
228foreach $sym (@syms) {
229 if ($sym =~ /^#(.*)$/) {
230 print FILE "/*\n";
231 print FILE " * ",$1,"\n";
232 print FILE " */\n";
233 }
234 elsif ($sym =~ /^INCLUDE[ \t]+(.*)$/) {
235 # do nothing
236 }
237 elsif ($sym ne "") {
238 generate_undef($sym, "_");
239 }
240 else {
241 print FILE "\n";
242 }
243}
244
245print FILE <<END;
246
247#endif /* TOPPERS_LABEL_ASM */
248
249$includes
250#endif /* $header_defsym */
251END
252
253close(FILE);
Note: See TracBrowser for help on using the repository browser.