setSeed(hash(text));
}
+/**
+ * Constructor.
+ */
+ReNullRandomizer::ReNullRandomizer() :
+ ReSingleSeedRandomizer("dummy")
+{
+}
+
+/**
+ * Modifies the seed.
+ * @param seed the modifier
+ */
+void ReNullRandomizer::modifySeed(int64_t seed)
+{
+ ReUseParameter(seed);
+ // nothing to do!
+}
+
+/**
+ * Returns the next seed.
+ * @return the next seed: 0L
+ */
+ReRandomizer::seed_t ReNullRandomizer::nextSeed64()
+{
+ return 0;
+}
/**
* @brief Constructor.
*/
m_buffer, markerLength);
TRACE1("marker: %s\n", m_buffer.constData());
}
- TRACE1("header-2 %s\n", hexBytes(m_header.constData(), 8).constData());
char* trg;
if (info.length() > 0){
int offset = sizeof(int64_t) + reservedLength + markerLength;
trg = reinterpret_cast<char*>(m_header.data() + offset);
memcpy(trg, info, min(m_header.length() - offset, info.length()));
}
- TRACE1("header-3 %s\n", hexBytes(m_header.constData(), 8).constData());
if (encryptedFrom < m_header.length()){
randomReset();
uint8_t* start = reinterpret_cast<uint8_t*>(m_header.data() + encryptedFrom);
{
return m_header;
}
+
+
seed_t m_lastSetSeed;
};
+/**
+ * A pseudo random generator returning constantly 0.
+ *
+ * This is useful for testing.
+ */
+class ReNullRandomizer: public ReSingleSeedRandomizer{
+public:
+ ReNullRandomizer();
+public:
+
+ // ReRandomizer interface
+public:
+ virtual void modifySeed(int64_t seed);
+ virtual seed_t nextSeed64();
+};
+
class ReCongruentialGeneratorBase {
public:
ReCongruentialGeneratorBase();
static char findCsvSeparator(FILE* fp, char* buffer, size_t bufferSize);
static int lengthOfUInt64(const char* text, int radix, quint64* pValue);
static int lengthOfReal(const char* text, qreal* pValue);
+ /** Returns the integer value of a hexadecimal digit.
+ * @param cc the digit to convert
+ * @return -1: invalid digit<br>
+ * otherwise: the integer value of the digit
+ */
+ inline static int valueOfHexDigit(char cc){
+ int rc = isdigit(cc) ? cc - '0'
+ : (cc = tolower(cc)) >= 'A' && cc <= 'F' ? cc - 'A' + 10 : -1;
+ return rc;
+ }
+
public:
static const QByteArray m_empty;
};
*/
-#ifndef RETRACEACTIVE_HPP
-#define RETRACEACTIVE_HPP
+#ifndef RETRACE_HPP
+#define RETRACE_HPP
#ifdef WITH_TRACE
#define TRACE(format) printf(format);
#define IF_TRACE(statem)
#endif
-QByteArray hexBytes(const void* arg, int length = 8){
+static QByteArray hexBytes(const void* arg, int length = 8){
char buffer[16+1];
const unsigned char* src = reinterpret_cast<const unsigned char*>(arg);
QByteArray rc;
}
return rc;
}
-#endif // RETRACEACTIVE_HPP
+#endif // RETRACE_HPP
#include "../base/rebase.hpp"
#include "../math/remath.hpp"
#include "../net/renet.hpp"
+#include "../expr/reexpr.hpp"
//#include "os/reos.hpp"
#include <QApplication>
}
static void testExpr() {
- /*
extern void testReMFParser();
extern void testRplBenchmark();
extern void testReVM();
extern void testReASTree();
extern void testReVM();
+ testReLexer();
+ /*
//testRplBenchmark();
if (s_allTest){
testReVM();
testReFileSystem();
}
void allTests() {
+ testExpr();
testOs();
testBase();
testGui();
if (s_allTest) {
testBase();
testMath();
- testExpr();
testNet();
testOs();
}
log("run");
}
- void testRead(){
+ void testDirRead(){
readMetaFile();
ReFileMetaDataList list;
checkEqu(3, listInfos(ReIncludeExcludeMatcher::allMatcher(), list));
entry = list.at(2);
checkEqu("tiger.in.india.mov", entry.m_node);
}
- void testWrite(){
+ void testDirWrite(){
addFile("Homunculus.txt");
addFile("NewYork.png");
addFile("tiger.in.india.mov");
m_hostFs = NULL;
m_cryptFs = NULL;
}
- void testWriteRead(){
+ void testDirWriteRead(){
MyReCryptFileSystem cryptFs1(*m_hostFs, m_contentRandom, &m_logger);
- cryptFs1.testWrite();
+ cryptFs1.testDirWrite();
MyReCryptFileSystem cryptFs2(*m_hostFs, m_contentRandom, &m_logger);
- cryptFs2.testRead();
-
-
+ cryptFs2.testDirRead();
}
virtual void run() {
init();
- testWriteRead();
+ testDirWriteRead();
destroy();
}
};
#include "base/rebase.hpp"
#include "expr/reexpr.hpp"
-class TestRplLexer: public ReTest, public ReToken {
+class TestReLexer: public ReTest, public ReToken {
public:
- TestRplLexer() :
- ReTest("ReLexer"),
- ReToken(TOKEN_ID) {
+ TestReLexer() :
+ ReTest("ReLexer"),
+ ReToken(TOKEN_ID) {
}
public:
- void testRplToken() {
+ void testReToken() {
// test constructor values:
checkEqu(TOKEN_ID, tokenType());
checkEqu(0, m_value.m_id);
}
ReToken* checkToken(ReToken* token, RplTokenType type, int id = 0,
- const char* string = NULL) {
+ const char* string = NULL) {
checkEqu(type, token->tokenType());
if (id != 0)
checkEqu(id, token->id());
reader.addSource("<main>", BLANKS1 BLANKS2);
source.addReader(&reader);
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_DECIMAL, ReLexer::SF_TICK,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_DECIMAL, ReLexer::SF_TICK,
+ ReLexer::STORE_ALL);
checkToken(lex.nextToken(), TOKEN_SPACE, 0, BLANKS1);
checkToken(lex.nextToken(), TOKEN_SPACE, 0, BLANKS2);
}
reader.addSource("<main>", blanks);
source.addReader(&reader);
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_TICK,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_TICK,
+ ReLexer::STORE_ALL);
ReToken* token = checkToken(lex.nextToken(), TOKEN_NUMBER);
checkEqu(321, token->asInteger());
token = checkToken(lex.nextNonSpaceToken(), TOKEN_NUMBER);
RBRACKET
};
ReLexer lex(&source, KEYWORDS, ops, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_TICK,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_TICK,
+ ReLexer::STORE_ALL);
checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, SHIFT);
checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, LT);
checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, SHIFT2);
COMMENT_1
};
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
+ ReLexer::STORE_ALL);
checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_MULTILINE,
- "/**/");
+ "/**/");
checkToken(lex.nextToken(), TOKEN_NUMBER);
checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_1, "//\n");
checkToken(lex.nextToken(), TOKEN_NUMBER);
checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_MULTILINE,
- "/***/");
+ "/***/");
checkToken(lex.nextToken(), TOKEN_NUMBER);
checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_1, "// wow\n");
checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_MULTILINE,
- "/*\n*\n*\n**/");
+ "/*\n*\n*\n**/");
}
void testStrings() {
ReSource source;
source.addReader(&reader);
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
+ ReLexer::STORE_ALL);
checkToken(lex.nextToken(), TOKEN_STRING, '"', "abc\t\r\n\a\v");
checkToken(lex.nextToken(), TOKEN_STRING, '\'', "1\tZ!A\t");
}
source.addReader(&reader);
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
+ ReLexer::STORE_ALL);
checkToken(lex.nextToken(), TOKEN_KEYWORD, KEY_IF);
checkToken(lex.nextNonSpaceToken(), TOKEN_KEYWORD, KEY_THEN);
checkToken(lex.nextNonSpaceToken(), TOKEN_KEYWORD, KEY_ELSE);
source.addReader(&reader);
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
+ ReLexer::STORE_ALL);
checkToken(lex.nextToken(), TOKEN_ID, 0, "i");
checkToken(lex.nextNonSpaceToken(), TOKEN_ID, 0, "ifs");
checkToken(lex.nextNonSpaceToken(), TOKEN_ID, 0,
- "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
+ "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
void testBasic() {
source.addReader(&reader);
reader.addSource("<main>", "if i>1 then i=1+2*_x9 fi");
ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_",
- "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
- ReLexer::STORE_ALL);
+ "A-Za-z0-9_", ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C,
+ ReLexer::STORE_ALL);
ReToken* token;
checkToken(lex.nextToken(), TOKEN_KEYWORD, KEY_IF);
checkToken(lex.nextToken(), TOKEN_SPACE, 0);
};
ReLexer lex(&source, KEYWORDS, "=\n+ -\n* /", "=",
COMMENTS, "A-Za-z_", "A-Za-z0-9_", ReLexer::NUMTYPE_ALL,
- ReLexer::SF_LIKE_C, ReLexer::STORE_ALL);
+ ReLexer::SF_LIKE_C, ReLexer::STORE_ALL);
checkT(lex.prioOfOp(O_ASSIGN) < lex.prioOfOp(O_PLUS));
checkEqu(lex.prioOfOp(O_PLUS), lex.prioOfOp(O_MINUS));
checkT(lex.prioOfOp(O_MINUS) < lex.prioOfOp(O_TIMES));
testOperators();
testNumeric();
testSpace();
- testRplToken();
+ testReToken();
}
};
void testReLexer() {
- TestRplLexer test;
+ TestReLexer test;
test.run();
}
INCLUDEPATH = ..
SOURCES += main.cpp \
+ cuReLexer.cpp \
cuReFileSystem.cpp \
cuReCryptFileSystem.cpp \
cuReRandomizer.cpp \
cuReFileUtils.cpp \
cuReByteStorage.cpp \
cuReException.cpp \
+ ../expr/ReSource.cpp \
+ ../expr/ReLexer.cpp \
../base/ReByteStorage.cpp \
../base/ReCharPtrMap.cpp \
../base/ReConfig.cpp \
* @param ... the values for the placeholders in the format.
*/
ReLexException::ReLexException(const ReSourcePosition& position,
- const char* format, ...) :
- ReException("") {
+ const char* format, ...) :
+ ReException("") {
char buffer[64000];
m_message = position.toString().toUtf8();
va_list ap;
* @param type token type
*/
ReToken::ReToken(RplTokenType type) :
- m_tokenType(type),
- m_string(),
- m_printableString()
+ m_tokenType(type),
+ m_string(),
+ m_printableString()
// m_value
{
memset(&m_value, 0, sizeof m_value);
* @param source source to copy
*/
ReToken::ReToken(const ReToken& source) :
- m_tokenType(source.m_tokenType),
- m_string(source.m_string),
- m_printableString(source.m_printableString),
- m_value(source.m_value) {
+ m_tokenType(source.m_tokenType),
+ m_string(source.m_string),
+ m_printableString(source.m_printableString),
+ m_value(source.m_value) {
}
/**
* @brief Assignment operator.
*/
bool ReToken::isOperator(int expected, int alternative) const {
return m_tokenType == TOKEN_OPERATOR
- && (m_value.m_id == expected || m_value.m_id == alternative);
+ && (m_value.m_id == expected || m_value.m_id == alternative);
}
/**
bool ReToken::isKeyword(int expected, int alternative) const {
return m_tokenType == TOKEN_KEYWORD
- && (m_value.m_id == expected || m_value.m_id == alternative);
+ && (m_value.m_id == expected || m_value.m_id == alternative);
}
/**
*/
bool ReToken::isCapitalizedId() const {
bool rc = m_tokenType == TOKEN_ID && isupper(m_string.at(0))
- && (m_string.length() == 1 || islower(m_string.at(1)));
+ && (m_string.length() == 1 || islower(m_string.at(1)));
return rc;
}
break;
case TOKEN_STRING:
qsnprintf(buffer, sizeof buffer, "'%.*s'", int(sizeof buffer) - 1,
- m_printableString.constData());
+ m_printableString.constData());
break;
case TOKEN_NUMBER:
qsnprintf(buffer, sizeof buffer, "%lld", m_value.m_integer);
break;
case TOKEN_ID:
qsnprintf(buffer, sizeof buffer, "'%.*s'", int(sizeof buffer) - 1,
- m_string.constData());
+ m_string.constData());
break;
case TOKEN_COMMENT_REST_OF_LINE:
case TOKEN_COMMENT_START:
*/
static void itemsToVector(const char* items, ReLexer::StringList& vector,
- int firstCharFlag, int secondCharFlag, int thirdCharFlag, int restCharFlag,
- int charInfo[]) {
+ int firstCharFlag, int secondCharFlag, int thirdCharFlag, int restCharFlag,
+ int charInfo[]) {
QByteArray array2(items);
QList < QByteArray > list = array2.split(' ');
QList<QByteArray>::iterator it;
}
static void charClassToCharInfo(const char* charClass, int flag,
- int charInfo[]) {
+ int charInfo[]) {
for (int ix = 0; charClass[ix] != '\0'; ix++) {
unsigned char cc = (unsigned char) charClass[ix];
if (cc < 128)
charInfo['-'] |= flag;
else if (cc >= ubound)
throw new ReException("wrong character class range: %c-%c (%s)",
- cc, ubound, charClass);
+ cc, ubound, charClass);
else {
for (int ii = cc + 1; ii <= ubound; ii++) {
charInfo[ii] |= flag;
* S_ORG_STRINGS | S_COMMENTS | S_BLANKS
*/
ReLexer::ReLexer(ReSource* source, const char* keywords, const char* operators,
- const char* rightAssociatives, const char* comments,
- const char* firstCharsId, const char* restCharsId, int numericTypes,
- int stringFeatures, int storageFlags) :
- m_source(source),
- m_keywords(),
- m_operators(),
- m_commentStarts(),
- m_commentEnds(),
- //m_charInfo()
- m_idFirstRare(),
- m_idRestRare(),
- m_numericTypes(numericTypes),
- m_idRest2(),
- m_currentToken(&m_token1),
- m_waitingToken(NULL),
- m_waitingToken2(NULL),
- m_token1(TOKEN_UNDEF),
- m_token2(TOKEN_UNDEF),
- m_currentPosition(NULL),
- m_waitingPosition1(NULL),
- m_waitingPosition2(NULL),
- m_maxTokenLength(64),
- m_input(),
- m_currentCol(0),
- m_hasMoreInput(false),
- m_stringFeatures(stringFeatures),
- m_storageFlags(storageFlags),
- // m_prioOfOp
- // m_assocOfOp
+ const char* rightAssociatives, const char* comments,
+ const char* firstCharsId, const char* restCharsId, int numericTypes,
+ int stringFeatures, int storageFlags) :
+ m_source(source),
+ m_keywords(),
+ m_operators(),
+ m_commentStarts(),
+ m_commentEnds(),
+ //m_charInfo()
+ m_idFirstRare(),
+ m_idRestRare(),
+ m_numericTypes(numericTypes),
+ m_idRest2(),
+ m_currentToken(&m_token1),
+ m_waitingToken(NULL),
+ m_waitingToken2(NULL),
+ m_token1(TOKEN_UNDEF),
+ m_token2(TOKEN_UNDEF),
+ m_currentPosition(NULL),
+ m_waitingPosition1(NULL),
+ m_waitingPosition2(NULL),
+ m_maxTokenLength(64),
+ m_input(),
+ m_currentCol(0),
+ m_hasMoreInput(false),
+ m_stringFeatures(stringFeatures),
+ m_storageFlags(storageFlags),
+ // m_prioOfOp
+ // m_assocOfOp
#if defined (RPL_LEXER_TRACE)
- m_trace(true),
+ m_trace(true),
#endif
- m_opNames() {
+ m_opNames() {
memset(m_prioOfOp, 0, sizeof m_prioOfOp);
memset(m_assocOfOp, 0, sizeof m_assocOfOp);
memset(m_charInfo, 0, sizeof m_charInfo);
itemsToVector(keywords, m_keywords, CC_FIRST_KEYWORD, CC_2nd_KEYWORD,
- CC_3rd_KEYWORD, CC_REST_KEYWORD, m_charInfo);
+ CC_3rd_KEYWORD, CC_REST_KEYWORD, m_charInfo);
prepareOperators(operators, rightAssociatives);
charClassToCharInfo(firstCharsId, CC_FIRST_ID, m_charInfo);
charClassToCharInfo(restCharsId, CC_REST_ID, m_charInfo);
* Lower position means lower priority
*/
void ReLexer::prepareOperators(const char* operators,
- const char* rightAssociatives) {
+ const char* rightAssociatives) {
QByteArray op2(operators);
QByteArray rightAssociatives2(" ");
rightAssociatives2 += rightAssociatives;
op2.replace("\n", " ");
itemsToVector(op2.constData(), m_operators, CC_FIRST_OP, CC_2nd_OP,
- CC_3rd_OP, CC_REST_OP, m_charInfo);
+ CC_3rd_OP, CC_REST_OP, m_charInfo);
// m_operators is now sorted:
// test whether the successor of 1 char operators is starting with this char:
// if not this operator will be marked with CC_OP_1_ONLY:
for (int ix = 0; ix < m_operators.size() - 1; ix++) {
// the entries of m_operators end with ' ' and id:
if (m_operators.at(ix).size() == 1 + 2
- && m_operators.at(ix).at(0) != m_operators.at(ix + 1).at(0)) {
+ && m_operators.at(ix).at(0) != m_operators.at(ix + 1).at(0)) {
int cc = (char) m_operators[ix].at(0);
m_charInfo[cc] |= CC_OP_1_ONLY;
}
int ix = comments2.indexOf(" ");
if (ix >= 0)
throw ReException(
- "more than one blank between comment pair(s): col %d %s",
- ix + 1, comments + ix);
+ "more than one blank between comment pair(s): col %d %s",
+ ix + 1, comments + ix);
// the index of m_commentEnds is the position number: we need a dummy entry:
m_commentEnds.append("");
if (ix % 2 != 0)
throw ReException("not only pairs in the comment list");
itemsToVector(starters, m_commentStarts, CC_FIRST_COMMENT_START,
- CC_2nd_COMMENT_START, CC_3rd_COMMENT_START, CC_REST_COMMENT_START,
- m_charInfo);
+ CC_2nd_COMMENT_START, CC_3rd_COMMENT_START, CC_REST_COMMENT_START,
+ m_charInfo);
}
}
/**
if (m_hasMoreInput) {
if (m_input.size() < m_maxTokenLength) {
m_source->currentReader()->fillBuffer(m_maxTokenLength, m_input,
- m_hasMoreInput);
+ m_hasMoreInput);
}
}
while (m_input.size() == 0 && m_source->currentReader() != NULL) {
if (m_source->currentReader()->nextLine(m_maxTokenLength, m_input,
- m_hasMoreInput)) {
+ m_hasMoreInput)) {
m_currentCol = 0;
}
}
* otherwise: the token
*/
ReToken* ReLexer::findTokenWithId(RplTokenType tokenType, int flag2,
- StringList& names) {
+ StringList& names) {
int length = 1;
int inputLength = m_input.size();
int cc;
}
ReToken* rc = NULL;
if (!(tokenType == TOKEN_KEYWORD && length < inputLength && (cc =
- m_input[length]) < CHAR_INFO_SIZE && (m_charInfo[cc] & CC_REST_ID))) {
+ m_input[length]) < CHAR_INFO_SIZE && (m_charInfo[cc] & CC_REST_ID))) {
int id;
// the length could be too long: the CC_2nd_.. flag could be ambigous
while ((id = findInVector(length, names)) <= 0) {
rc->m_tokenType = tokenType;
rc->m_value.m_id = id;
if (tokenType == TOKEN_COMMENT_START
- && (m_storageFlags & STORE_COMMENT) != 0)
+ && (m_storageFlags & STORE_COMMENT) != 0)
rc->m_string.append(m_input.mid(0, length));
m_input.remove(0, length);
m_currentCol += length;
int length;
quint64 value = 0;
if ((cc = m_input[0]) == '0' && inputLength > 1
- && (m_numericTypes & NUMTYPE_HEXADECIMAL)
- && (m_input[1] == 'x' || m_input[1] == 'X')) {
- length = ReStringUtil::lengthOfUInt64(m_input.constData() + 2, 16,
- &value);
+ && (m_numericTypes & NUMTYPE_HEXADECIMAL)
+ && (m_input[1] == 'x' || m_input[1] == 'X')) {
+ length = ReStringUtils::lengthOfUInt64(m_input.constData() + 2, 16,
+ &value);
if (length > 0)
length += 2;
else
throw ReException("invalid hexadecimal number: no digit behind 'x");
} else if (cc == '0' && (m_numericTypes & NUMTYPE_OCTAL)
- && inputLength > 1) {
+ && inputLength > 1) {
length = 1;
while (length < inputLength) {
if ((cc = m_input[length]) >= '0' && cc <= '7')
value = value * 8 + cc - '0';
else if (cc >= '8' && cc <= '9')
throw ReLexException(*m_currentPosition,
- "invalid octal digit: %c", cc);
+ "invalid octal digit: %c", cc);
else
break;
length++;
m_currentToken->m_value.m_integer = value;
m_currentToken->m_tokenType = TOKEN_NUMBER;
if (length + 1 < inputLength
- && ((cc = m_input[length]) == '.' || toupper(cc) == 'E')) {
+ && ((cc = m_input[length]) == '.' || toupper(cc) == 'E')) {
qreal realValue;
- int realLength = ReStringUtil::lengthOfReal(m_input.constData(),
- &realValue);
+ int realLength = ReStringUtils::lengthOfReal(m_input.constData(),
+ &realValue);
if (realLength > length) {
m_currentToken->m_tokenType = TOKEN_REAL;
m_currentToken->m_value.m_real = realValue;
while (length < inputLength && (cc = m_input[length]) != delim) {
length++;
if (cc != '\\'
- || (m_stringFeatures
- & (SF_C_ESCAPING | SF_C_HEX_CHARS | SF_C_SPECIAL)) == 0) {
+ || (m_stringFeatures
+ & (SF_C_ESCAPING | SF_C_HEX_CHARS | SF_C_SPECIAL)) == 0) {
m_currentToken->m_string.append(QChar(cc));
} else {
if (length >= inputLength)
throw ReLexException(*m_currentPosition,
- "backslash without following character");
+ "backslash without following character");
cc = m_input[length++];
if ((m_stringFeatures & SF_C_HEX_CHARS) && toupper(cc) == 'X') {
if (length >= inputLength)
throw ReLexException(*m_currentPosition,
- "missing hexadecimal digit behind \\x");
+ "missing hexadecimal digit behind \\x");
cc = m_input[length++];
- int hexVal = ReQStringUtil::valueOfHexDigit(cc);
+ int hexVal = ReStringUtils::valueOfHexDigit(cc);
if (hexVal < 0)
throw ReLexException(*m_currentPosition,
- "not a hexadecimal digit behind \\x: %lc",
- QChar(cc));
+ "not a hexadecimal digit behind \\x: %lc",
+ QChar(cc));
if (length < inputLength) {
cc = m_input[length];
- int nibble = ReQStringUtil::valueOfHexDigit(cc);
+ int nibble = ReStringUtils::valueOfHexDigit(cc);
if (nibble >= 0) {
length++;
hexVal = hexVal * 16 + nibble;
length++;
}
if ((m_stringFeatures & SF_DOUBLE_DELIM) && length < inputLength
- && m_input[length] == (char) delim) {
+ && m_input[length] == (char) delim) {
m_currentToken->m_printableString.append(delim);
length++;
again = true;
m_input.clear();
if (!fillInput())
throw ReLexException(*m_currentPosition,
- "comment end not found");
+ "comment end not found");
}
length = ix + commentEnd.size();
if (m_storageFlags & STORE_COMMENT)
} else if (isdigit(cc)) {
rc = scanNumber();
} else if ((cc == '"' && (m_stringFeatures & SF_QUOTE) != 0)
- || (cc == '\'' && (m_stringFeatures & SF_TICK) != 0)) {
+ || (cc == '\'' && (m_stringFeatures & SF_TICK) != 0)) {
rc = scanString();
} else {
if (cc >= CHAR_INFO_SIZE)
throw ReLexException(*m_currentPosition,
- "no lexical symbol can start with this char: %lc",
- cc);
+ "no lexical symbol can start with this char: %lc",
+ cc);
else {
if (rc == NULL
- && (m_charInfo[cc] & CC_FIRST_COMMENT_START)) {
+ && (m_charInfo[cc] & CC_FIRST_COMMENT_START)) {
rc = findTokenWithId(TOKEN_COMMENT_START,
- CC_2nd_COMMENT_START, m_commentStarts);
+ CC_2nd_COMMENT_START, m_commentStarts);
if (rc != NULL)
scanComment();
//waitingPosition = m_currentPosition;
if (rc == NULL && (m_charInfo[cc] & CC_FIRST_OP)) {
if ((m_charInfo[cc] & CC_OP_1_ONLY) == 0) {
rc = findTokenWithId(TOKEN_OPERATOR, CC_2nd_OP,
- m_operators);
+ m_operators);
} else {
rc = m_currentToken;
rc->m_tokenType = TOKEN_OPERATOR;
}
if (rc == NULL && (m_charInfo[cc] & CC_FIRST_KEYWORD)) {
rc = findTokenWithId(TOKEN_KEYWORD, CC_2nd_KEYWORD,
- m_keywords);
+ m_keywords);
}
if (rc == NULL && (m_charInfo[cc] & CC_FIRST_ID)) {
int length = 1;
while (length < m_input.size() && (cc =
- m_input[length]) < CHAR_INFO_SIZE
- && (m_charInfo[cc] & CC_REST_ID) != 0)
+ m_input[length]) < CHAR_INFO_SIZE
+ && (m_charInfo[cc] & CC_REST_ID) != 0)
length++;
rc = m_currentToken;
rc->m_tokenType = TOKEN_ID;
} else {
QByteArray symbol = m_input.mid(0, qMin(20, m_input.size() - 1));
throw ReLexException(*m_currentPosition,
- "unknown lexical symbol: %s", symbol.constData());
+ "unknown lexical symbol: %s", symbol.constData());
}
}
#if defined (RPL_LEXER_TRACE)
do {
rc = nextToken();
} while ((type = m_currentToken->tokenType()) == TOKEN_SPACE
- || type == TOKEN_COMMENT_START || type == TOKEN_COMMENT_END
- || type == TOKEN_COMMENT_REST_OF_LINE);
+ || type == TOKEN_COMMENT_START || type == TOKEN_COMMENT_END
+ || type == TOKEN_COMMENT_REST_OF_LINE);
return rc;
}
*/
int ReLexer::prioOfOp(int op) const {
int rc =
- op > 0 && (unsigned) op < sizeof m_prioOfOp / sizeof m_prioOfOp[0] ?
- m_prioOfOp[op] : 0;
+ op > 0 && (unsigned) op < sizeof m_prioOfOp / sizeof m_prioOfOp[0] ?
+ m_prioOfOp[op] : 0;
return rc;
}
#include "base/rebase.hpp"
#include "os/reos.hpp"
-
+//#define WITH_TRACE
+#include "base/retrace.hpp"
/**
* @file
*
ReFileMetaDataList::const_iterator it;
bool withDirs = (options & LO_DIRS) != 0;
bool withFiles = (options & LO_FILES) != 0;
+ if (! withDirs && ! withFiles)
+ withDirs = withFiles = true;
bool filterDirs = (options & LO_NAME_FILTER_FOR_DIRS);
list.clear();
for (it = m_list.cbegin(); it != m_list.cend(); ++it){
rc = initFromHeader(0, MARKER_LENGTH, META_INFO_LENGTH, 0, &header, info);
if (rc){
const MetaInfo_t* meta = reinterpret_cast<const MetaInfo_t*>(info.constData());
+ TRACE2("count: %d size: %d\n", meta->m_countFiles, meta->m_size);
if (meta->m_countFiles > 0){
m_fileBuffer.resize(m_blockSize);
m_entryBuffer.resize(0);
int sumLength = 0;
+ randomReset();
while ( (nRead = fread(m_fileBuffer.data(),
1, m_blockSize, fp)) > 0){
sumLength += nRead;
m_fileBuffer.resize(nRead);
m_contentRandom.codec(m_fileBuffer);
m_entryBuffer.append(m_fileBuffer);
- splitBlock(sumLength < meta->m_size,
+ splitBlock(sumLength >= meta->m_size,
m_entryBuffer);
}
if (sumLength != meta->m_size){
*/
bool ReCryptDirectory::writeMetaFile()
{
+ TRACE("writeMetaFile:\n");
bool rc = true;
- QByteArray header;
QByteArray meta;
meta.resize(sizeof(MetaInfo_t));
MetaInfo_t* meta2 = reinterpret_cast<MetaInfo_t*>(meta.data());
int length = it->m_node.toUtf8().length();
meta2->m_size += length + (length < 256 ? 0 : 1);
}
+ TRACE2("count: %d size: %d\n", meta2->m_countFiles, meta2->m_size);
initHeader(0, MARKER_LENGTH, META_INFO_LENGTH, 0, meta);
QByteArray node;
for (it = m_list.cbegin(); it != m_list.cend(); ++it){
m_logger->logv(LOG_ERROR, LOC_WRITE_META_1, "cannot write (%d): %s",
errno, fnMetaFile.constData());
} else {
- m_fileBuffer.append(header);
+ m_fileBuffer.resize(0);
+ m_fileBuffer.append(m_header);
+ int offset = m_header.length();
int ixList = 0;
+ randomReset();
while (ixList < m_list.length()){
const ReFileMetaData& file = m_list.at(ixList++);
FileEntry_t trg;
int length = node.length();
trg.m_nodeLength = length < 256 ? length : 0;
m_fileBuffer.append(reinterpret_cast<const char*>(&trg), sizeof trg);
+ TRACE2("%2d: %s", ixList, hexBytes(&trg, sizeof trg).constData());
m_fileBuffer.append(node);
+ TRACE2(" length: %d %s\n", length, node.constData());
if (length >= 256)
m_fileBuffer.append('\0');
int blockLength = m_fileBuffer.length();
bool lastBlock = ixList >= m_list.length();
- if (lastBlock ||blockLength >= m_blockSize - 512){
+ if (lastBlock || blockLength >= m_blockSize - 512){
if (! lastBlock && blockLength % sizeof(int64_t) != 0){
int newLength = blockLength - blockLength % sizeof(int64_t);
m_smallBuffer = m_fileBuffer.mid(newLength);
m_fileBuffer.resize(newLength);
}
- int offset = ixList <= 1 ? META_DIR_HEADER_LENGTH : 0;
m_contentRandom.codec(m_fileBuffer, m_fileBuffer, offset);
+ offset = 0;
int nWritten = fwrite(m_fileBuffer.constData(), 1,
m_fileBuffer.length(), fp);
if (nWritten != m_fileBuffer.length()){
const FileEntry_t* src = reinterpret_cast<const FileEntry_t*>
(block.constData());
ReFileMetaData file;
- int position = 0;
+ TRACE("splitBlock:\n");
+ IF_TRACE(int ix = 0);
const char* srcPtr = reinterpret_cast<const char*>(block.constData());
const char* endPtr = srcPtr + block.length() - (isLast ? 0 : MAX_ENTRY_SIZE);
while (srcPtr < endPtr){
const FileEntry_t* src = reinterpret_cast<const FileEntry_t*>(srcPtr);
+ TRACE2("%2d: %s", ++ix, hexBytes(&src, sizeof src).constData());
file.m_created.setMSecsSinceEpoch(src->m_created);
file.m_modified.setMSecsSinceEpoch(src->m_modified);
file.m_owner = src->m_owner;
srcPtr += sizeof(FileEntry_t);
int nodeLength = src->m_nodeLength != 0 ? src->m_nodeLength : strlen(srcPtr);
QByteArray node(srcPtr, nodeLength);
+ TRACE2(" Length: %d %s\n", nodeLength, node.constData());
file.m_node = node;
m_list.append(file);
srcPtr += nodeLength + (src->m_nodeLength != 0 ? 0 : 1);
virtual void close();
virtual bool exists(const QString& node, ReFileMetaData* metaInfo) const;
virtual int listInfos(const ReIncludeExcludeMatcher& matcher,
- ReFileMetaDataList& list, ListOptions options = LO_UNDEF);
+ ReFileMetaDataList& list, ListOptions options = LO_ALL);
virtual ErrorCode makeDir(const QString& node);
virtual ErrorCode read(const ReFileMetaData& source, int64_t offset,
int size, QByteArray& buffer);
LO_UNDEF = 0,
LO_FILES = 1,
LO_DIRS = 2,
+ LO_ALL = 3,
LO_NAME_FILTER_FOR_DIRS = 4,
};