This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <crm_internal.h>
20
21 #include <crm/crm.h>
22
23
24 static struct crm_option long_options[] = {
25
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
38
39 int
40 main(int argc, char **argv)
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
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 }