19 |
|
|
20 |
#include <stdio.h> /* for EOF */ |
#include <stdio.h> /* for EOF */ |
21 |
#include "libiberty.h" |
#include "libiberty.h" |
22 |
|
#include "safe-ctype.h" /* for HOST_CHARSET_ASCII */ |
23 |
|
|
24 |
|
#if EOF != -1 |
25 |
|
#error "hex.c requires EOF == -1" |
26 |
|
#endif |
27 |
|
|
28 |
/* |
/* |
29 |
|
|
44 |
|
|
45 |
@end deftypefn |
@end deftypefn |
46 |
|
|
47 |
@deftypefn Extension int hex_value (int @var{c}) |
@deftypefn Extension {unsigned int} hex_value (int @var{c}) |
48 |
|
|
49 |
Returns the numeric equivalent of the given character when interpreted |
Returns the numeric equivalent of the given character when interpreted |
50 |
as a hexidecimal digit. The result is undefined if you pass an |
as a hexidecimal digit. The result is undefined if you pass an |
51 |
invalid hex digit. Note that the value you pass will be cast to |
invalid hex digit. Note that the value you pass will be cast to |
52 |
@code{unsigned char} within the macro. |
@code{unsigned char} within the macro. |
53 |
|
|
54 |
|
The @code{hex_value} macro returns @code{unsigned int}, rather than |
55 |
|
signed @code{int}, to make it easier to use in parsing addresses from |
56 |
|
hex dump files: a signed @code{int} would be sign-extended when |
57 |
|
converted to a wider unsigned type --- like @code{bfd_vma}, on some |
58 |
|
systems. |
59 |
|
|
60 |
@end deftypefn |
@end deftypefn |
61 |
|
|
62 |
@undocumented _hex_array_size |
@undocumented _hex_array_size |
67 |
|
|
68 |
|
|
69 |
/* Are we ASCII? */ |
/* Are we ASCII? */ |
70 |
#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ |
#if HOST_CHARSET == HOST_CHARSET_ASCII |
|
&& 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \ |
|
|
&& EOF == -1 |
|
71 |
|
|
72 |
const char _hex_value[_hex_array_size] = |
const unsigned char _hex_value[_hex_array_size] = |
73 |
{ |
{ |
74 |
_hex_bad, _hex_bad, _hex_bad, _hex_bad, /* NUL SOH STX ETX */ |
_hex_bad, _hex_bad, _hex_bad, _hex_bad, /* NUL SOH STX ETX */ |
75 |
_hex_bad, _hex_bad, _hex_bad, _hex_bad, /* EOT ENQ ACK BEL */ |
_hex_bad, _hex_bad, _hex_bad, _hex_bad, /* EOT ENQ ACK BEL */ |
148 |
|
|
149 |
#else |
#else |
150 |
|
|
151 |
char _hex_value[_hex_array_size]; |
unsigned char _hex_value[_hex_array_size]; |
152 |
|
|
153 |
#endif /* not ASCII */ |
#endif /* not ASCII */ |
154 |
|
|