]> gitweb.hamatoma.de Git - reqt/commitdiff
writing crypt dir works
authorhama <hama@siduction.net>
Sat, 21 Nov 2015 01:16:15 +0000 (02:16 +0100)
committerhama <hama@siduction.net>
Sat, 21 Nov 2015 01:16:15 +0000 (02:16 +0100)
12 files changed:
base/ReRandomizer.cpp
base/ReRandomizer.hpp
base/ReStringUtils.hpp
base/retrace.hpp
cunit/allTests.cpp
cunit/cuReCryptFileSystem.cpp
cunit/cuReLexer.cpp
cunit/cunit.pro
expr/ReLexer.cpp
os/ReCryptFileSystem.cpp
os/ReCryptFileSystem.hpp
os/ReFileSystem.hpp

index 2bf9595e5a97dc5b3d458e808fbf3691cf8950e5..286bddf2a0ae08711892dc2a5d50c7fe0acf3e78 100644 (file)
@@ -711,6 +711,32 @@ void ReSingleSeedRandomizer::textToSeed(const QByteArray& text) {
        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.
  */
@@ -1223,14 +1249,12 @@ void ReByteScrambler::initHeader(int reservedLength, int markerLength,
                           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);
@@ -1258,3 +1282,5 @@ QByteArray& ReByteScrambler::header()
 {
        return m_header;
 }
+
+
index c56039ca9f712082b5b7812886fdb6815058ffb0..515defb417675261adfeccc648b32c4bcf17ec57 100644 (file)
@@ -184,6 +184,22 @@ protected:
        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();
index 26e54a783e4fd76d5c4f30f2fd101800427767d8..ba2306b75a4cf373dee3e91d6c620c79d0abaef8 100644 (file)
@@ -62,6 +62,17 @@ public:
        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;
 };
index 00641ab6298cfeaef155558429b4d2b52400b664..ea3c7925f95db45423eb5e08c865246df9f8d9f5 100644 (file)
@@ -7,8 +7,8 @@
 */
 
 
-#ifndef RETRACEACTIVE_HPP
-#define RETRACEACTIVE_HPP
+#ifndef RETRACE_HPP
+#define RETRACE_HPP
 
 #ifdef WITH_TRACE
 #define TRACE(format) printf(format);
@@ -24,7 +24,7 @@
 #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;
@@ -35,5 +35,5 @@ QByteArray hexBytes(const void* arg, int length = 8){
        }
        return rc;
 }
-#endif // RETRACEACTIVE_HPP
+#endif // RETRACE_HPP
 
index d12638729790ea3f3354ba23c8273dce1dd5fc97..e0bdf0c4eb1313499d0ebde98baa008838bde5c4 100644 (file)
@@ -11,6 +11,7 @@
 #include "../base/rebase.hpp"
 #include "../math/remath.hpp"
 #include "../net/renet.hpp"
+#include "../expr/reexpr.hpp"
 //#include "os/reos.hpp"
 #include <QApplication>
 
@@ -65,7 +66,6 @@ static void testMath() {
 
 }
 static void testExpr() {
-       /*
         extern void testReMFParser();
         extern void testRplBenchmark();
         extern void testReVM();
@@ -75,6 +75,8 @@ static void testExpr() {
         extern void testReASTree();
         extern void testReVM();
 
+        testReLexer();
+        /*
         //testRplBenchmark();
         if (s_allTest){
         testReVM();
@@ -97,13 +99,13 @@ static void testOs() {
        testReFileSystem();
 }
 void allTests() {
+       testExpr();
        testOs();
        testBase();
        testGui();
        if (s_allTest) {
                testBase();
                testMath();
-               testExpr();
                testNet();
                testOs();
        }
index 32dee6a4b1840295425edb7dcac0ab860c0b90a6..b622349c54ef08efc8cd9866da2bbadf1a8cc401 100644 (file)
@@ -28,7 +28,7 @@ public:
                log("run");
        }
 
-       void testRead(){
+       void testDirRead(){
                readMetaFile();
                ReFileMetaDataList list;
                checkEqu(3, listInfos(ReIncludeExcludeMatcher::allMatcher(), list));
@@ -39,7 +39,7 @@ public:
                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");
@@ -87,19 +87,17 @@ protected:
                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();
        }
 };
index 41cf43be92d7be92cde8ad2e5897249b7713f236..cdbfb93ed7c389cf9937486dd3b841a4155d8695 100644 (file)
 #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);
@@ -53,7 +53,7 @@ public:
        }
 
        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());
@@ -100,8 +100,8 @@ public:
                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);
        }
@@ -112,8 +112,8 @@ public:
                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);
@@ -142,8 +142,8 @@ public:
                        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);
@@ -177,19 +177,19 @@ public:
                        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;
@@ -199,8 +199,8 @@ public:
                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");
        }
@@ -212,8 +212,8 @@ public:
                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);
@@ -230,12 +230,12 @@ public:
                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() {
@@ -244,8 +244,8 @@ public:
                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);
@@ -273,7 +273,7 @@ public:
                };
                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));
@@ -290,10 +290,10 @@ public:
                testOperators();
                testNumeric();
                testSpace();
-               testRplToken();
+               testReToken();
        }
 };
 void testReLexer() {
-       TestRplLexer test;
+       TestReLexer test;
        test.run();
 }
index 66cd3e1ec9c87a627ec43e78dacb77a7d03748d7..824a079c0def01b3d9bb55b2d9fa9f8b2a6c22eb 100644 (file)
@@ -16,6 +16,7 @@ TEMPLATE = app
 INCLUDEPATH = ..
 
 SOURCES += main.cpp \
+       cuReLexer.cpp \
         cuReFileSystem.cpp \
         cuReCryptFileSystem.cpp \
         cuReRandomizer.cpp \
@@ -25,6 +26,8 @@ SOURCES += main.cpp \
         cuReFileUtils.cpp \
         cuReByteStorage.cpp \
         cuReException.cpp \
+       ../expr/ReSource.cpp \
+       ../expr/ReLexer.cpp \
         ../base/ReByteStorage.cpp \
         ../base/ReCharPtrMap.cpp \
         ../base/ReConfig.cpp \
index cb826116c4bb9e55febab342e54bec73f75a3d5c..5dd5a8bf6ac5d5f4d6b8e396a4904c911b8f84f7 100644 (file)
@@ -34,8 +34,8 @@
  * @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;
@@ -55,9 +55,9 @@ ReLexException::ReLexException(const ReSourcePosition& position,
  * @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);
@@ -74,10 +74,10 @@ ReToken::~ReToken() {
  * @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.
@@ -186,7 +186,7 @@ bool ReToken::isTokenType(RplTokenType expected) const {
  */
 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);
 }
 
 /**
@@ -201,7 +201,7 @@ bool ReToken::isOperator(int expected, int alternative) const {
 
 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);
 }
 
 /**
@@ -222,7 +222,7 @@ void ReToken::clear() {
  */
 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;
 }
 
@@ -246,7 +246,7 @@ QByteArray ReToken::asUtf8() const {
                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);
