いかがでしょうか。うまくいったでしょうか。でも、問題が一つあります。NEWLINEがくる前に EOFがくると、その行は、コピーされません。
C:\Users\Hiroya\Documents\ratfor\fortran\exe>.\copy 12345 12345 abcdef^Z C:\Users\Hiroya\Documents\ratfor\fortran\exe>
これは、read文の仕様のようです。従って読み込み行の終わりには必ずNEWLINEがくる事として、 ロジックを考えていきます。また、行の書き出し中にNEWLINEの前にEOFが出現した場合、書き出し途中の 文字列を強制的に書き出すようにします。この変更をしたputc()は、下記のとおり。
c putc3.for (extended version 2)-- put sharacter on standard output subroutine putc(c) integer*1 c integer*1 buf(80) ! MAXCARD(80) integer i,lastc data lastc/0/ if ((c .eq. -1) .and. (lastc .eq. 0)) then ! EOF(-1) return ! buffer is empty endif if ((lastc .ge. 80) .or. (c .eq. 10) .or. (c .eq. -1)) then ! MAXCARD(80) NEWLINE(10) EOF(-1) write(6,100) (buf(i),i=1,lastc) 100 format(80a1) ! MAXCARD(80) lastc = 0 endif if (c .ne. 10) then ! NEWLINE(10) lastc = lastc + 1 buf(lastc) = c endif return end
コンパイルとライブラリーへの追加は下記のとおり。
C:\Users\Hiroya\Documents\ratfor\fortran\bat>fc putc3 Open Watcom FORTRAN 77/32 Optimizing Compiler Version 1.9 Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details. ..\src\putc3.for: 19 ステートメント, 129 バイト, 4 拡張メッセージ, 0 警告エラー, 0 エラー 1 個のファイルを移動しました。 C:\Users\Hiroya\Documents\ratfor\fortran\bat>cd ..\obj C:\Users\Hiroya\Documents\ratfor\fortran\obj>wlib ratfor -putc2 +putc3 Open Watcom Library Manager Version 1.9 Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details.
putc()が新しくなりましたので、copyを作成し直してください。
※コメントの受付件数を超えているため、この記事にコメントすることができません。