forked from adesutherland/CMS-370-BREXX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c2d.c
41 lines (34 loc) · 834 Bytes
/
c2d.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
/*
* C2D - VM/370 Version
*/
#include "lstring.h"
/* ------------------- Lc2d ------------------------- */
void __CDECL
Lc2d(const PLstr to, const PLstr from, long n) {
int i;
bool negative;
long num;
L2STR(from);
if (!LLEN(*from) || !n) {
Licpy(to, 0);
return;
}
if (n < 1 || n > sizeof(long)) n = sizeof(long);
Lstrcpy(to, from);
Lreverse(to);
if (n <= LLEN(*to))
negative = LSTR(*to)[n - 1] & 0x80; /* msb = 1 */
else
negative = FALSE;
n = MIN(n, LLEN(*from));
num = 0;
for (i = n - 1; i >= 0; i--)
num = (num << 8) | ((byte) (LSTR(*to)[i]) & 0xFF);
if (negative) {
if (n == sizeof(long))
num = -(~num + 1);
else
num = num - (1L << (n * 8));
}
Licpy(to, num);
} /* Lc2d */