[388] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 | #
|
---|
| 4 | # TOPPERS Software
|
---|
| 5 | # Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 6 | #
|
---|
| 7 | # Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 8 | # Toyohashi Univ. of Technology, JAPAN
|
---|
| 9 | # Copyright (C) 2005-2016 by Embedded and Real-Time Systems Laboratory
|
---|
| 10 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 11 | #
|
---|
| 12 | # ä¸è¨èä½æ¨©è
|
---|
| 13 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 14 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 15 | # å¤ã»åé
|
---|
| 16 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | # ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | # è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | # ã¨ï¼
|
---|
| 31 | # (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | # (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | # å ±åãããã¨ï¼
|
---|
| 39 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 44 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 46 | # å
|
---|
| 47 | 責ãããã¨ï¼
|
---|
| 48 | #
|
---|
| 49 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 50 | ã
|
---|
| 51 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 52 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 53 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 54 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 55 | #
|
---|
| 56 | # $Id$
|
---|
| 57 | #
|
---|
| 58 |
|
---|
| 59 | #
|
---|
| 60 | # å
|
---|
| 61 | é ã«ã¤ããæåå
|
---|
| 62 | #
|
---|
| 63 | def prefixString(sym)
|
---|
| 64 | if sym =~ /[a-z]/
|
---|
| 65 | return("_kernel_")
|
---|
| 66 | else
|
---|
| 67 | return("_KERNEL_")
|
---|
| 68 | end
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 | #
|
---|
| 72 | # ãªãã¼ã å®ç¾©ãçæãã
|
---|
| 73 | #
|
---|
| 74 | def generateDefine(outFile, sym, prefix)
|
---|
| 75 | outFile.print("#define #{prefix}#{sym}");
|
---|
| 76 | outFile.print("\t" * [(6 - (sym.length + prefix.length) / 4), 0].max);
|
---|
| 77 | outFile.print("\t#{prefix}#{prefixString(sym)}#{sym}\n");
|
---|
| 78 | end
|
---|
| 79 |
|
---|
| 80 | #
|
---|
| 81 | # ãªãã¼ã 解é¤ãçæãã
|
---|
| 82 | #
|
---|
| 83 | def generateUndef(outFile, sym, prefix)
|
---|
| 84 | outFile.print("#undef #{prefix}#{sym}\n");
|
---|
| 85 | end
|
---|
| 86 |
|
---|
| 87 | #
|
---|
| 88 | # ã³ã¡ã³ããçæãã
|
---|
| 89 | #
|
---|
| 90 | def generateComment(outFile, comment)
|
---|
| 91 | outFile.print("/*\n")
|
---|
| 92 | outFile.print(" * #{comment}\n")
|
---|
| 93 | outFile.print(" */\n")
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | #
|
---|
| 97 | # ã¨ã©ã¼ãã§ãã¯
|
---|
| 98 | #
|
---|
| 99 | if ARGV.length < 1
|
---|
| 100 | abort("Usage: ruby genrename.rb <prefix>")
|
---|
| 101 | end
|
---|
| 102 |
|
---|
| 103 | #
|
---|
| 104 | # åæå
|
---|
| 105 | #
|
---|
| 106 | syms = []
|
---|
| 107 | name = ARGV.shift
|
---|
| 108 | NAME = name.upcase
|
---|
| 109 |
|
---|
| 110 | inFileName = name + "_rename.def"
|
---|
| 111 | headerDefineSymbol = "TOPPERS_" + NAME + "_RENAME_H"
|
---|
| 112 |
|
---|
| 113 | #
|
---|
| 114 | # ã·ã³ãã«ãªã¹ããèªã¿è¾¼ã
|
---|
| 115 | #
|
---|
| 116 | begin
|
---|
| 117 | inFile = File.open(inFileName)
|
---|
| 118 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
| 119 | abort(ex.message)
|
---|
| 120 | end
|
---|
| 121 |
|
---|
| 122 | inFile.each do |line|
|
---|
| 123 | syms.push(line.chomp)
|
---|
| 124 | end
|
---|
| 125 |
|
---|
| 126 | #
|
---|
| 127 | # ???_rename.h ãçæãã
|
---|
| 128 | #
|
---|
| 129 | begin
|
---|
| 130 | outFile = File.open(name + "_rename.h", "w")
|
---|
| 131 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
| 132 | abort(ex.message)
|
---|
| 133 | end
|
---|
| 134 |
|
---|
| 135 | outFile.print <<EOS
|
---|
| 136 | /* This file is generated from #{inFileName} by genrename. */
|
---|
| 137 |
|
---|
| 138 | #ifndef #{headerDefineSymbol}
|
---|
| 139 | #define #{headerDefineSymbol}
|
---|
| 140 |
|
---|
| 141 | EOS
|
---|
| 142 |
|
---|
| 143 | includes = ""
|
---|
| 144 | syms.each do |sym|
|
---|
| 145 | if /^#\s*(.*)$/ =~ sym
|
---|
| 146 | generateComment(outFile, $1)
|
---|
| 147 | elsif /^INCLUDE\s+(.*)$/ =~ sym
|
---|
| 148 | fileName = $1.sub(/([>"])$/, "_rename.h\\1")
|
---|
| 149 | includes += "#include #{fileName}\n"
|
---|
| 150 | elsif sym != ""
|
---|
| 151 | generateDefine(outFile, sym, "")
|
---|
| 152 | else
|
---|
| 153 | outFile.print("\n")
|
---|
| 154 | end
|
---|
| 155 | end
|
---|
| 156 |
|
---|
| 157 | outFile.print <<EOS
|
---|
| 158 |
|
---|
| 159 | #{includes}
|
---|
| 160 | #endif /* #{headerDefineSymbol} */
|
---|
| 161 | EOS
|
---|
| 162 |
|
---|
| 163 | #
|
---|
| 164 | # ???_unrename.h ãçæãã
|
---|
| 165 | #
|
---|
| 166 | begin
|
---|
| 167 | outFile = File.open(name + "_unrename.h", "w")
|
---|
| 168 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
| 169 | abort(ex.message)
|
---|
| 170 | end
|
---|
| 171 |
|
---|
| 172 | outFile.print <<EOS
|
---|
| 173 | /* This file is generated from #{inFileName} by genrename. */
|
---|
| 174 |
|
---|
| 175 | /* This file is included only when #{name}_rename.h has been included. */
|
---|
| 176 | #ifdef #{headerDefineSymbol}
|
---|
| 177 | #undef #{headerDefineSymbol}
|
---|
| 178 |
|
---|
| 179 | EOS
|
---|
| 180 |
|
---|
| 181 | includes = ""
|
---|
| 182 | syms.each do |sym|
|
---|
| 183 | if /^#\s*(.*)$/ =~ sym
|
---|
| 184 | generateComment(outFile, $1)
|
---|
| 185 | elsif /^INCLUDE\s+(.*)$/ =~ sym
|
---|
| 186 | fileName = $1.sub(/([>"])$/, "_unrename.h\\1")
|
---|
| 187 | includes += "#include #{fileName}\n"
|
---|
| 188 | elsif sym != ""
|
---|
| 189 | generateUndef(outFile, sym, "")
|
---|
| 190 | else
|
---|
| 191 | outFile.print("\n")
|
---|
| 192 | end
|
---|
| 193 | end
|
---|
| 194 |
|
---|
| 195 | outFile.print <<EOS
|
---|
| 196 |
|
---|
| 197 | #{includes}
|
---|
| 198 | #endif /* #{headerDefineSymbol} */
|
---|
| 199 | EOS
|
---|