File indexing completed on 2024-04-21 14:45:58
0001 0002 #include <stdio.h> 0003 #include <math.h> 0004 #include <string.h> 0005 0006 #define IDSIZE 64 0007 0008 #ifdef _WIN32 0009 typedef __int64 int64; 0010 typedef unsigned __int64 uint64; 0011 0012 typedef __int32 int32; 0013 typedef unsigned __int32 uint32; 0014 #else 0015 typedef long long int64; 0016 typedef unsigned long long uint64; 0017 0018 typedef long int32; 0019 typedef unsigned long uint32; 0020 #define IDHIGHBIT 0x8000000000000000LL 0021 #define IDHIGHBIT2 0x4000000000000000LL 0022 #endif 0023 0024 #define HTMNAMEMAX 32 0025 0026 #define HTM_INVALID_ID 1 0027 0028 int cc_ID2name(char *name, uint64 id) 0029 { 0030 uint32 size = 0, i; 0031 int c; /* a spare character; */ 0032 0033 #if defined(_WIN32) 0034 uint64 IDHIGHBIT = 1; 0035 uint64 IDHIGHBIT2 = 1; 0036 IDHIGHBIT = IDHIGHBIT << 63; 0037 IDHIGHBIT2 = IDHIGHBIT2 << 62; 0038 #endif 0039 0040 /* determine index of first set bit */ 0041 for (i = 0; i < IDSIZE; i += 2) 0042 { 0043 if ((id << i) & IDHIGHBIT) 0044 break; 0045 if ((id << i) & IDHIGHBIT2) /* invalid id */ 0046 return HTM_INVALID_ID; 0047 } 0048 if (id == 0) 0049 return HTM_INVALID_ID; 0050 0051 size = (IDSIZE - i) >> 1; 0052 0053 /* fill characters starting with the last one */ 0054 for (i = 0; i < size - 1; i++) 0055 { 0056 c = '0' + (int)((id >> i * 2) & (uint32)3); 0057 name[size - i - 1] = (char)c; 0058 } 0059 0060 /* put in first character */ 0061 if ((id >> (size * 2 - 2)) & 1) 0062 { 0063 name[0] = 'N'; 0064 } 0065 else 0066 { 0067 name[0] = 'S'; 0068 } 0069 name[size] = 0; /* end string */ 0070 0071 return 0; 0072 }