diff options
Diffstat (limited to 'app/bin/include/partcatalog.h')
-rw-r--r-- | app/bin/include/partcatalog.h | 100 |
1 files changed, 69 insertions, 31 deletions
diff --git a/app/bin/include/partcatalog.h b/app/bin/include/partcatalog.h index eec9d1e..365e78b 100644 --- a/app/bin/include/partcatalog.h +++ b/app/bin/include/partcatalog.h @@ -1,7 +1,7 @@ /** \file partcatalog.h * Manage the catalog of track parameter files */ -/* XTrkCad - Model Railroad CAD +/* XTrackCad - Model Railroad CAD * Copyright (C) 2019 Martin Fischer * * This program is free software; you can redistribute it and/or modify @@ -16,55 +16,93 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef HAVE_TRACKCATALOG_H #define HAVE_TRACKCATALOG_H #include <stdbool.h> +#include "include/utlist.h" #define MAXFILESPERCONTENT 10 /**< count of files with the same content header */ -#define ESTIMATED_CONTENTS_WORDS 10 /**< average count of words in CONTENTS header */ struct sCatalogEntry { - struct sCatalogEntry *next; - unsigned files; /**< current count of files */ - char *fullFileName[MAXFILESPERCONTENT]; /**< fully qualified file name */ - char *contents; /**< content field of parameter file */ - struct sCatalogEntry *indirect; /**< pointer to another catalog entry */ + struct sCatalogEntry *next, *prev; + unsigned files; /**< current count of files */ + char *fullFileName[MAXFILESPERCONTENT]; /**< fully qualified file name */ + char *contents; /**< content field of parameter file */ + char *tag; /**< data about the file */ }; - typedef struct sCatalogEntry CatalogEntry; -struct sIndexEntry { - CatalogEntry *value; /**< catalog entry having the key word in contents */ - char *keyWord; /**< keyword */ +struct sCatalog { + CatalogEntry *head; /**< The entries */ }; +typedef struct sCatalog Catalog; + +/** +An index entry. This struct holds a keyword pointer and an array of pointers to +CatalogEntry +It is managed as a linked list +*/ +struct sIndexEntry { + struct sIndexEntry *next; + struct sIndexEntry *prev; + char *keyWord; /**< keyword */ + dynArr_t *references; /**< references to the CatalogEntry */ +}; typedef struct sIndexEntry IndexEntry; -struct sTrackLibrary { - CatalogEntry *catalog; /**< list of files cataloged */ - IndexEntry *index; /**< Index for lookup */ - unsigned wordCount; /**< How many words indexed */ - void * words_array; /**< The array of words */ - unsigned trackTypeCount; /**< */ + +struct sParameterLib { + Catalog *catalog; /**< list of files cataloged */ + IndexEntry *index; /**< Index for lookup */ + unsigned wordCount; /**< How many words indexed */ + unsigned parameterFileCount; /**< */ + char *words; }; +typedef struct sParameterLib + ParameterLib; /**< core data structure for the catalog */ -typedef struct sTrackLibrary - TrackLibrary; /**< core data structure for the catalog */ +enum WORDSTATE { + SEARCHED, + DISCARDED, + NOTFOUND, + CLOSE, + STATE_COUNT +}; + +struct sSearchResult { + Catalog subCatalog; + unsigned totalFound; + unsigned words; /**< no of words in search string */ + struct sSingleResult { + char *keyWord; + unsigned count; + enum WORDSTATE state; + } *kw; +}; +typedef struct sSearchResult SearchResult; -CatalogEntry *InitCatalog(void); -TrackLibrary *InitLibrary(void); -TrackLibrary *CreateLibrary(char *directory); -void DeleteLibrary(TrackLibrary *tracklib); -bool GetTrackFiles(TrackLibrary *trackLib, char *directory); -int GetParameterFileInfo(int files, char ** fileName, void * data); -unsigned CreateLibraryIndex(TrackLibrary *trackLib); -unsigned SearchLibrary(TrackLibrary *library, char *searchExpression, CatalogEntry *resultEntries); -unsigned CountCatalogEntries(CatalogEntry *listHeader); -void EmptyCatalog(CatalogEntry *listHeader); -unsigned SearchLibrary(TrackLibrary *library, char *searchExpression, CatalogEntry *resultEntries); +Catalog *InitCatalog(void); +void DestroyCatalog(Catalog *catalog); +CatalogEntry * InsertInOrder(Catalog *catalog, const char *contents, + const char *tag); +void UpdateCatalogEntry(CatalogEntry *entry, char *path, char *contents, + char *tag); +ParameterLib *InitLibrary(void); +ParameterLib *CreateLibrary(char *directory); +void DestroyLibrary(ParameterLib *tracklib); +bool CreateCatalogFromDir(ParameterLib *trackLib, char *directory); +unsigned CreateLibraryIndex(ParameterLib *trackLib); +unsigned SearchLibrary(ParameterLib *library, char *searchExpression, + SearchResult *totalResult); +char *SearchStatistics(SearchResult *result); +void SearchDiscardResult(SearchResult *res); +unsigned CountCatalogEntries(Catalog *catalog); +void DiscardCatalog(ParameterLib *library); +EXPORT void CatalogDiscard(Catalog *catalog); bool FilterKeyword(char *word); #endif // !HAVE_TRACKCATALOG_H |