]>
Commit | Line | Data |
---|---|---|
b79f73df JL |
1 | /* Implement runtime actions for CHILL. |
2 | Copyright (C) 1992,1993 Free Software Foundation, Inc. | |
3 | Author: Wilfried Moser | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <errno.h> | |
24 | #include <string.h> | |
25 | ||
26 | #include "rtltypes.h" | |
27 | #include "iomodes.h" | |
28 | \f | |
29 | /* type definitions */ | |
30 | typedef void (*init_ptr) (); | |
31 | typedef void (*rts_init_ptr) (int *argc, char *argv []); | |
32 | ||
33 | typedef struct INIT_LIST | |
34 | { | |
35 | init_ptr code; | |
36 | struct INIT_LIST *forward; | |
37 | } InitList; | |
38 | ||
39 | InitList *_ch_init_list = 0; | |
40 | ||
41 | /* force linker to get correct RTS functions */ | |
42 | extern rts_init_ptr __RTS_INIT__; | |
43 | extern init_ptr __RTS_MAIN_LOOP__; | |
44 | extern init_ptr __RTS_FETCH_NUMBERS__; | |
45 | extern init_ptr __RTS_FETCH_NAMES__; | |
46 | static init_ptr *rts_dummies[4] = | |
47 | { | |
48 | &__RTS_INIT__, | |
49 | &__RTS_MAIN_LOOP__, | |
50 | &__RTS_FETCH_NUMBERS__, | |
51 | &__RTS_FETCH_NAMES__, | |
52 | }; | |
53 | ||
54 | /* chill argc and argv */ | |
55 | int chill_argc = 0; | |
56 | TVaryingCharType **chill_argv = NULL; | |
57 | ||
58 | /* the program name for debugging purpose */ | |
59 | char *progname = 0; | |
60 | \f | |
61 | extern void *__xmalloc_ (); | |
62 | ||
63 | /* | |
64 | * function __xrealloc_ | |
65 | * | |
66 | * parameter: | |
67 | * ptr pointer to reallocate | |
68 | * size new number of bytes | |
69 | * | |
70 | * returns: | |
71 | * void* | |
72 | * | |
73 | * abstract: | |
74 | * This is the general reallocation routine for libchill | |
75 | * | |
76 | */ | |
77 | ||
78 | void * | |
79 | __xrealloc_ (ptr, size) | |
80 | void *ptr; | |
81 | int size; | |
82 | { | |
83 | void *tmp = realloc (ptr, size); | |
84 | ||
85 | if (!tmp) | |
86 | { | |
87 | fprintf (stderr, "ChillLib: Out of heap space.\n"); | |
88 | fflush (stderr); | |
89 | exit (ENOMEM); | |
90 | } | |
91 | return (tmp); | |
92 | } /* __xrealloc_ */ | |
93 | \f | |
94 | static void | |
95 | setup_argc_argv (argc, argv) | |
96 | int argc; | |
97 | char *argv[]; | |
98 | { | |
99 | int i; | |
100 | ||
101 | chill_argv = __xmalloc_ ((argc + 1) * sizeof (TVaryingCharType *)); | |
102 | for (i = 0; i < argc; i++) | |
103 | { | |
104 | chill_argv[i] = __xmalloc_ (sizeof (TVaryingCharType) + strlen (argv[i]) + 1); | |
105 | chill_argv[i]->len = strlen (argv[i]); | |
106 | strcpy (chill_argv[i]->body, argv[i]); | |
107 | } | |
108 | chill_argv[chill_argc = argc] = NULL; | |
109 | ||
110 | if ((progname = strrchr (argv[0], '/')) == 0) | |
111 | progname = argv[0]; | |
112 | else | |
113 | progname++; | |
114 | ||
115 | } /* setup_argc_argv */ | |
116 | ||
117 | extern void __setexceptionStack (); | |
118 | ||
119 | /*--------- main entry for each CHILL - program ----------*/ | |
120 | int | |
121 | main (argc, argv) | |
122 | int argc; | |
123 | char *argv []; | |
124 | { | |
125 | /* call look up for tasking */ | |
126 | (*__RTS_INIT__) (&argc, argv); | |
127 | ||
128 | /* setup argc and argv */ | |
129 | setup_argc_argv (argc, argv); | |
130 | ||
131 | /* clear exception stack */ | |
132 | __setexceptionStack (0); | |
133 | ||
134 | /* now call code at module level */ | |
135 | while (_ch_init_list) | |
136 | { | |
137 | if (_ch_init_list->code) | |
138 | (*(_ch_init_list->code)) (); | |
139 | _ch_init_list = _ch_init_list->forward; | |
140 | } | |
141 | ||
142 | /* if we have rts linked, something will be done, else just return */ | |
143 | (*__RTS_MAIN_LOOP__) (); | |
144 | ||
145 | return (0); | |
146 | ||
147 | } /* main */ |