Sync'd with rev. 146 from the TheBar SVN archive.
[AROS-Contrib.git] / rexx / lstring / b2x.c
blobb2837d0d59bcc0534bc115f5535caa91691ec25d
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:37 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 09:51:19 bnv
8 * Changed: To use the new macros.
10 * Revision 1.1 1998/07/02 17:16:35 bnv
11 * Initial revision
15 #include <lerror.h>
16 #include <lstring.h>
18 /* ------------------- Lb2x ------------------- */
19 void
20 Lb2x( const PLstr to, const PLstr from )
22 long i;
23 int j,k;
24 char *c;
26 Lstrcpy(to,from);
27 Lreverse(to);
28 c = LSTR(*to);
30 for (i=j=k=0; i<LLEN(*to); i++) {
31 if (ISSPACE(LSTR(*to)[i])) continue;
32 if (LSTR(*to)[i]<'0' || LSTR(*to)[i]>'1')
33 Lerror(ERR_INVALID_HEX_CONST,0);
35 j |= ((LSTR(*to)[i]=='1')&1) << k;
36 if (++k==4) {
37 *c++ = chex[j];
38 j=k=0;
41 if (k) *c++ = chex[j];
42 *c = 0;
43 LLEN(*to) = STRLEN(LSTR(*to));
44 LTYPE(*to) = LSTRING_TY;
45 Lreverse(to);
46 } /* Lb2x */