forked from snej/MYUtilities
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetObjToARC.rb
executable file
·24 lines (22 loc) · 948 Bytes
/
setObjToARC.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env ruby
if ARGV.length == 0
puts "Usage: setObjToARC sourcefile ..."
puts ""
puts "Modifies input files in-place, updating setObj() calls to ARC-convertable equivalents"
exit 0
end
ARGV.each do |filename|
puts "#{filename} ..."
outfilename = filename + ".temp"
File.open(outfilename, "w") do |out|
IO.foreach(filename) do |line|
line.gsub!(/\bsetObj\(&(\w+),(.*)\);/, '(void)[\1 autorelease]; \1 = [\2 retain];')
line.gsub!(/\bsetObjCopy\(&(\w+),(.*)\);/, '(void)[\1 autorelease]; \1 = [\2 copy];')
line.gsub!(/\[nil (retain|copy)\]/, 'nil')
line.gsub!(/\bifSetObj\(&(\w+),(.*)\);/, '!$equal(\1, \2) && ((void)[\1 autorelease], \1 = [\2 retain], YES)')
line.gsub!(/\bifSetObjCopy\(&(\w+),(.*)\);/, '!$equal(\1, \2) && ((void)[\1 autorelease], \1 = [\2 copy], YES)')
out.puts line
end
end
File.rename(outfilename, filename)
end