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