LoginSignup
2
2

More than 5 years have passed since last update.

kbanner を mac os x で動かす

Posted at

unix 系OSによくインストールされているコマンドで、mac os x にもある banner という コマンドは知ってますか。


$echo test | banner -w 50
Message:                                #
                               #
              #######################
             ########################
            #########################
            ###                #
            ###
              #
                   ######
                ############
              ################
             #####   ##   #####
            ###      ##       ##
            #        ##        #
            #        ##        #
            #        ##       ##
             #       ##     ####
             ##      ##########
               ##    ########
                     ####
            #####        ###
            #####      #######
             ##      ##########
            ###      ######   ##
            ##      #####      #
            #       #####      #
            #      #####      ##
            ##     #####     ###
             ##   ######   #####
             ##########    #####
               ######
                               #
                               #
              #######################
             ########################
            #########################
            ###                #
            ###
              #

まぁ、こんなのです。これに漢字を流すと

$echo あ | banner -w 50
Message: banner: the character '�' is not in my character set
banner: the character '�' is not in my character set
banner: the character '�' is not in my character set

となります。残念です。

Solaris (SunOS) には、漢字に対応した kbanner というのがあるので、mac でコンパイルして使おうと思います。

bsd 系のリポジトリにみつかったり、リンクが切れてたりするんですが、現状だと、安岡孝一さんのサイトからDLできます。

download して make すると、ちょっとした error がでるので、

kbanner.c:267:7: error: non-void function 'kputchar' should return a value [-Wreturn-type]
      return;
      ^

通るようにします。

$diff kbanner.c.org kbanner.c
267c267
<       return;
---
>       return 0;

warning はいっぱい出ますが、気にしません。上記のように変えると make できるようになるので、下記のように試してみます。

$echo あ | ./kbanner












あれ?

$echo 天 | ./kbanner
              ##
              ##
################################
        ##            ##
          ####    ####
            ########
      ########    ########
########      ##        ########
          ####      ##
      ####      ####
          ##  ##            ##
################################
              ##              ##
        ##    ##      ##
    ######    ##      ######
######        ##          ######





              ##
              ##
      ####################
      ##                ##
      ##                ##
                      ####
                      ##
                    ####
                  ####
              ######
          ######

どうやら ShiftJIS を対象としているようですので、下記のようにします。

$echo 天 | iconv -f utf8 -t sjis | ./kbanner

################################
              ##
              ##
              ##
              ##
              ##
  ############################
            ##  ##
            ##  ####
          ####    ##
          ##      ####
        ####        ####
      ####            ####
    ####                ####
######                    ######

できました。

オプションもいろいろあるので、いろいろ試してみると楽しそうです。

go に移植するのも楽しそうですね。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2