From 72d71bc8dca7eb4a30343852ab8f2f0560cfc794 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 20 Feb 2007 21:30:27 +0000 Subject: [PATCH] Aligned Query.h/cpp with the BFS (Haiku) versions r20186. Updated Stack.h to . git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20187 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../userlandfs/r5/src/test/ramfs/Query.cpp | 72 ++++++++++--------- .../userlandfs/r5/src/test/ramfs/Query.h | 35 ++++----- .../userlandfs/r5/src/test/ramfs/Stack.h | 50 +++++++++---- 3 files changed, 84 insertions(+), 73 deletions(-) diff --git a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.cpp b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.cpp index e3862b1d5f..7f970a5b88 100644 --- a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.cpp +++ b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.cpp @@ -1,27 +1,23 @@ /* Query - query parsing and evaluation -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** The pattern matching is roughly based on code originally written -** by J. Kercheval, and on code written by Kenneth Almquist, though -** it shares no code. -** -** This file may be used under the terms of the OpenBeOS License. -*/ + * + * The pattern matching is roughly based on code originally written + * by J. Kercheval, and on code written by Kenneth Almquist, though + * it shares no code. + * + * Copyright 2001-2006, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ // Adjusted by Ingo Weinhold for usage in RAM FS. #include "Query.h" -//#include "bfs.h" #include "Debug.h" #include "Directory.h" #include "Entry.h" #include "Misc.h" #include "Node.h" -#include "Stack.h" #include "Volume.h" -//#include "Inode.h" -//#include "BPlusTree.h" #include "Index.h" #include @@ -34,12 +30,6 @@ #include - - - - - - // IndexWrapper // constructor @@ -1196,15 +1186,7 @@ Equation::GetNextMatching(Volume *volume, IndexIterator *iterator, // TODO: Check the buffer size. strncpy(dirent->d_name, entry->GetName(), B_FILE_NAME_LENGTH); dirent->d_name[B_FILE_NAME_LENGTH - 1] = '\0'; - -#ifdef KEEP_WRONG_DIRENT_RECLEN - // ToDo: The available file systems in BeOS apparently don't set the - // correct d_reclen - we are copying that behaviour if requested, but - // if it doesn't break compatibility, we will remove it. - dirent->d_reclen = strlen(dirent->d_name); -#else dirent->d_reclen = sizeof(struct dirent) + strlen(dirent->d_name); -#endif } if (status == MATCH_OK) @@ -1559,6 +1541,33 @@ Query::Query(Volume *volume, Expression *expression, uint32 flags) fExpression->Root()->CalculateScore(fIndex); fIndex.Unset(); + Rewind(); + + if (fFlags & B_LIVE_QUERY) + volume->AddQuery(this); +} + + +Query::~Query() +{ + if (fFlags & B_LIVE_QUERY) + fVolume->RemoveQuery(this); +} + + +status_t +Query::Rewind() +{ + // free previous stuff + + fStack.MakeEmpty(); + + delete fIterator; + fIterator = NULL; + fCurrent = NULL; + + // put the whole expression on the stack + Stack stack; stack.Push(fExpression->Root()); @@ -1581,15 +1590,7 @@ Query::Query(Volume *volume, Expression *expression, uint32 flags) FATAL(("Unknown term on stack or stack error")); } - if (fFlags & B_LIVE_QUERY) - volume->AddQuery(this); -} - - -Query::~Query() -{ - if (fFlags & B_LIVE_QUERY) - fVolume->RemoveQuery(this); + return B_OK; } @@ -1648,6 +1649,7 @@ Query::LiveUpdate(Entry *entry, const char *attribute, int32 type, const uint8 * status_t oldStatus = fExpression->Root()->Match(entry, attribute, type, oldKey, oldLength); status_t newStatus = fExpression->Root()->Match(entry, attribute, type, newKey, newLength); + int32 op; if (oldStatus == MATCH_OK && newStatus == MATCH_OK) { // only send out a notification if the name was changed diff --git a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.h b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.h index 6f3d1c7b62..54b44ad45e 100644 --- a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.h +++ b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Query.h @@ -1,12 +1,12 @@ +/* Query - query parsing and evaluation + * + * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + * + * Adjusted by Ingo Weinhold for usage in RAM FS. + */ #ifndef QUERY_H #define QUERY_H -/* Query - query parsing and evaluation -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** This file may be used under the terms of the OpenBeOS License. -*/ - -// Adjusted by Ingo Weinhold for usage in RAM FS. #include @@ -14,7 +14,6 @@ #include "Index.h" #include "Stack.h" -//#include "Chain.h" #include "ramfs.h" class Entry; @@ -25,9 +24,6 @@ class Term; class Volume; - - - #define B_QUERY_NON_INDEXED 0x00000002 @@ -69,11 +65,6 @@ private: }; - - - - - class Expression { public: Expression(char *expr); @@ -104,10 +95,12 @@ class Query { Query(Volume *volume, Expression *expression, uint32 flags); ~Query(); - status_t GetNextEntry(struct dirent *,size_t size); + status_t Rewind(); + status_t GetNextEntry(struct dirent *, size_t size); - void SetLiveMode(port_id port,int32 token); - void LiveUpdate(Entry *entry,const char *attribute,int32 type,const uint8 *oldKey,size_t oldLength,const uint8 *newKey,size_t newLength); + void SetLiveMode(port_id port, int32 token); + void LiveUpdate(Entry *entry, const char *attribute, int32 type, + const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength); Expression *GetExpression() const { return fExpression; } @@ -122,10 +115,6 @@ class Query { uint32 fFlags; port_id fPort; int32 fToken; - - private: -// friend Chain; -// Query *fNext; }; #endif /* QUERY_H */ diff --git a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Stack.h b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Stack.h index 9793eb2491..dc832aabf1 100644 --- a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Stack.h +++ b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/ramfs/Stack.h @@ -1,10 +1,10 @@ -#ifndef STACK_H -#define STACK_H -/* Stack - a template stack class -** -** Copyright 2001 pinc Software. All Rights Reserved. -** This file may be used under the terms of the OpenBeOS License. -*/ +/* Stack - a template stack class (plus some handy methods) + * + * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef KERNEL_UTIL_STACK_H +#define KERNEL_UTIL_STACK_H #include @@ -19,18 +19,28 @@ template class Stack { fMax(0) { } - + ~Stack() { - if (fArray) - free(fArray); + free(fArray); } - + + bool IsEmpty() const + { + return fUsed == 0; + } + + void MakeEmpty() + { + // could also free the memory + fUsed = 0; + } + status_t Push(T value) { if (fUsed >= fMax) { fMax += 16; - T *newArray = (T *)realloc(fArray,fMax * sizeof(T)); + T *newArray = (T *)realloc(fArray, fMax * sizeof(T)); if (newArray == NULL) return B_NO_MEMORY; @@ -39,7 +49,7 @@ template class Stack { fArray[fUsed++] = value; return B_OK; } - + bool Pop(T *value) { if (fUsed == 0) @@ -48,11 +58,21 @@ template class Stack { *value = fArray[--fUsed]; return true; } - + + T *Array() + { + return fArray; + } + + int32 CountItems() const + { + return fUsed; + } + private: T *fArray; int32 fUsed; int32 fMax; }; -#endif /* STACK_H */ +#endif /* KERNEL_UTIL_STACK_H */