annotate mpsplit.rb @ 553:c047dd7821b7

2019-0410 FD distributed version
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 08 Apr 2019 17:14:59 +0900
parents f2204bd941d5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
1 #!/usr/bin/env ruby21
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
2 # coding: binary
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
3 require 'nkf'
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
4 Encoding.default_external = Encoding::BINARY
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
5 Encoding.default_internal = Encoding::BINARY
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
6
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
7 boundary="--"+ARGV[0] # +"\r\n"
8
3db7524d3dea Add default images
HIROSE Yuuji <yuuji@gentei.org>
parents: 0
diff changeset
8 tmpdir=(ARGV[1] || "tmp").dup
3db7524d3dea Add default images
HIROSE Yuuji <yuuji@gentei.org>
parents: 0
diff changeset
9 tmpdir.untaint
3db7524d3dea Add default images
HIROSE Yuuji <yuuji@gentei.org>
parents: 0
diff changeset
10 test(?d, tmpdir) or Dir.mkdir(tmpdir)
0
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
11 stream=STDIN.readlines.join
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
12 stream.split(boundary)[1..-2].each do |x|
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
13 header = x.sub(/\r\n\r\n.*/, "")
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
14 name = header.scan(/\bname=([\"']?)(.*?)\1/)[0][1]
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
15 body = x.sub(/.*?\r\n\r\n/m, "").sub(/\r\n$/, "")
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
16 STDERR.printf("body[%s]=[%s]\n", name, body.length)
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
17 if /filename=(['\"]?)(.*?)\1/ =~ header && $2 > ""
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
18 fn = $2
8
3db7524d3dea Add default images
HIROSE Yuuji <yuuji@gentei.org>
parents: 0
diff changeset
19 fn.untaint if File.dirname(fn)=="."
3db7524d3dea Add default images
HIROSE Yuuji <yuuji@gentei.org>
parents: 0
diff changeset
20 open(File.expand_path(fn, tmpdir).untaint, "w") do |out|
0
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
21 out.write body
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
22 end
11
3565d93c2fb1 add mpsplit.pl
HIROSE Yuuji <yuuji@gentei.org>
parents: 8
diff changeset
23 ## printf("%s:filename=%s\n", name, fn)
3565d93c2fb1 add mpsplit.pl
HIROSE Yuuji <yuuji@gentei.org>
parents: 8
diff changeset
24 printf("%s:filename=%s\n", name, fn.unpack("H*")[0])
0
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
25 elsif /name=(['\"]?)(.*?)\1/ =~ header
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
26 v=$2
11
3565d93c2fb1 add mpsplit.pl
HIROSE Yuuji <yuuji@gentei.org>
parents: 8
diff changeset
27 printf("%s=%s\n", v, body.unpack("H*")[0])
0
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
28 end
b8a890828283 add se-blog.sh se-cgi.sh se-funcs.sh se-init.sh mpsplit.rb
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
29 end

yatex.org