Created
October 15, 2008 08:22
-
-
Save eban/16884 to your computer and use it in GitHub Desktop.
update version.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rubyのversion.hの日付けを更新するscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/ruby | |
formats = { | |
'DATE' => [/"\d{4}-\d\d-\d\d"/, '"%Y-%m-%d"'], | |
'TIME' => [/"\d\d:\d\d:\d\d"/, '"%H:%M:%S"'], | |
'CODE' => [/\d{8}/, '%Y%m%d'], | |
'YEAR' => [/\d{4}/, '%Y'], | |
'MONTH' => [/\d{1,2}/, '%m'], | |
'DAY' => [/\d{1,2}/, '%d'] | |
} | |
now = Time.now | |
File.rename "version.h", "version.h~" | |
open("version.h~") do |fold| | |
open("version.h", "w") do |fnew| | |
while line = fold.gets | |
if /RUBY_RELEASE_(#{formats.keys.join('|')})/o =~ line | |
regex, format = formats[$1] | |
line.sub!(regex) do | |
now.strftime(format).sub(/^0/, '') | |
end | |
end | |
fnew.print line | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment