summaryrefslogtreecommitdiff
path: root/app/bin/include/partcatalog.h
blob: 365e78b07d84fb15c8356853e2c964caea86216c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/** \file partcatalog.h
* Manage the catalog of track parameter files
*/
/*  XTrackCad - Model Railroad CAD
*  Copyright (C) 2019 Martin Fischer
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  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., 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 */

struct sCatalogEntry {
	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 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 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 */

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;

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