文字列の変換 -- translit ― 2014年12月07日 12:12
コマンドラインの引数がとれるようになったので、引数を使ったプログラムを 紹介します。 文字列の置き換えプログラムtranslitです。
translitは、標準入力から読み込んだ文字をコマンドラインの引数の指示に従い変換します。たとえば、
translit x y
は、文字"x"を文字"y"に変換します。また、
translit xy yx
は、文字"x"を文字"y"に、文字"y"を文字"x"に変換します。さらには、
translit a-z A-Z
は、英小文字を英大文字に変換します。"a-z"は、"abcdefghijklmnopqrstuvwxyz"の略記です。
translit a-zA-Z a
とすれば、英文字列を文字"a"一文字に押しつぶします。また、
translit 0-9 n
とすれば、数字列を文字"n"一文字に押しつぶします。
translit 0-9
とすれば、数字列を削除することになります。もう少し拡張します。
translit !a-z -
とすれば、英小文字以外は、改行も含め、"-"に変換されます。
脱出文字"@"も使えます。"@n"とすれば改行を意味し、"@t"は、タブです。"@"自身は"@@"と表現できます。
translit @n N
とすれば、改行が文字"N"に変換され、
translit @t T
とすれば、タブが文字"T"に変換されます。
このように、translitは一種のフィルターです。
translitのメイン部分は下記の通り。
# translit.r4 -- map characters character getc character arg(MAXARR), c, from(MAXSET), to(MAXSET) integer getarg, length, makset, xindex integer allbut, collap, i, lastto allbut = NO if (getarg(1, arg, MAXARR) == NO) call error('usage: translit from to.') else if (arg(1) == NOT) allbut = YES if (makset(arg, 2, from, MAXSET) == NO) call error('from: too large.') else allbut = NO if (makset(arg, 1, from, MAXSET) == NO) call error('from: too large.') if (getarg(2,arg,MAXARR) == NO) to(1) = EOS else if (makset(arg, 1, to, MAXSET) == NO) call error('to: too large.') lastto = length(to) if (length(from) > lastto | allbut == YES) collap = YES else collap = NO repeat { i = xindex(from, getc(c), allbut, lastto) if (collap == YES & i >= lastto & lastto > 0) { # collapse call putc(to(lastto)) repeat i = xindex(from, getc(c), allbut, lastto) until (i < lastto) } if (c == EOF) { call putc(EOF) break } if (i > 0 & lastto > 0) # translate call putc(to(i)) else if (i == 0) # copy call putc(c) # else delete } stop end
プログラムの前半は、コマンドラインの引数から、変換ルールの文字列を作成することに費やされています。 後半は、標準入力からEOFを読みとるまで、変換して標準出力へ書き出します。
Watcom Fortran77版は、下記の通り。
c translit.for -- map characters program translit integer*1 getc integer*1 arg(100), c, from(200), to(200) ! MAXARR(100) MAXSET(00) integer getarg, length, makset, xindex integer allbut, collap, i, lastto allbut = 0 ! NO(0) if (getarg(1, arg, 100) .eq. 0) then ! MAXARR(100) NO(0) call error('usage: translit from to.') else if (arg(1) .eq. 33) then ! NOT(33) allbut = 1 ! YES(1) if (makset(arg, 2, from, 200) .eq. 0) then ! MAXSET(200) NO(0) call error('from: too large.') end if else allbut = 0 ! NO(0) if (makset(arg, 1, from, 200) .eq. 0) then ! MAXSET(200) NO(0) call error('from: too large.') end if end if if (getarg(2, arg, 100) .eq. 0) then ! MAXARR(100) to(1) = -2 ! EOS else if (makset(arg, 1, to, 200) .eq. 0) then ! MAXSET(200) NO(0) call error('to: too large.') end if lastto = length(to) if (length(from) .gt. lastto .or. allbut .eq. 1) then ! YES(1) collap = 1 ! YES(1) else collap = 0 ! NO(0) end if loop i = xindex(from, getc(c), allbut, lastto) if (collap .eq. 1 1 .and. i .ge. lastto .and. lastto .gt. 0) then ! collapse call putc(to(lastto)) loop i = xindex(from, getc(c), allbut, lastto) until (i .lt. lastto) end if if (c .eq. -1) then ! EOF(-1) call putc(-1) ! EOF(-1) exit end if if (i .gt. 0 .and. lastto .gt. 0) then ! translate call putc(to(i)) else if (i .eq. 0) then ! copy call putc(c) end if ! else delete end loop stop end
次回からは、translitの下請けルーチンを紹介します。
コメント
_ Pof Mobile ― 2015年10月18日 05:29
_ quest protein bars review ― 2015年10月19日 00:57
_ quest bar reviews ― 2015年10月19日 11:23
_ quest-nutrition.com ― 2015年10月27日 00:45
_ plenty of fish dating site of free dating ― 2015年11月06日 05:29
I have saved as a favorite for later!
_ plenty of fish dating site of free dating ― 2015年11月06日 19:12
something else, Regardless I am here now and would just like to say thank you for a marvelous
post and a all round thrilling blog (I also love the theme/design), I don’t have time to go through it all at the
moment but I have saved it and also included your RSS feeds, so when I
have time I will be back to read a great deal more, Please do keep up the awesome b.
_ plenty Of fish dating site of free dating ― 2015年11月06日 22:48
We are a group of volunteers and starting a new project in a community in the same
niche. Your blog provided us beneficial information to work on. You have done a extraordinary job!
_ match.com free trial ― 2015年11月08日 18:49
well as with the layout on your weblog. Is this a paid theme
or did you modify it yourself? Anyway keep up the nice quality writing, it is rare to see a great blog like
this one nowadays.
_ kroger feedback ― 2015年11月11日 19:07
the latest information posted here.
_ quest bars ― 2015年11月30日 20:07
_ www.krogerfeedback.com ― 2015年12月04日 16:26
Look advanced to more added agreeable from you! By the way, how could
we communicate?
_ plenty of fish Dating site of free dating plenty of Fish dating site of free dating ― 2015年12月08日 05:55
no means found any fascinating article like
yours. It is pretty price sufficient for me. In my opinion, if all
website owners and bloggers made just right content material as you did, the internet
might be much more helpful than ever before.
_ www.krogerfeedback.com ― 2015年12月10日 08:35
never found any interesting article like yours.
It's pretty worth enough for me. In my view, if all
site owners and bloggers made good content as you
did, the web will be much more useful than ever before.
_ descargar facebook ― 2015年12月19日 10:08
You have some really great posts and I believe 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 send me an email if interested. Cheers!
_ Descargar Firefox ---- ― 2016年01月06日 14:51
I have book-marked it for later!
_ quest bars ― 2016年02月09日 13:49
seem to be running off the screen in Internet explorer.
I'm not sure if this is a format issue or something to do with internet browser compatibility but I thought
I'd post to let you know. The layout look
great though! Hope you get the issue solved soon. Kudos
_ quest bars ― 2016年02月10日 06:42
My website is in the very same niche as yours and my users would definitely
benefit from a lot of the information you provide here. Please let me know
if this okay with you. Many thanks!
_ quest bars ― 2016年02月19日 23:32
Extremely useful information specially the last part
:) I care for such information a lot. I was looking for this particular info for a
long time. Thank you and good luck.
_ bernie sanders ― 2016年03月31日 23:14
Did you create this website yourself? Please reply back as I'm
looking to create my own blog and want to find out where
you got this from or just what the theme is named. Thanks!
_ tinder dating site ― 2017年02月25日 22:45
visitors? Is gonna be back often to inspect new posts
_ tinder dating site ― 2017年02月26日 09:52
it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed
the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is completely off topic but I had to tell someone!
_ tinder dating site ― 2017年02月27日 13:03
is sharing data, that's truly good, keep up writing.
_ tinder dating site ― 2017年03月01日 02:31
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? Great work!
_ tinder dating site app ― 2017年03月02日 08:28
emails with the exact same comment. Perhaps there is a way you are able to
remove me from that service? Thanks!
_ minecraft ― 2017年03月02日 22:56
And i'm glad reading your article. But wanna remark on some general things, The site style
is great, the articles is really nice : D. Good job, cheers
_ tinder dating site free search ― 2017年03月05日 04:14
you make blogging look easy. The overall look of your
website is fantastic, let alone the content!
_ tinder dating site free search ― 2017年03月05日 12:03
It's on a completely different subject but it has pretty much the same layout and design.
Superb choice of colors!
_ solvang.mrdrain.com ― 2017年03月10日 02:09
I appreciate you taking the time and effort to put this article together.
I once again find myself spending a lot of time both reading and leaving comments.
But so what, it was still worthwhile!
_ tinyurl.com ― 2017年03月11日 02:38
content on our site. Keep up the great writing.
_ tinyurl.com ― 2017年03月11日 03:33
now each time a comment is added I get three e-mails with the same comment.
Is there any way you can remove me from that service?
Bless you!
_ tinyurl.com ― 2017年03月11日 16:31
information you have got right here on this post. I'll be returning to your web site
for more soon.
_ tinyurl.com ― 2017年03月11日 23:25
in news papers but now as I am a user of net therefore from now I am using net for articles or reviews,
thanks to web.
_ j.mp ― 2017年03月12日 11:04
of all friends regarding this article, while I am also keen of getting experience.
_ tinder dating site ― 2017年03月13日 13:34
I get in fact enjoyed account your blog posts. Anyway I'll
be subscribing to your feeds and even I achievement you
access consistently quickly.
_ tinder dating site app ― 2017年03月14日 07:03
Looking through this article reminds me of my
previous roommate! He continually kept talking about this.
I am going to send this post to him. Fairly certain he's going to have a very good
read. Many thanks for sharing!
_ tinder dating site ― 2017年03月15日 13:12
reviews, except this web site gives feature based
posts.
_ tinder dating site ― 2017年03月19日 02:19
website or even a blog from start to end.
_ tinder dating site ― 2017年03月19日 02:27
and you are just extremely wonderful. I actually like what you've acquired here, really like what you're stating and the
way in which you say it. You make it entertaining and you still take care of to keep
it sensible. I can not wait to read far more from you.
This is actually a great website.
_ tinder dating site ― 2017年03月20日 20:37
sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear
and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is
totally off topic but I had to tell someone!
_ free dating sites no email required ― 2017年03月22日 02:59
of writing to increase my knowledge.
_ free dating sites no fees ― 2017年03月22日 05:24
this site is truly excellent.
_ free dating sites no fees ― 2017年03月22日 06:06
on building up new webpage.
_ free dating sites no fees ― 2017年03月23日 10:19
Looking through this post reminds me of my previous roommate!
He continually kept preaching about this. I'll send this article to him.
Pretty sure he will have a good read. Thanks for sharing!
_ 100% free dating site reviews ― 2017年03月23日 10:35
I don't recognize who you might be however definitely you
are going to a well-known blogger if you are not already.
Cheers!
_ minecraft demo ― 2017年03月26日 00:30
I have joined your feed and look forward to seeking more of your excellent post.
Also, I have shared your website in my social networks!
_ minecraft demo ― 2017年03月27日 00:05
I mean, what you say is important and everything.
But just imagine if you added some great graphics or video clips to
give your posts more, "pop"! Your content is excellent but
with images and video clips, this website could certainly be one of
the most beneficial in its niche. Very good blog!
_ manicure ― 2017年03月30日 20:09
you made blogging look easy. The overall look of your website is magnificent, let alone the content!
_ manicure ― 2017年03月30日 20:12
Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post.
Thanks a million and please carry on the gratifying work.
_ manicure ― 2017年03月30日 20:21
wish for enjoyment, since this this web page conations actually good funny data too.
_ www.krogerfeedback.com ― 2017年04月29日 16:45
blogging. thanks.
※コメントの受付件数を超えているため、この記事にコメントすることができません。
トラックバック
このエントリのトラックバックURL: http://kida.asablo.jp/blog/2014/12/07/7511781/tb
最近のコメント