OSDN Git Service

r284@cf-ppc-macosx: monabuilder | 2008-12-07 10:57:41 +0900
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.hp / gdb.aCC / 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 (char *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 void vxmain (char *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 int main (int argc, char *argv[], char **envp)
41 /*int argc;
42 char *argv[], **envp;*/
43 {
44     int factorial (int);
45 #ifdef usestubs
46     set_debug_traps();
47     breakpoint();
48 #endif
49 #ifdef FAKEARGV
50     printf ("%d\n", factorial (1));
51 #else    
52     if (argc != 2) {
53         printf ("usage:  factorial <number>\n");
54         return 1;
55     } else {
56         printf ("%d\n", factorial (atoi (argv[1])));
57     }
58 #endif
59     return 0;
60 }
61
62 int factorial (int value)
63 /*int value;*/
64 {
65     int  local_var;
66
67     if (value > 1) {
68         value *= factorial (value - 1);
69     }
70     local_var = value;
71     return (value);
72 }