about summary refs log tree commit homepage
path: root/Documentation/update-footer.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-01-19 23:36:49 +0000
committerEric Wong <e@80x24.org>2015-01-19 23:56:42 +0000
commit5a0dbfc1cfddd2028ced800fc1f65e1c443126ab (patch)
treee0aebe0b90b41448a3cce3fb400cc5976386466a /Documentation/update-footer.rb
parentb524cec0d86da22a3ff8fdb93328f54d7ccbdf29 (diff)
downloaddtas-5a0dbfc1cfddd2028ced800fc1f65e1c443126ab.tar.gz
The documentation part is managed by the new
Documentation/update-copyright script.  For the future, the rest may
be managed by the update-copyright tool in gnulib
Diffstat (limited to 'Documentation/update-footer.rb')
-rwxr-xr-xDocumentation/update-footer.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/Documentation/update-footer.rb b/Documentation/update-footer.rb
new file mode 100755
index 0000000..30316ac
--- /dev/null
+++ b/Documentation/update-footer.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+# Copyright 2015 all contributors <dtas-all@nongnu.org>
+# License: GPLv3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>
+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: GPLv3 or later <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 => "" }
+    fp.each_line do |l|
+      case l
+      when /^(#.+)$/
+        state = $1.freeze
+        sections << state
+        sec[state] = ""
+      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