compile:细节修正。

This commit is contained in:
taynpg 2025-01-10 14:06:58 +08:00
parent ebf30ce7c1
commit 68a92f95bc
2 changed files with 53 additions and 15 deletions

34
Makefile Normal file
View File

@ -0,0 +1,34 @@
# 编译器和编译选项
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17 -O2
# 文件和目标
LIB_SRC = filecomplete.cpp
LIB_OBJ = $(LIB_SRC:.cpp=.o)
LIB_HEADER = filecomplete.h
MAIN_SRC = main.cpp
MAIN_OBJ = $(MAIN_SRC:.cpp=.o)
TARGET = main
# 默认目标
all: $(TARGET)
# 生成目标文件
$(TARGET): $(LIB_OBJ) $(MAIN_OBJ)
$(CXX) $(CXXFLAGS) -o $@ $^
# 编译库源文件
$(LIB_OBJ): $(LIB_SRC) $(LIB_HEADER)
$(CXX) $(CXXFLAGS) -c $< -o $@
# 编译主程序文件
$(MAIN_OBJ): $(MAIN_SRC)
$(CXX) $(CXXFLAGS) -c $< -o $@
# 清理生成文件
clean:
rm -f $(LIB_OBJ) $(MAIN_OBJ) $(TARGET)
# 伪目标
.PHONY: all clean

View File

@ -83,8 +83,6 @@ static std::vector<std::vector<char>> buf{};
static std::vector<char> word{};
static size_t wo{};
static size_t len{};
static short cy{};
static short cx{};
static char* main_buf{};
void trans2buf(char* buffer);
@ -210,9 +208,9 @@ std::pair<short, short> get_wh()
#endif
}
int get_u8_len(unsigned char ch)
size_t get_u8_len(unsigned char ch)
{
if (ch >= 0x00 && ch <= 0x7F) {
if (ch <= 0x7F) {
return 1;
} else if ((ch & 0xE0) == 0xC0) {
return 2;
@ -225,8 +223,10 @@ int get_u8_len(unsigned char ch)
} else if ((ch & 0xFE) == 0xFC) {
return 6;
} else {
return 0;
printf("invalid u8 first ch.");
exit(1);
}
return 0;
}
void supply(std::vector<char>& wch, char ch)
@ -436,13 +436,13 @@ char* fc_readline()
color_print(str_predict.data(), DEFAULT_PREDICT_COLOR);
}
// Move cursor
int cur_pos{};
size_t cur_pos{};
#if defined(STRCODE_GBK)
for (int i = 0; i < buf.size() && i < wo; ++i) {
cur_pos += static_cast<int>(buf[i].size());
cur_pos += buf[i].size();
}
#else
for (int i = 0; i < buf.size() && i < wo; ++i) {
for (size_t i = 0; i < buf.size() && i < wo; ++i) {
if (buf[i].size() > 1) {
cur_pos += 2;
} else {
@ -477,20 +477,20 @@ char* fc_readline()
// 在这里补全
if (!str_predict.empty()) {
std::vector<std::vector<char>> temp;
for (int i = 0; i < str_predict.size();) {
for (size_t i = 0; i < str_predict.size();) {
std::vector<char> b;
char curch = str_predict[i];
b.push_back(curch);
if (curch >= 0 && curch < 128) {
if (curch >= 0) {
temp.push_back(b);
++i;
} else {
#if defined(STRCODE_GBK)
int length = 2;
size_t length = 2;
#else
int length = get_u8_len(curch);
size_t length = get_u8_len(curch);
#endif
for (int z = 1; z < length; ++z) {
for (size_t z = 1; z < length; ++z) {
if ((i + z) < str_predict.size()) {
b.push_back(str_predict[i + z]);
}
@ -521,10 +521,14 @@ char* fc_readline()
#endif
switch (_getch()) {
case LEFT:
wo = wo < 1 ? 0 : (--wo);
if (wo > 0) {
--wo;
}
break;
case RIGHT:
wo = wo >= len ? len : (++wo);
if (wo < len) {
++wo;
}
break;
case UP:
break;