-
Notifications
You must be signed in to change notification settings - Fork 5
/
b2x.c
53 lines (48 loc) · 1.2 KB
/
b2x.c
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
/*
* $Id: b2x.c,v 1.5 2008/07/15 07:40:54 bnv Exp $
* $Log: b2x.c,v $
* Revision 1.5 2008/07/15 07:40:54 bnv
* #include changed from <> to ""
*
* Revision 1.4 2002/06/11 12:37:15 bnv
* Added: CDECL
*
* Revision 1.3 2001/06/25 18:49:48 bnv
* Header changed to Id
*
* Revision 1.2 1999/11/26 09:51:19 bnv
* Changed: To use the new macros.
*
* Revision 1.1 1998/07/02 17:16:35 bnv
* Initial revision
*
*/
#include "lerror.h"
#include "lstring.h"
#include <cmssys.h>
/* ------------------- Lb2x ------------------- */
void __CDECL
Lb2x(const PLstr to, const PLstr from) {
long i;
int j, k;
char *c;
Context *context = (Context *) CMSGetPG();
Lstrcpy(to, from);
Lreverse(to);
c = LSTR(*to);
for (i = j = k = 0; i < LLEN(*to); i++) {
if (ISSPACE(LSTR(*to)[i])) continue;
if (LSTR(*to)[i] < '0' || LSTR(*to)[i] > '1')
(context->lstring_Lerror)(ERR_INVALID_HEX_CONST, 0);
j |= ((LSTR(*to)[i] == '1') & 1) << k;
if (++k == 4) {
*c++ = chex[j];
j = k = 0;
}
}
if (k) *c++ = chex[j];
*c = 0;
LLEN(*to) = STRLEN(LSTR(*to));
LTYPE(*to) = LSTRING_TY;
Lreverse(to);
} /* Lb2x */