home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
178_01
/
tvx_2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-01-18
|
35KB
|
1,437 lines
/* -------------------------------- tvx_2.c ------------------------------- */
/* ========================================================================
tvx_2.c - Part 2 of main TVX code
============================================================================ */
#include "tvx_defs.ic" /* note tv_defs will #include stdio.h */
#include "tvx_glbl.ic"
/* =============================>>> KILLIN <<<============================= */
killin(cnt)
int cnt;
{ /* ## killin - kill cnt lines */
SLOW int i,lim;
SLOW int from,to,ityp,istrt;
if (cnt+curlin >= nxtlin || (curlin == nxtlin-1 && cnt >= 0))
{ /* special case: deleting rest of buffer */
svklin(nxtlin-1);
for (i = curlin ; i <= nxtlin-1 ; )
kline(*(lines+i++));
nxtlin = curlin--;
if (curlin > 0)
{
curchr = *(lines+curlin)+1;
newscr();
}
else
{
curchr=0;
tvclr();
}
return;
}
if (cnt < 0) /* negative kill */
{
cnt = min(-cnt,curlin-1); /* all upwards? */
dwnlin(-cnt); /* go up that far */
}
if (cnt != 0)
{
range(cnt,&to,&from); /* calculate the line numbers to kill */
curlin=to; /* remember new current line */
svklin(from); /* save one line */
for (i = to ; i <= from ; ) /* mark lines deleted */
kline(*(lines+i++));
lim = min(nxtlin-1,mxline);
for (++from ; from <= lim ; )
{
*(lines+to++) = *(lines+from++); /* copy next line number */
}
nxtlin=to;
if (nxtlin == curlin)
--curlin; /* don't go past end */
curchr = *(lines+curlin)+1; /* remember new current character */
if (cnt >= 0 && curlin+(tvlins-tvdlin) < nxtlin &&
tvdlin < tvlins) /* killing down */
{
tvxy(1,tvy); /* get to start of line */
ityp=min(tvlins-tvdlin+1,nxtlin-curlin);
if (cnt!=1 || !ckline[0])
{
tvescr(); /* erase the screen */
istrt=curlin;
}
else
{
sendcs(ckline);
istrt=curlin+ityp-1;
tvxy(1,tvlins);
ityp=1;
}
tvtype(istrt,ityp);
tvhdln(); /* home to display line */
}
else if ( cnt != 1) /* neg and > 1 too complicated */
newscr(); /* kill up, just retype whole screen */
else if (nxtlin < tvlins) /* top part of screen */
{
if (*ckline) /* kill line defined */
{
tvxy(1,tvy); /* get to start of line */
sendcs(ckline); /* just need to kill the line */
tvhdln();
}
else
newscr(); /* rewrite it all */
}
else if (tvdlin < tvlins) /* must be in last part of buffer */
{
if (*ckline && *ctopb) /* kill line & topb defined */
{
tvxy(1,tvy); /* get to start of line */
sendcs(ckline); /* kill the line */
if (curlin-tvdlin > 0) /* something to scroll */
{
tvtopb(1); /* scroll down one line */
tvtype(curlin-tvdlin,1); /* type the offscreen line */
tvdlin++; /* will start display on next line */
}
tvhdln();
}
else
newscr(); /* rewrite it all */
}
else /* if all else fails */
newscr();
}
}
/* =============================>>> KLINE <<<============================= */
kline(ptr)
BUFFINDEX ptr;
{ /* kline - kill off the line beginning at buff position ptr */
SLOW BUFFINDEX i;
for (i=ptr; *(buff+i) != ENDLINE ; ) /* insert GARBAGE to kill */
*(buff+i++)=GARBAGE;
*(buff+i)=GARBAGE; /* kill the endline */
}
/* =============================>>> KPREV <<<============================= */
kprev()
{ /* kprev - kill from cursor to beginning of line */
FAST int chrs;
svklin(curlin); /* save one line */
chrs = curchr - *(lines+curlin) - 1; /* how much to delete */
if (chrs > 0)
delnxt(-chrs); /* won't cause a combine, so don't worry */
}
/* =============================>>> KREST <<<============================= */
krest()
{ /* krest - kill the rest of the line, not including cursor and ENDLINE */
SLOW int chrs;
SLOW BUFFINDEX i;
svklin(curlin); /* save one line */
chrs=0;
for (i=curchr; *(buff+i)!=ENDLINE; ++i)
++chrs; /* count how much to delete */
if (chrs > 0)
delnxt(chrs); /* won't cause combine, so don't worry */
}
/* =============================>>> NEATEN <<<============================= */
int neaten(count)
int count;
{ /* neaten - fill lines to current margin */
SLOW int oldef, i;
SLOW BUFFINDEX linbeg;
SLOW int retval;
retval = TRUE;
oldef = echof;
if (count > 1)
echof = FALSE;
if (wraplm <= 1 || curlin >= nxtlin-1)
goto l900; /* work only if wrap limit turned on */
for (i=1 ; i<=count ; ++i)
{
beglin(); /* start at beginning of line */
if (curlin >= nxtlin-1)
goto l900;
/* don't neaten leading space, cr, period or tab */
if (*(buff+curchr) == '.')
{
dwnlin(1);
continue; /* skip dot commands */
}
while (*(buff+curchr)== ' ' || *(buff+curchr)==ENDLINE
|| *(buff+curchr) == 9)
{
right(1); /* skip this line */
}
do
{
if (*(buff+curchr) == ENDLINE)
{
if (tvx+leftmg < wraplm) /* combine lines! */
{
linbeg = *(lines+curlin+1)+1;
/* pt to first char of next line */
if (*(buff+linbeg) == ' ' || *(buff+linbeg) == ENDLINE
|| *(buff+linbeg) == 9 || *(buff+linbeg) == '.')
{
dwnlin(1);
break; /* no more combining */
}
if (! neat1(1,32))
goto l990;
goto NEATNEXT; /* tab over another word */
}
else
{
dwnlin(1); /* no more combining on line */
break;
}
}
NEATNEXT:
if (*(buff+curchr-1)==' ' && tvx+leftmg >= wraplm) /* change to cr */
{
if (! neat1(-1,CR)) /* delete the blank */
goto l990;
break;
}
wordr(1);
} /*# end of the repeat */
while (1);
} /*# end of the for */
l900:
echof = oldef;
if (oldef && count > 1)
newscr();
return (retval);
l990: /* failure return */
retval = FALSE;
goto l900;
}
/* =============================>>> NEAT1 <<<============================= */
neat1(dir, val)
int dir, val;
{ /* change character dir to val */
SLOW int oldwrp;
oldwrp = wraplm;
wraplm = 0;
if (! delnxt(dir))
goto l900;
if (! ins_chr(val))
goto l900;
wraplm = oldwrp;
return (TRUE);
l900:
wraplm = oldwrp;
return (FALSE);
}
/* =============================>>> NEWSCR <<<============================= */
newscr()
{ /* newscr - retype entire screen, updating cursor position if necessary */
SLOW int ibeg,cnt;
if (tvlins != tvhardlines || nxtlin-1 <= tvlins)
/* two kinds of screen rewrite */
tvclr(); /* clear the screen and home */
else
tvxy(1,1);
finddl(&ibeg,&cnt); /* calculate where it will go */
tvtype(ibeg,cnt); /* type it out */
tvhdln(); /* home to display line */
}
/* =============================>>> OPENLN <<<============================= */
openln(cnt)
int cnt;
{ /* openln - open a new line */
FAST int i;
SLOW int pcnt, oldauto;
oldauto = autoin; autoin = FALSE; /* don't allow autoindent */
pcnt = cnt >= 0 ? cnt : (-cnt); /* only allow positive opens */
for (i=1; i<=pcnt; ++i)
ins_chr(CR); /* insert right number of newlines */
dwnlin(-pcnt); /* and goto beginning of the opened line */
endlin();
autoin = oldauto;
}
/* =============================>>> RANGE <<<============================= */
range(cnt,lbeg,lend)
int cnt,*lbeg,*lend;
{ /* determine a legal line number range given cnt */
if (cnt <= 0)
{
*lbeg=max(curlin+cnt,1);
*lend=curlin;
if (cnt < 0)
*lend = (*lend)-1;
}
else
{
*lbeg=curlin;
*lend=min(nxtlin-1,curlin+cnt-1);
}
}
/* =============================>>> RIGHT <<<============================= */
right(cnt)
int cnt;
{ /* move cursor right cnt characters
newlines count as one character */
FAST int change,i;