compare -- ファイルの比較2015年03月01日 09:52

ファイルの入出力ができたので、ファイルを使った小さいプログラムの紹介をします。

まずは、compareです。

     compare file1 file2

file1とfile2を比較して、違っていたら表示します。まずは、RATFOR版から、

# compare2.r4 -- compare two files for equality
      character arg1(MAXLINE), arg2(MAXLINE)
      character line1(MAXLINE), line2(MAXLINE)
      integer getarg, equal, fopen, getlin
      integer infil1, infil2, lineno, m1, m2

      if (getarg(1, arg1, MAXLINE) == EOF
          | getarg(2, arg2, MAXLINE) == EOF) then
          call error('usage: compare file1 file2.')
      if (fopen(infil1, arg1, READ) == ERR)
          call cant(arg1)
      if (fopen(infil2, arg2, READ) == ERR)
          call cant(arg2)
      lineno = 0
      repeat {
          m1 = getlin(line1, infil1)
          m2 = getlin(line2, infil2)
          if ((m1 == EOF) | (m2 == EOF))
              break
          lineno = lineno + 1
          if (equal(line1,line2) == NO)
              call difmsg(lineno,line1,line2)
          }
      if (m1 == EOF & m2 != EOF)
          call remark('eof on file 1.')
      else if (m1 != EOF & m2 == EOF)
          call remark('eof on file 2.')
      stop
      end

まずは、引数を検査し入力ファイルをオープンします。次に、それぞれ1行ずつ読み込みながら 、逐次、比較し差違があれば、出力します。Watcom Fortran77版は、下記の通り。

c compare2.for -- compare two files for equality
      program compare
      integer*1 arg1(82), arg2(82)      ! MAXLINE(82)
      integer*1 line1(82), line2(82)    ! MAXLINE(82)
      integer getarg, equal, fopen , getlin
      integer infil1, infil2, lineno, m1, m2

      call initfile()

      if (getarg(1,arg1,82) .eq. -1) then ! MAXLINE(82) EOF(-1)
          call error('1:usage: compare2 file1 file2.')
      else if (getarg(2,arg2,82) .eq. -1) then ! MAXLINE(82) EOF(-1)
          call error('2:usage: compare2 file1 file2.')
      end if

      if (fopen(infil1,arg1,82) .ne. 1) then ! READ(82) YES(1)
          call cant(arg1)
      end if
      if (fopen(infil2,arg2,82) .ne. 1) then ! READ(82) YES(1)
          call cant(arg2)
      end if

      lineno = 0
      loop
          m1 = getlin(line1,infil1)
          m2 = getlin(line2,infil2)
          if ((m1 .eq. -1) .or. (m2 .eq. -1)) then ! EOF(-1)
              exit
          end if
          lineno = lineno + 1
          if (equal(line1,line2) .ne. 1) then ! YES(1)
              call difmsg(lineno,line1,line2)
          end if
      end loop

      if ((m1 .eq. -1) .and. (m2 .ne. -1)) then
          call remark('eof on file 1.')
      else if ((m1 .ne. -1) .and. (m2 .eq. -1)) then
          call remark('eof on file 2.')
      end if

      call fclose(infil1)
      call fclose(infil2)
      stop
      end

ファイルは、getlin()を使って行単位で、読み込みます。fgetc()を使って下記のようになります。

c getlin.for -- get line from infile

      integer function getlin(line,u)
      integer*1 line(*)
      integer u
      integer*1 c,fgetc
      integer col

      col = 1
      while (fgetc(u,c) .ne. -1) do ! EOF(-1)
          line(col) = c
          col = col + 1
          if (c .eq. 10) then           ! NEWLINE(10)
              line(col) = -2            ! EOS(-2)
              getlin = col - 1
              return
          end if
      end while
      getlin = -1                       ! EOF(-1)
      return
      end

実際の比較は、equal()を使います。RATFOR版は下記の通り。

# equal.r4 -- compare str1 to str2; return YES if equal, NO if not
      integer function equal(str1,str2)
      character str1(ARB), str2(ARB)
      integer i
      
      for (i = 1; str1(i) == str2(i); i = i + 1)
          if (str1(i) .eq. EOS) {
              equal = YES
              return
              }
      equal = NO
      return
      end

Watcom Fortran77版は下記の通り。

