Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 54cac1c2268db633d66eeff1b4faa585 > files > 519

frepple-doc-0.8.1-3.fc15.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>C++ API frePPLe: main.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="../styles.css" rel="stylesheet"  type="text/css">
</head>
<body>
<div id="container">

<div id="menubar"> 
<div id="logo" align="center">
<br/><img src='../frepple.bmp' alt="frepple" /><br/>
<a href='http://www.frepple.com/'>
<strong>a Free<br/>Production Planning<br/>Library</strong>
</a>
</div>
<div id="menu">
<br/>
<h3><a href='../Main/HomePage.html'>Main</a></h3>
<h3><a href='../UI/Main.html'>User Manual</a></h3>
<h3><a href='../Tutorial/Main.html'>Tutorial</a></h3>
<h3><a href='../Frepple/Main.html'>Reference Manual</a></h3>
<h3><a href='../Main/FAQ.html'>FAQ</a></h3>
<h3><a href='index.html'>C++ API</a></h3>
<br/>
</div>  
</div>

<div id="content">
<br/>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_88117dff2735251a69c8eb9084477714.html">src</a>
  </div>
</div>
<div class="contents">
<h1>main.cpp</h1><a href="a00217.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/***************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment">  file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/main.cpp $</span>
<a name="l00003"></a>00003 <span class="comment">  version : $LastChangedRevision: 1315 $  $LastChangedBy: jdetaeye $</span>
<a name="l00004"></a>00004 <span class="comment">  date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span>
<a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span>
<a name="l00008"></a>00008 <span class="comment"> *                                                                         *</span>
<a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye                               *</span>
<a name="l00010"></a>00010 <span class="comment"> *                                                                         *</span>
<a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span>
<a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published   *</span>
<a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or  *</span>
<a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version.                                     *</span>
<a name="l00015"></a>00015 <span class="comment"> *                                                                         *</span>
<a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful,         *</span>
<a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
<a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span>
<a name="l00019"></a>00019 <span class="comment"> * General Public License for more details.                                *</span>
<a name="l00020"></a>00020 <span class="comment"> *                                                                         *</span>
<a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public        *</span>
<a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software     *</span>
<a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span>
<a name="l00024"></a>00024 <span class="comment"> * USA                                                                     *</span>
<a name="l00025"></a>00025 <span class="comment"> *                                                                         *</span>
<a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="a00207.html" title="Public header file for C and C++.">freppleinterface.h</a>&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;sstream&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;cstring&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;cstdlib&gt;</span>
<a name="l00033"></a>00033 <span class="keyword">using namespace </span>std;
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="a00217.html#a2ef30c42cbc289d899a8be5d2d8f77d0">00036</a> <span class="keywordtype">void</span> <a class="code" href="a00217.html#a2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>()
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038   cout &lt;&lt; <span class="stringliteral">&quot;\nfrePPLe v&quot;</span> &lt;&lt; <a class="code" href="a00200.html#a597067b13c71006d886fb8c124a1d003">FreppleVersion</a>() &lt;&lt; <span class="stringliteral">&quot; command line application\n&quot;</span>
<a name="l00039"></a>00039     <span class="stringliteral">&quot;\nUsage:\n&quot;</span>
<a name="l00040"></a>00040     <span class="stringliteral">&quot;  frepple [options] [files | directories]\n&quot;</span>
<a name="l00041"></a>00041     <span class="stringliteral">&quot;\nThis program reads XML input data, and executes the modeling and\n&quot;</span>
<a name="l00042"></a>00042     <span class="stringliteral">&quot;planning commands included in them.\n&quot;</span>
<a name="l00043"></a>00043     <span class="stringliteral">&quot;The XML input can be provided in the following ways:\n&quot;</span>
<a name="l00044"></a>00044     <span class="stringliteral">&quot;  - Passing one or more XML files and/or directories as arguments.\n&quot;</span>
<a name="l00045"></a>00045     <span class="stringliteral">&quot;    When a directory is specified, the application will process\n&quot;</span>
<a name="l00046"></a>00046     <span class="stringliteral">&quot;    all files with the extension &apos;.xml&apos;.\n&quot;</span>
<a name="l00047"></a>00047     <span class="stringliteral">&quot;  - When passing no file or directory arguments, input will be read\n&quot;</span>
<a name="l00048"></a>00048     <span class="stringliteral">&quot;    from the standard input. XML data can be piped to the application.\n&quot;</span>
<a name="l00049"></a>00049     <span class="stringliteral">&quot;\nOptions:\n&quot;</span>
<a name="l00050"></a>00050     <span class="stringliteral">&quot;  -validate -v  Validate the XML input for correctness.\n&quot;</span>
<a name="l00051"></a>00051     <span class="stringliteral">&quot;  -check -c     Only validate the input, without executing the content.\n&quot;</span>
<a name="l00052"></a>00052     <span class="stringliteral">&quot;  -? -h -help   Show these instructions.\n&quot;</span>
<a name="l00053"></a>00053     <span class="stringliteral">&quot;\nEnvironment: The variable FREPPLE_HOME optionally points to a\n&quot;</span>
<a name="l00054"></a>00054     <span class="stringliteral">&quot;     directory where the initialization files init.xml, init.py,\n&quot;</span>
<a name="l00055"></a>00055     <span class="stringliteral">&quot;     frepple.xsd and module libraries will be searched.\n&quot;</span>
<a name="l00056"></a>00056     <span class="stringliteral">&quot;\nReturn codes: 0 when succesfull, non-zero in case of errors\n&quot;</span>
<a name="l00057"></a>00057     <span class="stringliteral">&quot;\nMore information on this program: http://www.frepple.com\n\n&quot;</span>
<a name="l00058"></a>00058     &lt;&lt; endl;
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 
<a name="l00062"></a><a class="code" href="a00217.html#a0ddf1224851353fc92bfbff6f499fa97">00062</a> <span class="keywordtype">int</span> <a class="code" href="a00217.html#a0ddf1224851353fc92bfbff6f499fa97">main</a> (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l00063"></a>00063 {
<a name="l00064"></a>00064 
<a name="l00065"></a>00065   <span class="comment">// Storing the chosen options...</span>
<a name="l00066"></a>00066   <span class="keywordtype">bool</span> validate = <span class="keyword">false</span>;
<a name="l00067"></a>00067   <span class="keywordtype">bool</span> validate_only = <span class="keyword">false</span>;
<a name="l00068"></a>00068   <span class="keywordtype">bool</span> input = <span class="keyword">false</span>;
<a name="l00069"></a>00069 
<a name="l00070"></a>00070   <span class="keywordflow">try</span>
<a name="l00071"></a>00071   {
<a name="l00072"></a>00072     <span class="comment">// Analyze the command line arguments.</span>
<a name="l00073"></a>00073     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; argc; ++i)
<a name="l00074"></a>00074     {
<a name="l00075"></a>00075       <span class="keywordflow">if</span> (argv[i][0] == <span class="charliteral">&apos;-&apos;</span>)
<a name="l00076"></a>00076       {
<a name="l00077"></a>00077         <span class="comment">// An option on the command line</span>
<a name="l00078"></a>00078         <span class="keywordflow">if</span> (!strcmp(argv[i],<span class="stringliteral">&quot;-validate&quot;</span>) || !strcmp(argv[i],<span class="stringliteral">&quot;-v&quot;</span>))
<a name="l00079"></a>00079           validate = <span class="keyword">true</span>;
<a name="l00080"></a>00080         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i],<span class="stringliteral">&quot;-check&quot;</span>) || !strcmp(argv[i],<span class="stringliteral">&quot;-c&quot;</span>))
<a name="l00081"></a>00081           validate_only = <span class="keyword">true</span>;
<a name="l00082"></a>00082         <span class="keywordflow">else</span>
<a name="l00083"></a>00083         {
<a name="l00084"></a>00084           <span class="keywordflow">if</span> (strcmp(argv[i],<span class="stringliteral">&quot;-?&quot;</span>)
<a name="l00085"></a>00085               &amp;&amp; strcmp(argv[i],<span class="stringliteral">&quot;-h&quot;</span>)
<a name="l00086"></a>00086               &amp;&amp; strcmp(argv[i],<span class="stringliteral">&quot;-help&quot;</span>))
<a name="l00087"></a>00087             cout &lt;&lt; <span class="stringliteral">&quot;\nError: Option &apos;&quot;</span> &lt;&lt; argv[i]
<a name="l00088"></a>00088             &lt;&lt; <span class="stringliteral">&quot;&apos; not recognized.&quot;</span> &lt;&lt; endl;
<a name="l00089"></a>00089           <a class="code" href="a00217.html#a2ef30c42cbc289d899a8be5d2d8f77d0">usage</a>();
<a name="l00090"></a>00090           <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l00091"></a>00091         }
<a name="l00092"></a>00092       }
<a name="l00093"></a>00093       <span class="keywordflow">else</span>
<a name="l00094"></a>00094       {
<a name="l00095"></a>00095         <span class="comment">// A file or directory name on the command line</span>
<a name="l00096"></a>00096         <span class="keywordflow">if</span> (!input)
<a name="l00097"></a>00097         {
<a name="l00098"></a>00098           <span class="comment">// Initialize the library if this wasn&apos;t done before</span>
<a name="l00099"></a>00099           <a class="code" href="a00200.html#a13335a18ae6783b5c2aa79a73c0947f9">FreppleInitialize</a>();
<a name="l00100"></a>00100           input = <span class="keyword">true</span>;
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102         <a class="code" href="a00200.html#aa13cb0cd869ffbb251070cbfd8710e00">FreppleReadXMLFile</a>(argv[i], validate, validate_only);
<a name="l00103"></a>00103       }
<a name="l00104"></a>00104     }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106     <span class="comment">// When no filenames are specified, we read the standard input</span>
<a name="l00107"></a>00107     <span class="keywordflow">if</span> (!input)
<a name="l00108"></a>00108     {
<a name="l00109"></a>00109       <a class="code" href="a00200.html#a13335a18ae6783b5c2aa79a73c0947f9">FreppleInitialize</a>();
<a name="l00110"></a>00110       <a class="code" href="a00200.html#aa13cb0cd869ffbb251070cbfd8710e00">FreppleReadXMLFile</a>(NULL, validate, validate_only);
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112   }
<a name="l00113"></a>00113   <span class="keywordflow">catch</span> (exception&amp; e)
<a name="l00114"></a>00114   {
<a name="l00115"></a>00115     ostringstream ch;
<a name="l00116"></a>00116     ch &lt;&lt; <span class="stringliteral">&quot;Error: &quot;</span> &lt;&lt; e.what();
<a name="l00117"></a>00117     <a class="code" href="a00200.html#a3e027e800aff06e2e732bb7c2b38e92c">FreppleLog</a>(ch.str());
<a name="l00118"></a>00118     <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l00119"></a>00119   }
<a name="l00120"></a>00120   <span class="keywordflow">catch</span> (...)
<a name="l00121"></a>00121   {
<a name="l00122"></a>00122     <a class="code" href="a00200.html#a3e027e800aff06e2e732bb7c2b38e92c">FreppleLog</a>(<span class="stringliteral">&quot;Error: Unknown exception type&quot;</span>);
<a name="l00123"></a>00123     <span class="keywordflow">return</span> EXIT_FAILURE;
<a name="l00124"></a>00124   }
<a name="l00125"></a>00125   <span class="keywordflow">return</span> EXIT_SUCCESS;
<a name="l00126"></a>00126 }
</pre></div></div>
<hr size="1"/><address style="align: right;"><small>Documentation generated for frePPLe by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"/></a></small></address>
</div>
</div>
</body>
</html>