Bringing ChocolateCaste-0.7 into the main branch.
[AROS-Contrib.git] / rexx / lstring / d2c.c
blobca38eb045d4466765c32fcb64ed8cf9aa5b0bbff
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:17:00 bnv
8 * Initial revision
12 #include <lstring.h>
14 /* -------------------- Ld2c -------------------- */
15 void
16 Ld2c( const PLstr to, const PLstr from, long n )
18 int i;
19 long num,n2;
20 bool negative;
22 num = Lrdint(from);
24 if (n==0) {
25 LZEROSTR(*to);
26 return;
28 if (n<0) n=0;
30 negative = (num<0);
31 if (negative)
32 num = -num-1;
34 if (n>sizeof(long)) n=sizeof(long);
35 Lfx(to,(size_t)n);
37 n2 = n? n: sizeof(long);
38 for (i=0; num && i<n2; i++) {
39 LSTR(*to)[i] = num & 0xFF;
40 if (negative)
41 LSTR(*to)[i] ^= 0xFF;
42 num >>= 8;
44 if (i==0) {
45 LSTR(*to)[i] = 0x00;
46 if (negative)
47 LSTR(*to)[i] ^= 0xFF;
48 i++;
51 while (i<n) {
52 LSTR(*to)[i] = negative? 0xFF : 0x00;
53 i++;
56 LTYPE(*to) = LSTRING_TY;
57 LLEN(*to) = i;
58 Lreverse(to);
59 } /* Ld2c */