DDraceNetwork Docs
config_common.h
Go to the documentation of this file.
1#include <base/logger.h>
2#include <base/system.h>
3#include <engine/storage.h>
4
6{
7 const char *m_pPath;
9};
10
11inline void ProcessItem(const char *pItemName, IStorage *pStorage)
12{
13 char aConfig[2048];
14
15 size_t Len = (size_t)str_length(pItemName) + 1; // including '\0'
16 if(Len > sizeof(aConfig))
17 {
18 dbg_msg("config_common", "can't process overlong filename '%s'", pItemName);
19 return;
20 }
21
22 if(!str_endswith(pItemName, ".map"))
23 {
24 dbg_msg("config_common", "can't process non-map file '%s'", pItemName);
25 return;
26 }
27
28 str_copy(aConfig, pItemName, sizeof(aConfig));
29 aConfig[Len - sizeof(".map")] = 0;
30 str_append(aConfig, ".cfg");
31 dbg_msg("config_common", "processing '%s'", pItemName);
32 Process(pStorage, pItemName, aConfig);
33}
34
35static int ListdirCallback(const char *pItemName, int IsDir, int StorageType, void *pUser)
36{
37 if(!IsDir)
38 {
39 SListDirectoryContext Context = *((SListDirectoryContext *)pUser);
40 char aName[2048];
41 str_format(aName, sizeof(aName), "%s/%s", Context.m_pPath, pItemName);
42 ProcessItem(aName, Context.m_pStorage);
43 }
44
45 return 0;
46}
47
48int main(int argc, const char **argv) // NOLINT(misc-definitions-in-headers)
49{
50 CCmdlineFix CmdlineFix(&argc, &argv);
52
53 IStorage *pStorage = CreateLocalStorage();
54 if(!pStorage)
55 return -1;
56
57 if(argc == 1)
58 {
59 dbg_msg("usage", "%s FILE1 [ FILE2... ]", argv[0]);
60 dbg_msg("usage", "%s DIRECTORY", argv[0]);
61 return -1;
62 }
63 else if(argc == 2 && fs_is_dir(argv[1]))
64 {
65 SListDirectoryContext Context = {argv[1], pStorage};
66 pStorage->ListDirectory(IStorage::TYPE_ALL, argv[1], ListdirCallback, &Context);
67 }
68
69 for(int i = 1; i < argc; i++)
70 {
71 ProcessItem(argv[i], pStorage);
72 }
73 return 0;
74}
Definition: system.h:2845
Definition: storage.h:20
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser)=0
@ TYPE_ALL
Definition: storage.h:26
int main(int argc, const char **argv)
Definition: config_common.h:48
void ProcessItem(const char *pItemName, IStorage *pStorage)
Definition: config_common.h:11
static int ListdirCallback(const char *pItemName, int IsDir, int StorageType, void *pUser)
Definition: config_common.h:35
void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
Definition: config_retrieve.cpp:6
void dbg_msg(const char *sys, const char *fmt,...)
Definition: system.cpp:164
int fs_is_dir(const char *path)
Definition: system.cpp:2363
void log_set_global_logger_default()
Definition: log.cpp:43
int str_length(const char *str)
Definition: system.cpp:2754
void str_append(char *dst, const char *src, int dst_size)
Definition: system.cpp:2703
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2720
IStorage * CreateLocalStorage()
Definition: storage.cpp:912
Definition: config_common.h:6
const char * m_pPath
Definition: config_common.h:7
IStorage * m_pStorage
Definition: config_common.h:8
#define str_format
Definition: system.cpp:2789
const char * str_endswith(const char *str, const char *suffix)
Definition: system.cpp:3021