-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (60 loc) · 1.42 KB
/
main.cpp
File metadata and controls
64 lines (60 loc) · 1.42 KB
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
//
// Created by ywj on 2025/7/29.
//
#include<string.h>
#include<unistd.h>
#include"config.h"
#include"log.h"
const static char* version="1.0.0";
static void usage( const char* prog )
{
LOG( LOG_INFO, "usage: %s [-h] [-v] [-f config_file]", prog );
}
int main(int argc,char**argv)
{
char cfg_file[1024];
memset( cfg_file, '\0', 100 );
int option;
while ( ( option = getopt( argc, argv, "f:xvh" ) ) != -1 )
{
switch ( option )
{
case 'x':
{
set_loglevel( LOG_DEBUG );
break;
}
case 'v':
{
log( LOG_INFO, __FILE__, __LINE__, "%s %s", argv[0], version );
return 0;
}
case 'h':
{
usage( basename( argv[ 0 ] ) );
return 0;
}
case 'f':
{
memcpy( cfg_file, optarg, strlen( optarg ) );
break;
}
case '?':
{
log( LOG_ERR, __FILE__, __LINE__, "un-recognized option %c", option );
usage( basename( argv[ 0 ] ) );
return 1;
}
}
}
if( cfg_file[0] == '\0' )
{
log( LOG_ERR, __FILE__, __LINE__, "%s", "please specifiy the config file" );
return 1;
}
if (!config::loadConfig(std::string(cfg_file)))
{
return 1;
}
return 0;
}