Forums: users (Thread #6063)

改行コード (2004-09-28 18:23 by Anonymous #11208)

Windows で --pipe --insert-flag をつけて使う場合、
元のファイルが改行 LF (UNIX) 形式であっても、
出力は改行 CRLF (DOS) 形式になってしまいます。

とりあえず以下のパッチを当てて、
ファイル入出力をすべてバイナリモードにするようにして
逃げていますが、何かいい方法はないでしょうか?

--- bsfilter.org Wed May 05 16:42:28 2004
+++ bsfilter Tue Jul 20 11:29:07 2004
@@ -263,6 +263,7 @@

def open_ro(file)
if (file == "-")
+ STDIN::binmode
fh = STDIN
yield fh
elsif (file.class == Array)
@@ -290,7 +291,7 @@
if (! FileTest::file?(file))
raise sprintf("%s is not file", file)
end
- fh = open(file)
+ fh = open(file, "rb")
yield fh
fh.close
end
@@ -298,9 +299,10 @@

def open_wo(file, &block)
if (file == "-")
+ STDOUT::binmode
fh = STDOUT
else
- fh = open(file, "w")
+ fh = open(file, "wb")
end
if (block)
yield fh
@@ -2110,6 +2112,7 @@
dbs.push(db)
if (Options["pipe"])
insert_headers!(buf, (Options["add-spam"] || Options["sub-clean"]), nil)
+ STDOUT::binmode
print buf
end
update_token_db_one(db)
@@ -3056,6 +3059,7 @@
DB[token_db.language].get_combined_probability(token_db)
insert_headers!(buf, token_db.spam_flag, token_db.probability)
if (Options["pipe"])
+ STDOUT::binmode
print buf
end
printf("%s\n", file) if (token_db.spam_flag && Options["list-spam"])

Reply to #11208×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 改行コード (2004-09-28 20:13 by a39 #11211)

メイルクライアントによって,改行コードがCR(MacOS)/CRLF(DOS/Windows)/LF(UNIX)と違うと思います.
オプショナルに選択できる実装の方が良いように思います.

Reply to #11208

Reply to #11211×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 改行コード (2004-09-28 20:46 by Anonymous #11213)

先のパッチのように、
入出力ともにバイナリモードにしておけば、
元ファイルの改行コードが何であろうと、
そのまま維持されて出力されると思うのですが、
どうでしょうか?
Reply to #11208

Reply to #11213×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 改行コード (2004-09-28 21:22 by a39 #11215)

追加されるheader(X-Spam-Flag:, X-Spam-Probability:)の末尾の改行コードは大丈夫でしょうか.
Rubyではbinary modeだと自動的にCR/CRLF/LFを使い分けてくれるのですか?
Reply to #11213

Reply to #11215×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 改行コード (2004-09-29 22:53 by nabeken #11231)

Windows上ではcygwinのrubyを使っていたため、
この現象に気付いていませんでした。
近日中にデバッグします。
入力ファイルの改行コードで出力する、というのが仕様です。
Reply to #11208

Reply to #11231×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login