c equal.for -- compare str1 to str2; return YES(1) if equal, NO(0) if not
      integer function equal(str1,str2)
      integer*1 str1(*),str2(*)
      integer i
      
      i = 1
      while (str1(i) .eq. str2(i)) do
          if (str1(i) .eq. -2) then     ! EOS(-2)
              equal = 1                 ! YES(1)
              return
          end if
          i = i + 1
      end while
      equal = 0                         ! NO(0)
      return
      end

さて、差違のある行の打ち出しはdifmsg()を使います。RATFOR版は下記の通り。

# difmsg.r4 -- print line numbers and differing lines
      subroutine difmsg(lineno, line1, line2)
      integer lineno
      character line1(ARB), line2(ARB)
      
      call putdec(lineno, 5)
      call putc(NEWLINE)
      call putlin(line1, STDOUT)
      call putlin(line2, STDOUT)
      return
      end

Watcom Fortran77版は下記の通り。

c difmsg.for -- print line numbers and differing lines
      subroutine difmsg(lineno, line1, line2)
      integer lineno
      integer*1 line1(*), line2(*)      ! ARB(*) ARB(*)
      
      call putdec(lineno, 5)
      call putc(10)                     ! NEWLINE(10)
      call putlin(line1, 6)             ! STDOUT(6)
      call putlin(line2, 6)             ! STDOUT(6)
      return
      end

行単位の出力は、putlin()を使います。これは、fputc()を使って、下記のようになります。

c putlin.for -- put lin to u
      subroutine putlin(lin,u)
      integer*1 lin(*)                 ! ARB(*)
      integer u,i

      i = 1
      while (lin(i) .ne. -2) do        ! EOS(-2)
          call fputc(u, lin(i))
          i = i + 1
      end while
      return
      end

コメント

_ Plenty Of Fish Sex ― 2015年10月18日 10:28

I could not resist commenting. Exceptionally well written!

_ cookies and cream quest bar ingredients ― 2015年10月19日 02:57

I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz reply as I'm looking to create my own blog and would like to find out where u got this from. kudos

_ free match search ― 2015年10月23日 10:37

I need to to thank you for this good read!! I absolutely enjoyed every bit of it. I have you book-marked to look at new stuff you post�

_ quest bar gluten free ― 2015年10月29日 06:22

Admiring the commitment you put into your website and in depth
information you present. It's good to come across a blog every
once in a while that isn't the same old rehashed information. Fantastic read!

I've saved your site and I'm including your RSS feeds to
my Google account.

_ plenty of fish dating site of free dating ― 2015年11月06日 06:08

This paragraph will assist the internet visitors for creating new weblog or even a blog from start to end.

_ plenty of fish dating site of free dating ― 2015年11月06日 19:47

Hey there! Do you use Twitter? I'd like to follow you if that would be okay.
I'm absolutely enjoying your blog and look forward to new updates.

_ plenty of fish dating site of free dating ― 2015年11月07日 11:03

Excellent beat ! I wish to apprentice even as you amend your site, how could i subscribe for
a blog site? The account helped me a acceptable deal.
I were tiny bit acquainted of this your broadcast provided bright
transparent idea

_ www.kroger.com digital coupons ― 2015年11月12日 10:57

I savour, cause I found exactly what I used to be having a
look for. You've ended my four day long hunt!
God Bless you man. Have a great day. Bye

_ www.krogerfeedback.com ― 2015年11月12日 15:57

Remarkable issues here. I'm very satisfied to see your article.

Thanks so much and I'm having a look ahead to touch you.
Will you kindly drop me a e-mail?

_ kroger digital coupons 2x fuel points ― 2015年11月17日 04:03

Please let me know if you're looking for a writer for your site.
You have some really good posts and I feel I would be a good asset.
If you ever want to take some of the load off, I'd absolutely love to write some content for your
blog in exchange for a link back to mine. Please blast me
an e-mail if interested. Thanks!

_ Www.Krogerfeedback.com ― 2015年12月09日 05:58

I every time used to read post in news papers but now as I am a user of internet therefore
from now I am using net for articles, thanks to web.

_ krogerfeedback.com ― 2015年12月10日 13:08

I was recommended this web site through my cousin. I'm not certain whether this put up is written through
him as nobody else know such distinctive about my difficulty.
You're amazing! Thanks!

_ quest bars ― 2016年02月09日 05:46

