コマンドの処理 1 APPEND,DELETE
2016-03-14


コマンドの処理 1 APPEND,DELETE

個々のコマンドの処理は、コマンドごとの処理ルーチンで行う。 処理にあたって、行番号の省略値の設定を行うルーチンdefalt()を示す。

RATFOR版は、以下の通り。

# defalt.r4 -- set default line numbers
      integer function defalt(def1,def2,status)
      integer def1,def2,status

      include clines.ri

      status = EOF)
      if (nlines == 0) {
          line1 = def1
          line2 = def2
          }

      if (line1 > line2 | line1 <= 0)
          status = ERR
      else
          status = OK
      defalt = status
      return
      end

WATCOM Fortran77版は以下の通り。

c defalt.f -- set default line numbers
      integer function defalt(def1,def2,status)
      integer def1,def2,status

      include clines.fi

      status = -1                       ! EOF(-1)
      if (nlines .eq. 0) then
          line1 = def1
          line2 = def2
      end if

      if ((line1 .gt. line2) .or. (line1 .le. 0)) then
          status = -3                   ! ERR(-3)
      else
          status = -2                   ! OK(-2)
      end if
      defalt = status
      return
      end

doprnt()は、行を印刷する。このルーチンはコマンド処理ルーチンの中から頻繁に呼ばれる。

RATFOR版は、以下の通り。

# doprnt.r4 -- print lines from through to
      integer function doprnt(from,to)
      integer from,to

      integer gettxt
      integer i,junk

      include clines.ri
      include ctxt.ri

      if (from <= 0) then
          doprnt = ERR
      else
          for (i = from; i <= to; i = i + 1) {
              junk = gettxt(i)
              call putlin(txt,6)
              }
          curln = to
          doprnt = OK
      end if
      return
      end

WATCOM Fortran77版は以下の通り。

c doprnt.f -- print lines from through to
      integer function doprnt(from,to)
      integer from,to

      integer gettxt
      integer i,junk

      include clines.fi
      include ctxt.fi

      if (from .le. 0) then
          doprnt = -3 ! ERR(-3)
      else
          i = from
          while (i .le. to) do
              junk = gettxt(i)
              call putlin(txt,6)
              i = i + 1
          end while
          curln = to
          doprnt = -2 ! OK(-2)
      end if
      return
      end

行を追加するAPPENDコマンドを処理するappend()を示す。

RATFOR版は、以下の通り。

# append.r4 -- append lines after "line"
      integer function append(line,glob)
      integer line,glob
      character lin(MAXLINE)
      integer getlin,inject

      include clines.ri

      if (glob == YES)
          append = YES
      else {
          curln = line
          for (append = NOSTATUS; append == NOSTATUS; )
              if (getlin(lin,STDIN) == EOF)
                   append = EOF
              else if (lin(1) == PERIOD & lin(2) == NEWLINE)
                   append = OK
              else if (inject(lin) == ERR
                  append = ERR
          }
      return
      end

WATCOM Fortran77版は以下の通り。

c append.f -- append lines after "line"
      integer function append(line,glob)
      integer line,glob

      integer*1 lin(82)                 ! MAXLINE(82)
      integer*1 getlin
      integer inject

      include clines.fi

      if (glob .eq. 1) then             ! YES(1)
          append = -3                   ! ERR(-3)
      else
          curln = line
          append = 0                    ! NOSTATUS(0)
          while (append .eq. 0) do      ! NOSTATUS(0)
              if (getlin(lin,5) .eq. -1) then ! EOF(-1)
                   append = -1          ! EOF(-1)
              else if ((lin(1) .eq. 46) ! PERIOD(46 '.')
     1             .and. (lin(2) .eq. 10)) then  ! NEWLINE(10)
                   append = -2          ! OK(-2)
              else if (inject(lin) .eq. -3) then ! ERR(-3)
                  append = -3           ! ERR(-3)
              end if
          end while
      end if
      return
      end

行を削除するDELETEコマンドでは、削除の確認のために行を打ち出すp印を 付けることができる。これを処理するckp()を示す。

RATFOR版は、以下の通り。

# ckp.r4 -- check for "p" after command
      integer function ckp(lin,i,pflag,stats)
      character lin(MAXLINE)
      integer i,j,pflag,status

      j = i
      if (lin(j) == PRINT)
          j = j + 1
          pflag = YES
      else
          pflag = NO
      if (lin(j) == NEWLINE)
          status = OK
      else
          status = ERR
      ckp = status
      return
      end

WATCOM Fortran77版は以下の通り。



続きを読む

[コンピューター]
[RATFOR]

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


記事を書く
powered by ASAHIネット