文書整形 -- 指令の解読 ― 2016年10月04日 17:49
指令は行頭から始まるので、とりあえず一文字目がなんであるかで、 その行が指令なのか、其れ以外なのか判断できる。そこで、メインルーチンは、 とりあえず、下記のように書ける。
RATFORでは、
# xformat -- text formater main program program xformat character inbuf(INSIZE) character getlin include cpage.ri call initfile call init while (getlin(inbuf,STDIN) != EOF) if (inbuf(1) == COMMAND) call comand(inbuf) # it's a command else call text(inbuf) # it's a text stop end
WATCOM fortran 77では、
c xformat -- text formater main program program xformat integer*1 inbuf(82) ! INSIZE(82) integer*1 getlin include cpage.fi call initfile call init while (getlin(inbuf,5) .ne. -1) do ! STDIN(5) EOF(-1) if (inbuf(1) .eq. 46) then ! COMMAND('.',46) call comand(inbuf) ! it's a command else call text(inbuf) ! it's a text end if end while stop end
ここで,サブルーチンinitは、大域変数を初期化するルーチンである。
RATFORでは、以下の通り。
# init.r4 -- set initial value subroutine init include cparam.ri include cpage.ri include cout.ri # cparam fill = YES lsval = 1 inval = 0 rmval = PAGEWIDTH tival = 0 ceval = 0 ulval = 0 # cpage curpag = 0 newpag = 1 lineno = 0 plval = PAGELEN m1val = 4 m2val = 1 m3val = 4 m4val = 1 bottom = plval - m3val - m4val header(1) = EOS footer(1) = EOS # cout outp = 0 outw = 0 outwds = 0 outbuf(1) = EOS # return end
WATCOM fortran77では、以下の通り。
c init.f -- set initial value subroutine init include cparam.fi include cpage.fi include cout.fi c cparam fill = 1 ! YES(1) lsval = 1 inval = 0 rmval = 60 ! PAGEWIDTH(60) tival = 0 ceval = 0 ulval = 0 c cpage curpag = 0 newpag = 1 lineno = 0 plval = 66 ! PAGELEN(66) m1val = 4 m2val = 1 m3val = 4 m4val = 1 bottom = plval - m3val - m4val header(1) = -2 ! EOS(-2) footer(1) = -2 ! EOS(-2) c cout outp = 0 outw = 0 outwds = 0 outbuf(1) = -2 ! EOS(-2) c return end
最近のコメント