(Linux)sysvbannerのソースコード

関連記事はコチラ
https://life-is-command.com/linux-command-beginner/

bannerを直接修正して、#を*に表示を変えてみます。
まずは任意のエディタでbanner.cを開きます。
全文載せてみます。

$ cat -n banner.c
     1  /*****************************************************************
     2   *
     3   * SYSVbanner.c
     4   *
     5   * This is a PD version of the SYS V banner program (at least I think
     6   * it is compatible to SYS V) which I wrote to use with the clock
     7   * program written by:
     8   **     DCF, Inc.
     9   **     14623 North 49th Place
    10   **     Scottsdale, AZ 85254
    11   * and published in the net comp.sources.misc newsgroup in early July
    12   * since the BSD banner program works quite differently.
    13   *
    14   * There is no copyright or responsibility accepted for the use
    15   * of this software.
    16   *
    17   * Brian Wallis, brw@jim.odr.oz, 4 July 1988
    18   *
    19   *****************************************************************/
    20
    21  /* Changes by David Frey, david@eos.lugs.ch, 3 February 1997:
    22   * 1. protoized and indented, 2. changed @ character to #
    23   */
    24
    25  #include <stdio.h>
    26  #include <string.h>
    27
    28  char *glyphs[] =
    29  {
    30    "         ###  ### ###  # #   ##### ###   #  ##     ###  ",
    31    "         ###  ### ###  # #  #  #  ## #  #  #  #    ###   ",
    32    "         ###   #   # ########  #   ### #    ##      #   ",
    33    "          #            # #   #####    #    ###     #    ",
    34    "                     #######   #  #  # ####   # #       ",
    35    "         ###           # #  #  #  # #  # ##    #        ",
    36    "         ###           # #   ##### #   ### #### #       ",
    37
    38    "   ##    ##                                            #",
    39    "  #        #   #   #    #                             # ",
    40    " #          #   # #     #                            #  ",
    41    " #          # ### ### #####   ###   #####           #   ",
    42    " #          #   # #     #     ###           ###    #    ",
    43    "  #        #   #   #    #      #            ###   #     ",
    44    "   ##    ##                   #             ###  #      ",
    45
    46    "  ###     #    #####  ##### #      ####### ##### #######",
    47    " #   #   ##   #     ##     ##    # #      #     ##    # ",
    48    "# #   # # #         #      ##    # #      #          #  ",
    49    "#  #  #   #    #####  ##### ####### ##### ######    #   ",
    50    "#   # #   #   #            #     #       ##     #  #    ",
    51    " #   #    #   #      #     #     # #     ##     #  #    ",
    52    "  ###   ##### ####### #####      #  #####  #####   #    ",
    53
    54    " #####  #####    #     ###      #           #     ##### ",
    55    "#     ##     #  # #    ###     #             #   #     #",
    56    "#     ##     #   #            #     #####     #        #",
    57    " #####  ######         ###   #                 #     ## ",
    58    "#     #      #   #     ###    #     #####     #     #   ",
    59    "#     ##     #  # #     #      #             #          ",
    60    " #####  #####    #     #        #           #       #   ",
    61
    62    " #####    #   ######  ##### ###### ############## ##### ",
    63    "#     #  # #  #     ##     ##     ##      #      #     #",
    64    "# ### # #   # #     ##      #     ##      #      #      ",
    65    "# # # ##     ####### #      #     ######  #####  #  ####",
    66    "# #### ########     ##      #     ##      #      #     #",
    67    "#     ##     ##     ##     ##     ##      #      #     #",
    68    " ##### #     #######  ##### ###### ########       ##### ",
    69
    70    "#     #  ###        ##    # #      #     ##     ########",
    71    "#     #   #         ##   #  #      ##   ####    ##     #",
    72    "#     #   #         ##  #   #      # # # ## #   ##     #",
    73    "#######   #         ####    #      #  #  ##  #  ##     #",
    74    "#     #   #   #     ##  #   #      #     ##   # ##     #",
    75    "#     #   #   #     ##   #  #      #     ##    ###     #",
    76    "#     #  ###   ##### #    # ########     ##     ########",
    77
    78    "######  ##### ######  ##### ########     ##     ##     #",
    79    "#     ##     ##     ##     #   #   #     ##     ##  #  #",
    80    "#     ##     ##     ##         #   #     ##     ##  #  #",
    81    "###### #     #######  #####    #   #     ##     ##  #  #",
    82    "#      #   # ##   #        #   #   #     # #   # #  #  #",
    83    "#      #    # #    # #     #   #   #     #  # #  #  #  #",
    84    "#       #### ##     # #####    #    #####    #    ## ## ",
    85
    86    "#     ##     ######## ##### #       #####    #          ",
    87    " #   #  #   #      #  #      #          #   # #         ",
    88    "  # #    # #      #   #       #         #  #   #        ",
    89    "   #      #      #    #        #        #               ",
    90    "  # #     #     #     #         #       #               ",
    91    " #   #    #    #      #          #      #               ",
    92    "#     #   #   ####### #####       # #####        #######",
    93
    94    "  ###                                                   ",
    95    "  ###     ##   #####   ####  #####  ###### ######  #### ",
    96    "   #     #  #  #    # #    # #    # #      #      #    #",
    97    "    #   #    # #####  #      #    # #####  #####  #     ",
    98    "        ###### #    # #      #    # #      #      #  ###",
    99    "        #    # #    # #    # #    # #      #      #    #",
   100    "        #    # #####   ####  #####  ###### #       #### ",
   101
   102    "                                                        ",
   103    " #    #    #        # #    # #      #    # #    #  #### ",
   104    " #    #    #        # #   #  #      ##  ## ##   # #    #",
   105    " ######    #        # ####   #      # ## # # #  # #    #",
   106    " #    #    #        # #  #   #      #    # #  # # #    #",
   107    " #    #    #   #    # #   #  #      #    # #   ## #    #",
   108    " #    #    #    ####  #    # ###### #    # #    #  #### ",
   109
   110    "                                                        ",
   111    " #####   ####  #####   ####   ##### #    # #    # #    #",
   112    " #    # #    # #    # #         #   #    # #    # #    #",
   113    " #    # #    # #    #  ####     #   #    # #    # #    #",
   114    " #####  #  # # #####       #    #   #    # #    # # ## #",
   115    " #      #   #  #   #  #    #    #   #    #  #  #  ##  ##",
   116    " #       ### # #    #  ####     #    ####    ##   #    #",
   117
   118    "                       ###     #     ###   ##    # # # #",
   119    " #    #  #   # ###### #        #        # #  #  # # # # ",
   120    "  #  #    # #      #  #        #        #     ## # # # #",
   121    "   ##      #      #  ##                 ##        # # # ",
   122    "   ##      #     #    #        #        #        # # # #",
   123    "  #  #     #    #     #        #        #         # # # ",
   124    " #    #    #   ######  ###     #     ###         # # # #"};
   125
   126
   127  int main(int argc, char **argv)
   128  {
   129    int a, b, c, len, ind;
   130    char line[80];
   131
   132    for (argv++; --argc; argv++) {
   133      len = strlen(*argv);
   134      if (len > 10)
   135        len = 10;
   136      for (a = 0; a < 7; a++) {
   137        for (b = 0; b < len; b++) {
   138          if ((ind = (*argv)[b] - ' ') < 0)
   139            ind = 0;
   140          for (c = 0; c < 7; c++) {
   141            line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c]
   142          }
   143          line[b * 8 + 7] = ' ';
   144        }
   145        for (b = len * 8 - 1; b >= 0; b--) {
   146          if (line[b] != ' ')
   147            break;
   148          line[b] = '\0';
   149        }
   150        puts(line);
   151      }
   152      puts("");
   153    }
   154    return 0;
   155  }

ざっとソースを見たところで一旦エディタを終了します。
#を*に置換すれば良いので、
sedを使いましょう。

以下のコマンドで、banner.c内の30行目から124行目までにある#を*に置換します。

$ sed -e '30,124s/#/*/g' -i banner.c

makeしてbannerを実行してみます。

$ ./banner HELLO

*     * ******* *       *       *******
*     * *       *       *       *     *
*     * *       *       *       *     *
******* *****   *       *       *     *
*     * *       *       *       *     *
*     * *       *       *       *     *
*     * ******* ******* ******* *******

コメント

タイトルとURLをコピーしました