[go: up one dir, main page]

Menu

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

Download this file

148 lines (134 with data), 5.4 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
/* **************************************************************************
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;
}