]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/run-hp.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / run-hp.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 #endif /* ! vxworks */
38
39 main (argc, argv, envp)
40 int argc;
41 char *argv[], **envp;
42 {
43 #ifdef usestubs
44 set_debug_traps();
45 breakpoint();
46 #endif
47 #ifdef FAKEARGV
48 printf ("%d\n", factorial (1));
49 #else
50 if (argc != 2) {
51 printf ("usage: factorial <number>\n");
52 return 1;
53 } else {
54 printf ("%d\n", factorial (atoi (argv[1])));
55 }
56 #endif
57 return 0;
58 }
59
60 int factorial (value)
61 int value;
62 {
63 int local_var;
64
65 if (value > 1) {
66 value *= factorial (value - 1);
67 }
68 local_var = value;
69 return (value);
70 }