root/src/dumpword.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include "package.h"
   2 #include "word.h"
   3 
   4 /**
   5  * @brief dumpwordコマンドのオプション
   6  */
   7 static struct option longopts[] = {
   8     { "arithmetic", no_argument, NULL, 'a' },
   9     { "logical", no_argument, NULL, 'l' },
  10     { "version", no_argument, NULL, 'v' },
  11     { "help", no_argument, NULL, 'h' },
  12     { 0, 0, 0, 0 },
  13 };
  14 
  15 /**
  16  * @brief dumpwordコマンドのメイン
  17  *
  18  * @return 正常終了時は0、エラー発生時は1
  19  *
  20  * @param argc コマンドライン引数の数
  21  * @param *argv[] コマンドライン引数の配列
  22  */
  23 int main(int argc, char *argv[])
  24 {
  25     bool logicalmode = false;    /* レジストリの内容を論理値(0から65535)で表示する場合はtrue */
  26     int opt = 0;
  27     int stat = 0;
  28     WORD word = 0;
  29     const char *version = PACKAGE_VERSION;
  30     const char *cmdversion = "dumpword of YACASL2 version %s\n";
  31     const char *usage = "Usage: %s [-alh] WORD\n";
  32 
  33     /* エラーの定義 */
  34     cerr_init();
  35     addcerrlist_word();
  36 
  37     /* オプションの処理 */
  38     while((opt = getopt_long(argc, argv, "alvh", longopts, NULL)) != -1) {
  39         switch(opt) {
  40         case 'l':
  41             logicalmode = true;
  42             break;
  43         case 'v':
  44             fprintf(stdout, cmdversion, version);
  45             goto dumpwordfin;
  46         case 'h':
  47             fprintf(stdout, usage, argv[0]);
  48             goto dumpwordfin;
  49         case '?':
  50             fprintf(stderr, usage, argv[0]);
  51             setcerr(999, "");
  52             goto dumpwordfin;
  53         }
  54     }
  55 
  56     if(argv[optind] == NULL) {
  57         fprintf(stderr, usage, argv[0]);
  58         setcerr(999, "");
  59         goto dumpwordfin;
  60     }
  61     /* WORD値に変換 */
  62     word = nh2word(argv[optind]);
  63     if(cerr->num > 0) {
  64         fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg);
  65         goto dumpwordfin;
  66     }
  67     fprintf(stdout, "%6s: ", argv[optind]);
  68     print_dumpword(word, logicalmode);
  69     fprintf(stdout, "\n");
  70 dumpwordfin:
  71     if(cerr->num > 0) {
  72         stat = 1;
  73     }
  74     freecerr();                 /* エラーの解放 */
  75     return stat;
  76 }

/* [<][>][^][v][top][bottom][index][help] */