Bringing ChocolateCaste-0.7 into the main branch.
[AROS-Contrib.git] / rexx / lstring / c2d.c
blobbbd0911f0067fa745960e8ac4a3d0bd0b95034bf
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.1 1998/07/02 17:16:35 bnv
8 * Initial revision
12 #include <lstring.h>
14 /* ------------------- Lc2d ------------------------- */
15 void
16 Lc2d( const PLstr to, const PLstr from, long n )
18 int i;
19 bool negative;
20 long num;
22 L2STR(from);
24 if (!LLEN(*from)) {
25 Licpy(to,0);
26 return;
28 if (n<1 || n>sizeof(long)) n = sizeof(long);
30 Lstrcpy(to,from);
31 Lreverse(to);
33 if (n <= LLEN(*to) )
34 negative = LSTR(*to)[n-1] & 0x80; /* msb = 1 */
35 else
36 negative = FALSE;
38 n = MIN(n,LLEN(*from));
39 num = 0;
40 for (i=n-1; i>=0; i--)
41 num = (num << 8) | ((byte)(LSTR(*to)[i]) & 0xFF);
42 if (negative) {
43 if (n==sizeof(long))
44 num = -(~num + 1);
45 else
46 num = num - (1L << (n*8));
48 Licpy(to,num);
49 } /* Lc2d */