Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9491a4ac
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9491a4ac
编写于
11月 01, 2020
作者:
F
freemine
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
port tconv to windows
上级
d117a0ae
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
18 deletion
+44
-18
src/connector/odbc/tests/CMakeLists.txt
src/connector/odbc/tests/CMakeLists.txt
+3
-1
src/connector/odbc/tests/tconv.c
src/connector/odbc/tests/tconv.c
+41
-17
未找到文件。
src/connector/odbc/tests/CMakeLists.txt
浏览文件 @
9491a4ac
...
...
@@ -8,9 +8,11 @@ IF (TD_LINUX)
ENDIF
()
IF
(
TD_WINDOWS_64
)
SET
(
CMAKE_C_FLAGS_DEBUG
"
${
CMAKE_C_FLAGS_DEBUG
}
/GL"
)
SET
(
CMAKE_C_FLAGS_RELEASE
"
${
CMAKE_C_FLAGS_RELEASE
}
/GL"
)
# AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE
(
tcodbc main.c
)
TARGET_LINK_LIBRARIES
(
tcodbc odbc32 odbccp32 user32 legacy_stdio_definitions os
)
ADD_EXECUTABLE
(
tconv tconv.c
)
TARGET_LINK_LIBRARIES
(
tconv
os
)
TARGET_LINK_LIBRARIES
(
tconv
tutil
)
ENDIF
()
src/connector/odbc/tests/tconv.c
浏览文件 @
9491a4ac
...
...
@@ -3,21 +3,21 @@
#ifdef _MSC_VER
#include <winsock2.h>
#include <windows.h>
#include "msvcIconv.h"
#else
#include <iconv.h>
#endif
#include <iconv.h>
#include <stdio.h>
#include <string.h>
static
void
usage
(
const
char
*
arg0
);
static
int
do_conv
(
iconv_t
cnv
,
FILE
*
fin
);
static
int
do_conv
(
iconv_t
cnv
,
FILE
*
fin
,
FILE
*
fout
);
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
from_enc
=
"UTF-8"
;
const
char
*
to_enc
=
"UTF-8"
;
const
char
*
dst_file
=
NULL
;
const
char
*
src
=
NULL
;
#ifdef _MSC_VER
from_enc
=
"CP936"
;
...
...
@@ -44,6 +44,14 @@ int main(int argc, char *argv[]) {
}
to_enc
=
argv
[
i
];
continue
;
}
else
if
(
strcmp
(
arg
,
"-o"
)
==
0
)
{
i
+=
1
;
if
(
i
>=
argc
)
{
fprintf
(
stderr
,
"expecing <dst_file>, but got nothing
\n
"
);
return
1
;
}
dst_file
=
argv
[
i
];
continue
;
}
else
if
(
arg
[
0
]
==
'-'
)
{
fprintf
(
stderr
,
"unknown argument: [%s]
\n
"
,
arg
);
return
1
;
...
...
@@ -56,33 +64,49 @@ int main(int argc, char *argv[]) {
continue
;
}
}
int
r
=
-
1
;
FILE
*
fin
=
src
?
fopen
(
src
,
"rb"
)
:
stdin
;
if
(
!
fin
)
{
fprintf
(
stderr
,
"failed to open file [%s]
\n
"
,
src
);
return
1
;
}
int
r
=
0
;
FILE
*
fout
=
dst_file
?
fopen
(
dst_file
,
"wb"
)
:
stdout
;
iconv_t
cnv
=
iconv_open
(
to_enc
,
from_enc
);
do
{
iconv_t
cnv
=
iconv_open
(
to_enc
,
from_enc
);
if
(
!
fin
)
{
fprintf
(
stderr
,
"failed to open file [%s]
\n
"
,
src
);
break
;
}
if
(
!
fout
)
{
fprintf
(
stderr
,
"failed to open file [%s]
\n
"
,
dst_file
);
break
;
}
#ifdef _MSC_VER
if
(
fout
==
stdout
)
{
r
=
_setmode
(
_fileno
(
fout
),
_O_BINARY
);
if
(
r
==
-
1
)
{
fprintf
(
stderr
,
"Cannot set binary mode for output stream: %d[%s]
\n
"
,
errno
,
strerror
(
errno
));
}
}
#endif
if
(
cnv
==
(
iconv_t
)
-
1
)
{
fprintf
(
stderr
,
"failed to open conv from [%s] to [%s]: [%s]
\n
"
,
from_enc
,
to_enc
,
strerror
(
errno
));
return
-
1
;
break
;
}
r
=
do_conv
(
cnv
,
fin
);
r
=
do_conv
(
cnv
,
fin
,
fout
);
iconv_close
(
cnv
);
cnv
=
(
iconv_t
)
-
1
;
}
while
(
0
);
fclose
(
fin
);
if
(
fin
&&
fin
!=
stdin
)
fclose
(
fin
);
if
(
fout
&&
fout
!=
stdout
)
fclose
(
fout
);
return
r
?
1
:
0
;
}
static
void
usage
(
const
char
*
arg0
)
{
fprintf
(
stderr
,
"%s -h | [-f <from_enc>] [-t <to_enc>] [file]
\n
"
,
arg0
);
fprintf
(
stderr
,
"%s -h | [-f <from_enc>] [-t <to_enc>] [
-o <dst file>] [
file]
\n
"
,
arg0
);
return
;
}
#define IN_SIZE (
256
*1024)
#define IN_SIZE (
64
*1024)
#define OUT_SIZE (8*IN_SIZE)
static
int
do_conv
(
iconv_t
cnv
,
FILE
*
fin
)
{
static
int
do_conv
(
iconv_t
cnv
,
FILE
*
fin
,
FILE
*
fout
)
{
int
r
=
0
;
char
src
[
IN_SIZE
];
size_t
slen
=
sizeof
(
src
);
...
...
@@ -117,7 +141,7 @@ static int do_conv(iconv_t cnv, FILE *fin) {
break
;
}
}
n
=
fwrite
(
dst
,
1
,
(
size_t
)(
dd
-
dst
),
std
out
);
n
=
fwrite
(
dst
,
1
,
(
size_t
)(
dd
-
dst
),
f
out
);
if
(
n
<
dd
-
dst
)
{
fprintf
(
stderr
,
"failed to write: [%s]
\n
"
,
strerror
(
errno
));
r
=
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录