revert between 56095 -> 55830 in arch
[AROS.git] / workbench / tools / Edit / Debug.h
bloba40bb432955b1d16fbf968237f9054133c012bd8
1 /*** Debug.h : Simple ressource tracking for Memory allocation
2 **** Written by T.Pierron june 27, 2001
3 ***/
4 // Changed from DEBUG to DEBUG_EDIT to avoid conflicts with <aros/debug.h>
5 #if DEBUG_EDIT /* Do not include this code if DEBUG isn't defined */
7 #if 0
8 #ifdef DEBUG_STUFF /* One arbitrary file must defined this macro */
10 #ifdef AllocVec /* Disable recursiv call! */
11 #undef AllocVec
12 #undef FreeVec
13 #endif
15 /* Track calling times of Alloc & Free */
16 static nballoc = 0, nbfree = 0;
17 void * my_alloc(unsigned long size, unsigned long type)
19 void * result;
20 nballoc ++;
21 result = (void *)AllocVec(size, type);
22 return result;
25 void my_free(void * ptr)
27 nbfree ++;
28 FreeVec(ptr);
30 #else /* simply redirect calls */
32 void * my_alloc (unsigned long, unsigned long);
33 void my_free (void *);
35 /** Redirect original calls **/
36 #define AllocMem(x,y) my_alloc(x,y)
37 #define FreeMem(x,y) my_free(x)
39 #endif
41 /** Redirect original calls **/
42 #define AllocVec(x,y) my_alloc(x,y)
43 #define FreeVec(x) my_free(x)
44 #endif
46 #ifdef DEBUG_UNDO_STUFF /* For undo/redo tracking */
47 extern UBYTE SizeOf[];
48 RBSeg rbs;
49 ULONG rbsz;
51 void print_n(char *p, int n)
53 printf("String: \"");
54 for( ; n; n--, p++)
56 if(*p < ' ') {
57 char *msg = NULL;
58 switch( *p )
60 case '\n': msg = "\\n"; break;
61 case '\t': msg = "\\t"; break;
62 case '\r': msg = "\\r"; break;
63 case 27: msg = "\\e"; break;
65 if(msg) printf("\e[1m%s\e[0m",msg);
66 else printf("\e[1m\\%02x\e[0m", *p);
68 else printf("%c",*p);
70 printf("\"\n");
73 void print_rbseg_buf( ULONG sz )
75 for(;;) {
76 /* The line in the rollback segment may be spread over several chunk */
77 if( rbsz >= sz ) {
78 print_n(rbs->data + (rbsz -= sz), sz);
79 break;
80 } else {
81 print_n(rbs->data, rbsz);
82 sz -= rbsz;
83 rbsz = (rbs = rbs->prev)->max;
88 int get_ln(Project p, LINE *ln)
90 LINE * l = p->the_line;
91 int n = 0;
92 while( l && l != ln ) l = l->next, n++;
93 return (l ? n : -1);
96 /** Show content of rollback segments (note: this is quick and dirty) **/
97 void show_modifs( JBuf jb )
99 RBOps buf; UWORD size, op, i = 0;
101 rbs = jb->rbseg;
102 rbsz = jb->rbsz;
103 printf("\e[1mRBSeg info: size=%d (0x%08lx) rbsz:%d (0x%08lx)\e[0m\n",
104 jb->size,jb->ops,jb->rbsz,jb->rbseg);
106 for(buf = jb->ops, size = jb->size; buf; size=buf->size, buf=buf->prev)
108 while(size != 0)
110 op = LAST_TYPE(buf->data + size);
111 size -= SizeOf[ op ];
112 switch( op )
114 case ADD_CHAR:
116 AddChar buf2 = (AddChar) (buf->data + size);
117 printf("%d \e[4mcharacters added\e[0m line %d, pos %d : ", buf2->nbc,
118 get_ln(PRJ(jb),buf2->line), buf2->pos);
119 print_n(buf2->line->stream+buf2->pos, buf2->nbc);
120 } break;
121 case REM_CHAR:
123 RemChar buf2 = (RemChar) (buf->data + size);
124 printf("%d \e[4mcharacters removed\e[0m line %d, pos %d : ", buf2->nbc,
125 get_ln(PRJ(jb),buf2->line), buf2->pos);
126 print_rbseg_buf(buf2->nbc);
127 } break;
128 case REM_LINE:
129 printf("\e[4mLine removed\e[0m\n");
130 break;
131 case JOIN_LINE:
132 { JoinLine buf2 = (JoinLine) (buf->data + size);
133 printf("\e[4mLine joined\e[0m pos %d\n", buf2->pos);
134 } break;
135 case GROUP_BY:
136 printf("\e[4m%s\e[0m of group\n", i&1 ? "End" : "Start"); i++;
137 break;
138 default:
139 printf("\e[2mUnsupported operation\e[0m (0x%x - size = %d)!\n", op, size);
140 return;
145 #endif
147 #endif