compile:细节修正。
This commit is contained in:
parent
ebf30ce7c1
commit
68a92f95bc
34
Makefile
Normal file
34
Makefile
Normal 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
|
@ -83,8 +83,6 @@ static std::vector<std::vector<char>> buf{};
|
|||||||
static std::vector<char> word{};
|
static std::vector<char> word{};
|
||||||
static size_t wo{};
|
static size_t wo{};
|
||||||
static size_t len{};
|
static size_t len{};
|
||||||
static short cy{};
|
|
||||||
static short cx{};
|
|
||||||
static char* main_buf{};
|
static char* main_buf{};
|
||||||
|
|
||||||
void trans2buf(char* buffer);
|
void trans2buf(char* buffer);
|
||||||
@ -210,9 +208,9 @@ std::pair<short, short> get_wh()
|
|||||||
#endif
|
#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;
|
return 1;
|
||||||
} else if ((ch & 0xE0) == 0xC0) {
|
} else if ((ch & 0xE0) == 0xC0) {
|
||||||
return 2;
|
return 2;
|
||||||
@ -225,8 +223,10 @@ int get_u8_len(unsigned char ch)
|
|||||||
} else if ((ch & 0xFE) == 0xFC) {
|
} else if ((ch & 0xFE) == 0xFC) {
|
||||||
return 6;
|
return 6;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
printf("invalid u8 first ch.");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void supply(std::vector<char>& wch, char ch)
|
void supply(std::vector<char>& wch, char ch)
|
||||||
@ -436,13 +436,13 @@ char* fc_readline()
|
|||||||
color_print(str_predict.data(), DEFAULT_PREDICT_COLOR);
|
color_print(str_predict.data(), DEFAULT_PREDICT_COLOR);
|
||||||
}
|
}
|
||||||
// Move cursor
|
// Move cursor
|
||||||
int cur_pos{};
|
size_t cur_pos{};
|
||||||
#if defined(STRCODE_GBK)
|
#if defined(STRCODE_GBK)
|
||||||
for (int i = 0; i < buf.size() && i < wo; ++i) {
|
for (int i = 0; i < buf.size() && i < wo; ++i) {
|
||||||
cur_pos += static_cast<int>(buf[i].size());
|
cur_pos += buf[i].size();
|
||||||
}
|
}
|
||||||
#else
|
#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) {
|
if (buf[i].size() > 1) {
|
||||||
cur_pos += 2;
|
cur_pos += 2;
|
||||||
} else {
|
} else {
|
||||||
@ -477,20 +477,20 @@ char* fc_readline()
|
|||||||
// 在这里补全
|
// 在这里补全
|
||||||
if (!str_predict.empty()) {
|
if (!str_predict.empty()) {
|
||||||
std::vector<std::vector<char>> temp;
|
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;
|
std::vector<char> b;
|
||||||
char curch = str_predict[i];
|
char curch = str_predict[i];
|
||||||
b.push_back(curch);
|
b.push_back(curch);
|
||||||
if (curch >= 0 && curch < 128) {
|
if (curch >= 0) {
|
||||||
temp.push_back(b);
|
temp.push_back(b);
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
#if defined(STRCODE_GBK)
|
#if defined(STRCODE_GBK)
|
||||||
int length = 2;
|
size_t length = 2;
|
||||||
#else
|
#else
|
||||||
int length = get_u8_len(curch);
|
size_t length = get_u8_len(curch);
|
||||||
#endif
|
#endif
|
||||||
for (int z = 1; z < length; ++z) {
|
for (size_t z = 1; z < length; ++z) {
|
||||||
if ((i + z) < str_predict.size()) {
|
if ((i + z) < str_predict.size()) {
|
||||||
b.push_back(str_predict[i + z]);
|
b.push_back(str_predict[i + z]);
|
||||||
}
|
}
|
||||||
@ -521,10 +521,14 @@ char* fc_readline()
|
|||||||
#endif
|
#endif
|
||||||
switch (_getch()) {
|
switch (_getch()) {
|
||||||
case LEFT:
|
case LEFT:
|
||||||
wo = wo < 1 ? 0 : (--wo);
|
if (wo > 0) {
|
||||||
|
--wo;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
wo = wo >= len ? len : (++wo);
|
if (wo < len) {
|
||||||
|
++wo;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UP:
|
case UP:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user