main.cpp
Go to the documentation of this file.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
00028 #include "freppleinterface.h"
00029 #include <iostream>
00030 #include <sstream>
00031 #include <cstring>
00032 #include <cstdlib>
00033 using namespace std;
00034
00035
00036 void usage()
00037 {
00038 cout << "\nfrePPLe v" << FreppleVersion() << " command line application\n"
00039 "\nUsage:\n"
00040 " frepple [options] [files | directories]\n"
00041 "\nThis program reads xml input data, and executes the modeling and\n"
00042 "planning commands included in them.\n"
00043 "The xml input can be provided in the following ways:\n"
00044 " - Passing one or more XML files and/or directories as arguments.\n"
00045 " When a directory is specified, the application will process\n"
00046 " all files with the extension '.xml'.\n"
00047 " - When passing no file or directory arguments, input will be read\n"
00048 " from the standard input. XML data can be piped to the application.\n"
00049 "\nOptions:\n"
00050 " -validate -v Validate the xml input for correctness.\n"
00051 " -check -c Only validate the input, without executing the content.\n"
00052 " -? -h -help Show these instructions.\n"
00053 "\nEnvironment: The variable FREPPLE_HOME optionally points to a\n"
00054 " directory where the initialization files init.xml, init.py,\n"
00055 " frepple.xsd and module libraries will be searched.\n"
00056 "\nReturn codes: 0 when succesfull, non-zero in case of errors\n"
00057 "\nMore information on this program: http://www.frepple.com\n\n"
00058 << endl;
00059 }
00060
00061
00062 int main (int argc, char *argv[])
00063 {
00064
00065
00066 bool validate = false;
00067 bool validate_only = false;
00068 bool input = false;
00069
00070 try
00071 {
00072
00073 for (int i = 1; i < argc; ++i)
00074 {
00075 if (argv[i][0] == '-')
00076 {
00077
00078 if (!strcmp(argv[i],"-validate") || !strcmp(argv[i],"-v"))
00079 validate = true;
00080 else if (!strcmp(argv[i],"-check") || !strcmp(argv[i],"-c"))
00081 validate_only = true;
00082 else
00083 {
00084 if (strcmp(argv[i],"-?")
00085 && strcmp(argv[i],"-h")
00086 && strcmp(argv[i],"-help"))
00087 cout << "\nError: Option '" << argv[i]
00088 << "' not recognized." << endl;
00089 usage();
00090 return EXIT_FAILURE;
00091 }
00092 }
00093 else
00094 {
00095
00096 if (!input)
00097 {
00098
00099 FreppleInitialize();
00100 input = true;
00101 }
00102 FreppleReadXMLFile(argv[i], validate, validate_only);
00103 }
00104 }
00105
00106
00107 if (!input)
00108 {
00109 FreppleInitialize();
00110 FreppleReadXMLFile(NULL, validate, validate_only);
00111 }
00112 }
00113 catch (exception& e)
00114 {
00115 ostringstream ch;
00116 ch << "Error: " << e.what();
00117 FreppleLog(ch.str());
00118 return EXIT_FAILURE;
00119 }
00120 catch (...)
00121 {
00122 FreppleLog("Error: Unknown exception type");
00123 return EXIT_FAILURE;
00124 }
00125 return EXIT_SUCCESS;
00126 }