2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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. */
25 #include "obstack.h" /* We use obstacks in lex.c */
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));
34 /* Current input file and output file IO streams. */
37 /* Current input filename. */
40 /* Executable name. */
43 /* Flags matching command line options. */
44 int flag_find_main = 0;
45 int flag_dump_class = 0;
46 int flag_list_filename = 0;
48 /* jc1-lite main entry point */
55 const char *output_file = NULL;
60 /* Default for output */
63 /* Process options first */
66 if (argv [i][0] == '-')
68 /* Dump result into a file */
69 if (!strcmp (argv [i], "-o") && i+1 < argc)
72 output_file = argv [++i];
76 /* Print the name of the class that contains main */
77 else if (!strcmp (argv [i], "--print-main"))
80 else if (!strcmp (argv [i], "--list-filename"))
81 flag_list_filename = 1;
83 /* List all the classes found in a source file */
84 else if (!strcmp (argv [i], "--list-class"))
88 warning ("Unrecognized argument `%s'", argv[i]);
90 /* non recognized argument ignored silently */
91 argv [i] = NULL; /* Nullify so it's not considered a file */
96 /* No flags? Do nothing */
97 if (!flag_find_main && !flag_dump_class)
100 /* Check on bad usage */
101 if (flag_find_main && flag_dump_class)
102 fatal ("Options `--print-main' and `--list-class' can't be turned on "
105 if (output_file && !(out = fopen (output_file, "w")))
106 fatal ("Can't open output file `%s'", output_file);
110 gcc_obstack_init (&temporary_obstack);
111 java_push_parser_context ();
113 for ( i = 1; i < argc; i++ )
116 input_filename = argv [i];
117 if ( (finput = fopen (argv [i], "r")) )
121 if (ftell (out) != ft)
128 fatal ("File not found `%s'", argv [i]);
131 /* Flush and close */
132 if (ftell (out) != ft)
140 /* Error report, memory, obstack initialization and other utility
144 fatal VPROTO((const char *s, ...))
146 #ifndef ANSI_PROTOTYPES
153 #ifndef ANSI_PROTOTYPES
154 s = va_arg (ap, const char *);
157 fprintf (stderr, "%s: error: ", exec_name);
158 vfprintf (stderr, s, ap);
159 fputc ('\n', stderr);
165 warning VPROTO((const char *s, ...))
167 #ifndef ANSI_PROTOTYPES
174 #ifndef ANSI_PROTOTYPES
175 s = va_arg (ap, const char *);
178 fprintf (stderr, "%s: warning: ", exec_name);
179 vfprintf (stderr, s, ap);
180 fputc ('\n', stderr);
185 gcc_obstack_init (obstack)
186 struct obstack *obstack;
188 /* Let particular systems override the size of a chunk. */
189 #ifndef OBSTACK_CHUNK_SIZE
190 #define OBSTACK_CHUNK_SIZE 0
192 /* Let them override the alloc and free routines too. */
193 #ifndef OBSTACK_CHUNK_ALLOC
194 #define OBSTACK_CHUNK_ALLOC xmalloc
196 #ifndef OBSTACK_CHUNK_FREE
197 #define OBSTACK_CHUNK_FREE free
199 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
200 (void *(*) (long)) OBSTACK_CHUNK_ALLOC,
201 (void (*) (void *)) OBSTACK_CHUNK_FREE);
208 register PTR val = (PTR) malloc (size);
211 fatal ("virtual memory exhausted");