00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define FREPPLE_CORE
00028 #include "frepple.h"
00029 #include "freppleinterface.h"
00030 using namespace frepple;
00031 #include <sys/stat.h>
00032
00033
00034 DECLARE_EXPORT(const char*) FreppleVersion()
00035 {
00036 return PACKAGE_VERSION;
00037 }
00038
00039
00040 DECLARE_EXPORT(void) FreppleInitialize()
00041 {
00042
00043 static bool initialized = false;
00044 if (initialized) return;
00045 initialized = true;
00046
00047
00048 LibraryModel::initialize();
00049 LibrarySolver::initialize();
00050
00051
00052 string init = Environment::searchFile("init.py");
00053 if (!init.empty())
00054 {
00055
00056 try
00057 {
00058 CommandPython cmd;
00059 cmd.setFileName(init);
00060 cmd.execute();
00061 }
00062 catch (...)
00063 {
00064 logger << "Exception caught during execution of 'init.py'" << endl;
00065 throw;
00066 }
00067 }
00068
00069
00070 init = Environment::searchFile("init.xml");
00071 if (!init.empty())
00072 {
00073
00074 try { CommandReadXMLFile(init).execute(); }
00075 catch (...)
00076 {
00077 logger << "Exception caught during execution of 'init.xml'" << endl;
00078 throw;
00079 }
00080 }
00081 }
00082
00083
00084 DECLARE_EXPORT(void) FreppleReadXMLData (const char* x, bool validate, bool validateonly)
00085 {
00086 if (x) CommandReadXMLString(string(x), validate, validateonly).execute();
00087 }
00088
00089
00090 DECLARE_EXPORT(void) FreppleReadXMLFile (const char* x, bool validate, bool validateonly)
00091 {
00092 CommandReadXMLFile(x, validate, validateonly).execute();
00093 }
00094
00095
00096 DECLARE_EXPORT(void) FreppleSaveFile(const char* x)
00097 {
00098 CommandSave(x).execute();
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 DECLARE_EXPORT(void) FreppleExit()
00108 {
00109
00110 Environment::setLogFile("");
00111 }
00112
00113
00114 DECLARE_EXPORT(void) FreppleLog(const string& msg)
00115 {
00116 logger << msg << endl;
00117 }
00118
00119
00120 extern "C" DECLARE_EXPORT(void) FreppleLog(const char* msg)
00121 {
00122 logger << msg << endl;
00123 }
00124
00125
00126 extern "C" DECLARE_EXPORT(int) FreppleWrapperInitialize()
00127 {
00128 try {FreppleInitialize();}
00129 catch (...) {return EXIT_FAILURE;}
00130 return EXIT_SUCCESS;
00131 }
00132
00133
00134 extern "C" DECLARE_EXPORT(int) FreppleWrapperReadXMLData(char* d, bool v, bool c)
00135 {
00136 try {FreppleReadXMLData(d, v, c);}
00137 catch (...) {return EXIT_FAILURE;}
00138 return EXIT_SUCCESS;
00139 }
00140
00141
00142 extern "C" DECLARE_EXPORT(int) FreppleWrapperReadXMLFile(const char* f, bool v, bool c)
00143 {
00144 try {FreppleReadXMLFile(f, v, c);}
00145 catch (...) {return EXIT_FAILURE;}
00146 return EXIT_SUCCESS;
00147 }
00148
00149
00150 extern "C" DECLARE_EXPORT(int) FreppleWrapperSaveFile(char* f)
00151 {
00152 try {FreppleSaveFile(f);}
00153 catch (...) {return EXIT_FAILURE;}
00154 return EXIT_SUCCESS;
00155 }
00156
00157
00158 extern "C" DECLARE_EXPORT(int) FreppleWrapperExit()
00159 {
00160 try {FreppleExit();}
00161 catch (...) {return EXIT_FAILURE;}
00162 return EXIT_SUCCESS;
00163 }
00164