OSDN Git Service

Fix another mips typo.
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / main.c
1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2    Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
3
4 This file is part of the GNU Fortran 95 runtime library (libgfor).
5
6 Libgfor is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 Libgfor is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with libgfor; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <math.h>
25 #include <stddef.h>
26
27 #include "libgfortran.h"
28
29 /* This is the offset (in bytes) required to cast from logical(8)* to
30    logical(4)*. and still get the same result.  Will be 0 for little-endian
31    machines and 4 for big-endian machines.  */
32 int l8_to_l4_offset;
33
34
35 /* Figure out endianness for this machine.  */
36
37 #define detetmine_endianness    prefix(determine_endianness)
38 static void
39 determine_endianness (void)
40 {
41   union
42   {
43     GFC_LOGICAL_8 l8;
44     GFC_LOGICAL_4 l4[2];
45   } u;
46
47   u.l8 = 1;
48   if (u.l4[0])
49     l8_to_l4_offset = 0;
50   else if (u.l4[1])
51     l8_to_l4_offset = 1;
52   else
53     runtime_error ("Unable to determine machine endianness");
54 }
55
56
57 static int argc_save;
58 static char **argv_save;
59
60 /* Set the saved values of the command line arguments.  */
61
62 void
63 set_args (int argc, char **argv)
64 {
65   argc_save = argc;
66   argv_save = argv;
67 }
68
69 /* Retrieve the saved values of the command line arguments.  */
70
71 void
72 get_args (int *argc, char ***argv)
73 {
74
75   *argc = argc_save;
76   *argv = argv_save;
77 }
78
79
80 /* Initialize the runtime library.  */
81
82 static void __attribute__((constructor))
83 init (void)
84 {
85   /* Figure out the machine endianness.  */
86   determine_endianness ();
87
88   /* Must be first */
89   init_variables ();
90
91   init_units ();
92
93 #ifdef DEBUG
94   /* Check for special command lines.  */
95
96   if (argc > 1 && strcmp (argv[1], "--help") == 0)
97     show_variables ();
98
99 /*  if (argc > 1 && strcmp(argv[1], "--resume") == 0) resume();  */
100 #endif
101
102   memory_init ();
103   random_seed(NULL,NULL,NULL);
104
105 }
106
107
108 /* Cleanup the runtime library.  */
109
110 static void __attribute__((destructor))
111 cleanup ()
112 {
113   close_units ();
114 }
115