⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ff.c

📁 这是我写的一个仿照linux下编辑器vim写的一个简单的全屏文本编辑器
💻 C
字号:
#include <stdio.h><stdlib.h>

#incl#ince "myExternal.h"

/*add a colum node*/



   if(!(temp =alloc(sizeof(Cnode))))

        return (Cnode *)0;

    /*if the node add at the front of the row*/

    if(current (Cnode *)m_x == 0) {

        haha->next = current_R->rowHead;

        if(current_R->rowHead != 0)

            current_R->rowHead->pre = haha;

        current_R->rowHead = haha;

        haha->pre = 0;

    } elaha->pre = target;

        haha->next = 0;

    } else {                    /*if the node add at the middle of  the row*/

        haha->next = target->next;

        target->next->pre = haha;

        haha->pre = target;

        target->xt = haha;

    }

    return haha;

}







/*delect a colum node*/

bool deleCnode(Cnode * target,Rnode * row)

{

    /*if the node is at the front of the row*/

    if(target->pre == 0) {

        row->rowHead = target->next;

        if(target->next != 0) {

            target->next->pre = 0;

        }

    } else if(target->next == 0) {    /*if the node is at the end of the row*/

        target->pre ->next = 0;

    } else {                    /*if the node is at the middle of the row*/

        target->pre->next = target->next;

        target->next->pre = target->pre;

    }

    free(target);

    return 1;

}







/*delect a row node*/

bool deleRnode(Rnode * target)

{

    if(target->pre == 0)

        return 0;

    /*if the node is at the end of the file*/

    if(target->next == 0) {

        target->pre->next = 0;

    } else {

        target->pre->next = target->next;

        target->next->pre = target->pre;

    }

    free(target);

    return 1;

}







/*add a row node*/

Rnode * addRnode()

{

    Rnode * haha;

    if(!(haha = (Rnode *)malloc(sizeof(Rnode))))

        return (Rnode *)0;

    /*if the node add at the end of the file*/

    if(current_R->next == 0) {

        haha->next = 0;

        current_R->next = haha;

        haha->pre = current_R;

        haha->rowHead = 0;

        haha->num = 0;

    } else {

        haha->next = current_R->next;

        current_R->next->pre = haha;

        haha->pre = current_R;

        current_R->next = haha;

        haha->rowHead = 0;

        haha->num = 0;

    }

    return haha;

}





void add_one(int ch)

{

    int i = 0;

    Cnode * p = current_R->rowHead;

    Cnode * haha = 0;

    while(i < current_x - 1 && p) {

        p = p->next;

        i++;

    }

    /*if the char is an enter*/

    if(ch == FKEY_ENTER || ch == '\n') {

        if(current_x == 0) {        /*if the enter is added at the front of the row*/

            haha = addCnode((Cnode *)0);

            haha->ch = '\n';

            current_R = addRnode();

            current_R->num = current_R->pre->num;

            current_R->pre->num = 1;

            current_R->rowHead = haha->next;

            if(haha->next != 0) {

                haha->next->pre = 0;

                haha->next = 0;

            }

            mvwaddch(edit,3,3,current_R->pre->rowHead->ch);

        } else if(current_x == current_R-> num) {    /*if the enter is added at the end of the row*/

            haha = addCnode(p);

            haha->ch = '\n';

            current_R->num++;

            current_R = addRnode();

            current_R->num = 0;

        } else {

            haha = addCnode(p);

            haha->ch = '\n';

            current_R = addRnode();

            current_R->num = current_R->pre->num - current_x;

            current_R->pre->num = current_x + 1;

            current_R->rowHead = haha->next;

            haha->next->pre = 0;

            haha->next = 0;/*update the associable variables*/

        }

        /*update the associable variables*/

        current_x = 0;

        cursor_y++;

        current_y++;



        if(/*current_R->pre  == editBot && totalLine >= LINES - 2*/cursor_y > LINES - 3) {

            cursor_y--;

            //editBot = editBot->next;

            editTop = editTop->next;

        }

        totalLine++;

        if(fileBot == current_R->pre)

            fileBot = current_R;

    } else {        /*if the char is not an enter*/

        if(current_x == 0) {        /*if the char is added at the front of the row*/

            haha = addCnode(0);

            current_R->num++;

            haha->pre = 0;

        } else if(current_x == current_R->num) {    /*if the char is added at the end of the row*/

            haha = addCnode(p);

            current_R->num++;

            haha->next = 0;

        } else {

            haha = addCnode(p);

            current_R->num++;

        }

        haha->ch = ch;

        current_x++;

    }

}







bool dele_one()

{

    long int i = 0;

    Cnode * p;

    Cnode * haha = 0;

    /*if the char to be delected is an enter that means the cursor is at the front of the line*/

    if(current_x == 0) {

        if(current_R == fileTop) {            /*if the cursor is at the first line of the file*/

            return 0;

        } else {                        /*if the cursor is not at the first line of the file*/

            p = current_R->pre->rowHead;

            while(p->ch != '\n')

                p = p->next;

            if(p->pre != 0) {

                haha = p->pre;

            }

            deleCnode(p,current_R->pre);

            if(haha == 0) {

                current_R->pre->rowHead = current_R->rowHead;

                //mvwaddch(edit,6,6,current_R->rowHead->ch);

            } else {

                haha->next = current_R->rowHead;

                if(current_R->rowHead != 0)

                    current_R->rowHead->pre = haha;

            }



            /*update the associable variables*/

            current_x = current_R->pre->num -1;

            current_R->pre->num = current_R->pre->num + current_R->num - 1;

            cursor_y--;

            current_y--;

            if(current_R == fileBot)

                fileBot = current_R->pre;

            if(editTop == current_R /*&& totalLine > LINES - 2*/) {

                editTop = editTop->pre;

                cursor_y++;

            }

            current_R = current_R->pre;

            deleRnode(current_R->next);

            totalLine--;

        }

    } else if(current_x == current_R->num) {    /*if the char to be delected is at the end of the line*/

        p = current_R->rowHead;

        while(p->next != 0)

            p = p->next;

        if(p->pre == 0)

            current_R->rowHead = 0;

        else {

            p->pre->next = 0;

            current_R->rowHead->pre = 0;

        }

        current_x--;

        current_R->num--;

        deleCnode(p,current_R);

    } else {                            /*if the char to be delected is at the middle of the line*/

        p = current_R->rowHead;

        while(i < current_x - 1) {

            p = p->next;

            i++;

        }

        if(p->pre == 0)

            current_R->rowHead = 0;

        else {

            p->pre->next = 0;

            current_R->rowHead->pre = 0;

        }

        current_x--;

        current_R->num--;

        deleCnode(p,current_R);

    }

}











bool readOneFile(char * pathName)

{

    int input;

    int i = 0;

    FILE * fp;

    if(!(fp = fopen(pathName,"r")))

        return false;

    while((input = getc(fp)) != EOF) {

        if(input == '\t')

            for(i = 0; i < 4; i++)

                add_one(' ');

        else

            add_one(input);

    }

    current_x = 0;

    current_y = 0;

    cursor_y = 0;

    current_R = fileTop;

    editTop = fileTop;

    fclose(fp);

    return 1;

}







bool writeOneFile(char * pathName)

{

    int output;

    Rnode * Rhaha;

    Cnode * Chaha;

    FILE * fp;

    if(!(fp = fopen(pathName,"w")))

        return false;

    for(Rhaha = fileTop; Rhaha != 0; Rhaha = Rhaha->next) {

        for(Chaha = Rhaha->rowHead; Chaha != 0; Chaha = Chaha->next) {

            putc(Chaha->ch,fp);

        }

    }

    fclose(fp);

    return 1;

}



















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -