[go: up one dir, main page]

Menu

[r9]: / src / main.cpp  Maximize  Restore  History

Download this file

161 lines (147 with data), 6.0 kB

  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
/* **************************************************************************
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)) // *** changed in 1.4.0 and 1.4.1
#include <argp.h> // *** added in 1.1
#endif
#include "eqc.h" // *** added in 1.1
#include "printing.h" // *** added in 1.1
extern int yyparse(void *);
#if ((!defined __MINGW32__) && (!defined _MSC_VER)) // *** changed in 1.4.0 and 1.4.1
/// Argument parsing *** added in 1.1
const char *argp_program_version = "EQC 1.4.2";
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();
//message::init();
//func::init();
//equation::init();
//eqc::init();
#ifdef _MSC_VER
// *** added in 1.4.1
Digits = 9;
#endif
#if ((!defined __MINGW32__) && (!defined _MSC_VER)) // *** changed in 1.4.0 and 1.4.1
/// Process options *** added in 1.1
struct arguments args;
argp_parse(&argp, argc, argv, 0, 0, &args);
int result;
std::string *file;
msg::info(0) << "This is " << argp_program_version << endline;
#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)) // *** changed in 1.4.0 and 1.4.1
// Initialize input file list *** changed in 1.0
msg::info().setlevel(0);
--argc; ++argv;
int result;
while (argc) { // Parse input, catch all remaining exceptions
try {
std::string fname = *argv; // *** changed in 1.3
result = yyparse((void *)&fname);
} catch (std::exception &e) {
msg::error(0) << *argv << ": " << e.what() << endline;
}
argc--;
argv++;
} // while()
#else
try {
//std::string fname = "cft-design.tex";
//args.file1 = &fname;
if (args.file1 != NULL)
result = yyparse((void*)args.file1);
for (int j = 0; args.files[j]; j++) {
file = new std::string(args.files[j]);
result = yyparse((void*)file);
}
} catch (std::exception &e) {
msg::error(0) << *argv << ": " << e.what() << endline;
}
#endif
remember_split.clear();
// for (std::map<unsigned, exrec*>::iterator i = remember_split.begin();
// i != remember_split.end(); ) { // *** added in 1.0
// if (i->second != NULL) { // TODO: ERASE_HACK
// if (msg::info().checkprio(0))
// msg::info().prio(0) << i->second->hits << " hits for " << i->second->e << endline;
// //delete(i->second); // TODO: ERASE_HACK
// i->second = NULL;
// remember_split.erase(i, ++i);
// } else
// i++;
// }
return result;
}