getc()とputc()2014年09月23日 08:17

前回取り上げたcopyプログラムで使用している、getc()とputc()を紹介します。

まずは、getc()。RATFOR版は以下の通り。

# getc.r4 (simple version) -- get one characters from standard input
      character function getc(c)
      character c
      
      character buf(MAXLINE)
      integer i, lastc
      data lastc /MAXLINE/, buf(MAXLINE) /NEWLINE/
      # note : MAXLINE = MACCARD + 1

      lastc = lastc + 1
      if (lastc > MAXLINE) {
          read(STDIN, 100,end=10) (buf(i),i = 1,MAXCARD)
              100 format(MAXCARD a1)
          lastc = 1
          }
      c = buf(lastc)
      getc = c
      return

   10 c = EOF
      getc = EOF
      return
      end

RATFORのif文が出てきています。"{" -- "}"で複数の文をブロック化しています。

Watcom Fortran 77では、if文が、"if () then -- else -- endif"に拡張されています。

Watcom Fortran 77版では、character型がありますが、数値定数を代入することができません。 integer*1型に文字を格納することとします。

c getc.for -- (simple version) get character from standard input
      integer*1 function getc(c)
      integer*1 c
      
      integer col,lastc
      integer*1 buf(81)  ! MAXLINE(81)
      data lastc/81/     ! MAXLINE(81)
      
      lastc = lastc + 1
      if (lastc .gt. 81) then                      ! MAXLINE(81)
          read(5,100,end=999) (buf(col),col=1,80)  ! MAXCARD(80)
  100     format(80a1)                             ! MAXCARD(80)
          lastc = 1
      endif

      c    = buf(lastc)
      getc = buf(lastc)
      return

  999 continue
      c    = -1 ! EOF(-1)
      getc = -1 ! EOF(-1)
      return
      end

これで、良さそうなのですが、問題が一つあります。それは、本来の行末に空白文字が 追加され、1行が80文字になってしまうのです。この問題を回避したのが、次の版です。

c getc2.for -- (extended version) get character from standard input
      integer*1 function getc(c)
      integer*1 c

      integer col,lastc
      integer*1 buf(82) ! MAXLINE(81)+1
      data lastc/81/    ! MAXLINE(81)
      data buf(81)/10/  ! MAXLINE(81) NEWLINE(10)
      data buf(82)/-2/  ! MAXLINE(81)+1 EOS(-2)

      lastc = lastc + 1
      if (buf(lastc) .eq. -2) then                ! EOS(-2)
          read(5,100,end=999) (buf(col),col=1,80) ! MAXCARD(80)
  100     format(80A1)                            ! MAXCARD(80)
          lastc = 1
          col = 80
          while (buf(col) .eq. 32) do  ! BLANK(32)
              col = col - 1
          end while
          buf(col+1) = 10         ! NEWLINE(10)
          buf(col+2) = -2         ! EOS(-2)
      endif

      c    = buf(lastc)
      getc = buf(lastc)
      return

  999 continue
      c    = -1 ! EOF(-1)
      getc = -1 ! EOF(-1)
      return
      end

一行読みとった後、行末から、行頭に向かって空白をスキャンし、空白以外の文字が出てきたら、 改めて、行末のマーキングをします。これで、余分な行末の空白の処理ができるようになりましたが、 一つ問題があります。全くの空白のみの行は、長さ0の行になってしまいます。今回は、これはまれな事とし、 めをつぶることとしました。

次は、サブルーチンputc()です。RATFOR版は次の通り。

# putc.r4 (simple version) -- put characters on standard output
      subroutine putc(c)
      character c

      character buf(MAXCARD)
      integer i,lastc
      data lastc /0/

      if (lastc >= MAXCARD | c == NEWLINE) {
          for (i = lastc+1; i <= MAXCARD; i = i + 1)
              buf(i) = BLANK
          write(STDOUT,100) (buf(i), i = 1, MAXCARD)
              100 format(MAXCARD a1)
          lastc = 0
          }
      if (c != NEWLINE)
          lastc = lastc + 1
          buf(lastc) = c
          }
      return
      end

for文が出てきています。これは、Watcom Fortran77にありません。 Cと同じように、初期設定、終了条件、再設定がコンパクトに書けます。 Watcom Fortran77では、while () do -- end whileを使用します。

