]> gcc.gnu.org Git - gcc.git/blame - libchill/chillrt0.c
gjavah.c (java_no_argument): Renamed from no_argument to avoid losing due to namespac...
[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
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 */
30typedef void (*init_ptr) ();
31typedef void (*rts_init_ptr) (int *argc, char *argv []);
32
33typedef struct INIT_LIST
34{
35 init_ptr code;
36 struct INIT_LIST *forward;
37} InitList;
38
39InitList *_ch_init_list = 0;
40
41/* force linker to get correct RTS functions */
42extern rts_init_ptr __RTS_INIT__;
43extern init_ptr __RTS_MAIN_LOOP__;
44extern init_ptr __RTS_FETCH_NUMBERS__;
45extern init_ptr __RTS_FETCH_NAMES__;
46static 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 */
55int chill_argc = 0;
56TVaryingCharType **chill_argv = NULL;
57
58/* the program name for debugging purpose */
59char *progname = 0;
60\f
61extern 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
78void *
79__xrealloc_ (ptr, size)
80void *ptr;
81int 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
94static void
95setup_argc_argv (argc, argv)
96int argc;
97char *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
117extern void __setexceptionStack ();
118
119/*--------- main entry for each CHILL - program ----------*/
120int
121main (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 */
This page took 0.044908 seconds and 5 git commands to generate.