comparison src/debug.c @ 34:07177825c91b

fix signed/unsigned to allow very small pst files with only leaf nodes
author carl
date Thu, 12 Jul 2007 14:59:13 -0700
parents 12cac756bc05
children b2f247463b83
comparison
equal deleted inserted replaced
33:12cac756bc05 34:07177825c91b
25 char * name; 25 char * name;
26 struct _debug_func *next; 26 struct _debug_func *next;
27 } *func_head=NULL, *func_ptr=NULL; 27 } *func_head=NULL, *func_ptr=NULL;
28 28
29 29
30 void _debug_init(char *fname);
31 void _debug_msg_info (int line, char *file, int type);
32 void _debug_msg(char* fmt, ...);
33 void _debug_hexdump(unsigned char *x, int y, int cols);
34 void _debug_func(char *function);
35 void _debug_func_ret();
36 void _debug_close();
37 void _debug_write();
38 void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size); 30 void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size);
39 void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col); 31 void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col);
40 void * xmalloc(size_t size); 32 void * xmalloc(size_t size);
41 33
42 // the largest text size we will store in memory. Otherwise we 34 // the largest text size we will store in memory. Otherwise we
51 va_end(ap); 43 va_end(ap);
52 } 44 }
53 45
54 46
55 #define NUM_COL 30 47 #define NUM_COL 30
56 void _pst_debug_hexdump(FILE *out, unsigned char *buf, size_t size, int col) { 48 void _pst_debug_hexdump(FILE *out, unsigned char *buf, size_t size, int col, int delta) {
57 int off = 0, toff; 49 int off = 0, toff;
58 int count = 0; 50 int count = 0;
59 51
60 if (!out) return; // no file 52 if (!out) return; // no file
61 if (col == -1) col = NUM_COL; 53 if (col == -1) col = NUM_COL;
62 fprintf(out, "\n"); 54 fprintf(out, "\n");
63 while (off < size) { 55 while (off < size) {
64 fprintf(out, "%X\t:", off); 56 fprintf(out, "%06X\t:", off+delta);
65 toff = off; 57 toff = off;
66 while (count < col && off < size) { 58 while (count < col && off < size) {
67 fprintf(out, "%02hhx ", buf[off]); 59 fprintf(out, "%02hhx ", buf[off]);
68 off++; count++; 60 off++; count++;
69 } 61 }
70 off = toff; 62 off = toff;
71 while (count < col) { 63 while (count < col) {
72 // only happens at end of block to pad the text over to the text column 64 // only happens at end of block to pad the text over to the text column
73 fprintf(out, " "); 65 fprintf(out, " ");
74 count++; 66 count++;
75 } 67 }
76 count = 0; 68 count = 0;
197 info_ptr = NULL; 189 info_ptr = NULL;
198 } 190 }
199 } 191 }
200 192
201 193
202 void _debug_hexdump(unsigned char *x, int y, int cols) { 194 void _debug_hexdump(unsigned char *x, int y, int cols, int delta) {
203 struct _debug_item *temp; 195 struct _debug_item *temp;
204 if (!debug_fp) return; // no file 196 if (!debug_fp) return; // no file
205 info_ptr = temp_list; 197 info_ptr = temp_list;
206 if (info_ptr) 198 if (info_ptr) temp_list = info_ptr->next;
207 temp_list = info_ptr->next;
208 temp = info_ptr; 199 temp = info_ptr;
209 _debug_write(); 200 _debug_write();
210 info_ptr = temp; 201 info_ptr = temp;
211 _debug_write_hex(info_ptr, x, y, cols); 202 _debug_write_hex(info_ptr, x, y, cols);
212 free(info_ptr->function); 203 free(info_ptr->function);
418 409
419 file_pos = ftell(debug_fp); 410 file_pos = ftell(debug_fp);
420 fwrite(item->function, strlen(item->function)+1, 1, debug_fp); 411 fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
421 fwrite(item->file, strlen(item->file)+1, 1, debug_fp); 412 fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
422 413
423 _pst_debug_hexdump(debug_fp, buf, size, col); 414 _pst_debug_hexdump(debug_fp, buf, size, col, 0);
424 fwrite(&zero, 1, 1, debug_fp); 415 fwrite(&zero, 1, 1, debug_fp);
425 lfile_rec.end = ftell(debug_fp)-file_pos; 416 lfile_rec.end = ftell(debug_fp)-file_pos;
426 417
427 index[2] = ftell(debug_fp); 418 index[2] = ftell(debug_fp);
428 fseek(debug_fp, index_pos, SEEK_SET); 419 fseek(debug_fp, index_pos, SEEK_SET);