home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource5
/
331_01
/
paint.c
< prev
next >
Wrap
Text File
|
1990-06-12
|
16KB
|
685 lines
/*
HEADER: CUG999.03;
TITLE: GED (nee QED) screen editor -- part 3;
DATE: 5/15/87;
DESCRIPTION: "Screen output functions.
KEYWORDS: screen, output;
SYSTEM: MS-DOS;
FILENAME: paint.c;
AUTHORS: G. Nigel Gilbert, James W. Haefner, Mel Tearle, G. Osborn.
COMPILERS: Microsoft 4.0
*/
/*
e/qed/ged/se screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
May 1986: converted to ged - Mel Tearle
FILE: paint.c
FUNCTIONS: putline, rewrite, putoffset, putstatusline, putlineno,
putpage, putmess, unmess, putstr, calcoffset,
resetcursor, setstatusname, error, error1, cerr, wait
PURPOSE: write text to screen
*/
#include <stdio.h>
#include "ged.h"
/* writes a line to the screen. Uses the text address pointer in the third
* argument instead of getline if the third argument is not NULL.
*
* On most systems the physical cursor will end at the end of the new
* line. It is not restored here because groups of lines are usually
* written and it is more efficiet to repositon the cursor after the
* group.
*/
putline(line,y,adr)
int line, y;
char *adr;
{
unsigned char vbuf[SWIDTH+1];
char *getline();
int bright, lastcol, off, i, j, x, sav;
unsigned char *p, c;
int cp, low, high;
sav = curson(NO);
vbuf[0] = '\0';
/* if block option and line in range then reverse field */
if ( blocking ) {
if (vbord2 == 0)
j = cline;
else
j = vbord2;
if (vbord1 < j)
i = vbord1;
else {
i = j;
j = vbord1;
}
bright = (line >= i) && (line <= j);
}
else {
bright = NO;
}
if (adr == NULL) {
if (altered && line == cline)
cerr(32); /* displayed data is obsolete */
p = getline(line);
}
else
p = adr;
if (offset > 0) {
lastcol = SWIDTH + offset;
off = offset;
if ( bright ) /* the markers are the opposite of the main color */
colornorm();
else
colorblock();
scr_aputch( 0, y, '<', ATTR2 );
x = 1;
}
else {
lastcol = SWIDTH;
off = 0;
x = 0;
}
if ( bright )
colorblock();
else
colornorm();
i = 0;
for ( cp = 0; (*p) && (cp < (lastcol)); p++, cp++ ) {
if ( (off == 0) || (cp > off) ) {
if ( *p >= 0 ) /* change limit to block control characters */
vbuf[i++] = *p;
else {
if ( *p == '\t' ) {
do {
if ( (off == 0) || (cp > off) && (cp < (lastcol+x)) )
vbuf[i++] = ' ';
}
while ( (++cp % tabwidth) != 0 );
cp--;
}
}
}
}
vbuf[i] = '\0';
scr_putstr( x, y, vbuf, attr );
if ( x + i < SWIDTH) {
scr_delete( x + i, y );
}
else {
/* if ( bright )
colornorm();
else
colorblock();
*/
c = *p;
if (( c != '\0') && (cp == (lastcol))) {
if ( *(++p) )
scr_aputch( SWIDTH, y, '>', ATTR2 );
else
scr_aputch( SWIDTH, y, c, attr );
}
else {
scr_aputch( SWIDTH, y, ' ', attr );
}
}
colornorm();
curson(sav);
return;
}
/* rewrites current line from char 'cp', col 'x', onwards. cp is the
* character index, >= 0. x is the virtual x cursor location.
*
* This routine could be called instead of rewrite to show line editing
* if it is known that the new cursor will be on-screen. The performance
* improvement in doing so is insignificant.
*
* putline and this routine should be modified to have a greater commonality
* than they do.
*/
rewrite1(cp,x)
int cp, x;
{
unsigned char vbuf[SWIDTH+1];
int h, i, j, k, begmark, sav;
unsigned char c;
sav = curson(NO);
vbuf[0] = '\0';
h = i = j = k = 0;
begmark = ( offset > 0 );
if (begmark == 0)
k = x;
else {
k = x - offset;
if (k < 1)
k = 1;
scr_putstr( 0, cursory, "<", ATTR2 );
}
while ( x < SWIDTH+offset && ( c = text[cp] ) ) {
if ( c == '\t' ) {
for ( i = tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
if ( x >= offset )
vbuf[j++] = ' ';
}
/* change following limit to block control characters */
else if ( (offset == 0) || ((x > offset) && (c >= 0) ))
vbuf[j++] = c;
cp++;
x++;
}
if (blocking)
colorblock();
else
colornorm();
vbuf[j] = '\0';
scr_putstr( k, cursory, vbuf, attr );
i = k + strlen(vbuf);
if (i <= SWIDTH)
scr_delete( i, cursory );
c = text[cp];
if ( (c > 0) && (x == SWIDTH+offset) ) {
if(text[cp+1] == '\0' )
scr_aputch( SWIDTH, cursory, c, attr );
else
scr_aputch( SWIDTH, cursory, '>' , ATTR2 );
}
curson(sav);
return;
}
putoffset()
{
gotoxy( 0, 0 ); /*?*/
gotoxy( (offset>0), cursory );
}
putstatusline(line)
int line;
{
int sav;
char buf[50];
sav = curson(NO);
putlineno( line );
strcpy(buf,justfile);
strcat(buf," ");
buf[29]=0; /* clear up to first time digit */
scr_aputs( FNPOS, 0, buf, ATTR3 );
show_time(1);
curson(sav);
blankedmess = NO;
if (sav)
resetpcursor();
return;
}
/* uses scr_aputs to move the cursor else uspr won't work right. call
* resetpcursor after this call
*/
putlineno(line)
int line;
{
int i, sav;
if ( !displaypos )
return;
sav = curson(NO);
scr_aputs( 0, 0, " Line ", ATTR3 );
displine = line;
for ( i=5-uspr(displine, 0L, ATTR3); i > 0; i-- )
scr_putch( ' ',ATTR3);
scr_aputs( COLPOS-1, 0, " Col ", ATTR3 );
dispcol = cursorx+1;
for ( i=4-uspr(dispcol, 0L, ATTR3); i > 0; i-- )
scr_putch( ' ',ATTR3 );
if (charep) {
scr_aputs(25,0," ",ATTR3);
scr_aputs(28,0,"Over",ATTR2);
/* adjust space count to just before filename field */
scr_aputs(32,0," ",ATTR3);
}
else
/* adjust space count to just before filename field */
scr_aputs(25,0," ",ATTR3);
curson(sav);
if (sav)
resetpcursor();
return;
}
/* exit help mode
*/
unmess()
{
if (topline == 1)
return;
topline = 1;
calp();
putpage();
return;
}
/* Write message to top line. Uses all of line and clears the last
* part.
*/
putmess(s)
char *s;
{
int i;
i = putmess1(s,0,SWIDTH+1);
gotoxy(i+1,0); /* position cursor for keyboard input */
return;
}
/* write underlined message in status line. Characters between || are
* written highlighted. xloc is the x cursor position of the first char.
* width is the field width. the trailing part if the field is cleared
* if the message does not fill it.
*/
putmess1( s, xloc, width )
char *s;
int xloc, width;
{
char c;
int i, cnt, norm;
cnt = 0;
gotoxy(abs(xloc), 0);
norm = 0;
color3();
while( (c = *s++) ) {
switch(c) {
case '|':
( norm = ~norm ) ? color4() : color3();
break;
case '\n':
break;
default :
scr_putch( c, attr );
cnt += 1;
}