1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
* main.cpp - TaskJuggler
*
* Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* As a special exception, you have permission to link this program with
* the Qt3 library and distribute executables, as long as you follow the
* requirements of the GNU GPL version 2 in regard to all of the software
* in the executable aside from Qt3.
*
* $Id: main.cpp 1260 2006-02-02 18:43:38Z cs $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <qapplication.h>
#include <qglobal.h>
#include <qfile.h>
#include "TjMessageHandler.h"
#include "tjlib-internal.h"
#include "taskjuggler.h"
#include "debug.h"
#include "Project.h"
#include "ProjectFile.h"
#include "ScenarioList.h"
#include "Scenario.h"
#include "Optimizer.h"
#include "OptimizerRun.h"
#include "ParserElement.h"
#include "kotrus.h"
void
banner()
{
qWarning(i18n("TaskJuggler v%1 - A Project Management Software")
.arg(VERSION));
}
void
copyright()
{
qWarning
(i18n(
"\nCopyright (c) 2001, 2002, 2003, 2004, 2005, 2006 \n"
"by Chris Schlaeger <cs@kde.org> and Klaas Freitag <freitag@suse.de>\n\n"
"This program is free software; you can redistribute it and/or\n"
"modify it under the terms of version 2 of the GNU General\n"
"Public License as published by the Free Software Foundation.\n\n"
"For more information about TaskJuggler see \n%1\n")
.arg(TJURL));
}
void
usage(QApplication& a)
{
qWarning
(i18n(
"TaskJuggler must be called with at least one file that\n"
"contains the project description and the report definitions.\n"
"\n"
"Usage: %1 [options] <filename1> [<filename2> ...]")
.arg(a.argv()[0]));
qWarning
(i18n(
" --help - print this message\n"
" --version - print the version and copyright info\n"
" -v - same as '--version'\n"
" -s - stop after syntax check\n"
" -M - output include dependencies for\n"
" make utilities\n"
" --makefile <file> - generate include dependencies for make\n"
" utilities into the specified file\n"
" --maxerrors N - stop after N errors. If N is 0 show all\n"
" errors\n"
" --nodepcheck - don't search for dependency loops\n"
" --debug N - print debug output, N must be between\n"
" 0 and 40, the higher N the more output\n"
" is printed\n"
" --dbmode N - activate debug mode only for certain\n"
" parts of the code\n"
" --updatedb - update the Kotrus database with the\n"
" new resource usage information\n"));
qWarning
(i18n(
"To report bugs please follow the instructions in the "
"manual\n"));
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv, false);
int debugLevel = 0;
int debugMode = -1;
int maxErrors = 10;
bool updateKotrusDB = FALSE;
bool checkOnlySyntax = FALSE;
bool generateMakeDepList = FALSE;
bool noDepCheck = FALSE;
bool showHelp = FALSE;
bool showCopyright = FALSE;
bool terminateProgram = FALSE;
QString makeDepFile;
int i;
for (i = 1 ; i < a.argc() && a.argv()[i][0] == '-'; i++)
if (strcmp(a.argv()[i], "--help") == 0)
showCopyright = showHelp = TRUE;
else if (strcmp(a.argv()[i], "--debug") == 0)
{
if (i + 1 >= a.argc())
{
qWarning(i18n("--debug needs numerical argument"));
showCopyright = showHelp = terminateProgram = TRUE;
}
debugLevel = QString(a.argv()[++i]).toInt();
}
else if (strcmp(a.argv()[i], "--dbmode") == 0)
{
if (i + 1 >= a.argc())
{
qWarning(i18n("--dbmode needs numerical argument"));
showCopyright = showHelp = terminateProgram = TRUE;
}
debugMode = QString(a.argv()[++i]).toInt();
}
else if (strcmp(a.argv()[i], "--makefile") == 0)
{
if (i + 1 >= a.argc())
{
qWarning(i18n("--makefile needs filename argument"));
showCopyright = showHelp = terminateProgram = TRUE;
}
makeDepFile = a.argv()[++i];
generateMakeDepList = TRUE;
}
else if (strcmp(a.argv()[i], "--maxerrors") == 0)
{
bool ok;
if (i + 1 >= a.argc() ||
(maxErrors = QString(a.argv()[++i]).toInt(&ok), !ok))
{
qWarning(i18n("--maxerrors needs a numerical argument"));
showCopyright = showHelp = terminateProgram = TRUE;
}
}
else if (strcmp(a.argv()[i], "--version") == 0 ||
strcmp(a.argv()[i], "-v") == 0)
showCopyright = TRUE;
else if (strcmp(a.argv()[i], "-s") == 0)
checkOnlySyntax = TRUE;
else if (strcmp(a.argv()[i], "-M") == 0)
generateMakeDepList = TRUE;
else if (strcmp(a.argv()[i], "--nodepcheck") == 0)
noDepCheck = TRUE;
else if (strcmp(a.argv()[i], "--updatedb") == 0)
updateKotrusDB = TRUE;
else
showCopyright = showHelp = terminateProgram = TRUE;
if (a.argc() - i < 1)
{
if (!showCopyright && !showHelp)
showCopyright = showHelp = TRUE;
terminateProgram = TRUE;
}
if (showCopyright)
{
banner();
copyright();
}
else if (debugLevel > 0)
banner();
if (showHelp)
usage(a);
if (terminateProgram)
exit(EXIT_FAILURE);
DebugCtrl.setDebugLevel(debugLevel);
DebugCtrl.setDebugMode(debugMode);
bool parseErrors = FALSE;
char cwd[1024];
if (getcwd(cwd, 1023) == 0)
qFatal("main(): getcwd() failed");
Project p;
p.setMaxErrors(maxErrors);
bool first = TRUE;
for ( ; i < argc; i++)
{
QString fileName = a.argv()[i];
if (fileName.right(4) == ".tjx")
{
XMLFile* xf = new XMLFile(&p);
if (!xf->readDOM(fileName, QFile::decodeName(cwd) + "/", "", TRUE))
exit(EXIT_FAILURE);
parseErrors |= !xf->parse();
delete xf;
}
else
{
if (fileName != "." &&
fileName.right(4) != ".tjp" &&
fileName.right(4) != ".tji")
{
qWarning(i18n("WARNING: %1 has an unsupported file extension. "
"Please use '.tjp' for toplevel files, '.tji' "
"for included files and '.tjx' for TaskJuggler "
"XML files.")
.arg(fileName));
// parseErrors = TRUE;
}
ProjectFile* pf = new ProjectFile(&p);
if (!pf->open(a.argv()[i], QFile::decodeName(cwd) + "/", "", TRUE))
exit(EXIT_FAILURE);
parseErrors |= !pf->parse();
if (generateMakeDepList)
pf->generateMakeDepList(makeDepFile, !first);
if (first)
first = FALSE;
delete pf;
}
}
p.readKotrus();
bool schedulingErrors = FALSE;
bool logicalErrors = !p.pass2(noDepCheck, schedulingErrors);
if (!schedulingErrors && !(checkOnlySyntax || generateMakeDepList))
{
schedulingErrors = !p.scheduleAllScenarios();
if (updateKotrusDB)
if (parseErrors || logicalErrors || schedulingErrors)
qWarning("Due to errors the Kotrus DB will NOT be "
"updated.");
else
p.updateKotrus();
p.generateReports();
}
return (parseErrors || logicalErrors || schedulingErrors ?
EXIT_FAILURE : EXIT_SUCCESS);
}
|