concatとxprint2015年04月19日 09:16

ファイルを使ったプログラムを2つ紹介します。concatとxprintです。

まずは、concatから。

concatは、引数にファイルを指定します。指定したファイルをひとつながりにして標準出力に書き出します。

     concat file1 file2 file2 ...

concatのメイン部分は下記の通り。引数がなくなるまで取り出し、 取り出してはファイルをオープンし標準出力に書き出します。

RATFOR版は下記の通り。

# concat.r4 -- concatenate named files onto standard output
      character name(NAMESIZE)
      integer getarg, fopen
      integer fin,i

      call initfile()

      for (i = 1; getarg(i,name,NAMESIZE) != EOF; i = i + 1) {
          fin = fopen(fin,name,READ)
          if (fin == ERR)
              call cant(name)
          end if
          call fcopy(fin,STDOUT)
          call fclose(fin)
     }
     stop
     end

WATCOM fortran77版は下記の通り。

c concat.for -- concatinate named files onto standard output
      program concat
      integer getarg,fopen
      integer fin,i
      integer*1 name(81)                  ! NAMESIZE(81)
 
      call initfile()
 
      i = 1
      while (getarg(i,name,81) .ne. -1) do  ! NAMESIZE(81) EOF(-1)
          if (fopen(fin,name,82) .eq. -1) then ! READ(LETR) ERR(-1)
              call cant(name)
          end if
          call fcopy(fin,6)             ! STDOUT(6)
          call fclose(fin)
          i = i + 1
      end while
      stop
      end

実際の書き出しはfcopy()が行います。fcopy()は次の通り。

まずは、RATFOR版。

# fcopy.r4 -- copy file in to file out
      subroutine fcopy(in,out)
      integer in,out
      character buf(MAXLINE+1)
      integer getlin
      
      while (getlin(buf,in) != EOF)
          call putlin(buf,out)
      return
      end

このように、単純に入力を出力に書き出します。

WATCOM Fortran77版。

c fcopy.for -- copy file in to file out
      subroutine fcopy(in,out)
      integer in,out
      integer*1 buf(81+1) ! MAXLINE(81)+1
      integer getlin
      
      while (getlin(buf,in) .ne. -1) do ! EOF(-1)
          call putlin(buf,out)
      end while
      return
      end

次に、xprintです。xprintは、ファイルを、1ページに、ファイル名とページ番号を適当に書き出すものです。

引数がなかった場合は、標準入力から読み込みます。この時はヘッダー部分にファイル名を書きません。

xprintのメインは下記の通り。

まずは、RATFOR版。

# xprint (default input STDIN)-- print files with headings
      character name(NAMESIZE)
      integer getarg,fopen
      integer fin,i
      string null ""

      call initfile()
      for (i = 1; getarg(i,name,NAMESIZE) != EOF; i = i + 1) {
          if (fopen(fin,name,READ) == ERR)
              call cant(name)
          end if
          call fprint(name,fin)
          call fclose(fin)
          }
      if (i == 1)
          call fprint(null,STDIN)

      stop
      end

WATCOMFortran77版は下記の通り。

c xprint (default input STDIN)-- print files with headings
      program xprint
      integer*1 name(81)                ! NAMESIZE(81)
      integer getarg,fopen
      integer fin,i
      integer*1 null
      data null/' '/

      call initfile()
      i = 1
      while(getarg(i,name,81) .ne. -1) do ! NAMESIZE(81) ERR(-1)
          if (fopen(fin,name,82) .eq. -1) then ! READ(LETR) ERR(-1)
              call cant(name)
          end if
          call fprint(name,fin)
          call fclose(fin)
          i = i + 1
      end while
      
      if (i .eq. 1) then
          call fprint(null,5)           ! STDIN(5)
      end if
      stop
      end

使い方は、下記の通り。

     xprint file

実際の書き出しは、fprint()が行います。fprint()は下記の通り。

RATFOR版です。

# fprint.r4 -- print file name from fin
      subroutine fprint(name,fin)
      character name(NAMESIZE),line(MAXLINE+1)
      integer fin,lineno,pageno
      integer getlin

      lineno = 0
      pageno = 0
      while (getlin(line,fin) != EOF) {
          if (lineno == 0) {
              call skip(MARGIN1)
              pageno = pageno + 1
              call head(name,pageno)
              call skip(MARGIN2)
              loneno = MARGIN1 + MARGIN2 + 1
              }
          call putlin(line,STDOUT)
          lineno = lineno + 1
          if (lineno >= BOTTOM) {
              call skip(PAGELEN-lineno)
              lineno = 0
              }
          }
      if (lineno > 0)
          call skip(PAGELEN-lineno)
      return
      end

WATCOM Fortran77版は下記の通り。

