00001 #include "config.h"
00002 #include "exception.h"
00003
00004 #include <string.h>
00005 #include <fstream>
00006 #include <iostream>
00007
00008 #include <typeinfo>
00009
00010 ostream *mycout;
00011 Configuration *globconfig;
00012
00016 void Configuration::printOptionInfo()
00017 {
00018 (*mycout) << endl;
00019 (*mycout) << " Unificator Options" << endl;
00020 (*mycout) << endl;
00021 (*mycout) << "unificator [OPTIONS] [FILE]" << endl;
00022 (*mycout) << endl;
00023 (*mycout) << "Options:" << endl;
00024 (*mycout) << " -help,-h : print this message" << endl;
00025 (*mycout) << " -step,-s : pause on every step of the unification" << endl;
00026 (*mycout) << " -beep,-b : emit a beep on every step of the unification and at the end (need \"beep\" for linux)" << endl;
00027 (*mycout) << " -nopbv : do not apply Presburger automata verification" << endl;
00028 (*mycout) << " -anniversary : emit a special beep on every step of the unification and at the end" << endl;
00029 (*mycout) << " -info,-i : print unification applied rules" << endl;
00030
00031 (*mycout) << " -latex,-l : print the steps and the final result in latex" << endl;
00032 (*mycout) << " -output,-o : redirect standard output in a file" << endl;
00033 (*mycout) << endl;
00034 (*mycout) << "If [FILE] is not given, the standard input is used to get data." << endl;
00035 printConsol();
00036 }
00037
00041 void Configuration::printConsol()
00042 {
00043 (*mycout) << endl;
00044 (*mycout) << " Unificator Syntax" << endl;
00045 (*mycout) << endl;
00046 (*mycout) << "Commands:" << endl;
00047 (*mycout) << " [TERM] : new term (see documentation for more details)" << endl;
00048 (*mycout) << " help : print this message" << endl;
00049 (*mycout) << " set [OPTION] : activate the option" << endl;
00050 (*mycout) << " set [OPTION] : activate the option" << endl;
00051 (*mycout) << endl;
00052 (*mycout) << "Options:" << endl;
00053 (*mycout) << " step : pause on every step of the unification" << endl;
00054 (*mycout) << " beep : emit a beep on every step of the unification" << endl;
00055 (*mycout) << " info : print unification applied rules" << endl;
00056
00057 (*mycout) << endl;
00058 }
00059
00063 Configuration::Configuration(int argc, char *argv[])
00064 {
00065 inputdatas = NULL;
00066 mycout = NULL;
00067 printRule = false;
00068 pauseEveryStep = false;
00069 NcanbeZero = false;
00070 fileInput = false;
00071 presBurgerVerif = true;
00072 disjonction = true;
00073 writeMode = Configuration::NORMAL;
00074 beep = 0;
00075 bool askhelp = false;
00076
00077 for(int i=1;i<argc;i++)
00078 {
00079 if(argv[i][0]=='-')
00080 {
00081 if((!strcmp(argv[i],"-step"))||(!strcmp(argv[i],"-s")))
00082 pauseEveryStep = true;
00083 else if((!strcmp(argv[i],"-info"))||(!strcmp(argv[i],"-i")))
00084 printRule = true;
00085
00086
00087 else if((!strcmp(argv[i],"-beep"))||(!strcmp(argv[i],"-b")))
00088 beep = 1;
00089 else if((!strcmp(argv[i],"-invbeep"))||(!strcmp(argv[i],"-ib")))
00090 beep = 2;
00091 else if((!strcmp(argv[i],"-anniversary"))||(!strcmp(argv[i],"-ann")))
00092 beep = 3;
00093 else if((!strcmp(argv[i],"-latex"))||(!strcmp(argv[i],"-l")))
00094 writeMode = Configuration::LATEX;
00095 else if(!strcmp(argv[i],"-nopbv"))
00096 presBurgerVerif = false;
00097 else if(!strcmp(argv[i],"-nodisj"))
00098 disjonction = false;
00099 else if((!strcmp(argv[i],"-output"))||(!strcmp(argv[i],"-o")))
00100 {
00101 if(!mycout)
00102 {
00103 i++;
00104 if(i>=argc)
00105 throw OptionException("no output file given");
00106 mycout = new fstream(argv[i],ios::out);
00107 if(mycout->fail())
00108 throw OptionException("can't open the output file");
00109 }
00110 else
00111 throw OptionException("several ouput files");
00112 }
00113 else if((!strcmp(argv[i],"-help"))||(!strcmp(argv[i],"-h")))
00114 askhelp = true;
00115 else
00116 {
00117 throw OptionException(string("unknow option \"") + argv[i] + "\"");
00118 }
00119 }
00120 else
00121 {
00122 if(!inputdatas)
00123 {
00124 fileInput = true;
00125 inputdatas = new fstream(argv[i],ios::in);
00126 if(inputdatas->fail())
00127 throw OptionException("can't open the input file");
00128 }
00129 else
00130 throw OptionException("several input files");
00131 }
00132 }
00133 if(!mycout)
00134 mycout = &cout;
00135 if(!inputdatas)
00136 inputdatas = &cin;
00137
00138 if(askhelp)
00139 {
00140 printOptionInfo();
00141 exit(0);
00142 }
00143 }
00144
00145 Configuration::~Configuration()
00146 {
00147
00148 }
00149