DDNet documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
config_common.h
Go to the documentation of this file.
1
#include <
base/dbg.h
>
2
#include <
base/fs.h
>
3
#include <
base/logger.h
>
4
#include <
base/os.h
>
5
#include <
base/str.h
>
6
7
#include <
engine/storage.h
>
8
9
struct
SListDirectoryContext
10
{
11
const
char
*
m_pPath
;
12
IStorage
*
m_pStorage
;
13
};
14
15
inline
void
ProcessItem
(
const
char
*pItemName,
IStorage
*pStorage)
16
{
17
char
aConfig[2048];
18
19
size_t
Len = (size_t)
str_length
(pItemName) + 1;
// including '\0'
20
if
(Len >
sizeof
(aConfig))
21
{
22
dbg_msg
(
"config_common"
,
"can't process overlong filename '%s'"
, pItemName);
23
return
;
24
}
25
26
if
(!
str_endswith
(pItemName,
".map"
))
27
{
28
dbg_msg
(
"config_common"
,
"can't process non-map file '%s'"
, pItemName);
29
return
;
30
}
31
32
str_copy
(aConfig, pItemName);
33
aConfig[Len -
sizeof
(
".map"
)] = 0;
34
str_append
(aConfig,
".cfg"
);
35
dbg_msg
(
"config_common"
,
"processing '%s'"
, pItemName);
36
Process(pStorage, pItemName, aConfig);
37
}
38
39
static
int
ListdirCallback
(
const
char
*pItemName,
int
IsDir,
int
StorageType,
void
*pUser)
40
{
41
if
(!IsDir)
42
{
43
SListDirectoryContext
Context = *((
SListDirectoryContext
*)pUser);
44
char
aName[2048];
45
str_format
(aName,
sizeof
(aName),
"%s/%s"
, Context.
m_pPath
, pItemName);
46
ProcessItem
(aName, Context.
m_pStorage
);
47
}
48
49
return
0;
50
}
51
52
int
main
(
int
argc,
const
char
**argv)
// NOLINT(misc-definitions-in-headers)
53
{
54
CCmdlineFix
CmdlineFix(&argc, &argv);
55
log_set_global_logger_default
();
56
57
std::unique_ptr<IStorage> pStorage =
CreateLocalStorage
();
58
if
(!pStorage)
59
{
60
log_error
(
"config_common"
,
"Error creating local storage"
);
61
return
-1;
62
}
63
64
if
(argc == 1)
65
{
66
dbg_msg
(
"usage"
,
"%s FILE1 [ FILE2... ]"
, argv[0]);
67
dbg_msg
(
"usage"
,
"%s DIRECTORY"
, argv[0]);
68
return
-1;
69
}
70
else
if
(argc == 2 &&
fs_is_dir
(argv[1]))
71
{
72
SListDirectoryContext
Context = {argv[1], pStorage.get()};
73
pStorage->ListDirectory(
IStorage::TYPE_ALL
, argv[1],
ListdirCallback
, &Context);
74
}
75
76
for
(
int
i = 1; i < argc; i++)
77
{
78
ProcessItem
(argv[i], pStorage.get());
79
}
80
return
0;
81
}
CCmdlineFix
Definition
os.h:43
IStorage
Definition
storage.h:21
IStorage::TYPE_ALL
@ TYPE_ALL
Definition
storage.h:27
main
int main(int argc, const char **argv)
Definition
client.cpp:4806
ProcessItem
void ProcessItem(const char *pItemName, IStorage *pStorage)
Definition
config_common.h:15
ListdirCallback
static int ListdirCallback(const char *pItemName, int IsDir, int StorageType, void *pUser)
Definition
config_common.h:39
dbg.h
fs.h
dbg_msg
void dbg_msg(const char *sys, const char *fmt,...)
Definition
dbg.cpp:57
fs_is_dir
int fs_is_dir(const char *path)
Definition
fs.cpp:437
log_set_global_logger_default
void log_set_global_logger_default()
Definition
log.cpp:54
str_length
int str_length(const char *str)
Definition
str.cpp:55
str_append
void str_append(char *dst, const char *src, int dst_size)
Definition
str.cpp:28
str_copy
int str_copy(char *dst, const char *src, int dst_size)
Definition
str.cpp:18
log_error
#define log_error(sys,...)
Definition
log.h:23
logger.h
os.h
CreateLocalStorage
std::unique_ptr< IStorage > CreateLocalStorage()
Definition
storage.cpp:928
storage.h
str_format
#define str_format
Definition
str.cpp:92
str_endswith
const char * str_endswith(const char *str, const char *suffix)
Definition
str.cpp:429
str.h
SListDirectoryContext
Definition
config_common.h:10
SListDirectoryContext::m_pPath
const char * m_pPath
Definition
config_common.h:11
SListDirectoryContext::m_pStorage
IStorage * m_pStorage
Definition
config_common.h:12
src
tools
config_common.h
Generated by
1.18.0