-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
203 lines (162 loc) · 6.6 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/****************************************************************
** OrangeBot Project
*****************************************************************
** *
** *
** * *
** ******* *
** *
*****************************************************************
** Debug.h
** Debug macros library for manual code profiling
****************************************************************/
/****************************************************************
** HISTORY VERSION
****************************************************************
** 1.0
** reworked an older version of the macros to be more consistent
****************************************************************/
/****************************************************************
** KNOWN BUGS
****************************************************************
**
****************************************************************/
/****************************************************************
** DESCRIPTION
****************************************************************
** This library implements file debug with macros
** It's common to want to profile function enter and exit with args with an history
**
** #define ENABLE_DEBUG
** commenting this line in debug.h will safely remove all debug code
**
** DSTART( 0 );
** by using number higher than 0, only calls nested enough will be shown.
** example DSTART( 2 ); will hide all debug from first and second function nesting level
**
** DSTART
** DEND
** Called in the main application to start and end the debug.
** In case of crash, the file won't work properly
** Fixing this requires doing a proper library with a parallel process
** to handle file edits
**
** DPRINT
** Write in the file like a printf while adding the right indents
**
** DPRINT_NOTAB
** Write on file with no indents. Used to write on same line
**
** DENTER
** call manually at the start of each function. Profile name and handle nesting level
**
** DRETURN
** call manually before the return of each function. Profile name and handle nesting level
**
** DENTER_ARG
** DRETURN_ARG
** expanded version that add a user line of text with arguments. Used to profile arguments and return value
****************************************************************/
/****************************************************************
** TODO
****************************************************************
**
****************************************************************/
/****************************************************************
** INCLUDE
****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
//MACRO Debug Library under test
#include "debug.h"
/****************************************************************
** GLOBAL VARIABILE
****************************************************************/
/****************************************************************
** FUNCTIONS
****************************************************************/
//dummy function
extern int my_function( int x );
/****************************************************************
** MAIN
****************************************************************
** INPUT:
** OUTPUT:
** RETURN:
** DESCRIPTION:
****************************************************************/
int main()
{
///----------------------------------------------------------------
/// STATIC VARIABILE
///----------------------------------------------------------------
///----------------------------------------------------------------
/// LOCAL VARIABILE
///----------------------------------------------------------------
///----------------------------------------------------------------
/// CHECK AND INITIALIZATIONS
///----------------------------------------------------------------
//Open debug file and start debugging. Show indentation level zero and above.
DSTART( 0 );
///----------------------------------------------------------------
/// BODY
///----------------------------------------------------------------
printf("reya\n");
//Enter function, write function name and increase indent level
DENTER();
DPRINT( "fully featured debug printf with fully featured argument handling and debug text indentation! %d! ", 42 );
DPRINT_NOTAB( "%s\n", "debug print with no tab");
//Recursive function that calls itself arg times
my_function( 5 );
///----------------------------------------------------------------
/// FINALIZATIONS
///----------------------------------------------------------------
//Return from main
DRETURN();
//Stop debugging and safely close debug file debug.log
DSTOP();
return 0;
} //end function: main
/****************************************************************************
** my_function
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
** recursive function to show off indentation handling
****************************************************************************/
int my_function( int x )
{
///--------------------------------------------------------------------------
/// STATIC VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// LOCAL VARIABILE
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// CHECK
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// INITIALIZATIONS
///--------------------------------------------------------------------------
DENTER_ARG( "x: %d\n", x);
///--------------------------------------------------------------------------
/// BODY
///--------------------------------------------------------------------------
DPRINT("function is doing things.\n");
x--;
if (x > 0)
{
my_function(x);
}
DPRINT("function is doing even more things.\n");
///--------------------------------------------------------------------------
/// FINALIZATIONS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RETURN
///--------------------------------------------------------------------------
DRETURN_ARG( "ret: %d\n", x );
return x;
} //end function: