Missing dependencies added.
[AROS-Contrib.git] / rexx / lstring / x2c.c
blob12e2d893b53fc7a398a565ec27f237c37e1106b3
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:38 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 12:52:25 bnv
8 * Changed: To use the new macros
10 * Revision 1.1 1998/07/02 17:20:58 bnv
11 * Initial Version
15 #include <ctype.h>
16 #include <lerror.h>
17 #include <lstring.h>
19 /* ------------------ Lx2c ------------------ */
20 void
21 Lx2c( const PLstr to, const PLstr from )
23 int i,j,r;
24 char *t,*f;
26 L2STR(from);
27 Lfx(to,LLEN(*from)/2+1); /* a rough estimation */
29 t = LSTR(*to); f = LSTR(*from);
31 for (i=r=0; i<LLEN(*from); ) {
32 for (; ISSPACE(f[i]) && (i<LLEN(*from)); i++) ;; /*skip spaces*/
33 for (j=i; ISXDIGIT(f[j]) && (j<LLEN(*from)); j++) ;; /* find hexdigits */
35 if ((i<LLEN(*from)) && (j==i)) { /* Ooops wrong character */
36 Lerror(ERR_INVALID_HEX_CONST,0);
37 LZEROSTR(*to); /* return null when error occures */
38 return;
41 if ((j-i)&1) { t[r++] = HEXVAL(f[i]); i++ ;}
42 for (; i<j; i+=2)
43 t[r++] = (HEXVAL(f[i])<<4) | HEXVAL(f[i+1]);
46 LTYPE(*to) = LSTRING_TY;
47 LLEN(*to) = r;
48 } /* Lx2c */