Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Ip2region
提交
ac102ca6
I
Ip2region
项目概览
int
/
Ip2region
上一次同步 11 个月
通知
19
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Ip2region
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ac102ca6
编写于
6月 28, 2022
作者:
L
lion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
xdb search and bench test program
上级
74a82e9b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
135 addition
and
0 deletion
+135
-0
binding/c/main.c
binding/c/main.c
+135
-0
未找到文件。
binding/c/main.c
0 → 100644
浏览文件 @
ac102ca6
// Copyright 2022 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file.
// ---
// @Author Lion <chenxin619315@gmail.com>
// @Date 2022/06/28
#include "stdio.h"
#include "stdlib.h"
#include "xdb_searcher.h"
void
print_help
(
char
*
argv
[])
{
printf
(
"ip2region xdb searcher
\n
"
);
printf
(
"%s [command] [command options]
\n
"
,
argv
[
0
]);
printf
(
"Command:
\n
"
);
printf
(
" search search input test
\n
"
);
printf
(
" bench search bench test
\n
"
);
}
void
test_search
(
int
argc
,
char
*
argv
[])
{
int
i
,
n
;
char
*
r
,
key
[
33
]
=
{
'\0'
},
val
[
256
]
=
{
'\0'
};
char
db_file
[
256
]
=
{
'\0'
},
cache_policy
[
16
]
=
{
"vectorIndex"
};
for
(
i
=
2
;
i
<
argc
;
i
++
)
{
r
=
argv
[
i
];
if
(
strlen
(
r
)
<
5
)
{
continue
;
}
if
(
r
[
0
]
!=
'-'
||
r
[
1
]
!=
'-'
)
{
continue
;
}
if
(
strchr
(
r
,
'='
)
==
NULL
)
{
printf
(
"missing = for args pair '%s'
\n
"
,
r
);
return
;
}
n
=
sscanf
(
r
+
2
,
"%32[^=]=%255[^
\n
]"
,
key
,
val
);
if
(
n
!=
2
)
{
printf
(
"invalid option flag `%s`
\n
"
,
r
);
return
;
}
// printf("key=%s, val=%s\n", key, val);
if
(
strcmp
(
key
,
"db"
)
==
0
)
{
snprintf
(
db_file
,
sizeof
(
db_file
),
"%s"
,
val
);
}
else
if
(
strcmp
(
key
,
"cache-policy"
)
==
0
)
{
memcpy
(
cache_policy
,
val
,
sizeof
(
cache_policy
)
-
1
);
// snprintf(cache_policy, sizeof(cache_policy), "%s", val);
}
else
{
printf
(
"undefined option `%s`
\n
"
,
r
);
return
;
}
}
if
(
strlen
(
db_file
)
<
1
)
{
printf
(
"%s search [command options]
\n
"
,
argv
[
0
]);
printf
(
"options:
\n
"
);
printf
(
" --db string ip2region binary xdb file path
\n
"
);
printf
(
" --cache-policy string cache policy: file/vectorIndex/content
\n
"
);
return
;
}
printf
(
"db_file=%s, cache_policy=%s
\n
"
,
db_file
,
cache_policy
);
}
void
test_bench
(
int
argc
,
char
*
argv
[])
{
int
i
,
n
;
char
*
r
,
key
[
33
]
=
{
'\0'
},
val
[
256
]
=
{
'\0'
};
char
db_file
[
256
]
=
{
'\0'
},
src_file
[
256
]
=
{
'\0'
},
cache_policy
[
16
]
=
{
"vectorIndex"
};
for
(
i
=
2
;
i
<
argc
;
i
++
)
{
r
=
argv
[
i
];
if
(
strlen
(
r
)
<
5
)
{
continue
;
}
if
(
r
[
0
]
!=
'-'
||
r
[
1
]
!=
'-'
)
{
continue
;
}
if
(
strchr
(
r
,
'='
)
==
NULL
)
{
printf
(
"missing = for args pair '%s'
\n
"
,
r
);
return
;
}
n
=
sscanf
(
r
+
2
,
"%32[^=]=%255[^
\n
]"
,
key
,
val
);
if
(
n
!=
2
)
{
printf
(
"invalid option flag `%s`
\n
"
,
r
);
return
;
}
if
(
strcmp
(
key
,
"db"
)
==
0
)
{
snprintf
(
db_file
,
sizeof
(
db_file
),
"%s"
,
val
);
}
else
if
(
strcmp
(
key
,
"src"
)
==
0
)
{
snprintf
(
src_file
,
sizeof
(
src_file
),
"%s"
,
val
);
}
else
if
(
strcmp
(
key
,
"cache-policy"
)
==
0
)
{
memcpy
(
cache_policy
,
val
,
sizeof
(
cache_policy
)
-
1
);
}
else
{
printf
(
"undefined option `%s`
\n
"
,
r
);
return
;
}
}
if
(
strlen
(
db_file
)
<
1
||
strlen
(
src_file
)
<
1
)
{
printf
(
"%s bench [command options]
\n
"
,
argv
[
0
]);
printf
(
"options:
\n
"
);
printf
(
" --db string ip2region binary xdb file path
\n
"
);
printf
(
" --src string source ip text file path
\n
"
);
printf
(
" --cache-policy string cache policy: file/vectorIndex/content
\n
"
);
return
;
}
printf
(
"db_file=%s, src_file=%s, cache_policy=%s
\n
"
,
db_file
,
src_file
,
cache_policy
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
print_help
(
argv
);
return
0
;
}
char
*
opt
=
argv
[
1
];
if
(
strcmp
(
opt
,
"search"
)
==
0
)
{
test_search
(
argc
,
argv
);
}
else
if
(
strcmp
(
opt
,
"bench"
)
==
0
)
{
test_bench
(
argc
,
argv
);
}
else
{
print_help
(
argv
);
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录