atob8.c revision 22347
1/* atob8.c: The opieatob8() library function.
2
3%%% portions-copyright-cmetz
4Portions of this software are Copyright 1996 by Craig Metz, All Rights
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11McDonald, All Rights Reserved. All Rights under this copyright are assigned
12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13License Agreement applies to this software.
14
15        History:
16
17	Modified by cmetz for OPIE 2.3. Return the output variable.
18	    Don't check parameters.
19	Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
20            Inlined and obseleted opieskipspace(). Inlined and obseleted
21            opiehtoi().
22        Created at NRL for OPIE 2.2 from opiesubr2.c
23*/
24#include "opie_cfg.h"
25#include <stdio.h>
26#include "opie.h"
27
28/* Convert 8-byte hex-ascii string to binary array
29 */
30char *opieatob8 FUNCTION((out, in), char *out AND char *in)
31{
32  register int i;
33  register int val;
34
35  for (i = 0; i < 8; i++) {
36    while (*in == ' ' || *in == '\t')
37      in++;
38    if (!*in)
39      return NULL;
40
41    if ((*in >= '0') && (*in <= '9'))
42      val = *(in++) - '0';
43    else
44      if ((*in >= 'a') && (*in <= 'f'))
45        val = *(in++) - 'a' + 10;
46      else
47        if ((*in >= 'A') && (*in <= 'F'))
48          val = *(in++) - 'A' + 10;
49        else
50	  return NULL;
51
52    *out = val << 4;
53
54    while (*in == ' ' || *in == '\t')
55      in++;
56    if (!*in)
57      return NULL;
58
59    if ((*in >= '0') && (*in <= '9'))
60      val = *(in++) - '0';
61    else
62      if ((*in >= 'a') && (*in <= 'f'))
63        val = *(in++) - 'a' + 10;
64      else
65        if ((*in >= 'A') && (*in <= 'F'))
66          val = *(in++) - 'A' + 10;
67        else
68          return NULL;
69
70    *out++ |= val;
71  }
72
73  return out;
74}
75