1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
|
/*
* Copyright (c) 2014 Red Hat.
* Copyright (c) 1995-2001,2003 Silicon Graphics, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdio.h>
#include <ctype.h>
#include "pmapi.h"
#include <ctype.h>
extern void __pmDumpErrTab(FILE *);
int
main(int argc, char **argv)
{
int code;
int sts;
char *p;
char *q;
if (argc > 1 &&
(strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "--list") == 0)) {
__pmDumpErrTab(stdout);
exit(1);
}
else if (argc > 1 &&
(strcmp(argv[1], "-?") == 0 || strcmp(argv[1], "--help") == 0)) {
argc = 0;
}
else if (argc > 1 && argv[1][0] == '-' && !isxdigit((int)argv[1][1])) {
fprintf(stderr, "Illegal option -- %s\n", &argv[1][1]);
argc = 0;
}
if (argc == 0) {
fprintf(stderr,
"Usage: pmerr [options] [code]\n\n"
" -l, --list causes all known error codes to be listed\n");
exit(1);
}
while (argc > 1) {
sts = 0;
p = argv[1];
if (*p == '0' && (p[1] == 'x' || p[1] == 'X')) {
p = &p[2];
for (q = p; isxdigit((int)*q); q++)
;
if (*q == '\0')
sts = sscanf(p, "%x", &code);
}
if (sts < 1)
sts = sscanf(argv[1], "%d", &code);
if (sts != 1) {
printf("Cannot decode \"%s\" - neither decimal nor hexadecimal\n", argv[1]);
goto next;
}
if (code > 0) {
code = -code;
printf("Code is positive, assume you mean %d\n", code);
}
printf("Code: %d 0x%x Text: %s\n", code, code, pmErrStr(code));
next:
argc--;
argv++;
}
return 0;
}
|