-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_list.rb
executable file
·48 lines (38 loc) · 1.08 KB
/
gen_list.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# -*- encoding: utf-8; -*-
require 'json'
if ARGV.empty?
puts "Usage: gen_list.rb directory/"
exit
end
puts (Dir.glob(File.join(ARGV.shift, "*.pmd")).sort_by{|v| v.downcase }.map do |filename|
File.open(filename, "rb:Shift_JIS:UTF-8") do |file|
part_num = file.getbyte
part_num = file.getbyte if part_num == 0
file_header = file.read(12 + 2 + 2 + 2)
header = file_header.unpack("v6vvv")
title_offset = header[7]
title2_offset = header[8]
title = ""
if title_offset != 0
file.seek(title_offset)
while (c = file.getc rescue "〓") && c != "\0" do
title << c
end
title.gsub!(/;/, "\n")
end
title2 = ""
if title2_offset != 0
file.seek(title2_offset)
while (c = file.getc rescue "〓") && c != "\0" do
title2 << c
end
title2.gsub!(/;/, "\n")
end
{
"href" => filename, "filename" => File.basename(filename),
"name" => File.basename(filename, ".pmd"),
"title" => title, "title2" => title2
}
end
end.to_json)