Good day! I could have sworn I've visited this web site before but after going through a few of the articles
I realized it's new to me. Anyhow, I'm certainly pleased I discovered it and I'll be bookmarking it and checking back often!

_ quest bars ― 2016年02月20日 00:56

Heya i'm for the first time here. I found this board and
I in finding It truly useful & it helped me out much.
I hope to present something again and aid others
such as you aided me.

_ bernie sanders ― 2016年03月31日 20:46

An impressive share! I have just forwarded this onto a friend who has been doing a little research on this.
And he in fact bought me dinner because I found it for him...
lol. So let me reword this.... Thank YOU for the meal!!
But yeah, thanks for spending the time to talk about this issue here on your internet site.

_ Bernie Sanders ― 2016年04月01日 21:25

Hey there! Do you know if they make any plugins to assist with Search Engine Optimization? I'm
trying to get my blog to rank for some targeted keywords but I'm
not seeing very good results. If you know of any please share.
Appreciate it!

_ tinder dating site ― 2017年02月25日 22:28

Hi, its fastidious paragraph regarding media print, we all be aware of media is a great
source of facts.

_ tinder dating site ― 2017年02月26日 07:18

I’m not that much of a online reader to be honest but your sites really nice, keep it up!
I'll go ahead and bookmark your website to come back later on.
Cheers

_ tinder dating site ― 2017年02月27日 12:58

Thanks for another informative site. Where else may I am getting that type of info written in such an ideal means?

I have a challenge that I'm simply now running on, and I've been on the look
out for such information.

_ tinder dating site ― 2017年02月27日 18:25

It's actually a great and useful piece of information. I am glad that
you simply shared this useful info with us. Please keep us up to date like this.
Thanks for sharing.

_ tinder dating site app ― 2017年02月28日 21:51

Today, while I was at work, my cousin stole my iPad and tested to see
if it can survive a 40 foot drop, just so she can be a youtube sensation. My iPad
is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone!

_ tinder dating site ― 2017年03月02日 08:55

Hi! I've been following your weblog for a long time
now and finally got the bravery to go ahead and give you a shout out from New
Caney Tx! Just wanted to tell you keep up the great job!

_ minecraft ― 2017年03月03日 01:08

Someone necessarily lend a hand to make seriously posts I would state.
This is the very first time I frequented your web page and to this point?
I surprised with the research you made to create
this actual submit extraordinary. Excellent activity!

_ tinder dating site ― 2017年03月05日 00:06

Fantastic beat ! I wish to apprentice while you amend your
site, how could i subscribe for a blog web site? The account
aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept

_ Dating Santa Clarita California ― 2017年03月09日 00:48

Since the admin of this site is working, no uncertainty very shortly it will be
famous, due to its quality contents.

_ manicure ― 2017年03月09日 14:08

Woah! I'm really loving the template/theme of this blog.
It's simple, yet effective. A lot of times it's very difficult
to get that "perfect balance" between usability and appearance.
I must say you have done a excellent job with this.
Also, the blog loads super quick for me on Chrome. Exceptional Blog!

_ http://chinohills.mrdrain.com ― 2017年03月09日 22:13

I love it when people come together and share opinions.

Great site, continue the good work!

_ tinyurl.com ― 2017年03月10日 21:44

Heya i'm for the first time here. I came across this board and I find It
really useful & it helped me out much. I hope to give something back and help others like you helped me.

_ tinyurl.com ― 2017年03月10日 23:40

Hi there it's me, I am also visiting this web site regularly, this web page
is really fastidious and the users are really sharing good thoughts.

_ tinyurl.com ― 2017年03月11日 14:02

Thanks for your personal marvelous posting!
I definitely enjoyed reading it, you will be a great author.I will make certain to bookmark your blog and will come back
in the future. I want to encourage one to continue your great job, have a nice weekend!

_ tinyurl.com ― 2017年03月11日 20:18

I'm impressed, I have to admit. Seldom do
I come across a blog that's both equally educative
and interesting, and without a doubt, you've hit the nail on the head.
The problem is something too few folks are speaking intelligently about.
I am very happy I came across this during my search for something regarding this.

_ http://j.mp/2m9zSBJ ― 2017年03月12日 07:51

Greate article. Keep posting such kind of info on your blog.
Im really impressed by your site.
Hi there, You've done an excellent job. I'll certainly digg it and individually recommend to
my friends. I am confident they'll be benefited from this
site.

