add new getcmd

This commit is contained in:
Heng Guo 2023-09-05 20:48:38 +08:00 committed by Aoran Zeng
parent 46ee35a40f
commit 898c7cf24c
2 changed files with 61 additions and 5 deletions

42
chsrc.c
View File

@ -1162,6 +1162,48 @@ os_gentoo_setsrc(char* option)
}
/**
*
*/
void
os_netbsd_setsrc(char* option)
{
int index = 0;
if (NULL!=option) {
index = lets_find_mirror(os_netbsd, option);
} else {
index = lets_test_speed(os_netbsd);
}
source_info source = os_netbsd_sources[index];
chsrc_say_selection(&source);
char* backup = "cp -rf /usr/pkg/etc/pkgin/repositories.conf /usr/pkg/etc/pkgin/repositories.conf.bak";
chsrc_logcmd(backup);
system(backup);
xy_info ("chsrc: 备份文件名: /usr/pkg/etc/pkgin/repositories.conf.bak");
char* cmd = xy_strjoin(6,"echo ",
source.url,
arch,
"/",
version,
"/All > /usr/pkg/etc/pkgin/repositories.conf");
chsrc_logcmd(cmd);
system(cmd);
// char* rm = "rm -rf /etc/portage/repos.conf/gentoo.conf.bak";
// system(rm);
chsrc_say_thanks(&source);
}
/************************************** Begin Target Matrix ****************************************/
def_target_info(pl_ruby);
def_target_info(pl_python);

24
xy.h
View File

@ -448,7 +448,7 @@ xy_str_strip (const char* str)
*
*/
char *
xy_getcmd(const char * cmd)
xy_getcmd(const char * cmd, bool (*func)(const char*))
{
const int BUFSIZE = 1024;
@ -465,15 +465,29 @@ xy_getcmd(const char * cmd)
// 从 stream 指针指向的文件中读取数据。
char *ret;
do {
ret = fgets(buf, sizeof(buf), stream);
if(ret==NULL)
break;
if(fgets(buf, sizeof(buf), stream)==NULL)
{
break;
}
if(func==NULL)
{
ret = buf;
}
else
{
if(func(buf))
{
ret = buf;
break;
}
}
}while(1);
// 关闭 stream 指针。
pclose(stream);
return buf;
return ret;
}
#endif