c putc.for (simple version) -- put sharacter on standard output
      subroutine putc(c)
      integer*1 c

      integer*1 buf(80) ! MAXCARD(80)
      integer i,lastc
      data lastc/0/

      if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10)
          i = lastc + 1
          while (i .le. 80) do             ! MAXCARD(80)
              buf(i) = 32                  ! BLANK(32)
              i = i + 1
          end while
          write(6,100) (buf(i),i=1,80)     ! MAXCARD(80)
  100     format(80a1)                     ! MAXCARD(80)
          lastc = 0
      endif
      if (c .ne. 10) then                  ! NEWLINE(10)
          lastc = lastc + 1
          buf(lastc) = c
      endif
      return
      end

一行80文字にするために、空白文字を詰め合わせています。これでは、元の空白文字なのか、 詰め物か判別できませんし、固定長レコードにする、意味がWindowsにはありません。 行末の無駄な空白文字を書き出さないよう、lastc文字分しか書き出さないように変更しました。

c putc2.for (extended version 1) -- put sharacter on standard output
      subroutine putc(c)
      integer*1 c

      integer*1 buf(80) ! MAXCARD(80)
      integer i,lastc
      data lastc/0/

      if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10)
          write(6,100) (buf(i),i=1,lastc)
  100     format(80a1)                     ! MAXCARD(80)
          lastc = 0
      endif
      if (c .ne. 10) then                  ! NEWLINE(10)
          lastc = lastc + 1
          buf(lastc) = c
      endif
      return
      end

コメント

_ Plentyofish ― 2015年10月18日 09:53

You're so cool! I don't believe I have read through anything like that before. So nice to discover somebody with genuine thoughts on this issue. Seriously.. thanks for starting this up. This website is one thing that is needed on the internet, someone with a little originality!

_ quest nutrition Bars Review ― 2015年10月19日 00:07

Thanks on your marvelous posting! I definitely enjoyed reading it, you are a great author. I will remember to bookmark your blog and may come back later on. I want to encourage continue your great posts, have a nice afternoon!

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

Pretty nice post. I just stumbled upon your weblog and wanted to say
that I&#39;ve really loved browsing your weblog posts.

In any case I&#39;ll be subscribing on your rss feed and I am hoping you
write again soon!

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

We absolutely love your blog and find nearly all of your post&#39;s to be
precisely what I&#39;m looking for. Would you offer guest writers to
write content in your case? I wouldn&#39;t mind composing a post or elaborating on a few of the subjects you write in relation to here.
Again, awesome site!

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

I have been browsing on-line greater than three hours as of late,
but I by no means discovered any interesting article like yours.
It is pretty value enough for me. In my opinion, if all webmasters and bloggers made good content as you probably did, the web will
likely be a lot more useful than ever before.

_ quest bar ― 2015年11月18日 02:13

I&#39;d like to find out more? I&#39;d like to find out some additional information.

_ plenty of fish ― 2015年11月22日 06:09

Excellent post. I was checking continuously
this blog and I&#39;m impressed! Very useful information specifically the last part :)
I care for such information much. I was seeking this certain info for a very long time.
Thank you and best of luck.

_ plenty of fish ― 2015年11月22日 14:43

Generally I don&#39;t read post on blogs, however I wish to say
that this write-up very forced me to try and do so! Your writing style has been surprised me.

Thanks, quite great post.

_ walmart black friday 2015 ― 2015年11月24日 14:49

I blog often and I seriously thank you for your content.
This article has truly peaked my interest.
I am going to take a note of your site and keep checking for new details about once per week.
I subscribed to your Feed too.

_ plenty of fish dating site of free dating ― 2015年11月24日 14:58

Hello there, just became alert to your blog through Google, and found
that it is truly informative. I am going to watch out for brussels.
I will be grateful if you continue this in future.

Lots of people will be benefited from your writing. Cheers!

_ krogerfeedback.com ― 2015年12月04日 15:42

It&#39;s actually a great and useful piece of information. I&#39;m happy that you shared this helpful information with
us. Please stay us up to date like this. Thank you for sharing.

_ kroger feedback survey ― 2015年12月06日 14:45

What&#39;s Going down i&#39;m new to this, I stumbled upon this I have discovered It positively
useful and it has aided me out loads. I am hoping to contribute &amp; help different customers like its
helped me. Good job.

_ krogerfeedback.com ― 2015年12月06日 22:40

Very nice write-up. I definitely appreciate this site.

Stick with it!

_ tinyurl.com ― 2015年12月07日 17:36

Pretty nice post. I just stumbled upon your blog and wanted to say that I&#39;ve truly enjoyed browsing your blog posts.
After all I will be subscribing to your feed and I hope you write again very soon!

_ tinyurl.com ― 2015年12月07日 20:13

First of all I would like to say awesome blog! I had a quick question that I&#39;d like to
ask if you don&#39;t mind. I was curious to find out how you center
yourself and clear your mind prior to writing. I&#39;ve had a tough time clearing
my mind in getting my ideas out. I do enjoy writing however it just seems like the
first 10 to 15 minutes are lost just trying to figure out how to
begin. Any suggestions or hints? Thank you!

_ plenty of fish dating site of Free dating plenty of fish dating site of free dating ― 2015年12月08日 09:02

For latest news you have to pay a quick visit the web and
on internet I found this website as a best site
for hottest updates.

_ tinyurl.com ― 2015年12月08日 10:21

Hello, i think that i saw you visited my site so i came to “return the
favor”.I am trying to find things to enhance my website!I suppose its ok to use a few of your ideas!!

_ krogerfeedback ― 2015年12月09日 00:26

Great post.

_ where to buy quest protein chips ― 2015年12月11日 20:57

My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.

But he&#39;s tryiong none the less. I&#39;ve been using Movable-type on several websites for about a
year and am nervous about switching to another platform.
I have heard fantastic things about blogengine.net.
Is there a way I can transfer all my wordpress content into it?
Any kind of help would be really appreciated!

_ quest bars for sale cheap ― 2015年12月11日 21:04

You really make it appear really easy together with your presentation but I find this topic to
be actually one thing which I feel I would never understand.
It sort of feels too complex and very vast for me. I&#39;m having a
look ahead in your next publish, I will try to get the grasp of it!

_ plenty of fish dating site of free dating ― 2015年12月11日 21:12

Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts.
Anyway I will be subscribing to your augment and even I achievement
you access consistently rapidly.

_ appdata minecraft ― 2015年12月12日 21:03

Wow, that&#39;s what I was seeking for, what a stuff!
existing here at this web site, thanks admin of this
web site.

_ Descargar El Facebook ― 2015年12月19日 07:48

You actually make it seem so easy with your presentation but I find this topic to be actually something which I think I
would never understand. It seems too complicated and extremely broad for me.
I am looking forward for your next post, I will try to get
the hang of it!

_ krogerfeedback.com !!! ― 2016年01月01日 02:07

Greetings from California! I&#39;m bored to death at work so I decided to check out your site on my iphone during lunch
break. I enjoy the information you provide here and can&#39;t wait to take a look when I get home.

I&#39;m amazed at how quick your blog loaded on my cell phone ..
I&#39;m not even using WIFI, just 3G .. Anyways, wonderful
blog!

_ quest bars ― 2016年02月09日 04:52

When I initially commented I clicked the &quot;Notify me when new comments are added&quot; checkbox and now each time
a comment is added I get three emails with the same comment.

Is there any way you can remove me from that service?
Appreciate it!

_ quest bars ― 2016年02月09日 12:37

Great article.

_ quest bars ― 2016年02月09日 18:32

Pretty nice post. I just stumbled upon your weblog and wished to say that I&#39;ve really enjoyed
browsing your blog posts. In any case I&#39;ll be subscribing
to your feed and I hope you write again soon!

_ plenty of fish dating site of free dating ― 2016年02月23日 15:58

I simply couldn&#39;t depart your web site prior to suggesting that I really enjoyed the
usual information an individual provide on your visitors?
Is going to be back ceaselessly to check out new posts

_ Bernie Sanders ― 2016年04月01日 22:26

It is appropriate time to make some plans for the longer term and it
is time to be happy. I&#39;ve read this post and if I may I desire to suggest you few fascinating issues or
tips. Maybe you could write subsequent articles regarding this article.
I want to read more things about it!

_ www.krogerfeedback.com ― 2016年06月05日 23:44

Awesome article.

_ quest Bars Cheap ― 2016年06月13日 08:51

Great goods from you, man. I have understand your stuff previous
to and you&#39;re just extremely fantastic. I really like what you&#39;ve acquired here, certainly like what
you are saying and the way in which you say it. You make it enjoyable and
you still care for to keep it sensible. I can not wait to read much
more from you. This is really a tremendous website.

_ mincraft ― 2016年07月03日 02:54

Excellent blog post. I certainly appreciate this site.

Thanks!

_ Mincraft ― 2016年07月03日 03:59

