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