1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/***************************************
$Header: /cvs/src/jbofihe/main.c,v 1.29 2001/03/09 22:18:56 richard Exp $
Top level file.
***************************************/
/**********************************************************************
* Copyright (C) Richard P. Curnow 1998-2001
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "nodes.h"
#include "functions.h"
#include "version.h"
/* The node into which the parser inserts the top node of the parse
tree */
TreeNode *top;
extern int yydebug;
extern int yyparse(void);
extern int full_yyparse(void);
extern DriverVector latex_driver, latex_block_driver;
extern DriverVector textout_driver, text_block_driver;
extern DriverVector html_driver;
/* Flag set by yyerror - i.e. there were syntax errors that were cleaned up so
didn't get reported by yyparse */
static int had_syntax_error;
/* Flag set in lexical analyser + morphology block, if there are invalid words
in the input stream. This causes the run to be aborted before the parse
phase. */
int had_bad_tokens;
/* Optional parameters to be read by backends */
int opt_output_width;
int insert_elidables;
/* Flag to allow cultural rafsi within lujvo (and as part of slinku'i test) */
int allow_cultural_rafsi;
/* Flag to use parser that requires all elidable separators and terminators to
be present */
int require_elidables;
/* Flag to show which elidables could safely have been elided but weren't,
and whether a verbose report is required */
int show_elisions;
int show_elisions_verbose;
/* Flag to display backtrace when a syntax error arises */
int show_backtrace;
/* Flag to show dictionary defects */
int show_dictionary_defects;
/* Error routine invoked from the parser */
void yyerror(char *s) {
/* Printing out the token dump is now done in tracebk.c */
had_syntax_error = 1;
}
/* Handle signals */
void
handle_signal(int x)
{
fprintf(stderr,"\n"
"--------------------------------------------------------------------------\n"
"An unexpected error has occurred whilst running jbofihe.\n\n"
"Please submit a report to <jbofihe@go.to>, with at least this information:\n"
" Version of jbofihe (jbofihe -v)\n"
" Command line options\n"
" The input text\n"
"--------------------------------------------------------------------------\n");
exit(1);
}
/* Print out usage information */
static void
show_usage(void)
{
fprintf(stderr, "jbofihe version %s\n", version_string);
fprintf(stderr, "Copyright 1998-2001 Richard P. Curnow <rpc@myself.com>\n\n"
"-k Show token lists before and after preprocessing\n"
"-t Show edited parse tree\n"
"-tf Show full parse tree\n"
"\n"
"These options produce formatted Lojban + partial English translation\n"
"-l Produce LaTeX output\n"
"-x Produce plain text output\n"
"-H Produce HTML output\n"
"-b Produce 'blocked' output (LaTeX & plain text only)\n"
"-w <width> Set output width (plain text)\n"
"\n"
"These options relate to handling elidable separators/terminators\n"
"-ie Display elided separators and terminators\n"
"-re Require elidable separators and terminators to be present\n"
"-se Show elidable separators/terminators that could be omitted\n"
"-sev Ditto, plus verbose detail\n"
"\n"
"These options relate to grammar options\n"
"-cr Allow cultural rafsi in lujvo (Reference Grammar section 4.16)\n"
"\n"
"These options relate to help & debug\n"
"-v Show version number and exit\n"
"-h Show this help information\n"
"-? Show this help information\n"
"-m Show memory usage statistics\n"
"-d Show debug information\n"
"-dd Report missing dictionary entries to stderr\n"
"-bt Show parser state backtrace when a syntax error occurs\n"
);
}
/* Main routine */
int
main (int argc, char **argv)
{
char *filename = NULL;
FILE *in = NULL;
int result;
int debug;
int token_lists;
int show_tree;
int full_tree;
int gloss;
int block;
int latex;
int textout;
int htmlout;
int show_memory;
debug = 0;
token_lists = 0;
show_tree = 0;
full_tree = 0;
gloss = 0;
latex = 0;
textout = 0;
htmlout = 0;
block = 0;
show_memory = 0;
opt_output_width = 79;
insert_elidables = 0;
require_elidables = 0;
show_elisions = 0;
show_elisions_verbose = 0;
allow_cultural_rafsi = 0;
show_backtrace = 0;
show_dictionary_defects = 0;
had_bad_tokens = 0;
while (++argv, --argc) {
if (!strcmp(*argv, "-d")) {
debug = 1;
} else if (!strcmp(*argv, "-v")) {
fprintf(stderr, "jbofihe version %s\n", version_string);
exit(0);
} else if (!strcmp(*argv, "-k")) {
token_lists = 1;
} else if (!strcmp(*argv, "-g")) {
gloss = 1;
} else if (!strcmp(*argv, "-t")) {
show_tree = 1;
} else if (!strcmp(*argv, "-tf")) {
show_tree = 1;
full_tree = 1;
} else if (!strcmp(*argv, "-l")) {
latex = 1;
} else if (!strcmp(*argv, "-x")) {
textout = 1;
} else if (!strcmp(*argv, "-H")) {
htmlout = 1;
} else if (!strcmp(*argv, "-b")) {
block = 1;
} else if (!strcmp(*argv, "-m")) {
show_memory = 1;
} else if (!strcmp(*argv, "-ie")) {
insert_elidables = 1;
} else if (!strcmp(*argv, "-re")) {
require_elidables = 1;
} else if (!strcmp(*argv, "-se")) {
show_elisions = 1;
} else if (!strcmp(*argv, "-sev")) {
show_elisions = 1;
show_elisions_verbose = 1;
} else if (!strcmp(*argv, "-cr")) {
allow_cultural_rafsi = 1;
} else if (!strcmp(*argv, "-bt")) {
show_backtrace = 1;
} else if (!strcmp(*argv, "-dd")) {
show_dictionary_defects = 1;
} else if (!strncmp(*argv, "-w", 2)) {
if (strlen(*argv) > 2) {
opt_output_width = atoi(*argv + 2);
} else {
/* Get next argument */
--argc, ++argv;
opt_output_width = atoi(*argv);
}
} else if (!strcmp(*argv, "--help")) {
show_usage();
exit(0);
} else if (!strcmp(*argv, "-h")) {
show_usage();
exit(0);
} else if (!strcmp(*argv, "-?")) {
show_usage();
exit(0);
} else if (!strncmp(*argv, "-", 1)) {
fprintf(stderr, "Unrecognized command line option %s\n", *argv);
exit(1);
} else {
filename = *argv;
}
}
/* Check flag compatibility */
if (require_elidables && show_elisions) {
fprintf(stderr, "-re and -se switches are not compatible, -se ignored\n");
show_elisions = 0;
}
#if !defined(EXPOSE_SIGNALS)
signal(SIGABRT, handle_signal);
#if !defined(DJGPP)
/* This signal doesn't seem to be defined on DJGPP */
signal(SIGBUS, handle_signal);
#endif
signal(SIGSEGV, handle_signal);
#endif
lex2_initialise();
if (filename) {
in = fopen(filename, "r");
if (!in) {
fprintf(stderr, "Could not open %s for input\n", filename);
exit(1);
}
}
parse_file(in ? in : stdin);
if (in) fclose(in);
if (had_bad_tokens) {
return 3;
}
if (token_lists) {
printf("\nToken list before preprocessing\n\n");
show_tokens();
}
preprocess_tokens();
/* Check again, lex2 can detect bad constructs as well. */
if (had_bad_tokens) {
return 3;
}
if (token_lists) {
printf("------------------------------\n"
"Token list after preprocessing\n\n");
show_tokens();
printf("------------------------------\n\n");
}
#if 1
yydebug = debug;
had_syntax_error = 0;
if (require_elidables) {
result = full_yyparse();
} else {
result = yyparse();
}
if (result == 0 && !had_syntax_error) {
expand_bahe_ui(top);
error_scan(top);
if (show_tree) {
if (!full_tree) {
compress_singletons(top);
}
print_parse_tree(top);
} else if (latex || textout || htmlout) {
terms_processing(top);
do_conversions(top);
tense_processing(top);
connectives_processing(top);
relative_clause_processing(top);
add_bracketing_tags(top);
if (latex) {
do_output(top, block ? &latex_block_driver : &latex_driver);
} else if (textout) {
do_output(top, block ? &text_block_driver: &textout_driver);
} else if (htmlout) {
do_output(top, &html_driver);
}
} else {
compress_singletons(top);
print_bracketed_text(top, gloss);
}
}
#endif
if (show_memory) {
print_memory_statistics();
}
return result ? 1 : had_syntax_error ? 2 : 0;
}
|