2 * FileToken.cpp - TaskJuggler
4 * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
12 #include "FileToken.h"
16 #include "tjlib-internal.h"
18 FileToken::FileToken(const QString& file, const QString& tp) :
26 m_tokenTypeBuf(INVALID),
31 FileToken::FileToken() :
39 m_tokenTypeBuf(INVALID),
44 QString FileToken::getPath() const
46 if (m_file.find('/') >= 0)
47 return m_file.left(m_file.findRev('/') + 1);
52 void FileToken::returnToken(TokenType tt, const QString& buf)
54 if (m_tokenTypeBuf != INVALID)
56 qFatal("Internal Error: Token buffer overflow!");
63 QString FileToken::cleanupLine(const QString& line)
66 for (uint i = 0; i < line.length(); ++i)
67 if (line[i] != QChar(EOMacro))
73 bool FileToken::readEnvironment()
77 if (nextToken(id) != ID)
79 errorMessage(i18n("Environment name expected"));
84 if (nextToken(token) != RBRACKET)
86 errorMessage(i18n("')' expected"));
90 char *value = getenv (id.ascii());
91 id = ( value ? value : "" );
93 // push expanded macro reverse into ungetC buffer.
94 for (int i = id.length() - 1; i >= 0; --i)
95 m_ungetBuf.append(id[i].latin1());
100 bool FileToken::getDateFragment(QString& token, QChar& c)
107 errorMessage(i18n("Corrupted date"));
112 while ((c = getC()).unicode() != EOFile && c.isDigit())
118 bool FileToken::readMacroCall()
122 /* For error reporting we need to replace the macro call with the macro
123 * text. So we save a copy of the current line buf (the ${ has already
124 * been removed) and copy it over the lineBuf again after we have read the
125 * complete macro call. */
126 QString lineBufCopy = m_lineBuf;
128 if ((tt = nextToken(id)) == QUESTIONMARK)
135 if ((tt = nextToken(id)) != ID && tt != INTEGER)
137 errorMessage(i18n("Macro ID expected"));
143 // Store all arguments in a newly created string list.
145 while ((tt = nextToken(token)) == STRING || tt == ID)
149 errorMessage(i18n("'}' expected"));
154 setLocation(m_file, m_currLine);
155 QString macro = resolve(&sl);
157 if (macro.isNull() && prefix.isEmpty())
160 m_lineBuf = lineBufCopy;
162 // Push pointer to macro on stack. Needed for error handling.
163 m_macroStack.append(getMacro(id));
166 m_ungetBuf.append(QChar(EOMacro));
167 // push expanded macro reverse into ungetC buffer.
168 for (int i = macro.length() - 1; i >= 0; --i)
169 m_ungetBuf.append(macro[i]);