#!/usr/bin/env ruby $KCODE='e' require 'connect2ch' BASE_DIR = ENV['HOME']+ '/.goRua_2ch/' NEW_BI_FILE = ARGV.shift OLD_BI_FILE = ARGV.shift FILE = ARGV.shift board_hash = {} different_board_hash = {} open(NEW_BI_FILE,'r'){ |file| while line=file.gets line=NKF::nkf('-exS',line).strip case line when REGEXP_BORAD_INFO_B,REGEXP_BORAD_INFO_A board_hash[$2.strip] = $1 end end } open(OLD_BI_FILE,'r'){ |file| while line=file.gets line=NKF::nkf('-exS',line).strip case line when REGEXP_BORAD_INFO_B,REGEXP_BORAD_INFO_A if board_hash[$2.strip] if board_hash[$2.strip] != $1 different_board_hash[$1] = board_hash[$2.strip] end end end end } different_board_hash.each{ |old,new| host,port,path = parse_http_url(old) old = host + '_' + "#{port}" + '_' + path.gsub(/\//,'_') host,port,path = parse_http_url(new) new = host + '_' + "#{port}" + '_' + path.gsub(/\//,'_') Dir.chdir(BASE_DIR + "/subject/") Dir.glob("#{old}*"){ |file| File.rename(file,file.sub(old,new)); } Dir.chdir(BASE_DIR + "/thread/") Dir.glob("#{old}*"){ |file| File.rename(file,file.sub(old,new)); } } open(FILE,'r'){ |file| while line=file.gets line=NKF::nkf('-exS',line).strip if /^([TSBAEU])\s+(http.+)\s+(.+)/ =~ line top = $1 url = $2 name = $3 different_board_hash.each{ |x,y| url.sub!(x,y) } print NKF::nkf('-sxE',"#{top} #{url} #{name}\n") else print NKF::nkf('-sxE',line) print "\n" end end }