|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <ctype.h> |
|
17 #include <string.h> |
|
18 #include <iomanip> |
|
19 |
|
20 #include "util.h" |
|
21 |
|
22 char hexChars[] = "0123456789abcdef"; |
|
23 |
|
24 unsigned int HexToVal(const char* aHex) |
|
25 { |
|
26 int shift = 0; |
|
27 int pos = (int)strlen(aHex) -1; |
|
28 unsigned int v = 0; |
|
29 int i; |
|
30 |
|
31 while (pos > 1 || ((!(aHex[0] == '0' && tolower(aHex[1]) == 'x')) && pos >= 0)) |
|
32 { |
|
33 for (i=0; i<16; i++) |
|
34 { |
|
35 if (hexChars[i] == tolower(aHex[pos])) |
|
36 { |
|
37 v += (i << shift); |
|
38 break; |
|
39 } |
|
40 } |
|
41 shift += 4; |
|
42 --pos; |
|
43 } |
|
44 |
|
45 return v; |
|
46 } |
|
47 |
|
48 void DumpBytes(std::ostream& aStream, const unsigned char* aData, unsigned int aLength, unsigned int* aZones, unsigned int aZoneCount) |
|
49 { |
|
50 unsigned int i = 0; |
|
51 unsigned int j = 0; |
|
52 unsigned int dumpLength = (aLength + 7) & ~7UL; |
|
53 unsigned int zone = 0; |
|
54 |
|
55 while (i < dumpLength) |
|
56 { |
|
57 aStream << " "; |
|
58 while (i < dumpLength) |
|
59 { |
|
60 if (i < aLength) |
|
61 { |
|
62 if (aZones |
|
63 && zone < aZoneCount |
|
64 && i == aZones[zone]) |
|
65 { |
|
66 aStream << "["; |
|
67 } |
|
68 else |
|
69 { |
|
70 aStream << " "; |
|
71 } |
|
72 aStream << std::noshowbase << std::setw(2) |
|
73 << std::setfill('0') << std::nouppercase << std::hex |
|
74 << int(aData[i]); |
|
75 |
|
76 if (aZones && ( |
|
77 (zone+1) < aZoneCount && i == aZones[zone+1]) |
|
78 || ((zone+1) == aZoneCount && (i+1) == aLength) |
|
79 ) |
|
80 { |
|
81 aStream << "]"; |
|
82 } |
|
83 else |
|
84 { |
|
85 aStream << " "; |
|
86 } |
|
87 } |
|
88 else |
|
89 { |
|
90 aStream << " "; |
|
91 } |
|
92 |
|
93 ++i; |
|
94 |
|
95 if (i % 8 == 0) |
|
96 { |
|
97 break; |
|
98 } |
|
99 else if (i % 4 == 0) |
|
100 { |
|
101 aStream << " - "; |
|
102 } |
|
103 } |
|
104 |
|
105 aStream << " "; |
|
106 |
|
107 while (j < dumpLength) |
|
108 { |
|
109 if (j < aLength) |
|
110 { |
|
111 if (isprint(aData[j])) |
|
112 { |
|
113 aStream << aData[j]; |
|
114 } |
|
115 else |
|
116 { |
|
117 aStream << "."; |
|
118 } |
|
119 } |
|
120 else |
|
121 { |
|
122 aStream << " "; |
|
123 } |
|
124 |
|
125 ++j; |
|
126 |
|
127 if ((j % 8) == 0) |
|
128 { |
|
129 break; |
|
130 } |
|
131 } |
|
132 |
|
133 aStream << std::endl; |
|
134 } |
|
135 } |
|
136 |
|
137 void DumpBytes(std::ostream& aStream, const unsigned char* aData, unsigned int aLength) |
|
138 { |
|
139 DumpBytes(aStream, aData, aLength, NULL, 0); |
|
140 /* |
|
141 unsigned int i = 0; |
|
142 unsigned int j = 0; |
|
143 unsigned int dumpLength = (aLength + 7) & ~7UL; |
|
144 while (i < dumpLength) |
|
145 { |
|
146 aStream << " "; |
|
147 while (i < dumpLength) |
|
148 { |
|
149 if (i < aLength) |
|
150 { |
|
151 aStream << std::noshowbase << std::setw(2) |
|
152 << std::setfill('0') << std::nouppercase << std::hex |
|
153 << int(aData[i]) << " "; |
|
154 } |
|
155 else |
|
156 { |
|
157 aStream << " "; |
|
158 } |
|
159 |
|
160 ++i; |
|
161 |
|
162 if (i % 8 == 0) |
|
163 { |
|
164 break; |
|
165 } |
|
166 else if (i % 4 == 0) |
|
167 { |
|
168 aStream << "- "; |
|
169 } |
|
170 } |
|
171 |
|
172 aStream << " "; |
|
173 |
|
174 while (j < dumpLength) |
|
175 { |
|
176 if (j < aLength) |
|
177 { |
|
178 if (isprint(aData[j])) |
|
179 { |
|
180 aStream << aData[j]; |
|
181 } |
|
182 else |
|
183 { |
|
184 aStream << "."; |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 aStream << " "; |
|
190 } |
|
191 |
|
192 ++j; |
|
193 |
|
194 if ((j % 8) == 0) |
|
195 { |
|
196 break; |
|
197 } |
|
198 } |
|
199 |
|
200 aStream << std::endl; |
|
201 } |
|
202 */ |
|
203 } |
|
204 |