I&#39;m not sure exactly why but this blog is loading very slow for me.
Is anyone else having this problem or is it a issue on my end?

I&#39;ll check back later on and see if the problem still exists.

_ Mincraft ― 2016年07月03日 04:58

Great blog! Do you have any suggestions for aspiring writers?

I&#39;m planning to start my own blog soon but I&#39;m a little lost on everything.

Would you propose starting with a free platform like Wordpress or go for a
paid option? There are so many options out there that I&#39;m
completely overwhelmed .. Any recommendations? Kudos!

_ tinyurl.com ― 2016年07月09日 12:48

Hello, yes this paragraph is truly good and I have learned lot of things from it concerning blogging.
thanks.

_ www.krogerfeedback.com ― 2016年07月14日 19:32

Hey there fantastic blog! Does running a blog similar to this
require a lot of work? I have very little understanding of programming but I had been hoping to start my own blog in the near future.
Anyway, if you have any suggestions or techniques
for new blog owners please share. I know this is off subject however I simply needed to ask.
Thanks!

_ www.krogerfeedback.com ― 2016年07月26日 04:53

I believe what you said made a ton of sense. But, think about this,
what if you added a little information? I mean, I don&#39;t
wish to tell you how to run your blog, but suppose you added something that makes people desire more?
I mean getc()とputc(): アナクロなコンピューターエンジニアのつぶやき is kinda vanilla.

You ought to glance at Yahoo&#39;s front page and watch how they create article titles to grab viewers to click.
You might add a video or a related pic or two to get people excited about everything&#39;ve written. Just my opinion, it would make your posts a little bit more interesting.

_ kroger digital coupons ― 2016年07月28日 05:22

Very good article. I&#39;m going through a few of these issues as well..

_ kroger digital coupons ― 2016年07月29日 15:10

Do you have any video of that? I&#39;d love to find
out more details.

_ quest bars ― 2016年09月09日 17:54

I have read so many articles on the topic of the blogger lovers however this piece of writing is truly a nice article,
keep it up.

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

Thanks for sharing your thoughts about Windows 10 Free Upgrade.
Regards

_ quest bars ― 2016年09月24日 12:01

Paragraph writing is also a fun, if you know after that
you can write or else it is complicated to
write.

_ minecraftsweet and awesome ― 2016年10月01日 04:04

Hi there! This article couldn&#39;t be written any better!
Going through this post reminds me of my previous roommate!
He always kept talking about this. I most certainly
will forward this information to him. Pretty sure
he&#39;s going to have a great read. Thank you for sharing!

_ plenty of fish dating site of free dating ― 2016年10月04日 13:20

It is perfect time to make some plans for the future
and it is time to be happy. I have read this post and if
I could I want to suggest you few interesting things or suggestions.

Perhaps you can write next articles referring to this
article. I desire to read even more things about it!

_ plenty of fish dating site of free dating ― 2016年10月05日 03:57

Hi there, I check your new stuff like every week.
Your story-telling style is awesome, keep it up!

_ quest bars ― 2016年10月06日 09:14

Hi! I know this is kinda off topic nevertheless I&#39;d figured I&#39;d ask.
Would you be interested in exchanging links or maybe guest
writing a blog post or vice-versa? My website goes over a lot of the same subjects as yours
and I believe we could greatly benefit from each other. If you might be interested feel free to shoot me an email.
I look forward to hearing from you! Wonderful blog by the way!

_ descargar minecraft launcher gratis ― 2016年10月12日 21:49

I do not know if it&#39;s just me or if perhaps everybody else experiencing issues with your blog.
It appears as if some of the text within your content are running off the screen. Can somebody else please
comment and let me know if this is happening to them too?

This could be a problem with my internet browser because I&#39;ve had this happen before.
Thanks

_ juegos de minecraft demo ― 2016年10月15日 02:41

This post is actually a good one it helps new internet users, who are wishing for blogging.

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

If you are going for most excellent contents like I do, simply pay a quick visit this
website all the time because it presents quality contents, thanks gamefly 3 month free
trial

_ quest nutrition quest protein bar ― 2016年11月20日 00:18

Good day I am so excited I found your site, I really found you by accident, while I
was looking on Digg for something else, Regardless I am here now
and would just like to say cheers for a tremendous post
and a all round interesting blog (I also love the theme/design), I don&#39;t have time to go through it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time
I will be back to read much more, Please do keep
up the great job.

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2014/09/23/7441242/tb