1
/* This file is part of Malaga, a system for Natural Language Analysis.
2
* Copyright (C) 1995-1999 Bjoern Beutel
5
* Universitaet Erlangen-Nuernberg
6
* Abteilung fuer Computerlinguistik
9
* e-mail: malaga@linguistik.uni-erlangen.de
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25
/* description ==============================================================*/
27
/* This program takes a rule file and compiles it to an intermediate code
30
/* includes =================================================================*/
43
#include "rule_type.h"
44
#include "rule_code.h"
45
#include "rule_compiler.h"
54
/* variables ================================================================*/
56
LOCAL string_t program_name; /* the name the program has been called by */
58
/* functions ================================================================*/
60
LOCAL void error_handler (string_t format, ...) NO_RETURN;
61
LOCAL void error_handler (string_t format, ...)
62
/* Print an error message and exit. */
66
fprintf (stderr, "%s: ", program_name);
68
if (current_line_number () != -1)
69
fprintf (stderr, "file \"%s\", line %ld, column %ld: ",
70
name_in_path (current_file_name ()), current_line_number (),
73
va_start (arg, format);
74
vfprintf (stderr, format, arg);
77
fprintf (stderr, "\n");
79
if (getenv ("MALAGA_MODE") != NULL && current_line_number () != -1)
80
printf ("SHOW \"%s\":%ld:%ld\n",
81
current_file_name (), current_line_number (), current_column ());
86
/*---------------------------------------------------------------------------*/
88
LOCAL void program_message (void)
89
/* Print some information about the program. */
91
printf ("%s (%s) - Copyright (C) 1995-1999 Bjoern Beutel\n",
92
program_name, MALAGA_VERSION);
93
printf ("It is part of Malaga, a system for Natural Language Analysis.\n");
94
printf ("This program comes with ABSOLUTELY NO WARRANTY.\n");
95
printf ("This is free software which you may redistribute "
96
"under certain conditions.\n");
97
printf ("For details, refer to the GNU General Public License.\n");
100
/*---------------------------------------------------------------------------*/
102
GLOBAL int main (int argc, string_t argv[])
103
/* The main function of "malrul". */
105
string_t rule_file, object_file, symbol_file;
108
/* Prevent warning about uninitialised variable. */
111
error = error_handler;
112
program_name = name_in_path (argv[0]);
118
if (argc == 2 && (strcmp_no_case (argv[1], "-version") == 0
119
|| strcmp_no_case (argv[1], "-v") == 0))
125
rule_file = object_file = symbol_file = NULL;
126
for (i = 1; i < argc; i++)
131
argument = new_string (argv[i], NULL);
133
argument = absolute_path (argv[i], NULL);
135
if (has_extension (argument, "all"))
137
set_file_name (&object_file, argument, "all_c");
138
rule_file = new_string (argument, NULL);
139
file_type = ALLO_RULE_FILE;
141
else if (has_extension (argument, "mor"))
143
set_file_name (&object_file, argument, "mor_c");
144
rule_file = new_string (argument, NULL);
145
file_type = MORPHO_RULE_FILE;
147
else if (has_extension (argument, "syn"))
149
set_file_name (&object_file, argument, "syn_c");
150
rule_file = new_string (argument, NULL);
151
file_type = SYNTAX_RULE_FILE;
153
else if (has_extension (argument, "sym_c"))
154
set_file_name (&symbol_file, argument, NULL);
155
else if (has_extension (argument, "esym_c"))
156
set_file_name (&symbol_file, argument, NULL);
158
error ("illegal argument \"%s\"", argument);
160
free_mem (&argument);
163
if (object_file == NULL)
164
error ("no file to compile");
166
if (symbol_file == NULL)
167
error ("missing symbol file name");
170
init_symbols (symbol_file);
172
compile_rule_file (rule_file, object_file, file_type);
174
terminate_symbols ();
177
free_mem (&symbol_file);
178
free_mem (&object_file);
179
free_mem (&rule_file);
188
/* end of file ==============================================================*/