1
1
#include <stdio.h>
2
2
#include <stdlib.h>
3
3
4
- #define DEBUG (fmt , ...) fprintf (stderr, fmt, __VA_ARGS__)
4
+ #ifdef DEBON
5
+ # define DEBUG (level , fmt , ...) \
6
+ if (Debug >= level) \
7
+ fprintf (stderr, fmt, __VA_ARGS__)
8
+ #else
9
+ # define DEBUG (level , fmt , ...)
10
+ #endif
11
+
12
+ int Debug = 0 ;
5
13
6
14
int process (int i1 , int i2 )
7
15
{
8
16
int val ;
9
17
10
- DEBUG ("process (%i, %i)\n" , i1 , i2 );
18
+ DEBUG (1 , "process (%i, %i)\n" , i1 , i2 );
11
19
val = i1 * i2 ;
12
- DEBUG ("return %i\n" , val );
20
+ DEBUG (3 , "return %i\n" , val );
13
21
14
22
return val ;
15
23
}
@@ -20,11 +28,13 @@ int main (int argc, char *argv[])
20
28
21
29
if ( argc > 1 )
22
30
arg1 = atoi (argv [1 ]);
23
- if ( argc == 3 )
31
+ if ( argc > 2 )
24
32
arg2 = atoi (argv [2 ]);
33
+ if ( argc == 4 )
34
+ Debug = atoi (& argv [3 ][2 ]);
25
35
26
- DEBUG ("processed %i arguments\n" , argc - 1 );
27
- DEBUG ("arg1 = %i, arg2 = %i\n" , arg1 , arg2 );
36
+ DEBUG (2 , "processed %i arguments\n" , argc - 1 );
37
+ DEBUG (2 , "arg1 = %i, arg2 = %i\n" , arg1 , arg2 );
28
38
printf ("%d\n" , process (arg1 , arg2 ));
29
39
30
40
return 0 ;
0 commit comments