gdb
[deliverable/binutils-gdb.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 #ifdef vxworks
7
8 # include <stdio.h>
9
10 /* VxWorks does not supply atoi. */
11 static int
12 atoi (z)
13 char *z;
14 {
15 int i = 0;
16
17 while (*z >= '0' && *z <= '9')
18 i = i * 10 + (*z++ - '0');
19 return i;
20 }
21
22 /* I don't know of any way to pass an array to VxWorks. This function
23 can be called directly from gdb. */
24
25 vxmain (arg)
26 char *arg;
27 {
28 char *argv[2];
29
30 argv[0] = "";
31 argv[1] = arg;
32 main (2, argv, (char **) 0);
33 }
34
35 #else /* ! vxworks */
36 # include <stdio.h>
37 # include <stdlib.h>
38 #endif /* ! vxworks */
39
40 #ifdef PROTOTYPES
41 int factorial (int);
42
43 int
44 main (int argc, char **argv, char **envp)
45 #else
46 int
47 main (argc, argv, envp)
48 int argc;
49 char *argv[], **envp;
50 #endif
51 {
52 #ifdef FAKEARGV
53 printf ("%d\n", factorial (1));
54 #else
55 if (argc != 2) {
56 printf ("usage: factorial <number>\n");
57 return 1;
58 } else {
59 printf ("%d\n", factorial (atoi (argv[1])));
60 }
61 #endif
62 return 0;
63 }
64
65 #ifdef PROTOTYPES
66 int factorial (int value)
67 #else
68 int factorial (value) int value;
69 #endif
70 {
71 int local_var;
72
73 if (value > 1) {
74 value *= factorial (value - 1);
75 }
76 local_var = value;
77 return (value);
78 }
This page took 0.036686 seconds and 4 git commands to generate.