| 10 | | exts = {'.cpp'=>license, '.c'=>license, '.h'=>license,'.s'=>license.dup.gsub("//",";"),'.rb'=>license.dup.gsub("//","#")} |
|---|
| | 13 | modelines = IO.readlines('modelines.txt').join |
|---|
| | 14 | exts = { |
|---|
| | 15 | '.cpp'=>[license, modelines], |
|---|
| | 16 | '.c'=>[license, modelines], |
|---|
| | 17 | '.h'=>[license, modelines], |
|---|
| | 18 | '.s'=>[license.gsub("//",";"), modelines.gsub("//",";")], |
|---|
| | 19 | '.rb'=>[license.gsub("//","#"), modelines.gsub("//","#")] |
|---|
| | 20 | } |
|---|
| 13 | | if File.file?(f) && exts.include?(File.extname(f)) |
|---|
| 14 | | lic = exts[File.extname(f)] |
|---|
| 15 | | content = IO.readlines(f).join |
|---|
| 16 | | if content.index(lic).nil? |
|---|
| 17 | | content = lic + content |
|---|
| 18 | | File.open(f+".new", "w") do |out| |
|---|
| 19 | | out.write content |
|---|
| 20 | | end |
|---|
| 21 | | begin |
|---|
| 22 | | File.rename(f+".new", f) |
|---|
| 23 | | rescue SystemCallError |
|---|
| 24 | | puts "Couldn't rename file #{f+".new"} to #{f}:", $! |
|---|
| 25 | | end |
|---|
| 26 | | puts "#{f} updated" |
|---|
| 27 | | else |
|---|
| 28 | | puts "#{f} is ok" |
|---|
| 29 | | end |
|---|
| 30 | | end |
|---|
| | 23 | if File.file?(f) && exts.include?(File.extname(f)) |
|---|
| | 24 | lic = exts[File.extname(f)][0] |
|---|
| | 25 | mod = exts[File.extname(f)][1] |
|---|
| | 26 | modified = false |
|---|
| | 27 | content = IO.readlines(f).join |
|---|
| | 28 | if content.index(lic).nil? |
|---|
| | 29 | content = lic + content |
|---|
| | 30 | modified = true |
|---|
| | 31 | end |
|---|
| | 32 | if content.index(mod).nil? |
|---|
| | 33 | content = content + mod |
|---|
| | 34 | modified = true |
|---|
| | 35 | end |
|---|
| | 36 | if modified |
|---|
| | 37 | File.open(f+".new", "w") do |out| |
|---|
| | 38 | out.write content |
|---|
| | 39 | end |
|---|
| | 40 | begin |
|---|
| | 41 | File.rename(f+".new", f) |
|---|
| | 42 | rescue SystemCallError |
|---|
| | 43 | puts "Couldn't rename file #{f+".new"} to #{f}:", $! |
|---|
| | 44 | end |
|---|
| | 45 | puts "#{f} updated" |
|---|
| | 46 | else |
|---|
| | 47 | puts "#{f} is ok" |
|---|
| | 48 | end |
|---|
| | 49 | end |
|---|