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

📄 sample

📁 linux 下类似于TC功能的编译器,但还没有完成,希望大家共同研究
💻
📖 第 1 页 / 共 3 页
字号:
w#include "codearea.h"int CodeArea::InitCodeArea(int Y,int X,int Height,int Width,int Color,int FontStyle,int WinType){        int ret=0;        if(InitBaseWindow(Y,X,Height,Width,Color,0,FontStyle,WinType,"")==FALSE)                return FALSE;        keypad(basewin,TRUE);        draw_box(0,0,Height,Width, COLOR_PAIR(Color)|' ',COLOR_PAIR(Color));        wmove(basewin,0,0);        curs_set(1);        wrefresh(basewin);        insertmode=TRUE;        currow=0;        curcol=0;        offline=0;        offcol=0;        totalrow=1;                        //in order to process untitled file        totalcol=0;        maxcol=0;        curpage=0;        totalpage=0;        pagelist=NULL;        beginpage=NULL;        multiremark=FALSE;        sym=SYM_NULL;        /*alloc the first page*/        if ((pagelist=AllocPage())==NULL)                ret=-ENOMEM;        pagelist->next=pagelist;        pagelist->prev=pagelist;        beginpage=pagelist;        return ret;}int CodeArea::CodeAreaDriver(int key){        int ret=0;        int i=0;        int tempy,tempx;        tempy=tempx=0;         switch(key)        {                case KEY_LEFT:                        if(curcol>0)                        {                                getyx(basewin,tempy,tempx);                                curcol--;                                if(tempx<=0 && offcol>0)                                {                                        offcol--;                                        ShowPage(offcol*TABSIZE);                                        wmove(basewin,tempy,tempx+TABSIZE-1);                                }                                else                                {                                        wmove(basewin,tempy,tempx-1);                                }                                ret = UPDATE_STATUS;                        }                        break;                case KEY_RIGHT:                        if(curcol<totalcol)                        {                                getyx(basewin,tempy,tempx);                                curcol++;                                if(tempx+1>=GetWidth())                                {                                        offcol++;                                        ShowPage(offcol*TABSIZE);                                        wmove(basewin,tempy,tempx-TABSIZE+1);                                }                                else                                {                                        wmove(basewin,tempy,tempx+1);                                }                                ret = UPDATE_STATUS;                        }                        break;                case KEY_UP:                        if(currow>0)                        {                                getyx(basewin,tempy,tempx);                                currow--;                                tempy--;                                totalcol=GetCurColWidth(NULL,currow);                                if( tempy < 0 )                                {                                        tempy++;                                        if( (int)((currow-tempy)/GetHeight()) !=curpage)                                        {                                                if (beginpage->prev!=pagelist->prev)                                                {                                                        beginpage=beginpage->prev;                                                        curpage--;                                                }                                        }                                        if(offcol>0)                                        {                                                curcol=0;                                                offcol=0;                                                tempx=curcol;                                        }                                        else                                        {                                                if (curcol>totalcol)                                                {                                                        tempx=totalcol;                                                        curcol=totalcol;                                                }                                        }                                        ShowPage();                                }                                else                                {                                        if(offcol>0)                                        {                                                currow++;                                                curcol=0;                                                offcol=0;                                                ShowPage();                                                currow--;                                                tempx=curcol;                                        }                                        else                                        {                                                if (curcol>totalcol)                                                {                                                        tempx=totalcol;                                                        curcol=totalcol;                                                }                                        }                                }                                wmove(basewin,tempy,tempx);                                                                        ret = UPDATE_STATUS;                        }                        break;                case KEY_DOWN:                        if(currow+1<totalrow)                        {                                getyx(basewin,tempy,tempx);                                currow++;                                tempy++;                                totalcol=GetCurColWidth(NULL,currow);                                if(tempy>=GetHeight())                                {                                        tempy--;                                        if( (int)((currow-tempy)/GetHeight()) !=curpage)                                        {                                                if (beginpage->next!=pagelist)                                                {                                                        beginpage=beginpage->next;                                                        curpage++;                                                }                                        }                                        if(offcol>0)                                        {                                                curcol=0;                                                offcol=0;                                                tempx=curcol;                                        }                                        else                                        {                                                if (curcol>totalcol)                                                {                                                        tempx=totalcol;                                                        curcol=totalcol;                                                }                                        }                                        ShowPage();                                }                                else                                {                                        if(offcol>0)                                        {                                                currow--;                                                curcol=0;                                                offcol=0;                                                ShowPage();                                                currow++;                                                tempx=curcol;                                        }                                        else                                        {                                                if (curcol>totalcol)                                                {                                                        tempx=totalcol;                                                        curcol=totalcol;                                                }                                        }                                }                                wmove(basewin,tempy,tempx);                                ret = UPDATE_STATUS;                        }                        break;                case KEY_HOME:                        curcol=0;                        getyx(basewin,tempy,tempx);                        if(offcol>0)                        {                                offcol=0;                                ShowPage();                        }                        wmove(basewin,tempy,curcol);                        ret =UPDATE_STATUS;                        break;                case KEY_END:                        getyx(basewin,tempy,tempx);                        curcol=totalcol;                        if(totalcol>=GetWidth())                        {                                offcol=(int)((totalcol-GetWidth())/TABSIZE)+1;                                ShowPage(offcol*TABSIZE);                                wmove(basewin,tempy,totalcol-offcol*TABSIZE);                        }                        else                                wmove(basewin,tempy,curcol);                        ret = UPDATE_STATUS;                        break;                case 10://KEY_ENTER:                        getyx(basewin,tempy,tempx);                        if(totalrow%GetHeight()==0)                //need a new page                        {                                PageList newp=NULL;                                PageList dptr=pagelist->prev;                                newp=AllocPage();                                InsertPage(dptr,newp);                        }                        ShiftLines(LocatePage(NULL,currow),currow%CODE_QSET,1);                        CopyLine(NULL,offcol*TABSIZE+tempx,totalcol-offcol*TABSIZE-tempx,TRUE);                        offcol=0;                        if(tempy+1>=CODE_QSET)                        {                                currow++;                                if( (int)((currow-tempy)/GetHeight()) !=curpage)                                {                                        if (beginpage->next!=pagelist)                                        {                                                beginpage=beginpage->next;                                                curpage++;                                        }                                }                                ShowPage();                        }                        else                        {                                ShowPage();                                currow++;                                tempy=tempy+1;                        }                        curcol=0;                        totalrow=totalrow+1;                        totalcol=GetCurColWidth(NULL,currow);                        wmove(basewin,tempy,curcol);                        ret = UPDATE_STATUS;                        break;                case KEY_F(2):                        LostActive();                        ret = ACTIVE_TOPMENU;                        break;                case KEY_BACKSPACE:                        int ln;                        PageList pg;                        getyx(basewin,tempy,tempx);                        pg=LocatePage(NULL,currow);                        ln=currow % CODE_QSET;                        if(tempx>0)                        {                                for(i=0;i<totalcol-curcol;i++)                                {                                        pg->data[ln][curcol-1+i]=pg->data[ln][curcol+i];                                }                                pg->data[ln][totalcol-1]='\0';                                totalcol--;/***Strictly speaking,maxcol should be set according to the maxium columns of the whole file.**However, in order to get exact value after "backspace" a character,width comparision action**must be taken among all lines in the file. It is time consuming very much. I just ignore it.**The result of doing so may lays that the scale of hscroll is rough in some circumstances.*///                                maxcol=(maxcol>totalcol)?(maxcol):(totalcol);                                tempx--;                                curcol--;                                ShowLine(pg->data[ln],curcol,GetWidth()-tempx,tempy,tempx);                                wmove(basewin,tempy,tempx);                        }                        else                        {                        }                        ret = UPDATE_STATUS;                        break;                case KEY_DC:                        break;                case KEY_PPAGE:                                                if(beginpage->prev!=pagelist->prev)                        {                                getyx(basewin,tempy,tempx);                                currow=currow-GetHeight();                                if(currow<0)                                        currow=0;                                beginpage=beginpage->prev;                                curpage--;                                offcol=0;                                curcol=0;                                totalcol=GetCurColWidth(NULL,currow);                                ShowPage();                                wmove(basewin,tempy,curcol);                                ret = UPDATE_STATUS;                        }                        break;                case KEY_NPAGE:                        getyx(basewin,tempy,tempx);                        if(beginpage->next!=pagelist && (currow-tempy+GetHeight())<totalrow)                        {                                int endline=currow-tempy+GetHeight()*2-1;                                int nextpgl=currow-tempy+GetHeight();                                currow=currow+GetHeight();                                beginpage=beginpage->next;                                curpage++;                                offcol=0;                                curcol=0;                                ShowPage();                                if(endline<totalrow || currow<totalrow)                                {                                        wmove(basewin,tempy,curcol);                                }                                else                                {

⌨️ 快捷键说明

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