mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-04-24 05:04:20 +08:00
Delete feature
This commit is contained in:
parent
e0046b6e9f
commit
d7d3268202
341
chsrc.h
341
chsrc.h
@ -1,341 +0,0 @@
|
||||
/* --------------------------------------------------------------
|
||||
* File : chsrc.h
|
||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
* Created on : <2023-08-29>
|
||||
* Last modified : <2023-09-01>
|
||||
*
|
||||
* chsrc:
|
||||
*
|
||||
* chsrc.c 头文件
|
||||
* -------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "helper.h"
|
||||
|
||||
typedef struct {
|
||||
const char* abbr;
|
||||
const char* name;
|
||||
const char* site;
|
||||
} mirror_info;
|
||||
|
||||
// 教育网
|
||||
// 我们目前根据 https://github.com/mirrorz-org/oh-my-mirrorz 挑选速度前10位
|
||||
//
|
||||
mirror_info
|
||||
MirrorZ = {"MirrorZ", "MirrorZ校园网镜像站", "https://mirrors.cernet.edu.cn/"},
|
||||
Tuna = {"TUNA", "清华大学开源软件镜像站", "https://mirrors.tuna.tsinghua.edu.cn/"},
|
||||
Sjtug_Zhiyuan = {"SJTUG-zhiyuan", "上海交通大学致远镜像站", "https://mirrors.sjtug.sjtu.edu.cn/"},
|
||||
Zju = {"ZJU", "浙江大学开源软件镜像站", "https://mirrors.zju.edu.cn/"},
|
||||
Lzuoss = {"LZUOSS", "兰州大学开源社区镜像站", "https://mirror.lzu.edu.cn/"},
|
||||
Jlu = {"JLU", "吉林大学开源镜像站", "https://mirrors.jlu.edu.cn/"},
|
||||
Bfsu = {"BFSU", "北京外国语大学开源软件镜像站","https://mirrors.bfsu.edu.cn/"},
|
||||
Pku = {"PKU", "北京大学开源镜像站", "https://mirrors.pku.edu.cn/"},
|
||||
Bjtu = {"BJTU", "北京交通大学自由与开源软件镜像站", "https://mirror.bjtu.edu.cn/"},
|
||||
Sustech = {"SUSTech", "南方科技大学开源软件镜像站", "https://mirrors.sustech.edu.cn/"},
|
||||
Ustc = {"USTC", "中国科学技术大学开源镜像站", "https://mirrors.ustc.edu.cn/"},
|
||||
|
||||
// 速度暂时处于10位以后,但是目前可用的源
|
||||
Nju = {"NJU", "南京大学开源镜像站", "https://mirrors.nju.edu.cn/"},
|
||||
Cqu = {"CQU", "重庆大学开源软件镜像站", "https://mirrors.cqu.edu.cn/"};
|
||||
|
||||
|
||||
// 大型公司
|
||||
// 注意,腾讯软件源中,有很多链接都已失效,请仔细检查
|
||||
mirror_info
|
||||
Ali = {"Ali OPSX", "阿里巴巴开源镜像站", "https://developer.aliyun.com/mirror/"},
|
||||
Tencent = {"Tencent", "腾讯软件源", "https://mirrors.tencent.com/"},
|
||||
Netease = {"Netease", "网易开源镜像站", "https://mirrors.163.com/"},
|
||||
Sohu = {"SOHU", "搜狐开源镜像站", "https://mirrors.sohu.com/"};
|
||||
|
||||
|
||||
// 开源社区
|
||||
mirror_info
|
||||
RubyChina = {"RubyChina", "Ruby China 社区", "https://ruby-china.org/"},
|
||||
GoProxyCN = {"Goproxy.cn", "七牛云 Goproxy.cn", "https://www.qiniu.com/"},
|
||||
GoProxyIO = {"GOPROXY.IO", "GOPROXY.IO", "https://goproxy.io/"},
|
||||
NugetOrg = {"NuGet Org", "Nuget Organization", "https://www.nuget.org/"};
|
||||
|
||||
|
||||
mirror_info*
|
||||
available_mirrors[] = {
|
||||
&MirrorZ, &Tuna, &Sjtug_Zhiyuan, &Zju, &Lzuoss, &Jlu, &Bfsu, &Pku, &Bjtu, &Sustech, &Ustc, &Nju, &Cqu,
|
||||
&Ali, &Tencent, &Netease, &Sohu,
|
||||
&RubyChina, &GoProxyCN, &GoProxyIO
|
||||
// 暂不支持 NugetOrg
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
const mirror_info* mirror;
|
||||
const char* url;
|
||||
} source_info;
|
||||
|
||||
|
||||
/**
|
||||
* 源信息
|
||||
*
|
||||
* 我们要求每个源至少有一个教育网镜像,至少有一个商业公司或开源社区维护的镜像
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-29 更新
|
||||
*
|
||||
* 速度已经过测试,目前北外最快,Ruby China 的源慢了一半
|
||||
*/
|
||||
static source_info
|
||||
pl_ruby_sources[] = {
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/rubygems/"},
|
||||
{&Ali, "https://mirrors.aliyun.com/rubygems/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rubygems/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/rubygems/"},
|
||||
{&RubyChina, "https://gems.ruby-china.com"},
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-29 更新
|
||||
*
|
||||
* 不要添加Zju,浙大的pypi在校外访问会自动转向Tuna
|
||||
*
|
||||
* TODO: 1. 速度只经过简单测试,请Python用户协助,
|
||||
* 2. 列表暂时未添加商业公司源,以及其他大学镜像
|
||||
*/
|
||||
pl_python_sources[] = {
|
||||
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/pypi/web/simple"},
|
||||
{&Tuna, "https://pypi.tuna.tsinghua.edu.cn/simple"},
|
||||
{&Lzuoss, "https://mirror.lzu.edu.cn/pypi/web/simple"},
|
||||
{&Jlu, "https://mirrors.jlu.edu.cn/pypi//web/simple"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/pypi/web/simple"}
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有
|
||||
*
|
||||
* 腾讯软件源虽然有npm的名,但名存实亡
|
||||
*/
|
||||
pl_nodejs_sources[] = {
|
||||
{&Ali, "https://registry.npmmirror.com"},
|
||||
{&Zju, "https://mirrors.zju.edu.cn/docs/npm/"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* 参考:https://help.mirrors.cernet.edu.cn/CPAN/
|
||||
*
|
||||
* Jlu 吉林大学没有该源
|
||||
*
|
||||
* TODO: 速度未经测试,请Perl用户协助
|
||||
*/
|
||||
pl_perl_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/CPAN/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CPAN/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/CPAN/"},
|
||||
{&Bjtu, "https://mirror.bjtu.edu.cn/cpan/"},
|
||||
{&Lzuoss, "https://mirror.lzu.edu.cn/CPAN/"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* TODO: 速度未经测试,请R用户协助
|
||||
*/
|
||||
pl_r_sources[] = {
|
||||
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/"},
|
||||
{&Ali, "https://mirrors.aliyun.com/CRAN/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/CRAN/"},
|
||||
{&Bjtu, "https://mirror.bjtu.edu.cn/cran/"},
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* 阿里云没有该源
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请Julia用户协助
|
||||
* 2. 缺少商业公司或开源社区软件源
|
||||
*/
|
||||
pl_julia_sources[] = {
|
||||
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/julia"},
|
||||
{&Pku, "https://mirrors.pku.edu.cn/julia"},
|
||||
{&Nju, "https://mirror.nju.edu.cn/julia"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请Go用户协助
|
||||
* 2. 缺少教育网软件源
|
||||
*/
|
||||
pl_go_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/goproxy/"},
|
||||
{&GoProxyCN, "https://goproxy.cn"},
|
||||
{&GoProxyIO, "https://goproxy.io"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请Rust用户协助
|
||||
* 2. 缺少商业公司或开源社区软件源
|
||||
*/
|
||||
pl_rust_sources[] = {
|
||||
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/crates.io-index/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/crates.io-index/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/crates.io-index/"},
|
||||
{&Cqu, "https://mirrors.cqu.edu.cn/crates.io-index/"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请Java用户协助
|
||||
* 2. 缺少教育网或开源社区软件源
|
||||
* 3. 当前仅有一个源
|
||||
*/
|
||||
pl_java_sources[] = {
|
||||
{&Ali, "https://maven.aliyun.com/repository/public/"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* 暂时未实现该换源功能
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请Java用户协助
|
||||
* 2. 缺少教育网或开源社区软件源
|
||||
* 3. 当前仅有一个源
|
||||
*/
|
||||
pl_dotnet_sources[] = {
|
||||
{&NugetOrg, "https://www.nuget.org/api/v2/"}
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-08-30 更新
|
||||
*
|
||||
* TODO: 1. 速度未经测试,请PHP用户协助
|
||||
* 2. 缺少教育网或开源社区软件源
|
||||
* 3. 当前仅有一个源
|
||||
*/
|
||||
pl_php_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/composer/"}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-01 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
static source_info
|
||||
os_ubuntu_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/ubuntu/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/ubuntu/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/ubuntu/"},
|
||||
{&Netease, "https://mirrors.163.com/ubuntu/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/ubuntu/"},
|
||||
},
|
||||
|
||||
/**
|
||||
* 2023-09-01 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
os_debian_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/debian/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/debian/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/debian/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/debian/"},
|
||||
{&Netease, "https://mirrors.163.com/debian/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/debian/"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-02 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
os_fedora_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/fedora/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/fedora/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/fedora/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/fedora/"},
|
||||
{&Netease, "https://mirrors.163.com/fedora/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/fedora/"},
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-02 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
os_kali_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/kali/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/kali/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/kali/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/kali/"},
|
||||
{&Netease, "https://mirrors.163.com/kali/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/kali/"},
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-02 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
os_openbsd_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/OpenBSD/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/OpenBSD/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/OpenBSD/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/OpenBSD/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/OpenBSD/"},
|
||||
{&Netease, "https://mirrors.163.com/OpenBSD/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/OpenBSD/"},
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-02 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
os_mysys2_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/msys2/"},
|
||||
{&Bfsu, "https://mirrors.bfsu.edu.cn/msys2/"},
|
||||
{&Ustc, "https://mirrors.ustc.edu.cn/msys2/"},
|
||||
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2/"},
|
||||
{&Tencent, "https://mirrors.tencent.com/msys2/"},
|
||||
{&Netease, "https://mirrors.163.com/msys2/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/msys2/"},
|
||||
}
|
||||
;
|
||||
|
||||
/* 函数签名 */
|
||||
bool does_the_program_exist (char* check_cmd, char* progname);
|
236
helper.h
236
helper.h
@ -1,236 +0,0 @@
|
||||
/* --------------------------------------------------------------
|
||||
* File : helper.h
|
||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
* Created on : <2023-08-28>
|
||||
* Last modified : <2023-08-31>
|
||||
*
|
||||
* helper:
|
||||
*
|
||||
* helper functions and macros
|
||||
* -------------------------------------------------------------*/
|
||||
|
||||
#ifndef XY_H
|
||||
#define XY_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
// #define NDEBUG
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static bool xy_on_windows = true;
|
||||
static bool xy_on_linux = false;
|
||||
static bool xy_on_macos = false;
|
||||
static bool xy_on_bsds = false;
|
||||
|
||||
#include <windows.h>
|
||||
#define xy_useutf8() SetConsoleOutputCP(65001)
|
||||
|
||||
#elif defined(__linux__) || defined(__linux)
|
||||
|
||||
static bool xy_on_windows = false;
|
||||
static bool xy_on_linux = true;
|
||||
static bool xy_on_macos = false;
|
||||
static bool xy_on_bsds = false;
|
||||
|
||||
#define xy_useutf8()
|
||||
|
||||
#elif defined(TARGET_OS_MAC) ||defined(__MACOSX__)
|
||||
|
||||
static bool xy_on_windows = false;
|
||||
static bool xy_on_linux = false;
|
||||
static bool xy_on_macos = true;
|
||||
static bool xy_on_bsds = false;
|
||||
|
||||
#define xy_useutf8()
|
||||
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
|
||||
|
||||
static bool xy_on_windows = false;
|
||||
static bool xy_on_linux = false;
|
||||
static bool xy_on_macos = false;
|
||||
static bool xy_on_bsds = true;
|
||||
|
||||
#define xy_useutf8()
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define xy_arylen(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
|
||||
static inline void*
|
||||
xy_malloc0 (size_t size)
|
||||
{
|
||||
void* ptr = malloc(size);
|
||||
memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
#define XY_INFO 00001
|
||||
#define XY_SUCCESS 00001<<1
|
||||
#define XY_WARN 00001<<2
|
||||
#define XY_ERROR 00001<<3
|
||||
|
||||
static void
|
||||
xy_log (int level, const char* str)
|
||||
{
|
||||
char* color_fmt_str = NULL;
|
||||
|
||||
bool to_stderr = false;
|
||||
|
||||
if (level & XY_INFO) {
|
||||
color_fmt_str = "\033[34m%s\033[0m"; // 蓝色
|
||||
}
|
||||
else if (level & XY_SUCCESS) {
|
||||
color_fmt_str = "\033[32m%s\033[0m"; // 绿色
|
||||
}
|
||||
else if (level & XY_WARN) {
|
||||
color_fmt_str = "\033[33m%s\033[0m\n"; // 黄色
|
||||
to_stderr = true;
|
||||
}
|
||||
else if (level & XY_ERROR) {
|
||||
color_fmt_str = "\033[31m%s\033[0m\n"; // 红色
|
||||
to_stderr = true;
|
||||
}
|
||||
else {
|
||||
//xy_assert ("CAN'T REACH!");
|
||||
}
|
||||
|
||||
// -2 把中间%s减掉
|
||||
size_t len = strlen(color_fmt_str) -2;
|
||||
char* buf = malloc(strlen(str) + len + 1);
|
||||
|
||||
sprintf (buf, color_fmt_str, str);
|
||||
if (to_stderr) {
|
||||
fprintf(stderr, buf);
|
||||
} else {
|
||||
puts(buf);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
#define xy_info(str) xy_log (XY_INFO, str)
|
||||
#define xy_error(str) xy_log (XY_ERROR, str)
|
||||
|
||||
|
||||
/**
|
||||
* 将str中所有的src字符替换成dest,并返回一个全新的字符串
|
||||
* 现在已经废弃不用
|
||||
*/
|
||||
static char*
|
||||
xy_strch (const char* str, char src,const char* dest)
|
||||
{
|
||||
size_t str_len = strlen(str);
|
||||
size_t dest_len = strlen(dest);
|
||||
size_t size = str_len*dest_len;
|
||||
char* ret = (char*)malloc(size);
|
||||
int i=0;
|
||||
int j=0;
|
||||
while(i<str_len) {
|
||||
if(str[i]==src) {
|
||||
int k=0;
|
||||
while(k<dest_len){
|
||||
ret[j++] = dest[k++];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
ret[j++] = str[i++];
|
||||
}
|
||||
}
|
||||
ret[j] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
xy_success (const char* str1)
|
||||
{
|
||||
char color_fmt_str[] = "\033[32m%s\033[0m";
|
||||
// -2 把中间%s减掉,-1 把末尾nul减掉
|
||||
size_t len = sizeof(color_fmt_str) -2 -1;
|
||||
char* buf = malloc(strlen(str1) + len + 1);
|
||||
|
||||
sprintf (buf, color_fmt_str, str1);
|
||||
puts(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
xy_warn (const char* str1)
|
||||
{
|
||||
// 注意,我们这里相比于xy_suceess()多了一个换行符
|
||||
char color_fmt_str[] = "\033[33m%s\033[0m\n";
|
||||
// -2 把中间%s减掉,-1 把末尾nul减掉
|
||||
size_t len = sizeof(color_fmt_str) -2 -1;
|
||||
char* buf = malloc(strlen(str1) + len + 1);
|
||||
|
||||
sprintf (buf, color_fmt_str, str1);
|
||||
fprintf(stderr, buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
xy_2strjoin (const char* str1, const char* str2)
|
||||
{
|
||||
size_t len = strlen(str1);
|
||||
size_t size = len + strlen(str2) + 1;
|
||||
char* ret = malloc(size);
|
||||
strcpy(ret, str1);
|
||||
strcpy(ret+len, str2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
xy_strjoin (unsigned int count, ...)
|
||||
{
|
||||
size_t al_fixed = 128;
|
||||
char* ret = calloc(1, al_fixed);
|
||||
// 已分配次数
|
||||
int al_times = 1;
|
||||
// 当前已分配量
|
||||
size_t al_cur = al_fixed;
|
||||
|
||||
const char* str = NULL;
|
||||
// 需要分配的量
|
||||
size_t al_need = 0;
|
||||
// 用于 strcpy() 到 ret 的哪个位置
|
||||
char* cur = ret + 0;
|
||||
|
||||
va_list args;
|
||||
va_start(args, count);
|
||||
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
str = va_arg(args, const char*);
|
||||
al_need += strlen(str);
|
||||
if (al_need > al_cur) {
|
||||
al_times += 1; al_cur = al_times * al_fixed;
|
||||
ret = realloc(ret, al_cur);
|
||||
if (NULL==ret) { xy_error ("xy: No availble memory!"); return NULL; }
|
||||
}
|
||||
strcpy(cur, str);
|
||||
cur += strlen(str);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
*cur = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
xy_streql(const char* str1, const char* str2) {
|
||||
return strcmp(str1, str2) == 0 ? true : false;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user