summaryrefslogtreecommitdiff
path: root/bin/strip-date
blob: 0b280797b6228184f550bfb8b38de7b481387629 (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
#!/usr/bin/ruby

id = ARGV[0].upcase
state = :idle
$stdin.binmode
$stdin.each do |line|
  case state
  when :idle
    if line =~ /^(\d+) (\d+) obj/
      state = :obj
    elsif line == "trailer\n"
      state = :trailerobj
    elsif line == "stream\n"
      state = :in_stream
    end
  when :obj
    state = line == "<<\n" ? :in_obj : :idle
  when :trailerobj
    state = line == "<<\n" ? :in_trailerobj : :idle
  when :in_obj
    state = :idle if line == ">>\n"
    line.sub!(/^(\/\S+Date\s+)\(D:\d+Z\)/, '\1(D:19700101000000Z)')
  when :in_trailerobj
    state = :idle if line == ">>\n"
    line.sub!(/^(\s+\/ID\s+)\[.*/, "\\1[<#{id}> <#{id}>]")
  when :in_stream
    state = :idle if line == "endstream\n"
    line.sub!(/^<(dc:date|xmp:(?:Metadata|Create)Date)>.*<\/\1>/,
             ' ' * (line.chomp.length))
  end
  $stdout.print line
end