-
Notifications
You must be signed in to change notification settings - Fork 26
/
dataBlock.C
99 lines (87 loc) · 2.75 KB
/
dataBlock.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
** dataBlock.C
**
** Author: $Author: phoncs $
** Date: $Date: 2010/09/21 19:37:49 $
**
** $Log: dataBlock.C,v $
** Revision 1.2 2010/09/21 19:37:49 phoncs
** DLW: change name of DWORD to PHDWORD
**
** Revision 1.1.1.1 2000/07/21 01:51:11 purschke
** mlp -- adding the new automakified "basic" module to CVS.
**
**
** Revision 1.4 1998/12/11 22:02:00 markacs
** (stephen markacs) adding log into cvs tags
**
*/
/*
** These are the routines for acces to and modification
** of the data block descriptor which are not inlined within
** dataBlock.h.
**/
#include "dataBlock.h"
/*
** Return the number of "words" stored in the unstructured block
** where a word is defined by the length stored in the descriptor
*/
VALUE_ret getUnstructPacketDataLengthBytes (PACKET_ptr packet_ptr)
{
PHDWORD dataBlockLengthDwords, dataBlockLengthBytes, paddingBytes;
dataBlockLengthDwords = getPacketDataLength(packet_ptr);
if (dataBlockLengthDwords == valueFailure) return valueFailure;
dataBlockLengthBytes = dataBlockLengthDwords*DWORD_SIZE;
paddingBytes = getUnstructPacketDataPadding(packet_ptr);
return dataBlockLengthBytes - paddingBytes;
}
/*
** Return the number of "words" stored in the unstructured block
** where a word is defined by the length stored in the descriptor
*/
VALUE_ret getUnstructPacketDataLengthWords (PACKET_ptr packet_ptr)
{
PHDWORD dataLengthBytes = getUnstructPacketDataLengthBytes(packet_ptr);
UINT wordSize = getUnstructPacketWordSize(packet_ptr);
PHDWORD dataLengthWords = dataLengthBytes/wordSize;
if (dataLengthBytes % wordSize != 0) {
setPacketError(FORMAT_ERR_DATA_INCONSISTENCY,packet_ptr,dataLengthBytes);
return valueFailure;
}
else return dataLengthWords;
}
/*
** Returns the length in DWORDS of the data block after addWords
** "words" of size wordSize are added to the data block in the
** packet. Updates the padding field in the packet.
*/
VALUE_ret extendUnstructPacketDataBlock (PACKET_ptr packet_ptr,
UINT addWords)
{
PHDWORD currentLength;
PHDWORD newLength, newLengthBytes, newLengthDwords;
UINT newPadding;
UINT modulo;
/*
** Get the current data block length
*/
currentLength = getUnstructPacketDataLengthWords(packet_ptr);
if (currentLength == valueFailure) return valueFailure;
/*
** Calculate the new length
*/
newLength = currentLength + addWords;
newLengthBytes = newLength*getUnstructPacketWordSize(packet_ptr);
/*
** Calculate the new length in dwords
*/
modulo = newLengthBytes % DWORD_SIZE;
if (modulo > 0) newPadding = DWORD_SIZE - modulo;
else newPadding = 0;
newLengthDwords = (newLengthBytes + newPadding)/DWORD_SIZE;
/*
** Now set the padding field
*/
setUnstructPacketDataPadding(packet_ptr, newPadding);
return newLengthDwords;
}