c fprint.for -- print file name from fin
      subroutine fprint(name,fin)
      integer*1 name(81)                ! NAMESIZE(81)
      integer fin
      integer*1 line(81+1)              ! MAXLINE(81)
      integer getlin,lineno,pageno

      lineno = 0
      pageno = 0
      while (getlin(line,fin) .ne. -1) do ! EOF(-1)
          if (lineno .eq. 0) then
              call skip(2)              ! MARGIN1(2)
              pageno = pageno + 1
              call head(name,pageno)
              call skip(3)              ! MARGIN2(3)
              loneno = 2 + 3 + 1
          endif
          call putlin(line,6) ! STDOUT(6)
          lineno = lineno + 1
          if (lineno .ge. 62) then      ! BOTTOM(62)
              call skip(66-lineno)      ! PAGELEN(66)
              lineno = 0
          endif
      end while
      if (lineno .gt. 0) then
          call skip(66-lineno)          ! PAGELEN(66)
      end if
      return
      end

MARGIN1,MARGIN2,BOTTOM,PAGELENはLetterサイズの用紙に合わせてありますので、 A4に書き出すときは変更が必要です。また、1行80文字で書き出すので、A4縦では はみ出してしまいますので、注意が必要です。

下請けルーチンのskip()は下記の通り。指定された分だけ改行を出力します。

RATFOR版。

# skip.r4 -- output n blank lines
      subroutine skip(n)
      integer i,n

      for (i = 1; i <= n; i = i + 1)
          call putc(NEWLINE)
      return
      end

WATCOM Fortran77版。

c skip.for -- output n blank lines
      subroutine skip(n)
      integer i,n

      i = 1
      while (i .le. n) do
          call putc(10)                 ! NEWLINE(10)
          i = i + 1
      end while
      return
      end

また、ヘッダーを書くhead()は下記の通り。

RATFOR版。

# head.r4 -- print top of page header
      subroutine head(name,pageno)
      character name(NAMESIZE)
      integer pageno
      string page "  page "

      call putlin(name,STDOUT)
      call putlin(page,STDOUT)
      call putdec(pageno,1)
      call putc(NEWLINE)
      return
      end

WATCOMM Fortran版。

c head.for -- print top of page header
      subroutine head(name,pageno)
      integer*1 name(81)                ! NAMESIZE(81)
      integer pageno
      integer*1 page(8)
      data page/' ',' ','p','a','g','e',' ',-2/ ! EOS(-2)

      call putlin(name,6)               ! STDOUT(6)
      call putlin(page,6)               ! STDOUT(6)
      call putdec(pageno,1)
      call putc(10)                     ! NEWLINE(10)
      return
      end

コメント

_ Plenty Of Fish Dating Site Of Free Dating ― 2015年10月18日 13:22

I do not know whether it's just me or if perhaps everyone else experiencing problems with your website. It appears as though some of the text within your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them as well? This could be a problem with my web browser because I've had this happen before. Cheers

_ lawsuit Against quest bars ― 2015年10月19日 00:20

I don't know if it's just me or if everybody else encountering issues with your site. It appears like some of the text in your content are running off the screen. Can someone else please comment and let me know if this is happening to them too? This could be a issue with my browser because I've had this happen previously. Many thanks

_ match 14 day free trial ― 2015年10月28日 14:59

Hey there! Quick question that&#39;s completely off topic.
Do you know how to make your site mobile friendly? My web site looks weird when browsing from
my iphone. I&#39;m trying to find a theme or plugin that might
be able to correct this issue. If you have any recommendations,
please share. Cheers!

_ match.com free trial month ― 2015年10月31日 15:40

It&#39;s going to be ending of mine day, except before finish I am reading this impressive post to improve my know-how.

_ forskolin extract ― 2015年11月03日 18:10

My spouse and I absolutely love your blog and find a lot
of your post&#39;s to be precisely what I&#39;m looking for.
can you offer guest writers to write content for yourself?
I wouldn&#39;t mind composing a post or elaborating on some of the subjects you write
about here. Again, awesome site!

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

Hey there! This is kind of off topic but I need some help from an established
blog. Is it hard to set up your own blog? I&#39;m not very techincal but
I can figure things out pretty fast. I&#39;m thinking about creating my own but I&#39;m not sure where
to begin. Do you have any tips or suggestions? Cheers

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

Hello are using Wordpress for your site platform? I&#39;m new to the blog world but I&#39;m trying to
get started and create my own. Do you require any html coding expertise to
make your own blog? Any help would be really appreciated!

_ www.krogerfeedback.com ― 2015年11月12日 14:07

