Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

main.cc

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2000 Idan Shoham <idan@m-tech.ab.ca>
00003 **  
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 ** 
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 ** 
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software 
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 #ifdef HAVE_CONFIG_H
00019 #include <config.h>
00020 #endif
00021 
00022 #include <iostream>
00023 #include <cstdio>
00024 #include <list>
00025 #include <unistd.h>
00026 
00027 using namespace std;
00028 
00029 #include "messenger.h"
00030 #include "project.h"
00031 #include "projectFile.h"
00032 
00033 
00034 #if 0
00035 #define DEBUG   1
00036 #endif
00037 
00039 typedef list<const char *> L_FILENAME;
00040 
00044 static void usage(FILE *out, const char *progName)
00045 {
00046   fprintf(out, "USAGE: %s [-d] [-v] [-h] file1 [file2 file3 ...]\n", progName);
00047 }
00048 
00050 void version (FILE * out)
00051 {
00052   // Print some version informations
00053 #if (defined(PACKAGE) && defined(VERSION))
00054   (void) fprintf (out, "%s %s\n", PACKAGE, VERSION);
00055 #else
00056   (void) fprintf (out,
00057                   "No package-version available (due to generation).\n"
00058                   "CVS/RCS informations: $RCSfile: main.cc,v $ $Revision: 1.8 $\n");
00059 #endif
00060 
00061   // Copyright notice
00062   (void) fprintf (out,
00063                   "Copyright (C) 2000 Idan Shoham\n"
00064                   "This program comes with NO WARRANTY.\n"
00065                   "You may redistribute copies of it under the terms of the\n"
00066                   "GNU General Public License.\n"
00067                   "For more information about these matters,\n"
00068                   "see the files named COPYING.\n");
00069 }
00070 
00071 int main(int argc, char **argv)
00072 {
00073     ProjectFile projectFile;
00074     L_FILENAME files;
00075     L_FILENAME::iterator file;
00076     extern char *optarg;
00077     extern int optind, opterr, optopt;
00078     int c;
00079     int nbErrors = 0;
00080 
00081     // Init
00082     MESSENGER::setGlobalDebug(false);
00083 
00084     while ((c = getopt(argc, argv, "vhd")) != -1)
00085       {
00086         switch (c)
00087           {
00088           case 'v': // Version is requested
00089             version(stdout);
00090             return EXIT_SUCCESS;
00091             break;
00092           case 'h': // Help is requested
00093             usage(stdout, argv[0]);
00094             return EXIT_SUCCESS;
00095             break;
00096           case 'd': // Debug is requested
00097             MESSENGER::setGlobalDebug(true);
00098             break;
00099           case '?':
00100           default:
00101             nbErrors++;
00102             break;
00103           }
00104       }
00105 
00106     /*
00107       if (optind < argc)
00108       {
00109       cerr << "Error: no files specified." << endl;
00110       nbErrors++;
00111       }
00112     */
00113     if (nbErrors > 0)
00114       {
00115         usage(stderr, argv[0]);
00116         return EXIT_FAILURE;
00117       }
00118 
00119     while (optind < argc)
00120       {
00121         files.push_back(argv[optind]);
00122         optind++;
00123       }
00124 
00125     try 
00126     {
00127         if ( files.size() == 0 )
00128         {
00129             projectFile.Load("workplan.sched");
00130         }
00131         else
00132         {
00133           for (file = files.begin() ; file != files.end() ; file++)
00134             {
00135               projectFile.Load(*file);
00136             }
00137         }
00138     }
00139     catch ( ProjectFileException & e )
00140     {
00141         cerr << "Project not loaded: " << e.what() << endl;
00142         return EXIT_FAILURE;
00143     }
00144 
00145     try 
00146     {
00147       projectFile.checkComplete();
00148 
00149 #ifdef DEBUG
00150       projectFile.Print();
00151 #endif
00152 
00153       Project project = projectFile.project();
00154       project.DoScheduling();
00155       
00156       Reporter reporter = projectFile.reporter();
00157       reporter.DoReports( &project );
00158     
00159     }
00160     catch ( OpenschedException & e )
00161     {
00162       cerr << e.what() << endl;
00163       return EXIT_FAILURE;
00164     }
00165 
00166     return EXIT_SUCCESS;
00167 }

Generated on Wed Feb 18 22:23:54 2004 for Opensched by doxygen1.2.15