~ubuntu-branches/ubuntu/breezy/malaga/breezy

« back to all changes in this revision

Viewing changes to source/malrul.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2005-01-10 11:52:04 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110115204-hpgncw5pb0m1t8i6
Tags: 6.13-5
debian/control (malaga-doc Recommends): Suggest gv as a
postscript-viewer instead of ghostview.  (Closes: #289701).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Malaga, a system for Natural Language Analysis.
2
 
 * Copyright (C) 1995-1999 Bjoern Beutel
3
 
 *
4
 
 * Bjoern Beutel
5
 
 * Universitaet Erlangen-Nuernberg
6
 
 * Abteilung fuer Computerlinguistik
7
 
 * Bismarckstrasse 12
8
 
 * D-91054 Erlangen
9
 
 * e-mail: malaga@linguistik.uni-erlangen.de 
10
 
 *
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.
15
 
 *
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.
20
 
 *
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 */
24
 
 
25
 
/* description ==============================================================*/
26
 
 
27
 
/* This program takes a rule file and compiles it to an intermediate code 
28
 
 * file. */
29
 
 
30
 
/* includes =================================================================*/
31
 
 
32
 
#include <stdio.h>
33
 
#include <stdarg.h>
34
 
#include <string.h>
35
 
#include <stdlib.h>
36
 
#include <time.h>
37
 
#include "basic.h"
38
 
#include "pools.h"
39
 
#include "values.h"
40
 
#include "symbols.h"
41
 
#include "scanner.h"
42
 
#include "files.h"
43
 
#include "rule_type.h"
44
 
#include "rule_code.h"
45
 
#include "rule_compiler.h"
46
 
 
47
 
#ifdef HANGUL
48
 
#include "hangul.h"
49
 
#endif
50
 
 
51
 
#undef GLOBAL
52
 
#define GLOBAL
53
 
 
54
 
/* variables ================================================================*/
55
 
 
56
 
LOCAL string_t program_name; /* the name the program has been called by */
57
 
 
58
 
/* functions ================================================================*/
59
 
 
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. */
63
 
{
64
 
  va_list arg;
65
 
  
66
 
  fprintf (stderr, "%s: ", program_name);
67
 
 
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 (), 
71
 
             current_column ());
72
 
  
73
 
  va_start (arg, format);
74
 
  vfprintf (stderr, format, arg);
75
 
  va_end (arg);
76
 
 
77
 
  fprintf (stderr, "\n");
78
 
 
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 ());
82
 
 
83
 
  exit (1);
84
 
}
85
 
 
86
 
/*---------------------------------------------------------------------------*/
87
 
 
88
 
LOCAL void program_message (void)
89
 
/* Print some information about the program. */
90
 
{
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");
98
 
}
99
 
 
100
 
/*---------------------------------------------------------------------------*/
101
 
 
102
 
GLOBAL int main (int argc, string_t argv[])
103
 
/* The main function of "malrul". */
104
 
{
105
 
  string_t rule_file, object_file, symbol_file;
106
 
  int_t file_type, i;
107
 
 
108
 
  /* Prevent warning about uninitialised variable. */
109
 
  file_type = 0;
110
 
  
111
 
  error = error_handler;
112
 
  program_name = name_in_path (argv[0]);
113
 
 
114
 
#ifdef HANGUL
115
 
  init_hangul ();
116
 
#endif
117
 
 
118
 
  if (argc == 2 && (strcmp_no_case (argv[1], "-version") == 0
119
 
                    || strcmp_no_case (argv[1], "-v") == 0))
120
 
  {
121
 
    program_message ();
122
 
    exit (0);
123
 
  }
124
 
 
125
 
  rule_file = object_file = symbol_file = NULL;
126
 
  for (i = 1; i < argc; i++) 
127
 
  {
128
 
    string_t argument;
129
 
 
130
 
    if (*argv[i] == '-') 
131
 
      argument = new_string (argv[i], NULL);
132
 
    else
133
 
      argument = absolute_path (argv[i], NULL);
134
 
    
135
 
    if (has_extension (argument, "all")) 
136
 
    {
137
 
      set_file_name (&object_file, argument, "all_c");
138
 
      rule_file = new_string (argument, NULL);
139
 
      file_type = ALLO_RULE_FILE;
140
 
    } 
141
 
    else if (has_extension (argument, "mor")) 
142
 
    {
143
 
      set_file_name (&object_file, argument, "mor_c");
144
 
      rule_file = new_string (argument, NULL);
145
 
      file_type = MORPHO_RULE_FILE;
146
 
    } 
147
 
    else if (has_extension (argument, "syn")) 
148
 
    {
149
 
      set_file_name (&object_file, argument, "syn_c");
150
 
      rule_file = new_string (argument, NULL);
151
 
      file_type = SYNTAX_RULE_FILE;
152
 
    } 
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);
157
 
    else 
158
 
      error ("illegal argument \"%s\"", argument);
159
 
 
160
 
    free_mem (&argument);
161
 
  }
162
 
  
163
 
  if (object_file == NULL)
164
 
    error ("no file to compile");
165
 
  
166
 
  if (symbol_file == NULL)
167
 
    error ("missing symbol file name");
168
 
 
169
 
  init_values ();
170
 
  init_symbols (symbol_file);
171
 
 
172
 
  compile_rule_file (rule_file, object_file, file_type);
173
 
    
174
 
  terminate_symbols ();
175
 
  terminate_values ();
176
 
 
177
 
  free_mem (&symbol_file);
178
 
  free_mem (&object_file);
179
 
  free_mem (&rule_file);
180
 
 
181
 
#ifdef HANGUL
182
 
  terminate_hangul ();
183
 
#endif
184
 
 
185
 
  return 0;
186
 
}
187
 
 
188
 
/* end of file ==============================================================*/