Hi I am so delighted I found your blog, I really found you by accident,
while I was browsing on Yahoo for something else, Regardless I am here now and would just like to say kudos for a fantastic post and
a all round exciting blog (I also love the theme/design), I don&#39;t have time to read 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 a great deal more, Please do keep up the awesome work.

_ Los Angeles, CA ― 2015年11月21日 12:13

No matter if some one searches for his required thing, thus he/she
desires to be available that in detail, therefore that thing is maintained over here.

_ Walmart black friday 2015 ― 2015年11月22日 13:47

Great web site. Lots of useful information here.
I am sending it to a few friends ans additionally sharing in delicious.
And certainly, thanks in your sweat!

_ plenty of fish ― 2015年11月26日 20:59

This is very attention-grabbing, You&#39;re a very skilled blogger.
I&#39;ve joined your rss feed and sit up for searching for more of your
magnificent post. Additionally, I have shared your site in my social networks

_ black friday quest bars ― 2015年11月27日 07:22

Hello my loved one! I wish to say that this article is awesome, great written and
include almost all vital infos. I&#39;d like to peer more posts like
this .

_ plenty of fish ― 2015年11月28日 07:31

Hi there to all, how is the whole thing, I
think every one is getting more from this web site, and your views
are nice for new users.

_ quest bars ― 2015年11月29日 21:37

you are truly a good webmaster. The site loading velocity is amazing.
It seems that you&#39;re doing any unique trick. In addition, The contents are masterwork.
you&#39;ve done a fantastic activity on this matter!

_ quest bars ― 2015年11月29日 21:44

Your style is really unique in comparison to other folks I have read stuff from.
Thank you for posting when you have the opportunity,
Guess I&#39;ll just book mark this site.

_ quest bars ― 2015年11月30日 16:51

I think that everything said was actually very reasonable.
But, what about this? suppose you added a little content?
I mean, I don&#39;t wish to tell you how to run your website, however what if you added a title that makes people want more?

I mean concatとxprint: アナクロなコンピューターエンジニアのつぶやき is kinda plain.
You ought to look at Yahoo&#39;s front page and see how they write post headlines to get viewers
to open the links. You might add a video or a picture or two to grab readers interested about everything&#39;ve got to
say. Just my opinion, it would bring your posts a little bit more interesting.

_ plenty of fish dating Site of Free dating ― 2015年12月01日 09:23

I do not even know how I ended up here, but I thought this post was
great. I do not know who you are but definitely you&#39;re going
to a famous blogger if you are not already ;) Cheers!

_ Krogerfeedback.com ― 2015年12月05日 15:22

This is very interesting, You&#39;re a very skilled blogger.
I have joined your rss feed and look forward to seeking more of your fantastic post.
Also, I have shared your website in my social networks!

_ www.krogerfeedback.com ― 2015年12月12日 09:45

Link exchange is nothing else however it is just placing the other person&#39;s website
link on your page at suitable place and other person will also do similar in support of
you.

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

Fine way of telling, and pleasant article to get facts about my presentation focus, which i am going to convey in college.

_ quest bars ― 2016年02月09日 03:48

I&#39;m really enjoying the design and layout of your site. It&#39;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? Outstanding work!

_ quest bars ― 2016年02月09日 17:35

This article provides clear idea in favor of the
new users of blogging, that in fact how to do blogging and
site-building.

_ quest bars ― 2016年02月19日 13:45

WOW just what I was looking for. Came here by
searching for quest bars

_ bernie sanders ― 2016年04月01日 18:10

Hello! I could have sworn I&#39;ve been to this website before but after going through many of the posts I realized it&#39;s new to me.
Anyways, I&#39;m certainly pleased I came across it
and I&#39;ll be bookmarking it and checking back often!

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

A fascinating discussion is definitely worth comment.
I do think that you should write more about this subject matter, it may not be a taboo subject but usually people don&#39;t discuss such subjects.

To the next! Best wishes!!

_ tinder dating site free ― 2017年02月27日 07:36

Woah! I&#39;m really loving the template/theme of this
blog. It&#39;s simple, yet effective. A lot of times it&#39;s difficult to get
that &quot;perfect balance&quot; between usability and visual appeal.
I must say you&#39;ve done a great job with this. Additionally,
the blog loads extremely fast for me on Internet explorer.
Outstanding Blog!

_ tinder dating site ― 2017年02月28日 08:17

Hello would you mind stating which blog platform you&#39;re using?
I&#39;m going to start my own blog soon but I&#39;m having a tough time selecting
between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your design and style seems different
then most blogs and I&#39;m looking for something completely unique.

P.S Sorry for being off-topic but I had to ask!

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

