root/tools/crm_error.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* 
   2  * Copyright (C) 2012 Andrew Beekhof <andrew@beekhof.net>
   3  * 
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public
   6  * License as published by the Free Software Foundation; either
   7  * version 2 of the License, or (at your option) any later version.
   8  * 
   9  * This software is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12  * General Public License for more details.
  13  * 
  14  * You should have received a copy of the GNU General Public
  15  * License along with this library; if not, write to the Free Software
  16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17  */
  18 
  19 #include <crm_internal.h>
  20 
  21 #include <crm/crm.h>
  22 
  23 /* *INDENT-OFF* */
  24 static struct crm_option long_options[] = {
  25     /* Top-level Options */
  26     {"help",       0, 0, '?', "\tThis text"},
  27     {"version",    0, 0, '$', "\tVersion information"  },
  28     {"verbose",    0, 0, 'V', "\tIncrease debug output"},
  29 
  30     {"name",    0, 0, 'n', "\tShow the error's name rather than the description."
  31      "\n\t\t\tUseful for looking for sources of the error in source code"},
  32 
  33     {"list",    0, 0, 'l', "\tShow all known errors."},
  34 
  35     {0, 0, 0, 0}
  36 };
  37 /* *INDENT-ON* */
  38 
  39 int
  40 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42     int rc = 0;
  43     int lpc = 0;
  44     int flag = 0;
  45     int option_index = 0;
  46 
  47     bool do_list = FALSE;
  48     bool with_name = FALSE;
  49 
  50     crm_log_cli_init("crm_error");
  51     crm_set_options(NULL, "[options] -- rc", long_options,
  52                     "Tool for displaying the textual name or description of a reported error code");
  53 
  54     while (flag >= 0) {
  55         flag = crm_get_option(argc, argv, &option_index);
  56         switch (flag) {
  57             case -1:
  58                 break;
  59             case 'V':
  60                 crm_bump_log_level(argc, argv);
  61                 break;
  62             case '$':
  63             case '?':
  64                 crm_help(flag, EX_OK);
  65                 break;
  66             case 'n':
  67                 with_name = TRUE;
  68                 break;
  69             case 'l':
  70                 do_list = TRUE;
  71                 break;
  72             default:
  73                 crm_help(flag, EX_OK);
  74                 break;
  75         }
  76     }
  77 
  78     if(do_list) {
  79         for (rc = 0; rc < 256; rc++) {
  80             const char *name = pcmk_errorname(rc);
  81             const char *desc = pcmk_strerror(rc);
  82             if(name == NULL || strcmp("Unknown", name) == 0) {
  83                 /* Unknown */
  84             } else if(with_name) {
  85                 printf("%.3d: %-25s  %s\n", rc, name, desc);
  86             } else {
  87                 printf("%.3d: %s\n", rc, desc);
  88             }
  89         }
  90         return 0;
  91     }
  92 
  93     for (lpc = optind; lpc < argc; lpc++) {
  94         rc = crm_atoi(argv[lpc], NULL);
  95         if(with_name) {
  96             printf("%s - %s\n", pcmk_errorname(rc), pcmk_strerror(rc));
  97         } else {
  98             printf("%s\n", pcmk_strerror(rc));
  99         }
 100     }
 101     return 0;
 102 }

/* [previous][next][first][last][top][bottom][index][help] */