Deleted Added
full compact
hex.c (104834) hex.c (130561)
1/* Hex character manipulation support.
2 Copyright (C) 1995, 2001 Free Software Foundation, Inc.
3
4This file is part of the libiberty library.
5Libiberty is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public
7License as published by the Free Software Foundation; either
8version 2 of the License, or (at your option) any later version.

--- 5 unchanged lines hidden (view full) ---

14
15You should have received a copy of the GNU Library General Public
16License along with libiberty; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18Boston, MA 02111-1307, USA. */
19
20#include <stdio.h> /* for EOF */
21#include "libiberty.h"
1/* Hex character manipulation support.
2 Copyright (C) 1995, 2001 Free Software Foundation, Inc.
3
4This file is part of the libiberty library.
5Libiberty is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public
7License as published by the Free Software Foundation; either
8version 2 of the License, or (at your option) any later version.

--- 5 unchanged lines hidden (view full) ---

14
15You should have received a copy of the GNU Library General Public
16License along with libiberty; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18Boston, MA 02111-1307, USA. */
19
20#include <stdio.h> /* for EOF */
21#include "libiberty.h"
22#include "safe-ctype.h" /* for HOST_CHARSET_ASCII */
22
23
24#if EOF != -1
25 #error "hex.c requires EOF == -1"
26#endif
27
23/*
24
25@deftypefn Extension void hex_init (void)
26
27Initializes the array mapping the current character set to
28corresponding hex values. This function must be called before any
29call to @code{hex_p} or @code{hex_value}. If you fail to call it, a
30default ASCII-based table will normally be used on ASCII systems.
31
32@end deftypefn
33
34@deftypefn Extension int hex_p (int @var{c})
35
36Evaluates to non-zero if the given character is a valid hex character,
37or zero if it is not. Note that the value you pass will be cast to
38@code{unsigned char} within the macro.
39
40@end deftypefn
41
28/*
29
30@deftypefn Extension void hex_init (void)
31
32Initializes the array mapping the current character set to
33corresponding hex values. This function must be called before any
34call to @code{hex_p} or @code{hex_value}. If you fail to call it, a
35default ASCII-based table will normally be used on ASCII systems.
36
37@end deftypefn
38
39@deftypefn Extension int hex_p (int @var{c})
40
41Evaluates to non-zero if the given character is a valid hex character,
42or zero if it is not. Note that the value you pass will be cast to
43@code{unsigned char} within the macro.
44
45@end deftypefn
46
42@deftypefn Extension int hex_value (int @var{c})
47@deftypefn Extension unsigned int hex_value (int @var{c})
43
44Returns the numeric equivalent of the given character when interpreted
45as a hexidecimal digit. The result is undefined if you pass an
46invalid hex digit. Note that the value you pass will be cast to
47@code{unsigned char} within the macro.
48
48
49Returns the numeric equivalent of the given character when interpreted
50as a hexidecimal digit. The result is undefined if you pass an
51invalid hex digit. Note that the value you pass will be cast to
52@code{unsigned char} within the macro.
53
54The @code{hex_value} macro returns @code{unsigned int}, rather than
55signed @code{int}, to make it easier to use in parsing addresses from
56hex dump files: a signed @code{int} would be sign-extended when
57converted to a wider unsigned type --- like @code{bfd_vma}, on some
58systems.
59
49@end deftypefn
50
51@undocumented _hex_array_size
52@undocumented _hex_bad
53@undocumented _hex_value
54
55*/
56
57
58/* Are we ASCII? */
60@end deftypefn
61
62@undocumented _hex_array_size
63@undocumented _hex_bad
64@undocumented _hex_value
65
66*/
67
68
69/* Are we ASCII? */
59#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
60 && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
61 && EOF == -1
70#if HOST_CHARSET == HOST_CHARSET_ASCII
62
71
63const char _hex_value[_hex_array_size] =
72const unsigned char _hex_value[_hex_array_size] =
64{
65 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* NUL SOH STX ETX */
66 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* EOT ENQ ACK BEL */
67 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* BS HT LF VT */
68 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* FF CR SO SI */
69 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* DLE DC1 DC2 DC3 */
70 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* DC4 NAK SYN ETB */
71 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* CAN EM SUB ESC */

--- 62 unchanged lines hidden (view full) ---

134 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
135 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
136 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
137};
138#define HEX_TABLE_INITIALIZED
139
140#else
141
73{
74 _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 */
76 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* BS HT LF VT */
77 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* FF CR SO SI */
78 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* DLE DC1 DC2 DC3 */
79 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* DC4 NAK SYN ETB */
80 _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* CAN EM SUB ESC */

--- 62 unchanged lines hidden (view full) ---

143 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
144 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
145 _hex_bad, _hex_bad, _hex_bad, _hex_bad,
146};
147#define HEX_TABLE_INITIALIZED
148
149#else
150
142char _hex_value[_hex_array_size];
151unsigned char _hex_value[_hex_array_size];
143
144#endif /* not ASCII */
145
146void
147hex_init ()
148{
149#ifndef HEX_TABLE_INITIALIZED
150 int i;

--- 30 unchanged lines hidden ---
152
153#endif /* not ASCII */
154
155void
156hex_init ()
157{
158#ifndef HEX_TABLE_INITIALIZED
159 int i;

--- 30 unchanged lines hidden ---