Hey there I am so glad I found your blog, I really found you
by accident, while I was browsing on Aol for something else, Anyways I am here now and would just like to
say cheers for a remarkable post and a all round enjoyable blog (I also love the theme/design), I don’t have
time to look over it all at the minute but I have saved it and also included your RSS
feeds, so when I have time I will be back to read more, Please do keep up the awesome b.

_ tinder dating site ― 2017年03月02日 15:43

Amazing things here. I am very happy to look your post.
Thank you a lot and I&#39;m having a look ahead to touch you.
Will you kindly drop me a e-mail?

_ minecraft ― 2017年03月02日 22:06

I love it when individuals come together and share thoughts.
Great site, keep it up!

_ minecraft ― 2017年03月03日 00:38

I was excited to uncover this website. I want to to thank you
for your time for this fantastic read!! I definitely loved every bit of it and I have you book marked to check
out new things in your blog.

_ tinder dating site ― 2017年03月05日 04:11

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

_ tinder dating site ― 2017年03月05日 13:21

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

_ Dating Lancaster California ― 2017年03月09日 04:41

Hi there, You have done a fantastic job. I will
definitely digg it and personally recommend to my friends.

I&#39;m confident they&#39;ll be benefited from this site.

_ http://redondobeach.mrdrain.com ― 2017年03月09日 22:46

Hmm is anyone else encountering problems with the pictures on this blog loading?
I&#39;m trying to determine if its a problem on my end or
if it&#39;s the blog. Any suggestions would be greatly appreciated.

_ http://tinyurl.com/ ― 2017年03月10日 21:36

Nice post. I learn something new and challenging on blogs I
stumbleupon every day. It&#39;s always useful to read articles
from other authors and practice something from their websites.

_ http://tinyurl.com ― 2017年03月11日 14:38

Howdy I am so thrilled I found your web site, I really found you by error,
while I was looking on Bing for something else, Anyhow I am here now and would just like to say thanks a lot for a remarkable
post and a all round entertaining blog (I also love the theme/design), I don&#39;t
have time to read it all at the moment but I have bookmarked it and also added your RSS
feeds, so when I have time I will be back to read more,
Please do keep up the fantastic job.

_ tinyurl.com ― 2017年03月11日 22:15

I am regular visitor, how are you everybody? This post posted at
this web site is genuinely pleasant.

_ tinder dating site ― 2017年03月14日 08:21

I really like your blog.. very nice colors &amp; theme.
Did you make this website yourself or did you hire someone
to do it for you? Plz answer back as I&#39;m looking to design my own blog and would like to know where u
got this from. thanks a lot

_ tinder dating site ― 2017年03月15日 11:24

Great article! We will be linking to this great content on our
site. Keep up the good writing.

_ tinder dating site ― 2017年03月18日 13:02

Pretty great post. I simply stumbled upon your weblog and
wanted to say that I have truly loved browsing your blog posts.
After all I&#39;ll be subscribing in your feed and I&#39;m hoping you write once more very soon!

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

I truly love your site.. Excellent colors &amp;
theme. Did you create this amazing site yourself? Please reply back as I&#39;m planning to
create my own blog and would love to find out where
you got this from or what the theme is called.
Thank you!

_ free dating sites no fees ― 2017年03月21日 19:26

What&#39;s up colleagues, nice paragraph and fastidious arguments
commented here, I am actually enjoying by these.

_ free dating sites online and local ― 2017年03月22日 06:59

I think the admin of this site is in fact working hard for his web page, for the reason that here every data is quality based data.

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

Thanks for your personal marvelous posting! I truly enjoyed reading it, you could be a great
author. I will remember to bookmark your blog and may come back
at some point. I want to encourage continue your great posts, have a nice morning!

_ 100% free dating websites massachusetts ― 2017年03月23日 08:55

I am extremely inspired together with your writing talents
and also with the structure for your blog. Is this a paid
theme or did you modify it yourself? Either way stay up the nice quality writing, it&#39;s rare to look a great
blog like this one today..

_ minecraft demo ― 2017年03月27日 05:56

magnificent issues altogether, you simply received a new reader.
What may you recommend in regards to your put
up that you just made a few days in the past? Any sure?

_ www.krogerfeedback.com ― 2017年04月29日 07:33

Have you ever thought about publishing an ebook or
guest authoring on other sites? I have a blog based upon on the same ideas you discuss and would love to have you share some
stories/information. I know my readers would appreciate your work.
If you&#39;re even remotely interested, feel free to shoot me an email.

_ manicure ― 2017年05月05日 00:54

I like the helpful info you provide in your articles.
I will bookmark your blog and check again here frequently.
I am quite sure I&#39;ll learn plenty of new stuff right here!
Best of luck for the next!

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

Good way of explaining, and good piece of writing to get facts on the topic of my presentation focus,
which i am going to deliver in school.

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2015/04/19/7614766/tb