[gdb/testsuite] Factor out lib/valgrind.exp
[external/binutils.git] / gdb / testsuite / gdb.base / run.c
1 /*
2  *      This simple classical example of recursion is useful for
3  *      testing stack backtraces and such.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include "../lib/unbuffer_output.c"
10
11 int factorial (int);
12
13 int
14 main (int argc, char **argv, char **envp)
15 {
16   gdb_unbuffer_output ();
17
18 #ifdef FAKEARGV
19     printf ("%d\n", factorial (1)); /* commands.exp: hw local_var out of scope */
20 #else    
21     if (argc != 2) {
22         printf ("usage:  factorial <number>\n");
23         return 1;
24     } else {
25         printf ("%d\n", factorial (atoi (argv[1])));
26     }
27 #endif
28     return 0;
29 }
30
31 int factorial (int value)
32 {
33     int  local_var;
34
35     if (value > 1) {
36         value *= factorial (value - 1);
37     }
38     local_var = value;
39     return (value);
40 } /* commands.exp: local_var out of scope  */