-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconfig.h
95 lines (77 loc) · 2.38 KB
/
config.h
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
/*****************************************
NanoShell Operating System
(C) 2022 iProgramInCpp
Kernel Configuration module header file
******************************************/
#ifndef _CONFIG_H
#define _CONFIG_H
#include <main.h>
#include <memory.h>
#include <string.h>
typedef struct ConfigEntry
{
uint32_t entry_hash;
char entry[64];
char value[250];
}
ConfigEntry;
/**
* A simple function to hash a string. Not cryptographically secure at all, but it should be fine.
*/
uint32_t HashString(const char *const str);
/**
* Initialize the configuration manager.
*/
void CfgInit(void);
/**
* Debug: Print the entries of the configuration.
*/
void CfgPrintEntries(void);
/**
* Loads configuration data from a piece of text.
*
* This operation destroys the text that's being worked on, for a function that does not, see `CfgLoadFromText()`.
*/
void CfgLoadFromTextBasic(char* work);
/**
* Loads configuration data from a file.
*/
void CfgLoadFromFile (const char * file);
/**
* Loads configuration data from a piece of text.
*/
void CfgLoadFromText (const char* parms);
/**
* Loads configuration data from a one line list of parameters. Useful to specify command line parameters.
*/
void CfgLoadFromParms(const char* parms);
//TODO: maybe duplicate these actually
//DON'T hold pointers to these, instead copy their values.
//If new entries are added the kernel may want to expand
//the array of config entries
/**
* Adds a configuration entry to the global config manager.
*/
ConfigEntry* CfgAddEntry(ConfigEntry *pEntry);
/**
* Gets the ConfigEntry pointer for a key, or NULL if it doesn't exist.
*
* Same TODO as CfgGetEntryValue.
*/
ConfigEntry* CfgGetEntry(const char* key);
/**
* Gets the value of a configuration entry, or NULL if it doesn't exist.
*
* TODO: duplicate the contents for save modification. A thread could slip in a
* modification while the application uses the return value of this function.
*/
const char *CfgGetEntryValue(const char *pKey);
/**
* Check if a configuration entry has the value specified.
*/
bool CfgEntryMatches(const char *pKey, const char *pValueCmp);
/**
* Gets an integer value from a config key, or 'default' if said key doesn't actually exist.
*/
void CfgGetIntValue(int* out, const char* key, int _default);
#endif//_CONFIG_H