/* **************************************************************************
main.cpp - Main function of eqc
-------------------
begin : Son Okt 21 10:33:44 CEST 2001
copyright : (C) 2001 by Jan Rheinlaender
email : jrheinlaender@users.sourceforge.net
***************************************************************************/
/* **************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdexcept> // *** changed to stdexcept in 0.7
#include "msgdriver.h"
#include "operands.h"
#if ((!defined __MINGW32__) && (!defined _MSC_VER))
#define option option_ // *** hack because of name conflict with optstack.h struct option
#include <argp.h>
#endif
#include "eqc.h"
#include "printing.h"
extern int yyparse(std::string *);
#if ((!defined __MINGW32__) && (!defined _MSC_VER))
/// Argument parsing
const char *argp_program_version = "EQC 1.4.19~beta3";
const char *argp_program_bug_address = "<jrheinlaender@users.sourceforge.net>";
static char doc[] = "Preprocesses EQC files into latex files\
\vThe files given on the command line are processed one by one and a corresponding\
.eqc file is written. This file can then be compiled with LaTeX in the normal way.";
static char args_doc[] = "FILE1 [FILE...]";
static struct argp_option opts[] = {
{"debug", 'd', "LEVEL", 0, "Produce debugging and informational output at level LEVEL" },
{"path", 'p', "PATH", 0, "Path to EQC specific files"},
{"verbose", 'v', 0, 0, "Produce verbose output (same as -d1" },
{"quiet", 'q', 0, 0, "Don't produce any output (same as -d-1)" },
{"silent", 's', 0, 0, "Don't produce any output (same as -d-1)" },
{ 0 }
};
struct arguments {
std::string *file1;
char **files;
int silent, verbose, abort;
std::string path;
int level;
};
// Parse the options
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct arguments *args = (struct arguments*)state->input;
switch (key) {
case 'd':
msg::info().setlevel(arg ? atoi (arg) : 13);
msg::error().setlevel(10);
msg::warn().setlevel(10);
break;
case 'p':
optstack::options->set(o_path, std::string(arg));
std::cerr << "Setting search path for EQC files to " << arg << std::endl;
break;
case 'q':
case 's': msg::info().setlevel(-1); break;
case 'v': msg::info().setlevel(1); break;
//case ARGP_KEY_NO_ARGS: argp_usage (state);
case ARGP_KEY_ARG:
args->file1 = new std::string(arg);
args->files = &(state->argv[state->next]);
state->next = state->argc;
break;
default: return ARGP_ERR_UNKNOWN;
}
return 0;
} // parse_opt()
static struct argp argp = { opts, parse_opt, args_doc, doc };
#endif
/**
@short The main routine of EQC is a loop over all input files supplied on the command line.
@author Jan Rheinlaender
It starts with initializing the necessary structures and then opens the input files one by one. A corresponding output file
with ".eqc" extension is created and the output of the parser directed to this file.
@param argc An integer containing the number of command line arguments
@param argv An array of character arrays containing the command line arguments (input files)
@returns 0 if there were no errors, 1 otherwise
**/
int main(int argc, char **argv) {
msg::init();
int result = 0;
#ifdef _MSC_VER
// *** added in 1.4.1
Digits = 9;
#endif
#if ((!defined __MINGW32__) && (!defined _MSC_VER))
/// Process options
struct arguments args;
args.file1 = NULL; // Prevent crash when eqc is called without a file
argp_parse(&argp, argc, argv, 0, 0, &args);
std::string *file;
std::cout << "This is " << argp_program_version << std::endl;
if (args.file1 == NULL) {
std::cout << "No file given on command line. Call with --help to see command-line syntax" << std::endl;
return result;
}
#endif
// Override GiNaC printing functions to get nicer LaTeX output
set_print_func<power, print_latex>(print_power_ltx);
#if ((defined __MINGW32__) || (defined _MSC_VER))
// Initialize input file list
msg::info().setlevel(0);
--argc; ++argv;
while (argc) { // Parse input, catch all remaining exceptions
try {
std::string fname = *argv;
result = yyparse(&fname);
} catch (std::exception &e) {
MSG_ERROR(0, *argv << ": " << e.what() << endline);
}
argc--;
argv++;
}
#else
try {
if (args.file1 != NULL)
result = yyparse(args.file1);
for (int j = 0; args.files[j]; j++) {
file = new std::string(args.files[j]);
result = yyparse(file);
}
} catch (std::exception &e) {
MSG_ERROR(0, *argv << ": " << e.what() << endline);
}
#endif
return result;
}