?? cut.c
字號:
#include "zped.h"
#include "myExternal.h"
bool deleMidLine(Rnode * target);
bool selectInit()
{
long int i = 0;
long int cursor_x;
long int number = 0;
Cnode * temp = current_R->rowHead;
selectLines = 1;
startLine = current_R;
endLine = current_R;
if(current_R == fileBot) {
number = current_R->num-1;
} else {
number = current_R->num-2;
}
if(current_x > number)
current_x = number;
if(number <= 0)
current_x = 0;
startx = current_x;
startp = startx;
while(i < startx) {
temp = temp->next;
i++;
}
startPoint = temp;
endPoint = temp;
cursor_x = whereisX();
wmove(edit,cursor_y,cursor_x);
wrefresh(edit);
return 1;
}
bool select_left()
{
Cnode * temp;
long int cursor_x;
move_x = current_x;
if(startPoint == endPoint)
Cflag = 1;
if(Cflag == 1) {
if(current_x > 0) {
current_x--;
move_x--;
startp--;
cursor_x = whereisX();
startPoint = startPoint->pre;
startx = current_x;
wmove(edit,cursor_y,cursor_x);
} else {
return 0;
}
return 1;
} else {
if(current_x > 0) {
current_x--;
move_x--;
cursor_x = whereisX();
endPoint = endPoint->pre;
startx = current_x;
wmove(edit,cursor_y,cursor_x);
} else {
return 0;
}
return 1;
}
return 1;
}
bool select_right()
{
long int cursor_x;
long int number = 0;
move_x = current_x;
if(startPoint == endPoint)
Cflag = 2;
if(current_R == fileBot) {
number = current_R->num-1;
} else {
number = current_R->num-2;
}
if(Cflag == 1) {
if(number > current_x) {
current_x++;
move_x++;
cursor_x = whereisX();
startPoint = startPoint->next;
startx = current_x;
wmove(edit,cursor_y,cursor_x);
} else {
return 0;
}
return 1;
} else {
if(number > current_x) {
current_x++;
move_x++;
cursor_x = whereisX();
endPoint = endPoint->next;
startx = current_x;
wmove(edit,cursor_y,cursor_x);
} else {
return 0;
}
return 1;
}
return 1;
}
bool select_up()
{
long int cursor_x;
long int i = 0;
bool fflag = false;
Cnode * temp;
if(startLine == endLine)
Rflag = 1;
if(current_R == fileTop) {
return 0;
//} else if(current_R->pre->num == 1) {
// return 0;
} else if(current_R == editTop /*&& totalLine >= LINES-2*/) {
editTop = editTop->pre;
current_R = current_R->pre;
} else {
current_R = current_R->pre;
cursor_y--;
}
if(current_R->num-2 < startx) {
current_x = current_R->num-2;
if(current_x < 0)
current_x = 0;
}
cursor_x = whereisX();
current_y--;
wmove(edit,cursor_y,cursor_x);
if(Rflag == 1) {
Cflag = 1;
selectLines++;
startLine = startLine->pre;
startPoint = current_R->rowHead;
while(i < current_x) {
startPoint = startPoint->next;
i++;
}
} else {
Cflag = 2;
selectLines--;
endLine = endLine->pre;
if(endLine == startLine) {
//endPoint = startPoint;
endPoint = current_R->rowHead;
fflag = true;
while(i < current_x) {
if(endPoint == startPoint)
fflag = false;
endPoint = endPoint->next;
i++;
}
if(fflag) {
Cflag = 1;
temp = endPoint;
endPoint = startPoint;
startPoint = temp;
}
} else {
endPoint = current_R->rowHead;
while(i < current_x) {
endPoint = endPoint->next;
i++;
}
}
}
return 1;
}
bool select_down()
{
long int cursor_x;
long int number;
long int i = 0;
bool fflag = false;
Cnode * temp;
if(startLine == endLine)
Rflag = 2;
if(current_R == fileBot) {
return 0;
} else if (current_R->next->num == 1 && current_R->next == fileBot) {
return 0;
} else if (/*current_R == editBot && totalLine >= LINES-2*/cursor_y == LINES - 3) {
//editBot = editBot->next;
editTop = editTop->next;
current_R = current_R->next;
} else {
current_R = current_R->next;
cursor_y++;
}
if(current_R == fileBot) {
number = current_R->num-1;
} else {
number = current_R->num-2;
}
if(number < startx)
current_x = number;
else
current_x = startx;
if(number <= 0)
current_x = 0;
cursor_x = whereisX();
current_y++;
wmove(edit,cursor_y,cursor_x);
if(Rflag == 1) {
Cflag = 1;
selectLines--;
startLine = startLine->next;
if(startLine == endLine) {
//startPoint = endPoint;
startPoint = startLine->rowHead;
while(i < current_x) {
if(startPoint == endPoint)
fflag = true;
startPoint = startPoint->next;
i++;
}
if(fflag) {
Cflag = 2;
temp = endPoint;
endPoint = startPoint;
startPoint = temp;
}
} else {
startPoint = startLine->rowHead;
while(i < current_x) {
startPoint = startPoint->next;
i++;
}
}
} else {
Cflag = 2;
selectLines++;
endLine = endLine->next;
endPoint = endLine->rowHead;
i = 0;
while(i < current_x) {
endPoint = endPoint->next;
i++;
}
}
return 1;
}
void freeList(Cnode * target)
{
Cnode * temp;
Cnode * next;
if(target == 0)
return;
if(target->next == 0) {
free(target);
} else {
temp = target;
next = target->next;
while(next != 0) {
free(temp);
temp = next;
next = next->next;
}
free(temp);
}
}
bool deleStartLine()
{
Cnode * temp;
long int i = 1;
bool empty_line = 0;
if(startLine == endLine) {
temp = startPoint;
while(temp != endPoint) {
temp = temp->next;
i++;
}
/*if the startPoint is at the front of the line*/
if(startPoint ->pre == 0) {
/*if the endPoint is at the fileBot or at the fileTop*/
if(endPoint->next == 0 && startLine == fileBot) {
startLine->rowHead = 0;
} else if(endPoint->next == 0 && startPoint->ch == '\n') {//empty line
if(startLine == fileTop) {
startLine = startLine->next;
fileTop = fileTop->next;
editTop = fileTop;
deleMidLine(startLine->pre);
}
else {
startLine = startLine->pre;
deleMidLine(startLine->next);
}
empty_line = true;
} else { /*if the endPoint is not at the fileBot*/
startLine->rowHead = endPoint->next;
endPoint->next->pre = 0;
}
} else { /*if the startPoint is not at the front of the line*/
if(endPoint->next == 0) {
startPoint->pre->next = 0;
} else {
startPoint->pre->next = endPoint->next;
endPoint->next->pre = startPoint->pre;
//mvwaddch(edit,4,4,'0'+i);
wrefresh(edit);
}
}
if(!empty_line) {
endPoint->next = 0;
wrefresh(edit);
freeList(startPoint);
startLine->num = startLine->num - i;
}
} else {
temp = startPoint;
while(temp->next != 0) {
temp = temp->next;
i++;
}
/*if the startPoint is at the front of the line*/
if(startPoint->pre == 0) {
startLine->rowHead = 0;
} else if(endPoint->next == 0 && startPoint->ch == '\n') {//empty line
if(startLine == fileTop) {
startLine->rowHead = 0;
} else {
startLine = startLine->pre;
empty_line = true;
deleMidLine(startLine->next);
}
} else { /*if the startPoint is not at the front of the line*/
startPoint->pre->next = 0;
}
if(!empty_line) {
freeList(startPoint);
startLine->num = startLine->num - i;
}
}
return 1;
}
bool deleMidLine(Rnode * target)
{
if(target == editTop)
editTop = startLine;
freeList(target->rowHead);
deleRnode(target);
totalLine--;
return 1;
}
bool deleEndLine()
{
long int i = 1;
Cnode * temp;
Cnode * target = endLine->rowHead;
if(endLine->rowHead->ch == '\n')
return 0;
if(endLine == fileBot)
fileBot = startLine;
/*if the endPoint is at the fileBot*/
if(endPoint->next == 0) {
endLine->num = 0;
endLine->rowHead = 0;
} else { /*if the endPoint is not at the fileBot*/
temp = endPoint;
while(temp->pre != 0) {
i++;
temp = temp->pre;
}
endLine->num = endLine->num - i;
endLine->rowHead = endPoint->next;
endPoint->next->pre = 0;
}
totalLine--;
endPoint->next = 0;
freeList(target);
return 1;
}
bool deleSelect()
{
Cnode * tempp;
Rnode * temp;
Rnode * next;
long int i = 0;
/*if the startLine is equal to the endLine*/
if(startLine == endLine) {
deleStartLine();
} else if(startLine->next == endLine) { /*if the startLine is just above the endLine*/
deleStartLine();
deleEndLine();
if(endLine->num == 0) {
deleRnode(endLine);
} else {
if(startLine->num == 0) {
startLine->rowHead = endLine->rowHead;
endLine->rowHead->pre = 0;
} else {
tempp = startLine->rowHead;
while(tempp->next != 0)
tempp = tempp->next;
tempp->next = endLine->rowHead;
endLine->rowHead->pre = tempp;
}
startLine->num += endLine->num;
deleRnode(endLine);
}
} else { /*if the startLine is at less one line above the endLine*/
temp = startLine->next;
while(temp != endLine) {
next = temp->next;
deleMidLine(temp);
temp = next;
}
deleStartLine();
deleEndLine();
if(endLine->num == 0) {
deleRnode(endLine);
} else {
if(startLine->num == 0) {
startLine->rowHead = endLine->rowHead;
endLine->rowHead->pre = 0;
} else {
tempp = startLine->rowHead;
while(tempp->next != 0)
tempp = tempp->next;
tempp->next = endLine->rowHead;
endLine->rowHead->pre = tempp;
}
startLine->num += endLine->num;
deleRnode(endLine);
}
}
temp = editTop;
i = 0;
while(temp != startLine) {
i++;
temp = temp->next;
}
cursor_y = i;
temp = fileTop;
i = 0;
while(temp != startLine) {
i++;
temp = temp->next;
}
current_y = i;
current_R = startLine;
current_x = MINV(startx,startp);
move_x = current_x;
dele_one();
return 1;
}
bool copyDestroy()
{
Bnode * Btemp;
Bnode * Bnext;
Btemp = buffer;
if(buffer == 0)
return 0;
if(buffer->next == 0)
free(Btemp);
else {
Bnext = Btemp->next;
while(Bnext) {
free(Btemp);
Btemp = Bnext;
Bnext = Bnext->next;
}
free(Btemp);
}
buffer = 0;
length = 0;
return 1;
}
bool copySelect()
{
Cnode * Ctemp;
Rnode * Rtemp;
Bnode * Btemp;
Bnode * Bnow;
int i = 0;
copyDestroy();
length = 0;
if(!(buffer = (Bnode *)malloc(sizeof(Bnode))))
return 0;
buffer->next = 0;
Bnow = buffer;
/*if the start line is just the end line*/
if(startLine == endLine) {
Ctemp = startPoint;
while(Ctemp != endPoint->next) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
} else if(startLine->next == endLine) { /* if the start is just abovt the end line*/
/*deal with the start line*/
Ctemp = startPoint;
while(Ctemp != 0) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
/*deal with the end line*/
Ctemp = endLine->rowHead;
while(Ctemp != endPoint->next) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
} else {
/*deal with the end line*/
Ctemp = startPoint;
while(Ctemp != 0) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
/*deal with the middle line*/
Rtemp = startLine->next;
while(Rtemp != endLine) {
Ctemp = Rtemp->rowHead;
while(Ctemp != 0) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
Rtemp = Rtemp->next;
}
/*deal with the end line*/
Ctemp = endLine->rowHead;
while(Ctemp != endPoint->next) {
Bnow->buf[i++] = Ctemp->ch;
length++;
Ctemp = Ctemp->next;
if(i == MAXSIZE) {
if(!(Btemp = (Bnode *)malloc(sizeof(Bnode))))
return 0;
Bnow->next = Btemp;
Bnow = Btemp;
Bnow->next = 0;
i = 0;
}
}
}
return 1;
}
bool pasteSelect()
{
Bnode * Btemp;
int i = 0;
long ll = 0;
Btemp = buffer;
while(Btemp != 0 && ll < length) {
while(i < MAXSIZE && ll <length) {
add_one(Btemp->buf[i++]);
ll++;
}
Btemp = Btemp->next;
i = 0;
}
return 1;
}
bool cutSelect()
{
copySelect();
deleSelect();
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -