'簡易フィルタ '2003/04/29 プログラムの整理と不具合の修正 ' 'cmd '1... '2... '3... '4... '5... dim lst$[4095] dim errflag proc main '不適切な状態での実行を拒否 if @hwnd=0 then errmsg "このマクロは文章編集中のみ実行できます。" elseif @select<>5 and @select<>6 then errmsg "フィルタ機能は範囲を選択していないと実行できません。" elseif @CanEditSel=FALSE then errmsg "文章が変更禁止に設定されています。" end if 'チェック済みの変数 dim tmpdir$,tmpfile$,tmpfile2$,tmpfile3$,tmpfile4$,codefile$ dim fnum dim tmp,tmp$,tmp2$ dim cmd$,cmd2$,cmd dim step_ct dim r1[255],r2[255],rct dim tmpnoext$ dim c1,c2,c3 dim m1,m2 dim info$ dim nowriteflag dim ct '未チェックの変数 dim ed,a,b$,b2$,p dim z$,q 'ファイル名の取得 tmpdir$=macrofilename$ tmpdir$=left$(tmpdir$,inrstr(tmpdir$,"\")) tmpfile$=tmpdir$+"$tmp(crfilter)-1-"+date0$+replace$(time0$,":","")+".$$$" tmpfile2$=tmpdir$+"$tmp(crfilter)-2-"+date0$+replace$(time0$,":","")+".$$$" tmpfile3$=tmpdir$+"$tmp(crfilter)-3-"+date0$+replace$(time0$,":","")+".$$$" tmpfile4$=tmpdir$+"$tmp(crfilter)-4-"+date0$+replace$(time0$,":","")+".$$$" tmpnoext$=tmpdir$+"tmp(crfilter)" codefile$=tmpdir$+"crfilter.dat" '初期の選択範囲を取得(Undo用) rct=1 r1[rct]=@selectstartline r2[rct]=@selectendline 'メニューファイルの作成(popupmenuf$利用のため) if filedatetime$(macrofilename$)>filedatetime$(macrofilename$+".$$$")then fnum=freefile open macrofilename$+".$$$" for output as #1 print#fnum,"cancel 0.dummy/none" print#fnum,"-" print#fnum,">行頭から指定位置まで削除" print#fnum,"指定文字列まで削除 1.del.to.str/string" print#fnum,"最後の指定文字列まで削除 1.del.to.last/string" print#fnum,"指定位置まで削除(半角単位) 1.del.to.row/xpos" print#fnum,"<" print#fnum,">指定位置から行末まで削除" print#fnum,"指定文字列から削除 1.del.from.str/string" print#fnum,"最後の指定文字列から削除 1.del.from.last/string" print#fnum,"指定位置から削除(半角単位) 1.del.from.row/xpos" print#fnum,"<" print#fnum,"-" print#fnum,">行頭か行末に文字列を追加" print#fnum,">行頭" print#fnum,"指定の文字列を追加 1.join.top.str/string" print#fnum,"連番を追加 1.join.top.num/num.step" print#fnum,"連番を追加(桁を指定する) 1.join.top.num0/num.step0" print#fnum,"-" print#fnum,"指定文字列が無ければそれを追加 1.join.top.lack/string" print#fnum,"-" print#fnum,"タブコードを追加 1.join.top.tab/none" print#fnum,"<" print#fnum,">行末" print#fnum,"指定の文字列を追加 1.join.bottom.str/string" print#fnum,"連番を追加 1.join.bottom.num/num.step" print#fnum,"連番を追加(桁を指定する) 1.join.bottom.num0/num.step0" print#fnum,"-" print#fnum,"指定文字列が無ければそれを追加 1.join.bottom.lack/none" print#fnum,"<" print#fnum,"<" print#fnum,">行の並び替え" print#fnum,"昇順 3.sort/sort" print#fnum,"降順 3.sort.reverse/sort" print#fnum,"<" print#fnum,">行の抽出" print#fnum,"指定文字列を含む行だけ残す 1.choice/string" print#fnum,"指定文字列を含む行だけ残して詰める 1.choice.cutdown/string" print#fnum,"-" print#fnum,"指定文字列を含む行以外を残す 1.choice.expect/string" print#fnum,"指定文字列を含む行以外を残して詰める 1.choice.expect.cutdown/string" print#fnum,"<" print#fnum,">クリップボード連携" print#fnum,"選択範囲をクリップボードに保存 4.clipboard.set/none" print#fnum,"-" print#fnum,"クリップボードの各行を文章の各行に追加(先頭) 1.join.top.clipboard/none" print#fnum,"クリップボードの各行を文章の各行に追加(行末) 1.join.bottom.clipboard/none" print#fnum,"<" print#fnum,"-" print#fnum,">ファイル連携" print#fnum,"選択範囲をファイルに保存 4.block.save/file" print#fnum,"選択範囲をファイルに保存し履歴登録 4.block.save.history/file" print#fnum,"-" print#fnum,"選択範囲をBATと見なして実行 4.exec.bat/none" print#fnum,"選択範囲をVBSと見なして実行 4.exec.vbs/none" print#fnum,"-" print#fnum,"選択範囲をBATと見なして実行(引数入力) 4.exec.bat.cmdline/string.引数を入力してください(省略で作業中止)" print#fnum,"選択範囲をVBSと見なして実行(引数入力) 4.exec.vbs.cmdline/string.引数を入力してください(省略で作業中止)" print#fnum,"<" print#fnum,"-" print#fnum,">文字種の変換" print#fnum,"小文字→大文字 2.standard.block.@BlockToCapital" print#fnum,"大文字→小文字 2.standard.block.@BlockToSmall" print#fnum,"-" print#fnum,"タブ→スペース 2.standard.block.@BlockToSpace" print#fnum,"スペース→タブ 2.standard.block.@BlockToTab" print#fnum,"-" print#fnum,"全角かな→全角カナ 2.standard.block.@BlockToKatakana" print#fnum,"全角カナ→全角かな 2.standard.block.@BlockToHiragana" print#fnum,"-" print#fnum,"全角文字→半角文字 2.standard.block.@BlockToHankaku" print#fnum,"半角文字→全角文字 2.standard.block.@BlockToZenkaku" print#fnum,"-" print#fnum,"全角半角変換文字種設定... 2.standard.block.@BlockToZenHan" print#fnum,"-" print#fnum,"中央寄せ 2.standard.block.@FormatCenter" print#fnum,"右寄せ 2.standard.block.@FormatRight" print#fnum,"左寄せ 2.standard.block.@FormatLeft" print#fnum,"<" print#fnum,">削除" print#fnum,">行の削除" print#fnum,"改行のみの行を削除 2.standard.block.@DeleteCrLine" print#fnum,"連続した改行のみの行をまとめる 2.standard.block.@DeleteCrLine2" print#fnum,"-" print#fnum,"前行と同じ行を削除 1.delete.overlap/none" print#fnum,"<" print#fnum,">改行の削除" print#fnum,"改行を削除 2.standard.block.@DeleteCr" print#fnum,"<" print#fnum,">空白の削除" print#fnum,"行の前後にある余分な空白を削除 1.trim/none" print#fnum,"<" print#fnum,"<" print#fnum,">置換(特殊文字は不可)" print#fnum,"置換(該当文字列全て) 1.replace/string2" print#fnum,"置換(各行1回のみ) 1.replace.one/string2" print#fnum,"<" print#fnum,">情報" print#fnum,"行数のカウント 5.print.line/none" print#fnum,"<" print#fnum,">Undo&Redo" print#fnum,"Undo 5.undo/none" print#fnum,"Redo 5.redo/none" print#fnum,"<" close#fnum end if codefile$=macrofilename$+".$$$" do while ed=0 'メニューを選択 cmd$=popupmenuf$(codefile$,0,0,1+2+4) cmd=val(left$(cmd$,instr(cmd$,".")-1)) cmd$=mid$(cmd$,instr(cmd$,".")+1) 'cmd$をcmd2$に分離 if instr(cmd$,"/") then cmd2$=mid$(cmd$,instr(cmd$,"/")+1) cmd$=left$(cmd$,instr(cmd$,"/")-1) else cmd2$="none" end if cmd$=cmd$+"." '入力が必要なものを処理 stopinputbox 1 if cmd2$="string"then b$=inputbox$("処理する文字列を入力してください(大小文字は区別されます)。","","","") elseif left$(cmd2$,7)="string."then b$=inputbox$(mid$(cmd2$,8),"","","") elseif cmd2$="xpos" then b$=trim$(str$(inputbox("処理するX座標(半角単位)を入力してください。",""))) '12/22/2001バグを修正 elseif cmd2$="num.step" then step_ct=val(str$(inputbox("初期番号を入力してください。","",0))) b$=trim$(str$(inputbox("一行ごとの数字の変化量を入力してください。","",1))) elseif cmd2$="num.step0" then step_ct=val(str$(inputbox("初期番号を入力してください。","",0))) b$=trim$(str$(inputbox("一行ごとの数字の変化量を入力してください。","",1))) b2$=trim$(str$(inputbox("連番の『桁数』を入力してください。","",len(trim$(str$(step_ct+val(b$)*(@selectendline-@selectstartline))))))) elseif cmd2$="string2"then b$=inputbox$("処理する文字列を入力してください(大小文字は区別されます)。","","","") b2$=inputbox$("置換後の文字列を入力してください。","","","") elseif cmd2$="file" then b$=getfilename$("","","保存するファイル名を入力してください。") if b$="" then end elseif cmd2$="sort" then if @selectendline-@selectstartline>4000 then errmsg "行が多すぎます。並べ替えできるのは4000行までです。" end if end if stopinputbox 0 '処理開始 if cmd=0 then end end if print"現在処理中です..." if cmd=0 then '明示的な終了 end elseif cmd=5 then '別窓を利用しない処理 if cmd$="print.line."then info$=str$(@selectendline-@selectstartline)+"行です。" elseif cmd$="undo."then if rct<>1 then rct-- @redraw=0 @undo @line=r1[rct] @blockselect @line=r2[rct] @redraw=1 end if elseif cmd$="redo."then if r1[rct+1]<>0 and r2[rct+1]<>0 then rct++ @redraw=0 @undoundo @line=r1[rct] @blockselect @line=r2[rct] @redraw=1 end if end if else '選択範囲をtmpファイルに保存 m1=@selectstartline m2=@selectendline @@redraw=0 kill tmpfile$ call @append(tmpfile$) @line=m1 @blockselect @line=m2 @@redraw=1 if cmd=4 then 'tmpファイルは使うが範囲は書き換えない処理 if cmd$="clipboard.set."then @@redraw=0 call @@openfile(tmpfile$) @blockselectall @blockclipboardcopy @undo @fileclose @@redraw=1 elseif cmd$="block.save." or cmd$="block.save.history."then open tmpfile$ for input as #1 open b$ for output as #2 do while eof(1)=0 lineinput#1,tmp$ print#2,tmp$ loop close#2 close#1 if cmd$="block.save.history."then @@redraw=0 call @@openfile(b$) @fileclose @@redraw=1 end if elseif left$(cmd$,5)="exec."then if left$(cmd$,9)="exec.bat."then tmp2$=".bat":tmp$="" if left$(cmd$,9)="exec.vbs."then tmp2$=".vbs":tmp$="wscript " if b$<>"" or right$(cmd$,9)<>".cmdline." then open tmpfile$ for input as #1 open tmpnoext$+tmp2$ for output as #2 do while eof(1)=0 lineinput#1,tmp$ print#2,tmp$ loop close#2 close#1 call shell(tmpnoext$+tmp2$+" "+b$,1) end if end if else if cmd=1 then 'tmpファイルをopen命令で処理 ct=0 open tmpfile$ for input as #1 open tmpfile2$ for output as #2 do while eof(1)=0 and errflag=FALSE lineinput #1,z$ ct++ nowriteflag=FALSE 'あとは一行ずつ処理を繰り返せばいいね if cmd$="del.to.str." then z$=mid$(z$,instr(z$,b$)+1) elseif cmd$="del.to.last." then z$=mid$(z$,inrstr(z$,b$)+1) elseif cmd$="del.to.row." then z$=mid$(z$,val(b$)+1) elseif cmd$="del.from.str." then z$=left$(z$,instr(z$,b$)-1) elseif cmd$="del.from.last." then z$=left$(z$,inrstr(z$,b$)-1) elseif cmd$="del.from.row." then z$=left$(z$,val(b$)-1) elseif cmd$="join.top.str." then z$=b$+z$ elseif cmd$="join.top.lack." then if left$(z$,len(b$))<>b$ then z$=b$+z$ elseif cmd$="join.top.num." then z$=trim$(str$(step_ct))+z$ step_ct=step_ct+val(b$) elseif cmd$="join.top.num0." then z$=right$(space$(val(b2$))+trim$(str$(step_ct)),val(b2$))+z$ step_ct=step_ct+val(b$) elseif cmd$="join.top.tab." then z$=chr$(9)+z$ elseif cmd$="join.bottom.str." then z$=z$+b$ elseif cmd$="join.bottom.lack." then if right$(z$,len(b$))<>b$ then z$=z$+b$ elseif cmd$="join.bottom.num." then z$=z$+trim$(str$(step_ct)) step_ct=step_ct+val(b$) elseif cmd$="join.bottom.num0." then z$=z$+right$(space$(val(b2$))+trim$(str$(step_ct)),val(b2$)) step_ct=step_ct+val(b$) elseif cmd$="choice." then if instr(z$,b$)=0 then z$="" elseif cmd$="choice.expect." then if instr(z$,b$)<>0 then z$="" elseif cmd$="choice.cutdown." then if instr(z$,b$)=0 then nowriteflag=TRUE elseif cmd$="choice.expect.cutdown." then if instr(z$,b$)<>0 then nowriteflag=TRUE elseif cmd$="trim." then z$=trim$(z$) elseif cmd$="join.top.clipboard." then z$=clipboard$(ct)+z$:z$=replace$(z$,chr$(13),""):z$=replace$(z$,chr$(10),"") elseif cmd$="join.bottom.clipboard." then z$=z$+clipboard$(ct):z$=replace$(z$,chr$(13),""):z$=replace$(z$,chr$(10),"") elseif cmd$="replace." then z$=replace$(z$,b$,b2$) elseif cmd$="replace.one." then z$=replaceone$(z$,b$,b2$) elseif cmd$="delete.overlap." then if z$=tmp$ and ct<>1 then nowriteflag=TRUE else tmp$=z$ end if else call msgbox(cmd$+"はダミ") end end if if nowriteflag=FALSE then print #2,z$ end if loop close #2 close #1 if errflag<>TRUE then tmp$=tmpfile$ tmpfile$=tmpfile2$ tmpfile2$=tmp$ end if elseif cmd=3 then 'ソート機能 ct=0 open tmpfile$ for input as #1 do while eof(1)=0 ct++ lineinput #1,tmp$ lst$[ct]=tmp$ loop close#1 dialog "DIALOG",0,0,100,100,0 control "",100,"LISTBOX",LBS_SORT,0,0,80,80 dlglistboxarray 100,lst$ call dlglistboxarray(100,lst$) if cmd$="sort." then c1=1:c2=ct:c3=1 if cmd$="sort.reverse." then c1=ct:c2=1:c3=-1 open tmpfile2$ for output as #1 for tmp=c1 to c2 step c3 tmp$=lst$[tmp] print#1,tmp$ next close#1 tmp$=tmpfile$ tmpfile$=tmpfile2$ tmpfile2$=tmp$ dim dummy$[1]:dlglistboxarray 100,dummy$:call dlglistboxarray(100,lst$) end if 'tmpファイルを開いて処理する @@redraw=0 call @@openfile(tmpfile$) if cmd=2 then 'QXの基本機能 @blockselectall cmd$=lcase$(mid$(cmd$,instr(cmd$,"@"))) tmp$=mid$(cmd$,16) if cmd$="@blocktocapital."then @BlockToCapital if cmd$="@blocktosmall." then @BlockToSmall if cmd$="@blocktospace." then @BlockToSpace if cmd$="@blocktotab." then @BlockToTab if cmd$="@blocktokatakana."then @BlockToKatakana if cmd$="@blocktohiragana."then @BlockToHiragana if cmd$="@blocktohankaku."then @BlockToHankaku if cmd$="@blocktozenkaku."then @BlockToZenkaku if cmd$="@formatcenter." then @FormatCenter if cmd$="@formatright." then @FormatRight if cmd$="@formatleft." then @FormatLeft if cmd$="@deletecrline." then @DeleteCrLine if cmd$="@deletecrline2."then @DeleteCrLine2 if cmd$="@deletecr." then @DeleteCr if cmd$="@blocktozenhan."then @BlockToZenHan end if @BlockSelectAll m2=m1+@selectendline-1 @blockcopy @undo @fileclose @UndoBlock=1 @blockdelete @Blockpaste @line=m1 @blockselect @line=m2 @UndoBlock=0 @@redraw=1 rct++ r1[rct]=@selectstartline r2[rct]=@selectendline end if end if kill tmpfile$ kill tmpfile2$ for tmp=1 to 60 if lcase$(@@filehistory$(tmp))=lcase$(tmpfile$) then @@filehistorydelete tmp:tmp=61 next for tmp=1 to 60 if lcase$(@@filehistory$(tmp))=lcase$(tmpfile2$) then @@filehistorydelete tmp:tmp=61 next print"" dim s if info$="" then info$="処理が完了しました。" end if s=msgbox(info$+chr$(13)+"選択範囲に他のフィルタ処理を行いますか?",MB_YESNO,"確認") info$="" if s=IDNO then @select=0:ed=1 loop @UndoBlock=0 end proc '----------------------------- function replaceone$(a$,b$,c$) dim d$ if instr(a$,b$)<>0 then d$=ileft$(a$,b$):a$=icut$(a$,b$) a$=d$+c$+a$ end if replaceone$=a$ end function function replace$(a$,b$,c$) dim d$ do while a$<>"" if instr(a$,b$)<>0 then d$=d$+left$(a$,instr(a$,b$)-1)+c$ a$=mid$(a$,instr(a$,b$)+len(b$)) else d$=d$+a$ a$="" end if loop replace$=d$ end function function ileft$(a$,b$) dim c c=instr(a$,b$) if c=0 then a$=a$ else a$=left$(a$,c-1) end if ileft$=a$ end function function icut$(a$,b$) dim c c=instr(a$,b$) if c=0 then a$="" else a$=mid$(a$,c+len(b$)) end if icut$=a$ end function '------------------ '------------------ sub errmsg(a$) call msgbox(a$,0,"簡易フィルタ 2003/04/29版") end end sub #comment #comment