@@ -260,7 +260,7 @@ QByteArray ReToken::asUtf8() const {
                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:
@@ -333,8 +333,8 @@ const char* ReToken::nameOfType(RplTokenType type) {
  */
 
 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;
@@ -370,7 +370,7 @@ static void itemsToVector(const char* items, ReLexer::StringList& vector,
 }
 
 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)
@@ -381,7 +381,7 @@ static void charClassToCharInfo(const char* charClass, int flag,
                                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;
@@ -418,45 +418,45 @@ static void charClassToCharInfo(const char* charClass, int 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);
@@ -494,20 +494,20 @@ int countBlanks(const char* start, const char* end) {
  *                      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;
                }
@@ -549,8 +549,8 @@ void ReLexer::initializeComments(const char* comments) {
                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("");
 
@@ -569,8 +569,8 @@ void ReLexer::initializeComments(const char* comments) {
                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);
        }
 }
 /**
@@ -630,13 +630,13 @@ bool ReLexer::fillInput() {
        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;
                }
        }
@@ -655,7 +655,7 @@ bool ReLexer::fillInput() {
  *                  otherwise: the token
  */
 ReToken* ReLexer::findTokenWithId(RplTokenType tokenType, int flag2,
-    StringList& names) {
+       StringList& names) {
        int length = 1;
        int inputLength = m_input.size();
        int cc;
@@ -684,7 +684,7 @@ ReToken* ReLexer::findTokenWithId(RplTokenType tokenType, int flag2,
        }
        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) {
@@ -698,7 +698,7 @@ ReToken* ReLexer::findTokenWithId(RplTokenType tokenType, int flag2,
                        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;
@@ -718,23 +718,23 @@ ReToken* ReLexer::scanNumber() {
        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++;
@@ -753,10 +753,10 @@ ReToken* ReLexer::scanNumber() {
        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;
@@ -784,27 +784,27 @@ ReToken*ReLexer::scanString() {
                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;
@@ -844,7 +844,7 @@ ReToken*ReLexer::scanString() {
                        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;
@@ -880,7 +880,7 @@ void ReLexer::scanComment() {
                        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)
@@ -961,18 +961,18 @@ ReToken* ReLexer::nextToken() {
                                } 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;
@@ -981,7 +981,7 @@ ReToken* ReLexer::nextToken() {
                                                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;
@@ -992,13 +992,13 @@ ReToken* ReLexer::nextToken() {
                                                }
                                                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;
@@ -1019,7 +1019,7 @@ ReToken* ReLexer::nextToken() {
                } 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)
@@ -1119,8 +1119,8 @@ ReToken* ReLexer::nextNonSpaceToken() {
        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;
 }
 
@@ -1154,8 +1154,8 @@ ReSource* ReLexer::source() {
  */
 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;
 }
 
index eaaa9b98e36d837c3d3ebd9c3679ecad8fe21c78..99e4096770ebebe943b530db85b7272f336c7e7b 100644 (file)
@@ -9,7 +9,8 @@
 
 #include "base/rebase.hpp"
 #include "os/reos.hpp"
-
+//#define WITH_TRACE
+#include "base/retrace.hpp"
 /**
  * @file
  *
@@ -134,6 +135,8 @@ int ReCryptFileSystem::listInfos(const ReIncludeExcludeMatcher& matcher,
        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){
@@ -453,10 +456,12 @@ bool ReCryptDirectory::readMetaFile()
                        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;
@@ -464,7 +469,7 @@ bool ReCryptDirectory::readMetaFile()
                                                        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){
@@ -487,8 +492,8 @@ bool ReCryptDirectory::readMetaFile()
  */
 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());
@@ -499,6 +504,7 @@ bool ReCryptDirectory::writeMetaFile()
                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){
@@ -513,8 +519,11 @@ bool ReCryptDirectory::writeMetaFile()
                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;
@@ -529,19 +538,21 @@ bool ReCryptDirectory::writeMetaFile()
                        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()){
@@ -574,11 +585,13 @@ void ReCryptDirectory::splitBlock(bool isLast, QByteArray& block){
        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;
@@ -591,6 +604,7 @@ void ReCryptDirectory::splitBlock(bool isLast, QByteArray& block){
                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);
index 6a92c218cd20cc559e226b5b068b446912da6020..45ed45d3b1ef408e2a9ea847fbfae30b376e2f27 100644 (file)
@@ -138,7 +138,7 @@ public:
        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);
index 8c6dd0047927de48f9f184e4e7388fbc880fd3e9..122b1138b0074ef7ec98f5f83333c25b7ffebda9 100644 (file)
@@ -52,6 +52,7 @@ public:
                LO_UNDEF = 0,
                LO_FILES = 1,
                LO_DIRS = 2,
+               LO_ALL = 3,
                LO_NAME_FILTER_FOR_DIRS = 4,
        };