summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c891194)
raw | patch | inline | side by side (parent: c891194)
author | ishmal <ishmal@users.sourceforge.net> | |
Sat, 3 Mar 2007 22:31:09 +0000 (22:31 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sat, 3 Mar 2007 22:31:09 +0000 (22:31 +0000) |
buildtool.cpp | patch | blob | history |
diff --git a/buildtool.cpp b/buildtool.cpp
index 458fca5a4d08ae2fdd06599fed38eebfdf4ca027..830d3f05db019a67eee28caecbb5f5b4d06828c9 100644 (file)
--- a/buildtool.cpp
+++ b/buildtool.cpp
*
*/
-#define BUILDTOOL_VERSION "BuildTool v0.6.4, 2007 Bob Jamison"
+#define BUILDTOOL_VERSION "BuildTool v0.6.5, 2007 Bob Jamison"
#include <stdio.h>
#include <unistd.h>
public:
Element()
{
- parent = NULL;
+ init();
}
Element(const String &nameArg)
{
- parent = NULL;
+ init();
name = nameArg;
}
Element(const String &nameArg, const String &valueArg)
{
- parent = NULL;
+ init();
name = nameArg;
value = valueArg;
}
* @param elem the element to output
*/
void print();
+
+ int getLine()
+ { return line; }
protected:
+ void init()
+ {
+ parent = NULL;
+ line = 0;
+ }
+
void assign(const Element &other)
{
parent = other.parent;
namespaces = other.namespaces;
name = other.name;
value = other.value;
+ line = other.line;
}
void findElementsRecursive(std::vector<Element *>&res, const String &name);
String name;
String value;
-
+
+ int line;
};
currentPosition = 0;
}
- void getLineAndColumn(long pos, long *lineNr, long *colNr);
+ int countLines(int begin, int end);
+
+ void getLineAndColumn(int pos, int *lineNr, int *colNr);
void error(char *fmt, ...);
- int peek(long pos);
+ int peek(int pos);
- int match(long pos, const char *text);
+ int match(int pos, const char *text);
- int skipwhite(long p);
+ int skipwhite(int p);
int getWord(int p0, String &buf);
bool keepGoing;
Element *currentNode;
- long parselen;
+ int parselen;
XMLCh *parsebuf;
- String cdatabuf;
- long currentPosition;
- int colNr;
-
+ String cdatabuf;
+ int currentPosition;
};
elem->parent = parent;
elem->attributes = attributes;
elem->namespaces = namespaces;
+ elem->line = line;
std::vector<Element *>::iterator iter;
for (iter = children.begin(); iter != children.end() ; iter++)
return res;
}
-void Parser::getLineAndColumn(long pos, long *lineNr, long *colNr)
+
+int Parser::countLines(int begin, int end)
{
- long line = 1;
- long col = 1;
+ int count = 0;
+ for (int i=begin ; i<end ; i++)
+ {
+ XMLCh ch = parsebuf[i];
+ if (ch == '\n' || ch == '\r')
+ count++;
+ }
+ return count;
+}
+
+
+void Parser::getLineAndColumn(int pos, int *lineNr, int *colNr)
+{
+ int line = 1;
+ int col = 1;
for (long i=0 ; i<pos ; i++)
{
XMLCh ch = parsebuf[i];
void Parser::error(char *fmt, ...)
{
- long lineNr;
- long colNr;
+ int lineNr;
+ int colNr;
getLineAndColumn(currentPosition, &lineNr, &colNr);
va_list args;
- fprintf(stderr, "xml error at line %ld, column %ld:", lineNr, colNr);
+ fprintf(stderr, "xml error at line %d, column %d:", lineNr, colNr);
va_start(args,fmt);
vfprintf(stderr,fmt,args);
va_end(args) ;
-int Parser::peek(long pos)
+int Parser::peek(int pos)
{
if (pos >= parselen)
return -1;
}
-int Parser::match(long p0, const char *text)
+int Parser::match(int p0, const char *text)
{
int p = p0;
while (*text)
-int Parser::skipwhite(long p)
+int Parser::skipwhite(int p)
{
while (p<parselen)
return p;
}
-int Parser::parseElement(int p0, Element *par,int depth)
+
+
+int Parser::parseElement(int p0, Element *par,int lineNr)
{
int p = p0;
if (ch!='<')
return p0;
+ int line, col;
+ //getLineAndColumn(p, &line, &col);
+
p++;
String openTagName;
//Add element to tree
Element *n = new Element(openTagName);
+ n->line = lineNr + countLines(p0, p);
n->parent = par;
par->addChild(n);
//# CHILD ELEMENT
if (ch == '<')
{
- p2 = parseElement(p, n, depth+1);
+ p2 = parseElement(p, n, lineNr + countLines(p0, p));
if (p2 == p)
{
/*
Element *rootNode = new Element("root");
pos = parseVersion(pos);
pos = parseDoctype(pos);
- pos = parseElement(pos, rootNode, 0);
+ pos = parseElement(pos, rootNode, 1);
return rootNode;
}
class MakeBase
{
public:
+
MakeBase()
- {}
+ { line = 0; }
virtual ~MakeBase()
{}
* Get an element value, performing substitutions if necessary
*/
bool getValue(Element *elem, String &result);
+
+ /**
+ * Set the current line number in the file
+ */
+ void setLine(int val)
+ { line = val; }
+
+ /**
+ * Get the current line number in the file
+ */
+ int getLine()
+ { return line; }
protected:
*/
bool getSubstitutions(const String &s, String &result);
+ int line;
};
{
va_list args;
va_start(args,fmt);
- fprintf(stderr, "Make error: ");
+ fprintf(stderr, "Make error line %d: ", line);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args) ;
/**
*
*/
- Task *createTask(Element *elem);
+ Task *createTask(Element *elem, int lineNr);
protected:
//## Execute the command
String outString, errString;
+ trace("BEFORE");
bool ret = executeCommand(cmd.c_str(), "", outString, errString);
+ trace("AFTER");
+
if (f)
{
fprintf(f, "########################### File : %s\n",
delType = DEL_DIR;
if (fileName.size()>0 && dirName.size()>0)
{
- error("<delete> can only have one attribute of file= or dir=");
+ error("<delete> can have one attribute of file= or dir=");
+ return false;
+ }
+ if (fileName.size()==0 && dirName.size()==0)
+ {
+ error("<delete> must have one attribute of file= or dir=");
return false;
}
String ret;
/**
*
*/
-Task *Task::createTask(Element *elem)
+Task *Task::createTask(Element *elem, int lineNr)
{
String tagName = elem->getName();
//trace("task:%s", tagName.c_str());
return NULL;
}
+ task->setLine(lineNr);
+
if (!task->parse(elem))
{
delete task;
*/
bool parseProperty(Element *elem);
- /**
- *
- */
- bool parseTask(Task &task, Element *elem);
-
/**
*
*/
{
status("######## PARSE : %s", uri.getPath().c_str());
+ setLine(0);
+
Parser parser;
Element *root = parser.parseFile(uri.getNativePath());
if (!root)
uri.getNativePath().c_str());
return false;
}
+
+ setLine(root->getLine());
if (root->getChildren().size()==0 ||
root->getChildren()[0]->getName()!="project")
for (unsigned int i=0 ; i<children.size() ; i++)
{
Element *elem = children[i];
+ setLine(elem->getLine());
String tagName = elem->getName();
//########## DESCRIPTION
{
Element *telem = telems[i];
Task breeder(*this);
- Task *task = breeder.createTask(telem);
+ Task *task = breeder.createTask(telem, telem->getLine());
if (!task)
return false;
allTasks.push_back(task);
//more work than targets[tname]=target, but avoids default allocator
targets.insert(std::make_pair<String, Target>(tname, target));
}
+ //######### none of the above
+ else
+ {
+ error("unknown toplevel tag: <%s>", tagName.c_str());
+ return false;
+ }
}