📄 search.c
字号:
#include "zped.h"
#include "myExternal.h"
bool searchInit()
{
long i = 0;
searchRow = current_R;
searchCol = current_R->rowHead;
for(i = 0; i < current_x; i++)
searchCol = searchCol->next;
searchTop = editTop;
search_x = current_x;
search_y = current_y;
Scursor_y = cursor_y;
return 1;
}
bool search_down()
{
int count = 0;
if(searchRow == 0 || searchTarget[0] == 0)
return 0;
while(searchRow != 0) {
count = 0;
while(searchCol != 0 && count < searchCount) {
if(searchTarget[count] == searchCol->ch) {
count++;
} else {
count = 0;
}
searchCol = searchCol->next;
search_x++;
}
if(count == searchCount)
return 1;
searchRow = searchRow->next;
if(searchRow != 0) {
searchCol = searchRow->rowHead;
if(Scursor_y == LINES-3)
searchTop = searchTop->next;
else
Scursor_y++;
search_y++;
search_x = 0;
}
}
return 0;
}
bool search_up()
{
int count = 0;
if(searchRow == 0 || searchTarget[0] == 0) {
mvwaddch(edit,5,5,'o');
wrefresh(edit);
sleep(1);
return 0;
}
while(searchRow != 0) {
count = searchCount-1;
while(searchCol != 0 && count >= 0) {
if(searchTarget[count] == searchCol->ch) {
count--;
} else {
count = searchCount-1;
}
searchCol = searchCol->pre;
search_x--;
}
if(count < 0) {
search_x++;
return 1;
}
searchRow = searchRow->pre;
if(searchRow != 0) {
searchCol = searchRow->rowHead;
while(searchCol->next != 0)
searchCol = searchCol->next;
if(Scursor_y == 0)
searchTop = searchTop->pre;
else
Scursor_y--;
search_y--;
search_x = searchRow->num-1;
}
}
return 0;
}
bool search_pre()
{
long int i;
/*do some initial jobs*/
if(current_x == 0) {
if(current_R == fileTop)
return 0;
else if(cursor_y == 0) {
searchTop = editTop->pre;
searchRow = current_R->pre;
searchCol = searchRow->rowHead;
while(searchCol->next != 0)
searchCol = searchCol->next;
search_x = searchRow->num-1;
search_y = current_y-1;
Scursor_y = cursor_y;
} else {
searchTop = editTop;
searchRow = current_R->pre;
searchCol = searchRow->rowHead;
while(searchCol->next != 0)
searchCol = searchCol->next;
search_x = searchRow->num-1;
search_y = current_y-1;
Scursor_y = cursor_y-1;
}
} else {
search_x = current_x - 1;
searchRow = current_R;
searchTop = editTop;
search_y = current_y;
Scursor_y = cursor_y;
searchCol = current_R->rowHead;
for(i = 0; i < search_x; i++)
searchCol = searchCol->next;
}
if(search_up())
return 1;
else
return 0;
}
bool search_next()
{
long int i;
if(current_R == fileBot && current_R->rowHead == 0)
return 0;
if(current_x == current_R->num-1) {
if(current_R == fileBot)
return 0;
else if(cursor_y == LINES-3) {
searchTop = editTop->next;
searchRow = current_R->next;
searchCol = searchRow->rowHead;
search_x = 0;
search_y = current_y+1;
Scursor_y = cursor_y;
} else {
searchTop = editTop;
searchRow = current_R->next;
searchCol = searchRow->rowHead;
search_x = 0;
search_y = current_y+1;
Scursor_y = cursor_y+1;
}
} else {
search_x = current_x + 1;
searchRow = current_R;
searchTop = editTop;
search_y = current_y;
Scursor_y = cursor_y;
searchCol = current_R->rowHead;
for(i = 0; i < search_x; i++)
searchCol = searchCol->next;
}
if(search_down())
return 1;
else
return 0;
}
bool replace_line(char * replaceWord,int n)
{
int count = 0;
int i = 0;
bool flat = 0;
searchRow = current_R;
searchCol = searchRow->rowHead;
searchTop = editTop;
search_x = 0;
search_y = current_y;
Scursor_y = cursor_y;
if(strcmp(replaceWord,searchTarget) == 0 || searchTarget[0] == 0)
return 1;
while(searchCol) {
count = 0;
while(searchCol != 0 && count < searchCount) {
if(searchTarget[count] == searchCol->ch) {
count++;
} else {
count = 0;
}
searchCol = searchCol->next;
search_x++;
}
if(count == searchCount) {
flat = 1;
current_x = search_x;
i = 0;
while(i < searchCount) {
dele_one();
i++;
}
i = 0;
while(i < n) {
add_one(replaceWord[i]);
i++;
}
search_x = current_x;
}
}
if(flat) {
current_x -= n;
return 1;
} else
return 0;
}
bool replace_below(char * replaceWord,int n)
{
int i = 0;
bool flat = 0;
searchInit();
if(strcmp(replaceWord,searchTarget) == 0 || searchTarget[0] == 0)
return 1;
while(searchRow) {
if(search_down()) {
flat = 1;
current_R = searchRow;
editTop = searchTop;
current_x = search_x;
current_y = search_y;
cursor_y = Scursor_y;
i = 0;
while(i < searchCount) {
dele_one();
i++;
}
i = 0;
while(i < n) {
add_one(replaceWord[i]);
i++;
}
search_x = current_x;
}
}
if(flat) {
current_x -= n;
return 1;
}
else
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -