📄 edmisc.c
字号:
{ tlp = lforw(tlp); tbo = 0; c = '\n'; } else c = lgetc(tlp, tbo++); if (c != *pp++) goto fail; } curwp->w_dotp = tlp; curwp->w_doto = tbo; curwp->w_flag |= WFMOVE; return (TRUE); }fail:; } mlwrite("Not found"); return (FALSE); }/* * Reverse search. Get a search string from the user, and search, starting at * "." and proceeding toward the front of the buffer. If found "." is left * pointing at the first character of the pattern [the last character that was * matched. Bound to "C-R". */#if IBM_TBC#pragma argsused#endifgloble int backsearch(f, n)int f,n; { register LINE *clp; register int cbo; register LINE *tlp; register int tbo; register int c; register char *epp; register char *pp; register int s; if ((s = readpattern("Reverse search")) != TRUE) return (s); for (epp = &pat[0]; epp[1] != 0; ++epp) ; clp = curwp->w_dotp; cbo = curwp->w_doto; for (;;) { if (cbo == 0) { clp = lback(clp); if (clp == curbp->b_linep) { mlwrite("Not found"); return (FALSE); } cbo = llength(clp)+1; } if (--cbo == llength(clp)) c = '\n'; else c = lgetc(clp, cbo); if (c == *epp) { tlp = clp; tbo = cbo; pp = epp; while (pp != &pat[0]) { if (tbo == 0) { tlp = lback(tlp); if (tlp == curbp->b_linep) goto fail; tbo = llength(tlp)+1; } if (--tbo == llength(tlp)) c = '\n'; else c = lgetc(tlp, tbo); if (c != *--pp) goto fail; } curwp->w_dotp = tlp; curwp->w_doto = tbo; curwp->w_flag |= WFMOVE; return (TRUE); } fail:; }}/******************************************************** * This function will search backward through the file* * and replace all occurences of an old string by a * * new string. * ********************************************************/#if IBM_TBC#pragma argsused#endifgloble int bkwrdrpl(f, n)int f,n; { LINE *clp; int cbo; LINE *tlp; int tbo; int c,count = 0; char *epp,buf[40]; char *pp; char *pat2; int s; if ((s = readpattern("Rev. replace all occrs of")) != TRUE) return (s); pat2 = (char *) genalloc((unsigned) strlen (pat) + 1); /* Pat2 is first pattern */ strcpy(pat2,pat); if((s = mlreply("Replace with: ",pat,NPAT)) == ABORT) { genfree((VOID *) pat2, (unsigned) strlen(pat) + 1); return(s); } for (epp = &pat2[0];epp[1] != 0 ; ++epp); clp = curwp->w_dotp; cbo = curwp->w_doto; if (clp == curbp->b_linep) { clp = lback(clp); cbo = llength(clp) + 1; } while(clp != curbp->b_linep) { if (cbo <= 0) { clp = lback(clp); if (clp != curbp->b_linep) cbo = llength(clp) + 1; } if (clp == curbp->b_linep) break; if (--cbo == llength(clp)) c = '\n'; else c = lgetc(clp,cbo); if(c == *epp) { tbo = cbo; tlp = clp; pp = epp; while(pp != pat2) { if (tbo <= 0) { tlp = lback(tlp); if (tlp != curbp->b_linep) tbo = llength(tlp) + 1; } if ( tlp == curbp->b_linep) break; if(--tbo == llength(tlp)) c = '\n'; else c = lgetc(tlp,tbo); if (c != *--pp) break; } if ((pp == pat2)&&(c == *pp)) { curwp->w_dotp = clp; curwp->w_doto = tbo; count++; lreplace(pat2); clp = curwp->w_dotp; cbo = curwp->w_doto - strlen(pat); } } } curwp->w_doto -= strlen(pat); curwp->w_flag |= WFMOVE; update(); sprintf(buf," %d Replacement[s] ",count); mlwrite(buf); return(TRUE); }/******************************************************************** * This function will search backward for the occurences of an old * * string and replace some of them with a new string. * ********************************************************************/#if IBM_TBC#pragma argsused#endifgloble int bkwrdcr(f, n)int f,n; { LINE *clp; int cbo; LINE *tlp; int tbo; int c; char *epp,*pp; char *pat2; int s; if ((s = readpattern("Rev. replace some occrs. of")) != TRUE) return (s); pat2 = (char *) genalloc((unsigned) strlen (pat) + 1); strcpy(pat2,pat); if((s = mlreply("Replace with: ",pat,NPAT)) == ABORT) { genfree((VOID *) pat2,(unsigned) strlen(pat) + 1); return(s); } for (epp = &pat2[0]; epp[1] != 0; ++epp) ; clp = curwp->w_dotp; cbo = curwp->w_doto; if (clp == curbp->b_linep) { clp = lback(clp); cbo = llength(clp) + 1; } while (clp != curbp->b_linep) { if (cbo <= 0) { clp = lback(clp); if (clp != curbp->b_linep) cbo = llength(clp)+1; } if (clp == curbp->b_linep) break; if (--cbo == llength(clp)) c = '\n'; else c = lgetc(clp, cbo); if (c == *epp) { tlp = clp; tbo = cbo; pp = epp; while (pp != &pat2[0]) { if (tbo <= 0) { tlp = lback(tlp); if (tlp != curbp->b_linep) tbo = llength(tlp)+1; } if (tlp == curbp->b_linep) break; if (--tbo == llength(tlp)) c = '\n'; else c = lgetc(tlp, tbo); if (c != *--pp) break; } if ((pp == pat2)&&(c == *pp)) { curwp->w_dotp = clp; curwp->w_doto = tbo; curwp->w_flag |= WFMOVE; /************************************************* * Read a character from standard i/o * * if charater is a blank(comparable to Zmacs) * * or 'y' or 'Y' the replacement will occur. * * Else if character is 'n' or 'N' it will skip * * and go to next occurence of string. * * Else exit the function * *************************************************/ mlwrite("Do you want to replace this? [y/n]"); update(); c = (*term.t_getchar)(); if((c ==' ')||(c == 'y')||(c == 'Y')) { lreplace(pat2); clp = curwp->w_dotp; cbo = curwp->w_doto - strlen(pat); } else if ((c == 'n')||(c == 'N')) cbo = tbo; else return(TRUE); } } } curwp->w_flag |= WFMOVE; curwp->w_doto -= strlen(pat); update(); mlwrite("No more occurrences of [%s] in buffer",pat2); genfree((VOID *) pat2,(unsigned) strlen(pat) + 1); return(TRUE); }/****************************************************** * FORWARD * * Search all the occurences of a string and replace * * with a new string * ******************************************************/#if IBM_TBC#pragma argsused#endifgloble int frwsr(f,n)int f,n;{ LINE *clp,*tlp; int cbo,tbo,c,s,count = 0 ; char *pp,buf[40]; char *pat2; /* Read the string to be replaced */ if((s = readpattern ("Replace the occurences of?")) != TRUE) return (s); pat2 = (char *) genalloc ((unsigned) strlen(pat) + 1); strcpy (pat2,pat); /* Read the string to replace with */ if((s = mlreply("Replace with: ",pat,NPAT)) == ABORT) { genfree((VOID *) pat2,(unsigned) strlen(pat) + 1); return(s); } clp = curwp->w_dotp; cbo = curwp->w_doto; while (clp != curbp->b_linep) /* While not eof ,search for string*/ { if(cbo >= llength(clp)) /* if end of line go to new line */ { clp = lforw(clp); cbo = 0; c = '\n'; } else /* else begin to read in a new character */ c = lgetc(clp,cbo++); if (c == pat2[0]) /* and compare it */ { /* to the string to be replaced */ tlp = clp; tbo = cbo; pp = &pat2[1]; while (*pp) { if(tlp == curbp->b_linep) break; if(tbo >= llength(tlp)) { tlp = lforw(tlp); tbo = 0; c = '\n'; } else c = lgetc(tlp,tbo++); if(c != *pp) break; pp++; } if(!(*pp)) /* if string is found replace it with new string */ { curwp->w_dotp = clp; curwp->w_doto = cbo - 1; count++; lreplace(pat2); clp = curwp->w_dotp; cbo = curwp->w_doto; } } } curwp->w_doto -= strlen(pat); curwp->w_flag |= WFMOVE; update(); sprintf(buf,"%d replacement[s]",count); mlwrite(buf); return(TRUE);}/*************************************************** * Search all the occurences of a string and * * replace some of them * ***************************************************/#if IBM_TBC#pragma argsused#endifgloble int querysr(f,n)int f,n;{ LINE *clp,*tlp; int cbo,tbo,c,s; char *pp; char *pat2; /* Read the string to be replaced */ if((s = readpattern ("Query_replace ?")) != TRUE) return (s); pat2 = (char *) genalloc((unsigned) strlen(pat) + 1); strcpy (pat2,pat); /* Read the string to replace with */ if((s = mlreply("Replace with: ",pat,NPAT)) == ABORT) { genfree((VOID *) pat2,(unsigned) strlen(pat) + 1); return(s); } clp = curwp->w_dotp; cbo = curwp->w_doto; while (clp != curbp->b_linep) /* While not eof ,search for string*/ { if(cbo >= llength(clp)) /* if end of line go to new line */ { clp = lforw(clp); cbo = 0; c = '\n'; } else /* else begin to read in a new character */ c = lgetc(clp,cbo++); if (c == pat2[0]) /* and compare it */ { /* to the string to be replaced */ tlp = clp; tbo = cbo; pp = &pat2[1]; while (*pp) { if(tlp == curbp->b_linep) break; if(tbo >= llength(tlp)) { tlp = lforw(tlp); tbo = 0; c = '\n'; } else c = lgetc(tlp,tbo++); if(c != *pp) break; pp++; } if(!(*pp)) /* if string is found */ { curwp->w_dotp = clp; curwp->w_doto = cbo - 1; curwp->w_flag |= WFMOVE; /************************************************* * Read a character from standard i/o * * if charater is a blank(comparable to Zmacs) * * or 'y' or 'Y' the replacement will occur. * * Else if character is 'n' or 'N' it will skip * * and go to next occurence of string. * * Else exit the function * *************************************************/ mlwrite("Do you want to replace this? [y/n]"); update(); c = (*term.t_getchar)();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -