コマンドの処理 7 docmd()(再掲)とメインルーチンedit2016年08月01日 09:18

コマンドの処理 7 docmd()(再掲)とメインルーチンedit

行の複写指令を含めたdocmd()を以下に示す。docmd()は指令文字を一つ一つ 比較しながら分岐を行い、各指令の前提条件確認し、指令を実行する。

docmd()のRATFOR版は以下の通り。

# docmd.r4 -- handle all commands except globals
      integer function docmd(lin,i,glob,status)
      character lin(MAXLINE)
      integer i,glob,status

      integer append,doprnt,defalt,nextln,prevln,move,ckp,getone
      integer dodel,getrhs,subst,getfn,doread,dowrit
      integer line3
      character file(MAXLINE)
      integer pflag,gflag,optpat

      include clines.ri
      include cfile.ri
      include cpat.ri

      pflag = NO
      status = ERR
      if (lin(i) == APPENDCOM) {
          if (lin(i+1) == NEWLINE)
              status = append(line2,glob)
          }
      else if (lin(i) == CHANGE) {
          if (lin(i+1) == NEWLINE)
              if (defalt(curln,curln,status) == OK)
                  if (delete(line1,line2,status) == OK)
                      status = append(prevln(line1),glob)
          }
      else if (lin(i) == DELETE) {
          if (ckp(lin,i+1,pflag,status) == OK)
              if (defalt(curln,curln,status) == OK)
                  if (dodel(line1,line2,status) == OK)
                      if (nextln(curln) == 0)
                          curln = nextln(curln)
          }
      else if (lin(i) == INSERT) {
          if (lin(i+1) == NEWLINE)
              status = append(prevln(line2),glob)
          }
      else if (lin(i) == PRINTCUR) {
          if (ckp(lin,i+1,pflag,status) == OK) {
              call putdec(line2,1)
              call putc(NEWLINE)
              }
          }
      else if (lin(i) == COPYCMD) {
          i = i + 1
          if (getone(lin,i,line3,status) == EOF)
              status = ERR
          if (status == OK)
              if (ckp(lin,i,pflag,status) == OK)
                  if (defalt(curln,curln,status) == OK)
                      status = kopy(line3)
          }
      else if (lin(i) == MOVECOM) {
          i = i + 1
          if (getone(lin,i,line3,status) == EOF)
              status = ERR
          if (status == OK)
              if (ckp(lin,i,pflag,status) == OK)
                  if (defalt(curln,curln,status) ==OK)
                      status = move(line3)
          }
      else if (lin(i) == SUBSTITUTE) {
          i = i + 1
          if (optpat(lin,i) == OK)
              if (getrhs(lin,i,sub,gflag) == OK)
                  if (ckp(lin,i+1,pflag,status) == OK)
                      if (defalt(curln,curln,status) == OK)
                          status = subst(sub,gflag)
          }
      else if (lin(i) == ENTER) {
          if (nlines == 0) then
              if (getfn(lin,i,file) == OK) {
                  call scopy(file,1,savfil,1)
                  call clrbuf
                  call setbuf
                  status = doread(0,file)
              }
          }
      else if (lin(i) == PRINTFIL) {
          if (nlines == 0)
              if (getfn(lin,i,file) == OK) {
                  call scopy(file,1,savfil,1)
                  call putlin(savfil,STDOUT)
                  call putc(NEWLINE)
                  status = OK
              }
          }
      else if (lin(i) == READCOM) {
          if (getfn(lin,i,file) == OK)
              status = doread(line2,file)
          }
      else if (lin(i) ==WRITECOM) {
          if (getfn(lin,i,file) == OK)
              if (defalt(1,lastln,status) == OK)
                  status = dowrit(line1,line2,file)
              end if
          }
      else if (lin(i) == PRINT) {
          if (lin(i+1) == NEWLINE)
              if (defalt(curln,curln,status) == OK)
                  status = doprnt(line1,line2)
          }
      else if (lin(i) == QUIT) {
          if (lin(i+1) == NEWLINE & nlines == 0 & glob == NO)
              status = EOF
          }
      # else status is ERR
      end if

      if (status == OK & pflag == YES)
          status = doprnt(curln,curln)
      docmd = status
      return
      end

WATCOM fortran77版は以下の通り。

c docmd.f -- handle all commands except globals
      integer function docmd(lin,i,glob,status)
      integer*1 lin(82)                 ! MAXLINE(82)
      integer i,glob,status

      integer append,doprnt,defalt,nextln,prevln,move,ckp,getone
      integer delcmd,getrhs,subst,getfn,doread,dowrit
      integer line3,pflag,gflag,optpat
      integer*1 file(82),sub(82)        ! MAXLINE(82) MAXPAT(82)

      include clines.fi
      include cfile.fi
      include cpat.fi

      pflag = 0                         ! NO(0)
      status = -3                       ! ERR(-3)
      if (lin(i) .eq. 97) then          ! APPENDCOM(97 'a')
          if (lin(i+1) .eq. 10) then    ! NEWLINE(10)
              status = append(line2,glob)
          end if
      else if (lin(i) .eq. 99) then     ! CHANGE(99,'c')
          if (lin(i+1) .eq. 10) then    ! NEWLINE(10)
              if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                  if (delete(line1,line2,status) .eq. -2) then ! OK(-2)
                      status = append(prevln(line1),glob)
                  end if
              end if
          end if
      else if (lin(i) .eq. 107) then    ! COPYCMD(107, 'k')
          i = i + 1
          if (getone(lin,i,line3,status) .eq. -1) then ! EOF(-1)
              call putdec(line3,1)
              call putc(10)
              status = -3               ! ERR(-3)
          end if 
          if (status .eq. -2) then           ! OK(-2)
              if (ckp(lin,i,pflag,status) .eq. -2) then ! OK(-2)
                  if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                      status = kopy(line3)
                  end if
              end if
          end if
      else if (lin(i) .eq. 100) then    ! DELETE(100,'d')
          if (ckp(lin,i+1,pflag,status) .eq. -2) then ! OK(-2)
              if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                  if (delcmd(line1,line2,status) .eq. -2) then ! OK(-2)
                      if (nextln(curln) .ne. 0) then
                          curln = nextln(curln)
                      end if
                   end if
              end if
          end if
      else if (lin(i) .eq. 105) then    ! INSERT(105,'i')
          if (lin(i+1) .eq. 10) then    ! NEWLINE(10)
              status = append(prevln(line2),glob)
          end if
      else if (lin(i) .eq. 61) then     ! PRINTCUR(61,'=')
          if (ckp(lin,i+1,pflag,status) .eq. -2) then ! OK(-2)
              call putdec(line2,1)
              call putc(10)             ! NEWLINE(10)
          end if
      else if (lin(i) .eq. 109) then    ! MOVECOM(109,'m')
          i = i + 1
          if (getone(lin,i,line3,status) .eq. -1) then ! EOF(-1)
              status = -3               ! ERR(-3)
          end if
          if (status .eq. -2) then      ! OK(-2)
              if (ckp(lin,i,pflag,status) .eq. -2) then ! OK(-2)
                  if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                      status = move(line3)
                  end if
              end if
          end if
      else if (lin(i) .eq. 115) then    ! SUBSTITUTE(115,'s')
          i = i + 1
          if (optpat(lin,i)) then
              if (getrhs(lin,i,sub,gflag) .eq. -2) then ! OK(-2)
                  if (ckp(lin,i+1,pflag,status) .eq. -2) then ! OK(-2)
                      if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                          status = subst(sub,gflag)
                      end if
                  end if
              end if
          end if
      else if (lin(i) .eq. 101) then    ! ENTER(101,'e')
          if (nlines .eq. 0) then
              if (getfn(lin,i,file) .eq. -2) then ! OK(-2)
                  call scopy(file,1,savfil,1)
                  call clrbuf
                  call setbuf
                  status = doread(0,file)
              end if
          end if
      else if (lin(i) .eq. 102) then    ! PRINTFIL(102,'f')
          if (nlines .eq. 0) then
              if (getfn(lin,i,file) .eq. -2) then ! OK(-2)
                  call scopy(file,1,savfil,1)
                  call putlin(savfil,6) ! STDOUT(6)
                  call putc(10)         ! NEWLINE(10)
                  status = -2           ! OK(-2)
              end if
          end if
      else if (lin(i) .eq. 114) then    ! READCOM(114,'r')
          if (getfn(lin,i,file) .eq. -2) then ! OK(-2)
              status = doread(line2,file)
          end if
      else if (lin(i) .eq. 119) then    ! WRITECOM(119'w')
          if (getfn(lin,i,file) .eq. -2) then ! OK(-2)
              if (defalt(1,lastln,status) .eq. -2) then
                  status = dowrit(line1,line2,file)
              end if
          end if
      else if (lin(i) .eq. 112) then    ! PRINT(112 'p')
          if (lin(i+1) .eq. 10) then    ! NEWLINE(10)
              if (defalt(curln,curln,status) .eq. -2) then ! OK(-2)
                  status = doprnt(line1,line2)
              end if 
          end if
      else if (lin(i) .eq. 113) then    ! QUIT(113 'q')
          if ((lin(i+1) .eq. 10) .and.  ! NEWLINE(10)
     1       (nlines .eq. 0) .and. (glob .eq. 0)) then ! NO(0)
              status = -1               ! EOF(-1)
          end if
      ! else status is ERR
      end if

      if ((status .eq. -2) .and. (pflag .eq. 1)) then ! OK(-2) YES(1)
          status = doprnt(curln,curln)
      end if
      docmd = status
      return
      end
メインルーチンeidtは、標準入力から指令を読み取り、前処理を行い、問題がなければ、 docmd()を呼び出す。

editのRATFOR版は以下の通り。

# edit.r4 (in memory) -- text editor
      program edit
      integer*1 getlin,lin(MAXLINE)
      integer getlst,doglob,docmd,ckglob,doread
      integer i,status,cursav
      integer getarg

      include cfile.fi
      include clines.fi
      include cpat.fi

      call initfile
      call setbuf

      pat(1) = EOS
      status = ERR

      if (getarg(1,savfil,MAXLINE != EOF)
          if (doread(0,savfil) == ERR)
              call remark('?.')

      while (getlin(lin,STDIN) != EOF) {
          i = 1
          cursav = curln
          if (getlst(lin,i,status) == OK)
              if (ckglob(lin,i,status) == OK)
                  status = doglob(lin,i,cursav,status)
              else if (status != ERR)
                  status = docmd(lin,i,NO,status)
              ! else error, do nothing

          if (status == ERR) {
               call remark('?.')
               curln = cursav
               }
          else if (status == EOF)
               break
          ! else OK, loop
          }
      call clrbuf

      stop
      end

WATCOM fortran77版は以下の通り。

c edit.f (in memory) -- text editor
      program edit
      integer*1 getlin,lin(82)          ! MAXLINE(82)
      integer getlst,doglob,docmd,ckglob,doread
      integer i,status,cursav
      integer getarg

      include cfile.fi
      include clines.fi
      include cpat.fi

      call initfile
      call setbuf

      pat(1) = -2                       ! EOS(-2)
      status = -3                       ! ERR(-3)

      if (getarg(1,savfil,82) .ne. -1) then  ! MAXLINE(82) EOF(-1)
          if (doread(0,savfil) .eq. -3) then ! ERR(-3)
              call remark('?.')
          end if
      end if

      while (getlin(lin,5) .ne. -1) do  ! STDIN(5) EOF(-1)
          i = 1
          cursav = curln
          if (getlst(lin,i,status) .eq. -2) then       ! OK(-2)
              if (ckglob(lin,i,status) .eq. -2) then   ! OK(-2)
                  status = doglob(lin,i,cursav,status)
              else if (status .ne. -3) then            ! ERR(-3)
                  status = docmd(lin,i,0,status)       ! NO(0)
              ! else error, do nothing
              end if
          end if
          if (status .eq. -3) then      ! ERR(-3)
               call remark('?.')
               curln = cursav
          else if (status .eq. -1) then ! EOF(-1)
               exit
          ! else OK, loop
          end if
      end while
      call clrbuf

      stop
      end

コメント

_ plenty of fish dating site of free dating ― 2016年09月08日 00:31

Amazing things here. I am very satisfied to look your article.

Thanks a lot and I am having a look ahead to contact you.

Will you kindly drop me a mail?

_ quest bars ― 2016年09月09日 08:38

My spouse and I stumbled over here coming from a different web address and thought I may
as well check things out. I like what I see so now i'm following you.
Look forward to looking at your web page for a second time.

_ plenty of fish dating site of free dating ― 2016年09月10日 18:11

Please let me know if you're looking for a article author for your weblog.
You have some really great posts and I feel I would be a good asset.
If you ever want to take some of the load off, I'd really like to write some articles for your
blog in exchange for a link back to mine.

Please blast me an e-mail if interested. Cheers!

_ plenty of fish dating site of free dating ― 2016年09月11日 12:57

Hello there, You've done an excellent job. I will definitely digg it and personally suggest
to my friends. I'm sure they will be benefited from this site.

_ Windows 10 Free Upgrade ― 2016年09月14日 08:16

When someone writes an post he/she keeps the image
of a user in his/her brain that how a user can know it.

Therefore that's why this piece of writing is great. Thanks!

_ Height boosting insoles ― 2016年09月14日 21:05

I blog often and I really thаnk you forr your information.
The article haѕ truly peaked my inteгest.
I'm going to take a note of your ѕite and keep cheсkinmg for new dɗеtails
abоut once pᥱr week. I oрted in forr your RSS feed toо.

_ Windows 10 Free Upgrade ― 2016年09月16日 18:52

I know this if off topic but I'm looking into starting my own weblog and
was wondering what all is required to get setup? I'm assuming having a blog like yours would cost a pretty penny?

I'm not very web smart so I'm not 100% sure. Any tips or advice would be greatly
appreciated. Cheers

_ quest bars ― 2016年09月24日 13:16

Hi, I think your blog might be having browser compatibility issues.
When I look at your blog in Opera, it looks fine but when opening
in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads
up! Other then that, amazing blog!

_ quest bars ― 2016年09月25日 12:42

I'm truly enjoying the design and layout of your
site. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often.
Did you hire out a designer to create your theme? Superb work!

_ minecraft sweet and unblocked ― 2016年10月01日 15:39

This is a great tip particularly to those new to the blogosphere.

Simple but very precise information… Appreciate your sharing this one.
A must read article!

_ sweet awesome minecraft ― 2016年10月03日 23:14

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more enjoyable for me
to come here and visit more often. Did you hire out a designer to create your theme?
Superb work!

_ plenty of fish dating site of free dating ― 2016年10月04日 21:55

Hiya! Quick question that's totally off topic. Do you know how to make your site mobile friendly?

My site looks weird when browsing from my iphone 4.
I'm trying to find a template or plugin that might be able to resolve this issue.
If you have any recommendations, please share.
Appreciate it!

_ quest bars ― 2016年10月05日 19:39

This is a very good tip especially to those new to the blogosphere.
Simple but very precise information… Many thanks for sharing this one.
A must read post!

_ quest bars ― 2016年10月06日 08:54

I blog quite often and I genuinely appreciate your content.

Your article has really peaked my interest.
I am going to bookmark your blog and keep checking for new information about once per
week. I opted in for your RSS feed as well.

_ como descargar minecraft ― 2016年10月09日 04:33

You could definitely see your skills within the work you write.

The arena hopes for even more passionate writers like you who are not afraid to mention how
they believe. Always go after your heart.

_ como descargar minecraft pocket edition ― 2016年10月12日 00:52

Very quickly this site will be famous among all blogging
and site-building visitors, due to it's nice articles

_ minecraft ― 2016年10月12日 01:22

I do not even know the way I ended up right here,
but I believed this publish used to be great. I don't recognise who
you are however definitely you're going to a well-known blogger
should you are not already. Cheers!

_ minecraft ― 2016年10月12日 22:39

My brother recommended I might like this web site.
He was totally right. This post actually made my day.
You can not imagine just how much time I had spent for this info!
Thanks!

_ minecraft ― 2016年10月13日 20:33

Can you tell us more about this? I'd want to find out some additional information.

_ minecraft ― 2016年10月14日 14:03

Howdy! This is my first visit to your blog! We are a team of volunteers and starting a
new project in a community in the same niche. Your blog provided us useful information to work on. You have
done a extraordinary job!

_ gamefly 3 month free trial ― 2016年11月15日 16:01

Wonderful, what a webpage it is! This webpage provides valuable information to us,
keep it up. Gamefly 3 month free trial

_ gamefly 3 month free trial ― 2016年11月16日 00:47

Hi there, yup this paragraph is in fact fastidious and I have learned lot of things from
it about blogging. thanks. Gamefly 3 month free trial

_ where can i buy cheap quest bars ― 2016年11月20日 03:06

Fine way of telling, and fastidious article to
take information on the topic of my presentation subject
matter, which i am going to convey in school.

_ http://tinyurl.com/jnf8mgx ― 2016年12月01日 18:34

Hi, Neat post. There is an issue along with your site in web explorer, might test this?
IE still is the market leader and a good element of other folks will pass over
your wonderful writing due to this problem.

_ http://tinyurl.com/hksozee ― 2016年12月02日 00:50

Thanks very nice blog!

_ free dating sites no fees ― 2016年12月10日 16:26

Excellent site you have here but I was wondering if you knew of any
community forums that cover the same topics discussed in this article?
I'd really like to be a part of online community where I can get suggestions from other experienced people that
share the same interest. If you have any recommendations, please let me know.

Thank you!

_ Gamefly Free Trial ― 2016年12月18日 11:00

You have made some really good points there.

I looked on the internet to find out more about the issue and found most individuals will
go along with your views on this site.

_ Gamefly Free Trial ― 2016年12月18日 14:50

I visited several sites except the audio feature for audio songs current at this web
site is actually excellent.

_ Gamefly Free Trial ― 2016年12月19日 00:40

Good post. I learn something new and challenging on sites I stumbleupon every day.

It's always helpful to read content from other
writers and practice something from other sites.

_ Gamefly ― 2016年12月20日 06:00

Hello, i feel that i noticed you visited my site thus i got here to return the desire?.I am attempting to find issues to enhance my website!I assume its ok to make use of some of
your ideas!!

_ www.krogerfeedback.com ― 2016年12月24日 16:43

Hello there! I could have sworn I've visited your blog before
but after looking at a few of the posts I realized
it's new to me. Anyways, I'm certainly delighted I came across it
and I'll be book-marking it and checking back frequently!

_ www.krogerfeedback.com ― 2016年12月24日 20:29

For most recent news you have to visit world wide web and on world-wide-web I found this site as
a finest site for hottest updates.

_ www.krogerfeedback.com ― 2016年12月25日 04:47

Wow, incredible blog layout! How long have you
been blogging for? you make blogging look easy.
The overall look of your site is magnificent, as well as the content!

_ www.krogerfeedback.com ― 2016年12月25日 16:27

Fantastic website. Lots of useful info here. I am sending it to several buddies ans additionally sharing in delicious.

And certainly, thanks in your effort!

_ www.krogerfeedback.com ― 2016年12月26日 02:39

Nice answers in return of this issue with genuine arguments and describing all on the topic of that.

_ www.krogerfeedback.com ― 2016年12月26日 02:40

Pretty great post. I just stumbled upon your weblog and wanted
to say that I've truly loved browsing your weblog posts.
In any case I will be subscribing on your rss feed
and I'm hoping you write once more soon!

_ www.krogerfeedback.com ― 2016年12月26日 03:37

I'm impressed, I must say. Seldom do I encounter a blog that's equally educative and entertaining,
and let me tell you, you've hit the nail on the head.
The problem is an issue that not enough men and women are speaking
intelligently about. Now i'm very happy I stumbled across this in my hunt for
something regarding this.

_ plenty of fish dating site of free dating ― 2016年12月27日 22:21

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You obviously know what youre talking about, why throw away your intelligence on just posting videos to your site when you could be giving us something informative to read?

_ free dating sites no fees ― 2017年01月06日 06:26

I am regular reader, how are you everybody? This paragraph posted at this
website is truly pleasant.

_ free dating sites no fees ― 2017年01月06日 16:37

Truly no matter if someone doesn't know after that its up to other people that
they will assist, so here it takes place.

_ free dating sites no fees ― 2017年01月07日 03:00

Hello, its nice paragraph regarding media print, we all be
familiar with media is a fantastic source of data.

_ free dating sites for seniors ― 2017年01月07日 23:07

Hello! Quick question that's completely off topic. Do you
know how to make your site mobile friendly? My blog looks weird when browsing
from my apple iphone. I'm trying to find a theme or plugin that might be able to correct this issue.
If you have any recommendations, please share. Thanks!

_ free dating sites online ― 2017年01月08日 17:26

Hello excellent website! Does running a blog like this require
a massive amount work? I have no expertise in coding however I was hoping to start my own blog in the near future.

Anyways, should you have any recommendations or techniques
for new blog owners please share. I know this is off subject however I simply wanted to ask.
Thank you!

_ quest bars sale australia ― 2017年01月10日 08:21

Hello! I've been reading your weblog for some time
now and finally got the courage to go ahead
and give you a shout out from Huffman Tx! Just wanted to tell you
keep up the excellent work!

_ gamefly free trial ― 2017年01月10日 18:30

I constantly spent my half an hour to read this website's posts every day along with a cup of coffee.

_ gamefly ― 2017年01月11日 13:10

I really love your website.. Excellent colors & theme.

Did you develop this site yourself? Please reply back as I'm hoping to create my own personal website
and would like to find out where you got this from or exactly
what the theme is named. Appreciate it!

_ www.krogerfeedback.com ― 2017年01月12日 12:27

What's up, for all time i used to check web site posts here in the early hours
in the morning, for the reason that i love to find out more and more.

_ www.krogerfeedback.com ― 2017年01月13日 08:21

If you are going for best contents like I do, just go to see
this website everyday since it offers feature contents, thanks

_ www.krogerfeedback.com ― 2017年01月14日 03:06

Very nice post. I simply stumbled upon your weblog and wished to say that I have truly loved surfing
around your blog posts. After all I will be subscribing in your feed and I
hope you write once more very soon!

_ www.krogerfeedback.com ― 2017年01月14日 17:28

Howdy this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding expertise
so I wanted to get guidance from someone with experience.
Any help would be enormously appreciated!

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2016/08/01/8143915/tb