mirror of
https://github.com/RubyMetric/chsrc
synced 2025-06-09 04:16:21 +08:00
add new getcmd
This commit is contained in:
parent
46ee35a40f
commit
898c7cf24c
42
chsrc.c
42
chsrc.c
@ -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 ****************************************/
|
/************************************** Begin Target Matrix ****************************************/
|
||||||
def_target_info(pl_ruby);
|
def_target_info(pl_ruby);
|
||||||
def_target_info(pl_python);
|
def_target_info(pl_python);
|
||||||
|
22
xy.h
22
xy.h
@ -448,7 +448,7 @@ xy_str_strip (const char* str)
|
|||||||
* 注意:执行结果后面有回车换行
|
* 注意:执行结果后面有回车换行
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
xy_getcmd(const char * cmd)
|
xy_getcmd(const char * cmd, bool (*func)(const char*))
|
||||||
{
|
{
|
||||||
const int BUFSIZE = 1024;
|
const int BUFSIZE = 1024;
|
||||||
|
|
||||||
@ -465,15 +465,29 @@ xy_getcmd(const char * cmd)
|
|||||||
// 从 stream 指针指向的文件中读取数据。
|
// 从 stream 指针指向的文件中读取数据。
|
||||||
char *ret;
|
char *ret;
|
||||||
do {
|
do {
|
||||||
ret = fgets(buf, sizeof(buf), stream);
|
if(fgets(buf, sizeof(buf), stream)==NULL)
|
||||||
if(ret==NULL)
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
if(func==NULL)
|
||||||
|
{
|
||||||
|
ret = buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(func(buf))
|
||||||
|
{
|
||||||
|
ret = buf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}while(1);
|
}while(1);
|
||||||
|
|
||||||
// 关闭 stream 指针。
|
// 关闭 stream 指针。
|
||||||
pclose(stream);
|
pclose(stream);
|
||||||
return buf;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user