Fix regression in default.exp caused by _caller_is, etc.
[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 51{
c906108c 52#ifdef FAKEARGV
95e4302a 53 printf ("%d\n", factorial (1)); /* commands.exp: hw local_var out of scope */
c906108c
SS
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
085dd6e6
JM
65#ifdef PROTOTYPES
66int factorial (int value)
67#else
68int factorial (value) int value;
69#endif
c906108c 70{
085dd6e6
JM
71 int local_var;
72
c906108c
SS
73 if (value > 1) {
74 value *= factorial (value - 1);
75 }
085dd6e6 76 local_var = value;
c906108c 77 return (value);
95e4302a 78} /* commands.exp: local_var out of scope */
This page took 1.716429 seconds and 4 git commands to generate.