Browse Source

[util] Add optional debug messages to zbin.c

tags/v0.9.6
Michael Brown 16 years ago
parent
commit
96ea558e98
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      src/util/zbin.c

+ 27
- 0
src/util/zbin.c View File

@@ -6,6 +6,8 @@
6 6
 #include "nrv2b.c"
7 7
 FILE *infile, *outfile;
8 8
 
9
+#define DEBUG 0
10
+
9 11
 struct input_file {
10 12
 	void *buf;
11 13
 	size_t len;
@@ -151,6 +153,11 @@ static int process_zinfo_copy ( struct input_file *input,
151 153
 		return -1;
152 154
 	}
153 155
 
156
+	if ( DEBUG ) {
157
+		fprintf ( stderr, "COPY [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
158
+			  output->len, ( output->len + len ) );
159
+	}
160
+
154 161
 	memcpy ( ( output->buf + output->len ),
155 162
 		 ( input->buf + offset ), len );
156 163
 	output->len += len;
@@ -184,6 +191,11 @@ static int process_zinfo_pack ( struct input_file *input,
184 191
 		return -1;
185 192
 	}
186 193
 
194
+	if ( DEBUG ) {
195
+		fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
196
+			  output->len, ( output->len + packed_len ) );
197
+	}
198
+
187 199
 	output->len += packed_len;
188 200
 	if ( output->len > output->max_len ) {
189 201
 		fprintf ( stderr, "Output buffer overrun on pack\n" );
@@ -200,6 +212,8 @@ static int process_zinfo_subtract ( struct input_file *input,
200 212
 	size_t offset = subtract->offset;
201 213
 	void *target;
202 214
 	long delta;
215
+	unsigned long old;
216
+	unsigned long new;
203 217
 
204 218
 	if ( ( offset + datasize ) > output->len ) {
205 219
 		fprintf ( stderr, "Subtract at %#zx outside output buffer\n",
@@ -214,21 +228,34 @@ static int process_zinfo_subtract ( struct input_file *input,
214 228
 	switch ( datasize ) {
215 229
 	case 1: {
216 230
 		uint8_t *byte = target;
231
+		old = *byte;
217 232
 		*byte += delta;
233
+		new = *byte;
218 234
 		break; }
219 235
 	case 2: {
220 236
 		uint16_t *word = target;
237
+		old = *word;
221 238
 		*word += delta;
239
+		new = *word;
222 240
 		break; }
223 241
 	case 4: {
224 242
 		uint32_t *dword = target;
243
+		old = *dword;
225 244
 		*dword += delta;
245
+		new = *dword;
226 246
 		break; }
227 247
 	default:
228 248
 		fprintf ( stderr, "Unsupported subtract datasize %d\n",
229 249
 			  datasize );
230 250
 		return -1;
231 251
 	}
252
+
253
+	if ( DEBUG ) {
254
+		fprintf ( stderr, "SUBx [%#zx,%#zx) (%#lx+(%#lx/%#lx)-(%#lx/%#lx)) = %#lx\n",
255
+			  offset, ( offset + datasize ), old, output->len, subtract->divisor,
256
+			  input->len, subtract->divisor, new );
257
+	}
258
+
232 259
 	return 0;
233 260
 }
234 261
 

Loading…
Cancel
Save