about summary refs log tree commit homepage
path: root/Documentation/update-footer.rb
blob: a6e16cb99e4d2816af308da53d683d9a78be3736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
# Copyright 2015-2016 all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <http://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
contact = %q{
All feedback welcome via plain-text mail to: <dtas-all@nongnu.org>\
Mailing list archives available at <http://80x24.org/dtas-all/> and
<ftp://lists.gnu.org/dtas-all/>\
No subscription is necessary to post to the mailing list.
}

copyright = %q{
Copyright %s all contributors <dtas-all@nongnu.org>.\
License: GPL-3.0+ <http://www.gnu.org/licenses/gpl-3.0.txt>
}

ENV['TZ'] = 'UTC'
now_year = Time.now.strftime("%Y")
ARGV.each do |file|
  cmd = %W(git log --reverse --pretty=format:%ad --date=short -- #{file})
  beg_year = IO.popen(cmd, &:gets).split('-')[0]
  years = beg_year == now_year ? beg_year : "#{beg_year}-#{now_year}"

  File.open(file, "r+") do |fp|
    state = :top
    sections = [ state ]
    sec = { state => ''.dup }
    fp.each_line do |l|
      case l
      when /^(#.+)$/
        state = $1.freeze
        sections << state
        sec[state] = ''.dup
      else
        sec[state] << l
      end
    end

    fp.truncate(0)
    fp.rewind
    sec["# CONTACT"] = contact
    sec["# COPYRIGHT"] = sprintf(copyright, years)
    while section = sections.shift
      fp.puts(section) if String === section
      blob = sec[section].sub(/\A\n+/, '').sub(/\n+\z/, '')
      fp.puts("\n") if String === section
      fp.write(blob)
      fp.puts("\n")
      fp.puts("\n") if sections[0]
    end
    fp.rewind
  end
end