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

📄 lineedit.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
📖 第 1 页 / 共 2 页
字号:
            curPos++;        }        if (curPos < eol) {            new = curPos+1;            strcpy(now,new);            cnt = strlen(now);            putbytes(now,cnt);            curPos = now + cnt;            while(curPos <= eol) {                putchar(' ');                curPos++;                cnt++;            }            backup(cnt);        }        else {            curPos = now;            delete_to_end();            return;        }        curPos = now;        lineLen = strlen(startOfLine);    }}static voiddelete_to_end(){    char    *eol, *now, *sol;    eol = startOfLine + lineLen;    now = curPos;    if (curPos == eol)        return;    while(curPos < eol) {        putchar(' ');        curPos++;    }    if (now == startOfLine)        sol = now+1;    else        sol = now;    while(curPos >= sol) {        putchar('\b');        curPos--;    }    lineLen = now - startOfLine;    if (lineLen == 0) {        curPos = startOfLine;        *curPos = 0;    }    else        *(curPos+1) = '\0';}static voidldelete(){    char    *eol, *now;    int cnt;    if (lineLen == 0)        return;    cnt = 0;    eol = startOfLine + lineLen - 1;    now = curPos;    if (curPos != eol) {        while(curPos <= eol) {            *curPos = *(curPos+1);            curPos++;            cnt++;        }        putbytes(now,cnt-1);        putchar(' ');        backup((int)cnt);    }    else {        puts(" \b\b");        *eol = '\0';        now--;    }    curPos = now;    lineLen--;    if (lineLen == 0)        curPos = startOfLine;}/* showdone(): * Used as common completion code for the showprev() and * shownext() functions below. */static voidshowdone(int idx){    if (idx == HMAX) {        printf("History buffer empty.\007\n");        lMode = NEITHER;        return;    }    backup((int)(curPos - startOfLine));    lineLen = strlen(cmdhistory[shwidx]);    putbytes(cmdhistory[shwidx],lineLen);    lerase((int)(lastsize-lineLen));    backup((int)(lineLen));    strcpy(startOfLine,cmdhistory[shwidx]);    curPos = startOfLine;    lastsize = lineLen;}/* showprev() & shownext(): * Show previous or next command in history list based on  * the current position in the list being established by * the shwidx variable. */static voidshowprev(){    int i;    if (shwidx == 0)        shwidx = HMAX-1;    else        shwidx--;    for(i=0;i<HMAX;i++) {        if (*cmdhistory[shwidx])            break;        if (shwidx == 0)            shwidx = HMAX-1;        else            shwidx--;    }    showdone(i);}static voidshownext(){    int i;    if (shwidx == HMAX-1)        shwidx = 0;    else        shwidx++;    for(i=0;i<HMAX;i++) {        if (*cmdhistory[shwidx])            break;        if (shwidx == HMAX)            shwidx = 0;        else            shwidx++;    }    showdone(i);}static voidbackup(count)int count;{    char    string[MAXLINESIZE];    int i;    if (count <= 0)        return;    *string = '\0';    for(i=0;i<count;i++)        strcat(string,"\b");    putbytes(string,count);}static voidlerase(int count){    char    string[MAXLINESIZE];    int i;    if (count <= 0)        return;    *string = '\0';    for(i=0;i<count;i++)        strcat(string," ");    for(i=0;i<count;i++)        strcat(string,"\b");    putbytes(string,count*2);}static voidgotoend(){    char    string[MAXLINESIZE], *eol;    int i;    eol = startOfLine + lineLen -1;    for (i=0;i<MAXLINESIZE-1;i++) {        if (curPos == eol)            break;        string[i] = *curPos++;    }    if (i)        putbytes(string,i);}static voidgotobegin(){    char    string[MAXLINESIZE];    int i;    i = 0;    while(curPos != startOfLine) {        string[i++] = '\b';        curPos--;    }    putbytes(string,i);}/* History(): * Command used at the CLI to allow the user to dump the content * of the history buffer. */char * HistoryHelp[] = {        "Display command history",        "",        0,};    intHistory(int argc,char *argv[]){    int i;    for(i=stridx;i<HMAX;i++) {        if (cmdhistory[i][0])            printf("%s\n",cmdhistory[i]);    }    if (stridx) {        for(i=0;i<stridx;i++) {            if (cmdhistory[i][0])                printf("%s\n",cmdhistory[i]);        }    }    return(CMD_SUCCESS);}/* historyinit(): * Initialize the command history... */voidhistoryinit(){    int i;    shwidx = stridx = 0;    for (i=0;i<HMAX;i++)        cmdhistory[i][0] = 0;}/* historylog(): * This function is called by the CLI retrieval code to store away * the command in the CLI history list, a circular queue * (size HMAX) of most recent commands. */voidhistorylog(char *cmdline){    int idx;    if (strlen(cmdline) >= HISTLINESIZE)        return;    if (stridx == 0)        idx = HMAX-1;    else        idx = stridx -1;    /* don't store if this command is same as last command */    if (strcmp(cmdhistory[idx],cmdline) == 0)        return;    if (stridx == HMAX)        stridx = 0;    strcpy(cmdhistory[stridx++],cmdline);}static voidhistorysearch(void){    static char string[100];    char    *s, *ptr, *last, C;    int size, len, count;    lerase((int)lastsize);    s = string;    size = 0;    while(1) {        C = getchar();        if (C == '\b') {            if (size == 0)                continue;            puts("\b \b");            s--;            size--;            continue;        }        if ((C == '\r') || (C == '\n'))            break;        putchar(C);        size++;        *s++ = C;    }    backup((int)(size+1));    if (size != 0)        *s = '\0';    else         size = strlen(string);    count = 0;    while(1) {        ptr = cmdhistory[srchidx];        len = strlen(ptr);        last = ptr + len - size + 1;        while(ptr < last) {            if (strncmp(ptr,string,size) == 0)                 goto gotmatch;            ptr++;        }        if (srchidx == 0)            srchidx = HMAX-1;        else            srchidx--;        if (++count == HMAX) {            backup((int)(curPos - startOfLine));            lineLen = 0;            lerase((int)(size+1));            backup((int)(lineLen));            *startOfLine = '\0';            curPos = startOfLine;            lastsize = lineLen;            return;        }    }gotmatch:    backup((int)(curPos - startOfLine));    lineLen = strlen(cmdhistory[srchidx]);    putbytes(cmdhistory[srchidx],lineLen);    lerase((int)(lastsize-lineLen));    backup((int)(lineLen));    strcpy(startOfLine,cmdhistory[srchidx]);    curPos = startOfLine;    lastsize = lineLen;    if (srchidx == 0)        srchidx = HMAX-1;    else        srchidx--;    return;}#endif

⌨️ 快捷键说明

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