文字バッファの表現と文書行の管理
2016-03-06


文字バッファの表現と文書行の管理

編集するテキストは、バッファbuf()にしまい込む。この中には、行と行をリンクさせる 指標も含む。

     buf(k+0)   PREV 前の行の指標
     buf(k+4)   NEXT 次の行の指標
     buf(k+8)   MARK 広域指定の処理に使用
     buf(k+9)   TEXT 文字列の第一文字
     buf(k+10)  ...  第二文字・・・

このバッファを操作するルーチンをは、下記の通り。

     setbuf()  バッファを初期化して、第0行をだけを含む状態にする。
     clrbuf()  作業ファイルを捨てる。現状の版では、何もしない。
     inject(lin) linのテキストをバッファに転写する。
               curlinは、最後に送り込まれた行を指させる。
     getind(n) 行番号nをその行を占める指標に変換する。
     gettxt()  行の内容を共通領域ctxtのtxtに転写する。
     relink(k1,k2,k3,k4) 指標のつなぎ替えを行う。k2の逆方向の指標にk1をささせる。
               k3の順方向の指標にはk4を指させる。

文字バッファbufは共通領域cbufに置かれる。 共通領域cbufのRATFOR版は、以下の通り。

# cbuf.ri
      common /cbuf/buf,lastbf
      character buf(MAXBUF) # buffer for pointers plus text
      integer lastbf        # last element used in buf

WATCOM Fortran77版は以下の通り。

c cbuf.fi
      common /cbuf/buf,lastbf
      integer*1 buf(20000000) ! MAXBUF(20000000) buffer for pointers plus text
      integer lastbf          ! last element used in buf

文字バッファの文書は必要に応じてバッファtxtに転写される。 バッファtxtは共通領域ctxtに置かれる。 共通領域ctxtのRATFOR版は、以下の通り。

# ctxt.ri
      common /ctxt/txt
      character txt(MAXLINE) # text line for matching and output

WATCOM Fortran77版は以下の通り。

c ctxt.fi
      common /ctxt/txt
      integer*1 txt(81)               ! MAXLINE(81) text line for matching and output

setbuf()のRATFOR版は、以下の通り。

# setbuf.r4 (in memory) -- initialize line storage buffer
      subroutine setbuf
      logical addset,junk
      include cbuf.ri
      include clines.ri

      call relink(LINE0,LINE0,LINE0,LINE0)
      lastbf = LINE0 + TEXT
      junk = addset(EOF,buf,lastbf,MAXBUF)
      curln = 0
      lastln = 0
      return
      end

WATCOM Fortran77版は以下の通り。

c setbuf.f (in memory) -- initialize line storage buffer
      subroutine setbuf
      integer addset,junk

      include cbuf.fi
      include clines.fi

      call relink(1,1,1,1)              ! LINE0(1)
      lastbf = 1 + 12                   ! LINE0(1) TEXT(12)
      junk = addset(-2,buf,lastbf,20000000) ! EOS(-2) MAXBUF(20000000)
      curln = 0
      lastln = 0
      return
      end

clrbuf()のRATFOR版は、以下の通り。

# clrbuf.r4 -- initialize for new file
      subroutine clrbuf

      return # nothing to do
      end

WATCOM Fortran77版は以下の通り。

c clrbuf.for -- initialize for new file
      subroutine clrbuf
      return ! nothing to do
      end

getind()のRATFOR版は、以下の通り。getbufptr()は、バッファbufから、integerの 指標を取り出すためのルーチンである。

# getind.r4 -- locate line index in buffer
      integer function getind(line)
      integer line
      integer j,k,getbufptr

      include cbuf.fi

      k = LINE0
      for (j = 0; j < line; j = j + 1)
          k = getbufptr(buf(k+NEXT))
      getind = k
      return
      end

WATCOM Fortran77版は以下の通り。

c getind.f -- locate line index in buffer
      integer function getind(line)
      integer line
      integer j,k,getbufptr

      include cbuf.fi

      k = 1                    ! LINE0(1)
      j = 0
      while (j .lt. line) do
          k = getbufptr(buf(k+4)) ! NEXT(4)
          j = j + 1
      end while
      getind = k
      return
      end

getbufptr()のRATFOR版は、以下の通り。

# getbufptr.r4
      integer function getbufptr(buf)
      integer buf

      getbufptr = buf
      return
      end

WATCOM Fortran77版は以下の通り。

c getbufptr.for
      integer function getbufptr(buf)
      integer buf

      getbufptr = buf
      return
      end

inject()のRATFOR版は、以下の通り。



続きを読む

[コンピューター]

コメント(全50件)
※コメントの受付件数を超えているため、この記事にコメントすることができません。


記事を書く
powered by ASAHIネット