#include "ded.h" #include "lines.h" /************************************************************************ * * * copyright Richard Bornat 1981 * * * ************************************************************************/ /************************************************************************ * * * procedures to move lines up or down to make or delete space * * * ************************************************************************/ shuffile(fline,incr,stretch) int fline; int incr,stretch; { xshuffile(fline, incr, stretch); adj_maxl(); } /* the procedure which really does the work */ xshuffile(fline, incr, stretch) register int fline; register int incr; int stretch; { register int i; if (incr == 0) return; else if (incr > 0) /* moving up */ { if (maxl+incr > NLINES) editerror("too many lines in file [xshuffile]"); for (i=maxl; i>=fline; i--) l_offset[i+incr] = l_offset[i]; } else if (incr < 0) /* moving down */ { if (fline < (-incr)) editerror("attempt to shuffle lines off top of file [xshuffile]"); for (i=fline; i<=maxl; i++) l_offset[i+incr] = l_offset[i]; stretch = 0; /* it must be this value when moving down */ } /* alter topl */ sh_sync(&topl, fline, incr, 0); /* alter ranges */ for (i=0; i=fline+incr && e=fline+incr) b_range[i] = e_range[i] = (unsigned)-1; else { sh_sync(&b_range[i], fline, incr, 0); sh_sync(&e_range[i], fline-stretch, incr, 1); } } /* fix maxl */ maxl += incr; /* adjust topl and maxl */ while (topl+LASTINROW>maxl) inc_maxl(); tmp_changed = true; } /* procedure to help keep ranges, etc. in line */ sh_sync(a_var, fline, incr, adj) int *a_var; register int fline; register int incr; int adj; { register int var = *a_var; #ifdef DBUG if (dbug('g')) dbugprintf("in sh_sync - var is %d, fline %d, incr %d", var, fline, incr); #endif if (var>=fline) var += incr; else if (var>=fline+incr) var = fline+incr-adj; /* special treatment for negative increments */ *a_var = var; #ifdef DBUG if (dbug('g')) dbugprintf("and now var is %d, fline %d, incr %d", *a_var, fline, incr); #endif } /* procedures to shift lines about */ copyline(source, destination) register int source, destination; { register unsigned ls; while(source>maxl) inc_maxl(); ls = l_offset[source]; /* don't let shuffile delete any lines */ xshuffile(destination, 1, 0); l_offset[destination] = ls; } moveline(source, destination) int source, destination; { register int i; copyline(source, destination); if (source >= destination) source++; for (i=0; i