2023-09-09 16:49:06 +08:00
|
|
|
/** ------------------------------------------------------------
|
|
|
|
* File : chsrc.h
|
|
|
|
* License : GPLv3
|
|
|
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
|
|
|
* Created on : <2023-08-29>
|
2023-09-15 12:24:16 +08:00
|
|
|
* Last modified : <2023-09-15>
|
2023-09-09 16:49:06 +08:00
|
|
|
*
|
|
|
|
* chsrc:
|
|
|
|
*
|
|
|
|
* chsrc.c 头文件
|
|
|
|
* ------------------------------------------------------------*/
|
2023-08-29 23:04:54 +08:00
|
|
|
|
2023-09-03 14:56:49 +08:00
|
|
|
#include "xy.h"
|
2023-09-15 12:44:50 +08:00
|
|
|
#include "sources.h"
|
2023-09-03 14:48:53 +08:00
|
|
|
|
|
|
|
/* 辅助函数 */
|
|
|
|
int
|
|
|
|
dblary_maxidx(double* array, int size)
|
|
|
|
{
|
|
|
|
double maxval = array[0];
|
2023-09-06 19:45:37 +08:00
|
|
|
int maxidx = 0;
|
2023-09-03 14:48:53 +08:00
|
|
|
|
|
|
|
for (int i=1; i<size; i++) {
|
|
|
|
if (array[i]>maxval) {
|
|
|
|
maxval = array[i];
|
|
|
|
maxidx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return maxidx;
|
|
|
|
}
|
|
|
|
|
2023-09-04 15:24:09 +08:00
|
|
|
/**
|
|
|
|
* 用于告知用户 chsrc 所执行的操作
|
|
|
|
*/
|
|
|
|
void
|
2023-09-04 15:39:49 +08:00
|
|
|
chsrc_logcmd (const char* cmd)
|
2023-09-04 15:24:09 +08:00
|
|
|
{
|
|
|
|
xy_info(xy_2strjoin("chsrc: 运行 ", cmd));
|
|
|
|
}
|
|
|
|
|
2023-09-10 12:23:45 +08:00
|
|
|
void
|
|
|
|
chsrc_runcmd (const char* cmd)
|
|
|
|
{
|
|
|
|
chsrc_logcmd(cmd);
|
|
|
|
system(cmd);
|
|
|
|
}
|
|
|
|
|
2023-09-03 17:57:45 +08:00
|
|
|
/**
|
|
|
|
* 用于 _setsrc 函数
|
|
|
|
*/
|
|
|
|
void
|
2023-09-04 15:39:49 +08:00
|
|
|
chsrc_say_selection (source_info* source)
|
2023-09-03 17:57:45 +08:00
|
|
|
{
|
2023-09-05 15:29:53 +08:00
|
|
|
xy_info (xy_strjoin(5, "chsrc: 选中镜像站: ", source->mirror->abbr, " (", source->mirror->code, ")"));
|
2023-09-03 17:57:45 +08:00
|
|
|
}
|
|
|
|
|
2023-09-04 15:39:49 +08:00
|
|
|
void
|
|
|
|
chsrc_say_thanks (source_info* source)
|
|
|
|
{
|
2023-09-05 15:29:53 +08:00
|
|
|
xy_success(xy_2strjoin("chsrc: 感谢镜像提供方: ", source->mirror->name));
|
2023-09-04 15:39:49 +08:00
|
|
|
}
|
|
|
|
|
2023-09-03 14:48:53 +08:00
|
|
|
|
2023-09-02 19:07:30 +08:00
|
|
|
/* Target Info */
|
|
|
|
typedef struct {
|
|
|
|
void (*setfn)(char* option);
|
|
|
|
void (*getfn)(char* option);
|
|
|
|
source_info* sources;
|
|
|
|
size_t sources_n;
|
|
|
|
} target_info;
|
|
|
|
|
2023-09-04 09:01:33 +08:00
|
|
|
#define def_target_info(t) target_info t##_target = {t##_setsrc, t##_getsrc, t##_sources, t##_sources_n}
|