#! ruby -Ks # coding:windows-31j #! /usr/bin/env ruby require 'nkf' #OCRA でコンパイルする時に内容チェックさせない。 unless (defined?(Ocra)) inf=ARGV[0] linesep=ARGV[1] f = open(inf, "r") str = f.read f.close unless NKF.guess(str)==NKF::UTF8 || NKF.guess(str)==NKF::SJIS then puts "Only for UTF-8 or Shift-JIS" exit end linesep2=linesep if linesep==nil linesep="-Lu" linesep2="-Lw" end # -Lw:Windows(CRLF) -Lu:UNIX(LF) -Lm:Mac(CR) print "\nOption of Line Separator : "+linesep+"\n" doc_nbom=NKF.nkf('-w80 '+linesep,str) doc_sjis=NKF.nkf('-s '+linesep2,str) NBOMf=File.dirname(inf)+"/"+File.basename(inf,".*")+"_NBOM"+File.extname(inf) BOMf=File.dirname(inf)+"/"+File.basename(inf,".*")+"_BOM"+File.extname(inf) SJISf=File.dirname(inf)+"/"+File.basename(inf,".*")+"_SJIS"+File.extname(inf) ot = open(NBOMf,"w") ot.print doc_nbom print "\nCreated UTF-8 without BOM(NBOM) Formated File\n" print " "+NBOMf+"\n" ot.close ot2 = open(BOMf,"w") ot2.print("\xEF\xBB\xBF") ot2.print doc_nbom print "\nCreated UTF-8 with BOM Formated File\n" print " "+BOMf+"\n" ot2.close ot3= open(SJISf,"w") ot3.print doc_sjis print "\nCreated Shift-JIS Formated File\n" print " "+SJISf+"\n" ot3.close end