/* * putctext: * replace the current line with the passed in text * * char *iline; contents of new line */ int putctext(char *iline) { int status; /* delete the current line */ curwp->w_doto = 0; /* starting at the beginning of the line */ if ((status = killtext(TRUE, 1)) != TRUE) return status; /* insert the new line */ if ((status = linstr(iline)) != TRUE) return status; status = lnewline(); backline(TRUE, 1); return status; }
PASCAL NEAR makefold(f, n) { register int status; /* return status */ BUFFER *bp; /* buffer being folded*/ WINDOW *wp; /* windows to fix up pointers in as well */ REGION creg; /* region boundry structure */ char foldstr[NSTRING]; /* Fold string to insert into buffer/file */ LINE *topboundary; /* Line before fold */ LINE *botboundary; /* Line after fold */ int i; /* Loop */ char mprefix[NSTRING]; /* mark prefix */ int lm; /* left margin value */ LINE *lp; /* line pointer */ short ltype; /* saved line type */ if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ /* find the proper buffer */ bp = curwp->w_bufp; /* find the boundries of the current region */ /* remember these could be fold lines */ /* call getrawregion first, cos this will check if we cross crease */ if ((status=getrawregion(&creg)) != TRUE) return(status); /* check if we have to indent the fold marker */ i = 0; lm = curwp->w_markp[0]->l_lmargin; if (curwp->w_marko[0] > lm) { while (((curwp->w_markp[0]->l_text[i + lm] == ' ') || (curwp->w_markp[0]->l_text[i + lm] == '\t')) && (i + lm < curwp->w_marko[0])) { mprefix[i] = curwp->w_markp[0]->l_text[i + lm]; i++; } } mprefix[i] = NULL; if ((status=getregion(&creg)) != TRUE) return(status); curwp->w_dotp = creg.r_linep; /* only by full lines */ curwp->w_doto = 0; creg.r_size += (long)creg.r_offset; if (creg.r_size <= (long)curwp->w_dotp->l_used) { mlwrite(TEXT222); /* "%%Must fold at least 1 full line" */ return(FALSE); } /* insert the mapped fold-start line at top */ /* have to insert and backup since it could already be a fold line */ /* Unless line is normal cannot insert nl at left margin */ ltype = curwp->w_dotp->l_type; curwp->w_dotp->l_type = LNORMAL; curwp->w_doto = curwp->w_dotp->l_lmargin; lnewline(); /* Reset line type, backup and insert fold symbol */ curwp->w_dotp->l_type = ltype; curwp->w_dotp = curwp->w_dotp->l_bp; strcpy(foldstr, mprefix); strcat(foldstr, FOLDSYMBOL); linstr(foldstr); topboundary = curwp->w_dotp; curwp->w_dotp = curwp->w_dotp->l_fp; curwp->w_doto = 0; /* move forward to the end of this region (a long number of bytes perhaps) */ while (creg.r_size > (long)32000) { forwchar(TRUE, 32000); creg.r_size -= (long)32000; } forwchar(TRUE, (int)creg.r_size); curwp->w_doto = 0; /* only full lines! */ /* Unless line is normal cannot insert nl at left margin */ ltype = curwp->w_dotp->l_type; /* exception is end of open fold */ if (ltype == LEOEFOLD) curwp->w_doto = loffset(curwp->w_dotp); else { curwp->w_dotp->l_type = LNORMAL; curwp->w_doto = curwp->w_dotp->l_lmargin; } lnewline(); /* Reset line type, backup and insert end fold symbol */ curwp->w_dotp->l_type = ltype; curwp->w_dotp = curwp->w_dotp->l_bp; strcpy(foldstr, mprefix); strcat(foldstr, ENDFOLD); linstr(foldstr); botboundary = curwp->w_dotp; /* set the fold pointers and line types */ topboundary->l_type = LSOFOLD; topboundary->l_foldp = botboundary; botboundary->l_type = LEOFOLD; botboundary->l_foldp = topboundary; /* set left margin? */ if (i) { curwp->w_dotp = topboundary->l_fp; i += curwp->w_dotp->l_lmargin; while (curwp->w_dotp != botboundary) { if (loffset(curwp->w_dotp) < i) { /* insert prefix - else problems! */ curwp->w_doto = curwp->w_dotp->l_lmargin; linstr(mprefix); } if (curwp->w_dotp->l_lmargin < i) /* not inner fold */ curwp->w_dotp->l_lmargin = i; curwp->w_dotp = curwp->w_dotp->l_fp; /* lforw() won't find the line */ } } /* move cursor to fold line */ curwp->w_dotp = topboundary; curwp->w_doto = llength(curwp->w_dotp); /* clear out marks */ for (i = 0; i < NMARKS; i++) bp->b_markp[i] = (LINE *)NULL; /* let all the proper windows be updated */ wp = wheadp; while (wp) { if (wp->w_bufp == bp) wp->w_flag |= (WFHARD|WFMODE); wp = wp->w_wndp; } mlwrite(TEXT224); /* "[Buffer folded]" */ return(TRUE); }