_ tinder dating site ― 2017年03月14日 05:50

Whoa! This blog looks just like my old one! It's on a totally different subject but it
has pretty much the same layout and design. Superb choice of colors!

_ tinder dating site ― 2017年03月15日 12:58

Greetings from California! I'm bored at work so I decided to check out
your blog on my iphone during lunch break. I love the information you present here and can't wait to take a look when I get home.
I'm shocked at how quick your blog loaded on my cell phone
.. I'm not even using WIFI, just 3G .. Anyhow,
great site!

_ tinder dating site ― 2017年03月19日 12:46

fantastic issues altogether, you just gained a logo new reader.

What could you suggest about your publish that you just
made some days ago? Any certain?

_ tinder dating site ― 2017年03月19日 13:40

Way cool! Some very valid points! I appreciate you penning
this post plus the rest of the website is extremely good.

_ tinder dating site ― 2017年03月20日 03:48

Everything said was very reasonable. However, think about this, what if you wrote
a catchier title? I am not suggesting your information isn't solid., but suppose you added a headline that grabbed a person's attention? I mean compare -- ファイルの比較:
アナクロなコンピューターエンジニアのつぶやき is
a little boring. You might glance at Yahoo's home page and see
how they create news titles to grab people to click. You might
try adding a video or a related pic or two to grab readers excited about what you've written. Just my opinion, it would
make your posts a little livelier.

_ free dating sites no fees ― 2017年03月22日 04:52

Hey excellent blog! Does running a blog similar to this take a massive amount
work? I've absolutely no expertise in programming but I had been hoping
to start my own blog soon. Anyways, if you have any ideas or techniques for new blog owners please share.
I know this is off subject nevertheless I just wanted to ask.
Thanks!

_ best free dating sites 2017 ― 2017年03月22日 04:54

When someone writes an piece of writing he/she retains the thought of a
user in his/her mind that how a user can understand it. So that's why this piece of writing is great.
Thanks!

_ free dating sites no fees ― 2017年03月22日 05:27

Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is fundamental and all. Nevertheless think about if you added some great photos or videos to give your posts more, "pop"!

Your content is excellent but with pics and clips, this blog could undeniably
be one of the very best in its niche. Excellent blog!

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

We stumbled over here coming from a different web address and
thought I may as well check things out. I like what
I see so i am just following you. Look forward to looking over your web page yet again.

_ free dating sites no fees ― 2017年03月23日 08:13

It's awesome for me to have a website, which is beneficial in favor of my experience.

thanks admin

_ free dating no card always free sites ― 2017年03月23日 09:08

Hmm it seems like your website ate my first comment (it was
super long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog.
I as well am an aspiring blog writer but I'm still new to everything.

Do you have any suggestions for rookie blog writers?
I'd certainly appreciate it.

_ minecraft free download ― 2017年03月26日 01:56

Magnificent beat ! I would like to apprentice while you amend your website,
how could i subscribe for a blog website? The account helped me a acceptable
deal. I had been tiny bit acquainted of this
your broadcast provided bright clear concept

_ minecraft ― 2017年03月26日 14:33

Thanks in favor of sharing such a nice opinion, piece of writing is good, thats why i have read it completely

_ www.krogerfeedback.com ― 2017年04月29日 09:38

I loved as much as you'll receive carried out right here.
The sketch is attractive, your authored subject matter stylish.

nonetheless, you command get got an nervousness over that you wish be delivering the following.
unwell unquestionably come more formerly again since exactly the same
nearly very often inside case you shield this increase.

_ www.krogerfeedback.com ― 2017年05月01日 09:38

Paragraph writing is also a excitement, if you be familiar with afterward you can write or else it is difficult to
write.

_ manicure ― 2017年05月04日 15:14

Hi there, just became aware of your blog through Google,
and found that it's truly informative. I am gonna watch out for
brussels. I'll be grateful if you continue this in future.
Many people will be benefited from your writing.
Cheers!

_ Minecraft ― 2017年05月19日 20:28

Link exchange is nothing else except it is simply placing the other person's
website link on your page at proper place and other person will also do same in favor of
you.

_ Minecraft ― 2017年05月20日 06:06

I like the helpful info you provide in your articles. I will bookmark your blog and check again right here regularly.
I'm moderately certain I will be informed a lot
of new stuff proper here! Best of luck for the following!

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2015/03/01/7581877/tb