📄 ledlib.c
字号:
curPs = 1; break; case 'n': case 'N': if (histLn [0] == EOS) { beep (ledId->outFd); break; } save (); if (ch == 'N') histLn [0] = histLn [0] == '/' ? '?' : '/'; if (! histFind (ledId, histLn, curLn)) { beep (ledId->outFd); curLn [0] = EOS; } curPs = 0; break; case 'k': case '-': save (); do { if (histPrev (ledId, curLn) == ERROR) { beep (ledId->outFd); break; } } while (--number > 0); number = 0; curPs = 0; break; case 'j': case '+': save (); do { if (histNext (ledId, curLn) == ERROR) { beep (ledId->outFd); break; } } while (--number > 0); number = 0; curPs = 0; break; case 'h': do { if (curPs > 0) curPs--; } while (--number > 0); number = 0; break; case 'l': case ' ': do { if ((strlen (curLn) != 0)&&(curPs < strlen (curLn) - 1)) curPs++; } while (--number > 0); number = 0; break; case 'w': case 'W': /* ignore punctuation */ case 'b': case 'B': /* ignore punctuation */ case 'e': case 'E': /* ignore punctuation */ { int origPs = curPs; int dir = (ch == 'b' || ch == 'B') ? BACKWARD :FORWARD; BOOL word = ch != 'w' && ch != 'W'; do { search (isupper ((int)ch), word, curLn, &curPs, dir); } while (curPs != origPs && --number > 0); number = 0; break; } case 'f': case 't': /* doesn't backward step * XXX - not implemented */ setPreempt (&catchFunc, (FUNCPTR)findFwd); break; case 'F': case 'T': /* doesn't forward step * XXX - not implemented */ setPreempt (&catchFunc, (FUNCPTR)findBwd); break; case 'r': strcpy (saveLn, curLn); setPreempt (&catchFunc, (FUNCPTR)replace); break; case 'R': strcpy (saveLn, curLn); overStrike = TRUE; ledId->cmdMode = FALSE; break; case 'A': curPs = strlen (curLn); /* drop thru */ case 'a': ledId->cmdMode = FALSE; strcpy (saveLn, curLn); if (curPs < strlen (curLn)) curPs++; break; case 'x': strcpy (saveLn, curLn); number = min (number, strlen (curLn) - curPs); ix = 0; do { ledId->buffer [ix++] = curLn [curPs]; if (curPs < strlen (curLn) - 1) strcpy (&curLn [curPs], &curLn [curPs + 1]); else { curLn [curPs] = EOS; if (curPs > 0) curPs--; else break; } } while (--number > 0); number = 0; ledId->buffer [ix] = EOS; break; case 'X': strcpy (saveLn, curLn); ix = 0; do { if (curPs > 0) { curPs--; ledId->buffer [ix++] = curLn [curPs]; strcpy (&curLn [curPs], &curLn [curPs + 1]); } else if (strlen (curLn) == 1) { ledId->buffer [ix++] = curLn [curPs]; curLn [curPs] = EOS; } else break; } while (--number > 0); number = 0; ledId->buffer [ix] = EOS; break; case 'c': strcpy (saveLn, curLn); setPreempt (&catchFunc, (FUNCPTR)change); break; case 'C': strcpy (saveLn, curLn); ledId->cmdMode = FALSE; curLn [curPs] = EOS; break; case 's': strcpy (saveLn, curLn); number = number ? number : 1; ix = 0; if (number >= strlen (curLn) - curPs) curLn [curPs] = EOS; else { do { ledId->buffer [ix++] = curLn [curPs]; if (curPs < strlen (curLn) - 1) strcpy (&curLn [curPs], &curLn [curPs + 1]); else { curLn [curPs] = EOS; if (curPs > 0) curPs--; else break; } } while (--number > 0); } number = 0; ledId->buffer [ix] = EOS; ledId->cmdMode = FALSE; break; case 'S': strcpy (saveLn, curLn); if (change ('c', curLn, &curPs, &number, ledId) == ERROR) beep (ledId->outFd); break; case 'd': strcpy (saveLn, curLn); setPreempt (&catchFunc, (FUNCPTR)deletec); break; case 'D': strcpy (saveLn, curLn); strncpy (ledId->buffer, &curLn [curPs], strlen (&curLn [curPs]) + 1); /* +EOS */ curLn [curPs] = EOS; if (curPs > 0) curPs--; break; case 'I': curPs = 0; /* drop thru */ case 'i': strcpy (saveLn, curLn); number = 0; /* can't handle "count" */ ledId->cmdMode = FALSE; break; case 'p': if (strlen (ledId->buffer) == 0) break; if (strlen (curLn) == 0) goto caseP; /* treat like 'P' */ number = 0; /* can't handle "count" */ if (strlen (curLn) + strlen (ledId->buffer) < maxBytes) { strcpy (saveLn, curLn); if (++curPs < strlen (curLn)) { /* insert buffer into curLn */ bcopy (&curLn [curPs], &curLn [curPs + strlen (ledId->buffer)], strlen (&curLn [curPs]) + 1); /* +EOS */ bcopy (ledId->buffer, &curLn [curPs], strlen (ledId->buffer)); } else /* buffer goes after curLn */ strcat (curLn, ledId->buffer); curPs += strlen (ledId->buffer) - 1; } else beep (ledId->outFd); break; case 'P': caseP: number = 0; /* can't handle "count" */ if (strlen (ledId->buffer) == 0) break; if (strlen (curLn) + strlen (ledId->buffer) < maxBytes) { strcpy (saveLn, curLn); /* insert buffer into curLn */ bcopy (&curLn [curPs], &curLn [curPs + strlen (ledId->buffer)], strlen (&curLn [curPs]) + 1); /* +EOS */ bcopy (ledId->buffer, &curLn [curPs], strlen (ledId->buffer)); if (curPs == 0) curPs--; curPs += strlen (ledId->buffer); } else beep (ledId->outFd); break; case 'u': case 'U': /* restore original line * XXX - not implemented */ if (strlen (saveLn) != 0) { bswap (curLn, saveLn, max (strlen (curLn), strlen (saveLn)) + 1); /* +EOS */ if (curPs == strlen (saveLn) - 1 || curPs > strlen (curLn)) { curPs = strlen (curLn) - 1; } } else beep (ledId->outFd); break; case RET_CHAR: done = TRUE; returnVal = strlen (curLn); break; case '$': curPs = strlen (curLn) - 1; break; case '0': if (number == 0) { curPs = 0; break; } /* drop thru */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (number < 0) number = 0; number = number * 10 + (ch - '0'); break; case '~': strcpy (saveLn, curLn); ch = curLn [curPs]; if (isalpha ((int)ch)) curLn [curPs] = islower ((int)ch) ? toupper ((int)ch) : tolower (ch); if (curPs < strlen (curLn) - 1) curPs++; break; case '^': for (curPs = 0; curLn [curPs] != EOS && isspace ((int)curLn[curPs]); curPs++) ; break; case RDW_CHAR: write (ledId->outFd, "\n", 1); (void)writen (ledId->outFd, ' ', curPs); strcpy (oldLn, ""); break; case CMP_CHAR: strcpy (saveLn, curLn); if (! completeName (curLn, &curPs)) beep (ledId->outFd); break; default: beep (ledId->outFd); break; } } else { /* input mode */ if (ch == tyEofChar && curPs == 0) { /* only return EOF when used at the beginning of line */ done = TRUE; returnVal = EOF; } else if (ch == tyBackspaceChar) { if (curPs > 0) { strcpy (&curLn [curPs - 1], &curLn [curPs]); curPs--; } } else if (ch == tyDeleteLineChar) { curLn [0] = EOS; curPs = 0; } else switch (ch) { case ESC_CHAR: overStrike = FALSE; if (! srchMode) { ledId->cmdMode = TRUE; if (curPs > 0) curPs--; break; } /* drop thru */ case RET_CHAR: if (srchMode) { if (strcmp (curLn, "/") == 0 || strcmp (curLn, "?") ==0) /* just use previous history search */ strcpy (curLn, histLn); else /* new history search */ strcpy (histLn, curLn); if (! histFind (ledId, histLn, curLn)) { curLn [0] = EOS; beep (ledId->outFd); } curPs = 0; srchMode = FALSE; ledId->cmdMode = TRUE; } else { done = TRUE; returnVal = strlen (curLn); } break; case CMP_CHAR: strcpy (saveLn, curLn); if (! completeName (curLn, &curPs)) beep (ledId->outFd); else /* if (isalpha(curLn [curPs]) || isdigit(curLn[curPs]) || curLn [curPs] == '_') */ while (isalpha((int)curLn [curPs]) || isdigit((int)curLn[curPs]) || curLn [curPs] == '_') { curPs++; } break; default: if (strlen (curLn) < maxBytes) { if (overStrike && curPs < strlen (curLn)) curLn [curPs++] = ch; else { bcopy (&curLn [curPs], &curLn [curPs + 1], strlen (&curLn [curPs]) + 1); /* + EOS */ curLn [curPs++] = ch; } } else beep (ledId->outFd); break; } } } if (returnVal == EOF) {#ifndef UNIX_DEBUG /* turn echo & line mode back on */ ioctl(ledId->inFd, FIOSETOPTIONS, oldoptions);#endif /* UNIX_DEBUG */ return (EOF); } histAdd (ledId, curLn); write (ledId->outFd, "\n", 1); /* must fix up BOS */ bcopy (&string [1], &string [0], strlen (curLn) + 1); /* +EOS */#ifndef UNIX_DEBUG /* turn echo & line mode back on */ ioctl (ledId->inFd, FIOSETOPTIONS, oldoptions);#endif /* UNIX_DEBUG */ return (returnVal); }/********************************************************************************* ledControl - change the line-editor ID parameters** This routine changes the input/output file* descriptor and the size of the history list.** RETURNS: N/A*/void ledControl (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -