-#ifdef sun
-/* subst: change all text matching a pattern in a range of lines according to
- a substitution template; return status */
-subst(pat, gflag)
- pattern_t *pat;
- int gflag;
-{
- undo_t *up = NULL;
- char *txt;
- char *eot;
- line_t *bp, *ep, *np;
- long ocl;
- long nsubs = 0;
- int len;
-
- ep = getlp(curln = line2);
- for (bp = getlp(line1); bp != ep->next; bp = bp->next)
- if ((len = regsub(pat, bp, gflag)) < 0)
- return ERR;
- else if (!len) {
- /* add copy of bp after current line - this avoids
- overloading the undo structure, since only two
- undo nodes are needed for the whole substitution;
- the cost is high, but the less than if undo is
- overloaded on a Sun evidently. XXX */
- if ((np = lpdup(bp)) == NULL)
- return ERR;
- spl1();
- lpqueue(np);
- if (up)
- up->t = getlp(curln);
- else if ((up = upush(UADD, curln, curln)) == NULL) {
- spl0();
- return ERR;
- }
- spl0();
- } else {
- txt = rbuf;
- eot = rbuf + len;
- spl1();
- do {
- if ((txt = puttxt(txt)) == NULL) {
- spl0();
- return ERR;
- } else if (up)
- up->t = getlp(curln);
- else if ((up = upush(UADD, curln, curln)) == NULL) {
- spl0();
- return ERR;
- }
- } while (txt != eot);
- spl0();
- nsubs++;
- }
- ocl = curln;
- lndelete(line1, line2);
- curln = ocl - (line2 - line1 + 1);
- if (nsubs == 0 && !(gflag & GLB)) {
- sprintf(errmsg, "no match");
- return ERR;
- } else if ((gflag & (GPR | GLS | GNP))
- && doprint(curln, curln, gflag) < 0)
- return ERR;
- return 1;
-}
-#else /* sun */
-
-