OSDN Git Service

Update copyrights for the last patch
[pf3gnuchains/gcc-fork.git] / gcc / java / jv-scan.c
1 /* Main for jv-scan
2    Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24
25 #include "obstack.h"            /* We use obstacks in lex.c */
26
27 void fatal VPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
28 void warning VPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
29 void gcc_obstack_init PROTO ((struct obstack *obstack));
30 extern void reset_report PROTO ((void));
31
32 #define JC1_LITE
33 #include "parse.h"
34
35 /* Current input file and output file IO streams.  */
36 FILE *finput, *out;
37
38 /* Current input filename.  */
39 char *input_filename;
40
41 /* Executable name.  */
42 char *exec_name;
43
44 /* Flags matching command line options.  */
45 int flag_find_main = 0;
46 int flag_dump_class = 0;
47 int flag_list_filename = 0;
48
49 /* jc1-lite main entry point */
50 int
51 main (argc, argv)
52   int argc;
53   char **argv;
54 {
55   int i = 1;
56   char *output_file = NULL;
57   long ft;
58
59   exec_name = argv[0];
60
61   /* Default for output */
62   out = stdout;
63
64   /* Process options first */
65   while (argv [i])
66     {
67       if (argv [i][0] == '-')
68         {
69           /* Dump result into a file */
70           if (!strcmp (argv [i], "-o") && i+1 < argc)
71             {
72               argv [i] = NULL;
73               output_file = argv [++i];
74               argv [i] = NULL;
75             }
76
77           /* Print the name of the class that contains main */
78           else if (!strcmp (argv [i], "--print-main"))
79             flag_find_main = 1;
80
81           else if (!strcmp (argv [i], "--list-filename"))
82             flag_list_filename = 1;
83
84           /* List all the classes found in a source file */
85           else if (!strcmp (argv [i], "--list-class"))
86             flag_dump_class = 1;
87
88           else
89             warning ("Unrecognized argument `%s'", argv[i]);
90
91           /* non recognized argument ignored silently */ 
92           argv [i] = NULL;      /* Nullify so it's not considered a file */
93         }
94       i++;
95     }
96
97   /* No flags? Do nothing */
98   if (!flag_find_main && !flag_dump_class)
99     exit (0);
100
101   /* Check on bad usage */
102   if (flag_find_main && flag_dump_class)
103     fatal ("Options `--print-main' and `--list-class' can't be turned on "
104            "at the same time");
105
106   if (output_file && !(out = fopen (output_file, "w")))
107     fatal ("Can't open output file `%s'", output_file);
108
109   ft = ftell (out);
110
111   gcc_obstack_init (&temporary_obstack);
112   java_push_parser_context ();
113
114   for ( i = 1; i < argc; i++ )
115     if (argv [i])
116       {
117         input_filename = argv [i];
118         if ( (finput = fopen (argv [i], "r")) )
119           {
120             java_init_lex ();
121             yyparse ();
122             if (ftell (out) != ft)
123               fputc ('\n', out);
124             ft = ftell (out);
125             fclose (finput);
126             reset_report ();
127           }
128         else
129           fatal ("File not found `%s'", argv [i]);
130       }
131
132   /* Flush and close */
133   if (ftell (out) != ft)
134     fputc ('\n', out);
135   if (!output_file)
136     fclose (out);
137
138   exit (0);
139 }
140
141 /* Error report, memory, obstack initialization and other utility
142    functions */
143
144 void
145 fatal VPROTO((const char *s, ...))
146 {
147 #ifndef ANSI_PROTOTYPES
148   const char *s;
149 #endif
150   va_list ap;
151
152   VA_START (ap, s);
153
154 #ifndef ANSI_PROTOTYPES
155   s = va_arg (ap, const char *);
156 #endif
157
158   fprintf (stderr, "%s: error: ", exec_name);
159   vfprintf (stderr, s, ap);
160   fputc ('\n', stderr);
161   va_end (ap);
162   exit (1);
163 }
164
165 void
166 warning VPROTO((const char *s, ...))
167 {
168 #ifndef ANSI_PROTOTYPES
169   const char *s;
170 #endif
171   va_list ap;
172
173   VA_START (ap, s);
174
175 #ifndef ANSI_PROTOTYPES
176   s = va_arg (ap, const char *);
177 #endif
178
179   fprintf (stderr, "%s: warning: ", exec_name);
180   vfprintf (stderr, s, ap);
181   fputc ('\n', stderr);
182   va_end (ap);
183 }
184
185 void
186 gcc_obstack_init (obstack)
187      struct obstack *obstack;
188 {
189   /* Let particular systems override the size of a chunk.  */
190 #ifndef OBSTACK_CHUNK_SIZE
191 #define OBSTACK_CHUNK_SIZE 0
192 #endif
193   /* Let them override the alloc and free routines too.  */
194 #ifndef OBSTACK_CHUNK_ALLOC
195 #define OBSTACK_CHUNK_ALLOC xmalloc
196 #endif
197 #ifndef OBSTACK_CHUNK_FREE
198 #define OBSTACK_CHUNK_FREE free
199 #endif
200   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
201                   (void *(*) ()) OBSTACK_CHUNK_ALLOC,
202                   (void (*) ()) OBSTACK_CHUNK_FREE);
203 }
204
205 PTR
206 xmalloc (size)
207   size_t size;
208 {
209   register PTR val = (PTR) malloc (size);
210  
211   if (val == 0)
212     fatal ("virtual memory exhausted");
213   return val;
214 }