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