import gdb-1999-06-28 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / run.c
CommitLineData
c906108c
SS
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. */
11static int
12atoi (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
25vxmain (arg)
26char *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>
085dd6e6 37# include <stdlib.h>
c906108c
SS
38#endif /* ! vxworks */
39
085dd6e6
JM
40#ifdef PROTOTYPES
41int factorial (int);
42
43int
44main (int argc, char **argv, char **envp)
45#else
46int
c906108c
SS
47main (argc, argv, envp)
48int argc;
49char *argv[], **envp;
085dd6e6 50#endif
c906108c
SS
51{
52#ifdef usestubs
53 set_debug_traps();
54 breakpoint();
55#endif
56#ifdef FAKEARGV
57 printf ("%d\n", factorial (1));
58#else
59 if (argc != 2) {
60 printf ("usage: factorial <number>\n");
61 return 1;
62 } else {
63 printf ("%d\n", factorial (atoi (argv[1])));
64 }
65#endif
66 return 0;
67}
68
085dd6e6
JM
69#ifdef PROTOTYPES
70int factorial (int value)
71#else
72int factorial (value) int value;
73#endif
c906108c 74{
085dd6e6
JM
75 int local_var;
76
c906108c
SS
77 if (value > 1) {
78 value *= factorial (value - 1);
79 }
085dd6e6 80 local_var = value;
c906108c
SS
81 return (value);
82}
This page took 0.03463 seconds and 4 git commands to generate.