Files
scc/runtime/libcore/include/core_stream.h
zzy 63f6f13883 feat(cbuild): 重构构建系统并迁移至 tools/cbuild
将 `cbuild.py` 迁移至 `tools/cbuild/` 并进行大量功能增强。引入依赖解析器、支持颜色日志输出、
改进包配置默认值处理、完善构建目标识别与拓扑排序依赖管理。同时添加 `.gitignore` 和
`pyproject.toml` 以支持标准 Python 包结构,并更新 README 文档。

新增命令支持:tree(显示依赖树)、clean(带文件统计)、test(运行测试)等,
优化了 Windows 平台下的可执行文件扩展名处理逻辑。

移除了旧的 `wc.py` 行数统计脚本。
2025-11-22 15:08:49 +08:00

68 lines
1.7 KiB
C

#ifndef __SMCC_CORE_STREAM_H__
#define __SMCC_CORE_STREAM_H__
#include "core_impl.h"
#include "core_macro.h"
#include "core_mem.h"
#include "core_str.h"
struct core_stream;
typedef struct core_stream core_stream_t;
#define core_stream_eof (-1)
struct core_stream {
cstring_t name;
/// @brief 读取指定数量的字符到缓冲区
usize (*read_buf)(core_stream_t *stream, char *buffer, usize count);
/// @brief 获取下一个字符
int (*peek_char)(core_stream_t *stream);
/// @brief 重置字符流位置
void (*reset_char)(core_stream_t *stream);
/// @brief 读取并消费下一个字符(移动流位置)
int (*next_char)(core_stream_t *stream);
/// @brief 释放资源
void (*free_stream)(core_stream_t *steam);
};
static inline usize core_stream_read_buf(core_stream_t *self, char *buffer,
usize count) {
return self->read_buf(self, buffer, count);
}
static inline int core_stream_peek_char(core_stream_t *self) {
return self->peek_char(self);
}
static inline void core_stream_reset_char(core_stream_t *self) {
self->reset_char(self);
}
static inline int core_stream_next_char(core_stream_t *self) {
return self->next_char(self);
}
static inline void core_stream_free_stream(core_stream_t *self) {
self->free_stream(self);
}
#ifndef __SMCC_CORE_NO_MEM_STREAM__
typedef struct core_mem_stream {
core_stream_t stream;
const char *data;
usize data_length;
usize curr_pos;
usize peek_pos;
cbool owned;
} core_mem_stream_t;
core_stream_t *core_mem_stream_init(core_mem_stream_t *stream, const char *data,
usize length, cbool need_copy);
#endif
#endif /* __SMCC_CORE_STREAM_H__ */