📄 sctpred.c
字号:
"Start is less than zero." );
#endif
Result.Length = 0;
} else if ( SubLength <= 0 ) {
#ifdef XECSOP
xSDLOpError("SubString in sort Bit_String",
"SubLength is less than or equal to zero." );
#endif
Result.Length = 0;
} else if ( Start+SubLength > B.Length ) {
#ifdef XECSOP
xSDLOpError("SubString in sort Bit_String",
"Start + Substring length is greater than string length." );
#endif
Result.Length = 0;
} else {
/* Modified by GBU,000103 added cast since "SDL_Integer" and "int" may differ in size */
/*
Result.Length = SubLength;
*/
Result.Length = (int)SubLength;
Result.Bits = xAlloc_SDL_Bit_String((xptrint)(Result.Length));
(void)memcpy((void *)Result.Bits, (void *)&(B.Bits[Start]), Result.Length);
}
if (! B.IsAssigned) xFree_SDL_Bit_String((void **)&B);
return Result;
}
/*---+---------------------------------------------------------------
xBitStr_SDL_Bit_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Bit_String xBitStr_SDL_Bit_String (
SDL_Charstring C )
#else
SDL_Bit_String xBitStr_SDL_Bit_String ( C )
SDL_Charstring C;
#endif
{
SDL_Bit_String Result;
int i;
Result.Length = xLength_SDL_Charstring(C);
Result.IsAssigned = (xbool)0;
Result.IsUsedInSignal = (xbool)0;
Result.Bits = xAlloc_SDL_Bit_String((xptrint)(Result.Length));
for (i=0; i<Result.Length; i++) {
if (C[i+1] == '0') {
Result.Bits[i] = (SDL_Bit)0;
} else if (C[i+1] == '1') {
Result.Bits[i] = (SDL_Bit)1;
} else {
#ifdef XECSOP
xSDLOpError("BitStr in sort Bit_String",
"Illegal character in Charstring (not 0 or 1)." );
#endif
Result.Bits[i] = (SDL_Bit)1;
}
}
return Result;
}
/*---+---------------------------------------------------------------
xHexStr_SDL_Bit_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Bit_String xHexStr_SDL_Bit_String (
SDL_Charstring C )
#else
SDL_Bit_String xHexStr_SDL_Bit_String ( C )
SDL_Charstring C;
#endif
{
SDL_Bit_String Result;
int C_length, C_index, value;
C_length = xLength_SDL_Charstring(C);
Result.Length = C_length*4;
Result.IsAssigned = (xbool)0;
Result.IsUsedInSignal = (xbool)0;
Result.Bits = xAlloc_SDL_Bit_String((xptrint)Result.Length);
for (C_index=1; C_index<=C_length; C_index++) {
value = (int)(C[C_index]) - 'a' + 10;
if (value < 10) value = (int)(C[C_index]) - 'A' + 10;
if (value < 10) value = (int)(C[C_index]) - '0';
if (value < 0 || value > 15) {
#ifdef XECSOP
xSDLOpError("HexStr in sort Bit_String",
"Illegal character in Charstring (not digit or a-f)." );
#endif
Result.Bits[(C_index-1)*4] = 0;
Result.Bits[(C_index-1)*4+1] = 0;
Result.Bits[(C_index-1)*4+2] = 0;
Result.Bits[(C_index-1)*4+3] = 0;
} else {
Result.Bits[(C_index-1)*4] = (unsigned char)(value/8);
Result.Bits[(C_index-1)*4+1] = (unsigned char)((value/4)%2);
Result.Bits[(C_index-1)*4+2] = (unsigned char)((value/2)%2);
Result.Bits[(C_index-1)*4+3] = (unsigned char)(value%2);
}
}
return Result;
}
#endif
/* XNOUSEOFOCTETBITSTRING */
/*** Octet *********************************************************/
#ifndef XNOUSEOFOCTETBITSTRING
/*---+---------------------------------------------------------------
yAddr_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Bit * yAddr_SDL_Octet(
SDL_Octet *B,
SDL_Integer Index)
#else
SDL_Bit * yAddr_SDL_Octet( B, Index )
SDL_Octet *B;
SDL_Integer Index;
#endif
{
if ( (Index < 0) || (Index >= 8 )) {
#ifdef XECSOP
xSDLOpError("Modify! in sort Octet",
"Index out of bounds." );
#endif
return B;
}
return B; /* &((*B).Bits[Index]); ????? */
}
/*---+---------------------------------------------------------------
xExtr_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Bit xExtr_SDL_Octet(
SDL_Octet B,
SDL_Integer Index )
#else
SDL_Bit xExtr_SDL_Octet( B, Index )
SDL_Octet B;
SDL_Integer Index;
#endif
{
if ( (Index < 0) || (Index >= 8) ) {
#ifdef XECSOP
xSDLOpError("Extract! in sort Octet",
"Index out of bounds." );
#endif
return 0;
}
return (B & ((unsigned char)1 << Index)) ? 1 : 0;
}
#ifdef XEINTDIV
/*---+---------------------------------------------------------------
xDiv_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xDiv_SDL_Octet(
SDL_Octet i,
SDL_Octet k )
#else
SDL_Octet xDiv_SDL_Octet( i, k )
SDL_Octet i;
SDL_Octet k;
#endif
{
if ( k == 0 ) {
xSDLOpError("Division in sort Octet", "Octet division with 0" );
return 0;
} else
return (SDL_Octet)(i/k);
}
/*---+---------------------------------------------------------------
xMod_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xMod_SDL_Octet(
SDL_Octet i,
SDL_Octet k )
#else
SDL_Octet xMod_SDL_Octet( i, k )
SDL_Octet i;
SDL_Octet k;
#endif
{
if ( k == 0 ) {
xSDLOpError("Mod operator in sort Octet", "Right operand is 0" );
return 0;
} else
return (SDL_Octet)(i%k);
}
/*---+---------------------------------------------------------------
xRem_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xRem_SDL_Octet(
SDL_Octet i,
SDL_Octet k )
#else
SDL_Octet xRem_SDL_Octet( i, k )
SDL_Octet i;
SDL_Octet k;
#endif
{
if ( k == 0 ) {
xSDLOpError("Rem operator in sort Octet", "Right operand is 0" );
return 0;
} else
return (SDL_Octet)(i%k);
}
#endif
/* XEINTDIV */
/*---+---------------------------------------------------------------
xBitStr_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xBitStr_SDL_Octet (
SDL_Charstring C )
#else
SDL_Octet xBitStr_SDL_Octet ( C )
SDL_Charstring C;
#endif
{
SDL_Octet Result;
int len, i;
len = xLength_SDL_Charstring(C);
if (len > 8) {
#ifdef XECSOP
xSDLOpError("BitStr in sort Octet",
"An Octet should consist of not more than 8 characters 0 or 1." );
#endif
return (SDL_Octet)0;
}
Result = 0;
for (i=1; i<=len; i++) {
Result <<= 1;
if (C[i] == '1') {
Result++;
} else if (C[i] != '0') {
#ifdef XECSOP
xSDLOpError("BitStr in sort Octet",
"An Octet should consist only of characters 0 or 1." );
#endif
return (SDL_Octet)0;
}
}
for ( ; i<=8; i++) {
Result <<= 1;
}
return Result;
}
/*---+---------------------------------------------------------------
xHexStr_SDL_Octet
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xHexStr_SDL_Octet (
SDL_Charstring C )
#else
SDL_Octet xHexStr_SDL_Octet ( C )
SDL_Charstring C;
#endif
{
SDL_Octet Result;
if (xLength_SDL_Charstring(C) != 2) {
#ifdef XECSOP
xSDLOpError("HexStr in sort Octet",
"An Octet should consist of 2 HEX values." );
#endif
return (SDL_Octet)0;
}
if ( '0' <= C[1] && C[1] <= '9') {
Result = (SDL_Octet)(16 * ((int)(C[1]) - '0'));
} else if ( 'A' <= C[1] && C[1] <= 'F') {
Result = (SDL_Octet)(16 * ((int)(C[1]) - 'A' + 10));
} else if ( 'a' <= C[1] && C[1] <= 'f') {
Result = (SDL_Octet)(16 * ((int)(C[1]) - 'a' + 10));
} else {
#ifdef XECSOP
xSDLOpError("HexStr in sort Octet",
"Illegal character in Charstring (not digit or a-f)." );
#endif
return (SDL_Octet)0;
}
if ( '0' <= C[2] && C[2] <= '9') {
Result += (SDL_Octet)(((int)(C[2]) - '0'));
} else if ( 'A' <= C[2] && C[2] <= 'F') {
Result += (SDL_Octet)(((int)(C[2]) - 'A' + 10));
} else if ( 'a' <= C[2] && C[2] <= 'f') {
Result += (SDL_Octet)(((int)(C[2]) - 'a' + 10));
} else {
#ifdef XECSOP
xSDLOpError("HexStr in sort Octet",
"Illegal character in Charstring (not digit or a-f)." );
#endif
return (SDL_Octet)0;
}
return Result;
}
#endif
/* XNOUSEOFOCTETBITSTRING */
/*** Octet_String **************************************************/
#ifndef XNOUSEOFOCTETBITSTRING
/*---+---------------------------------------------------------------
yAddr_SDL_Octet_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet * yAddr_SDL_Octet_String(
SDL_Octet_String *B,
SDL_Integer Index)
#else
SDL_Octet * yAddr_SDL_Octet_String( B, Index )
SDL_Octet_String *B;
SDL_Integer Index;
#endif
{
if ( (Index < 0) || (Index >= (*B).Length) ) {
#ifdef XECSOP
xSDLOpError("Modify! in sort Octet_String",
"Index out of bounds." );
#endif
if ((*B).Bits != 0)
return &((*B).Bits[0]);
else
return (SDL_Octet *)xAlloc((xptrint)1); /* ??? */
} else
return &((*B).Bits[Index]);
}
/*---+---------------------------------------------------------------
xExtr_SDL_Octet_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet xExtr_SDL_Octet_String(
SDL_Octet_String B,
SDL_Integer Index )
#else
SDL_Octet xExtr_SDL_Octet_String( B, Index )
SDL_Octet_String B;
SDL_Integer Index;
#endif
{
SDL_Octet Result;
if ( (Index < 0) || (Index >= B.Length) ) {
#ifdef XECSOP
xSDLOpError("Extract! in sort Octet_String",
"Index out of bounds." );
#endif
Result = 0;
} else
Result = B.Bits[Index];
if (! B.IsAssigned) xFree_SDL_Bit_String((void **)&B);
return Result;
}
/*---+---------------------------------------------------------------
xBitStr_SDL_Octet_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet_String xBitStr_SDL_Octet_String (
SDL_Charstring C )
#else
SDL_Octet_String xBitStr_SDL_Octet_String ( C )
SDL_Charstring C;
#endif
{
SDL_Octet_String Result;
int i, len;
len = xLength_SDL_Charstring(C);
Result.Length = len/8 + (len%8>0 ? 1 : 0);
Result.IsAssigned = (xbool)0;
Result.IsUsedInSignal = (xbool)0; /* FBI July-1998 */
Result.Bits = xAlloc_SDL_Bit_String((xptrint)Result.Length);
for (i=0; i<len; i++) {
Result.Bits[i/8] <<= 1;
if (C[i+1] == '1') {
Result.Bits[i/8] += 1;
#ifdef XECSOP
} else if (C[i+1] != '0') {
xSDLOpError("BitStr in sort Octet_String",
"An Octet_String should consist of 0 and 1." );
#endif
}
}
for ( ; i<8*Result.Length; i++)
Result.Bits[i/8] <<= 1;
return Result;
}
/*---+---------------------------------------------------------------
xHexStr_SDL_Octet_String
-------------------------------------------------------------------*/
#ifndef XNOPROTO
SDL_Octet_String xHexStr_SDL_Octet_String (
SDL_Charstring C )
#else
SDL_Octet_String xHexStr_SDL_Octet_String ( C )
SDL_Charstring C;
#endif
{
SDL_Octet_String Result;
int C_length, C_index, res;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -