use the -newos toolchain even if -elf is present.
[newos.git] / apps / fibo / main.c
blob71bcfc0c01bdceb581862fd2fcf8a53fe261f8ad
1 /*
2 ** Copyright 2002, Manuel J. Petit. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
6 #include <string.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <sys/syscalls.h>
11 static
12 void
13 usage(char const *app)
15 printf("usage: %s [-s] ###\n", app);
16 exit(-1);
19 int
20 main(int argc, char *argv[])
22 int num= 0;
23 int silent= 0;
24 int result;
26 switch(argc) {
27 case 2:
28 num= atoi(argv[1]);
29 break;
30 case 3:
31 if(strcmp(argv[1], "-s")== 0) {
32 num= atoi(argv[2]);
33 silent= 1;
34 } else {
35 usage(argv[0]);
37 break;
38 default:
39 usage(argv[0]);
40 break;
43 if(num< 2) {
44 result= 1;
45 } else {
46 proc_id pid;
47 int retcode;
48 char buffer[64];
49 char *aaargv[]= { argv[0], "-s", buffer, NULL };
50 int aaargc= 3;
52 sprintf(buffer, "%d", num-1);
53 pid= _kern_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, 5, 0);
54 _kern_proc_wait_on_proc(pid, &retcode);
55 result= retcode;
57 sprintf(buffer, "%d", num-2);
58 pid= _kern_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, 5, 0);
59 _kern_proc_wait_on_proc(pid, &retcode);
60 result+= retcode;
63 if(silent) {
64 return result;
65 } else {
66 printf("%d\n", result);
67 return 0;