mirror of
https://github.com/RubyMetric/chsrc
synced 2025-12-22 18:29:48 +08:00
add new getcmd
This commit is contained in:
24
xy.h
24
xy.h
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user