home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
TCXLANSI
/
PUTANSI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-10
|
12KB
|
290 lines
//
// putansi.c P.J. van Zeeland
// Het Wapenschild 27
// 8255 DP Swifterbant
// The Netherlands
//
// prototype : VOID CTYP putansi(ChrP ansiname,WndT win)
//
// This subroutine may be called to display an ANSI picture
// in a full-screen (virtual) window. This should be acceptable to
// any compiler, using TCXL 6.XX
// For TCXL 5.XX just change the single occurence of WVprtc() to Wprtc()
//
// Use, modify, or share this source code freely.
//
// However, if you use this in any of your programs, please be so kind
// to drop me a line in the Fidonet CXL area, and upload any improvements
// to the IDC support board.
// Peter Van.Zeeland
// -----------------
//
#include <stdio.h> // just a few headers.
#include <stdlib.h> // may be overkill
#include <string.h>
#include <dir.h>
#include <dos.h>
#include <bios.h>
#include <io.h>
#include <conio.h>
#include <fcntl.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <ctype.h>
#include <TCXLwin.h>
#include <TCXLcur.h>
#include <TCXLmnu.h>
#include <TCXLent.h>
#include <TCXLsel.h>
#include <TCXLinp.h>
#include <TCXLhlp.h>
#include <TCXLcod.h>
#include <TCXLstr.h>
#include <TCXLmem.h>
VOID CTYP putansi(ChrP ansiname,WndT win)
{// ------------
FILE *ansifile; // file handle for pic
ChrT ch[50]; // used to build esc seq
IntT item,c,number;
AtrT color=LGREY|_BLACK; // initial color
IntT row=1,col=1,saverow,savecol; // initial coords
ansifile=fopen(ansiname,"rb"); // open file
if(ansifile==NULL) // if not found
return; // quit
getseq: // get a complete sequence
c=0; // in array ch, indexed by c
getone:
item=fgetc(ansifile); // get next element
if(item==EOF) // end-of-file found ?
{
fclose(ansifile); // close it
return; // done
}
if(item==27) // escape found ?
{
ch[c]=(ChrT) item; // get next element
while(item !='A' && // xA = cursor up x
item !='B' && // xB = cursor down x
item !='C' && // xC = cursor right x
item !='D' && // xD = cursor left x
item !='f' && // x;yf = goto xy
item !='H' && // x;yH = goto xy
item !='J' && // 2J = cls
item !='K' && // K = deleol
item !='m' && // xm = attribute m
item !='s' && // s = save cursor
item !='u' && // u = restore cursor
ch[c]!= 0)
{
item=fgetc(ansifile); // get next item from file
c++;
if(item==EOF)
ch[c]=0;
else
ch[c]=(ChrT)item;
}
if(ch[1] != '[') // if not a proper esc seq
ch[c] = ' '; // ignore it by changing termin.
switch(ch[c]) // terminator tells us what to do
{
case 0 : fclose(ansifile); // end of file found
return;
// up n lines
case 'A' : if(c==2) number=1;
if(c==3) number=(ch[2]-'0');
if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
row -= number;
if(row<1) row = 1;
break;
// down n lines
case 'B' : if(c==2) number=1;
if(c==3) number=(ch[2]-'0');
if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
row += number;
if(row>VidDep) row = VidDep;
break;
// right n columns
case 'C' : if(c==2) number=1;
if(c==3) number=(ch[2]-'0');
if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
col += number;
if(col>VidWid) col = VidWid;
break;
// left n columns
case 'D' : if(c==2) number=1;
if(c==3) number=(ch[2]-'0');
if(c==4) number=(ch[2]-'0')*10+(ch[3]-'0');
col -= number;
if(col<1) col = 1;
break;
// goto xy
case 'f' :
case 'H' :
if(ch[2]=='H') // no coords ? then home
{
row=col=1;
break;
}
c=2; // first digit of row
row=(ch[c++]-'0');
if(ch[c]!=';' && ch[c] != 'H')
{
row*=10; // 2nd digit of row
row+=(ch[c++]-'0');
}
if(ch[c]!='H') // column specified too ?
{
c++; // skip semicolon
col=(ch[c++]-'0'); // first digit of column
if(ch[c]!='H')
{
col*=10; // 2n digit
col+=(ch[c]-'0');
}
}
else // no column specified
col=1;
break;
// clear screen & home cursor
case 'J' : if(ch[2]=='2')
{
WchgAtrV(WinLoc(win),color,color);
WclearV(WinLoc(win));
row=col=1;
}
break;
// clear to end of line
case 'K' : while(col-1<VidWid)
{
WVprtc(win,row-1,col-1,color,' ');
col++;
}
break;
// set color
case 'm' :
c=2;
while(ch[c] != 'm')
{
number=(ch[c++]-'0');
if(ch[c]!=';' && ch[c] != 'm')
{
number*=10;
number+=(ch[c++]-'0');
}
switch(number)
{
case 0 : color = LGREY|_BLACK;
break;
case 1 : color |= INTENSE;
break;
case 5 : color |= _BLINK;
break;
case 7 : color &= BLACK|_LGREY;
break;
case 8 : color = BLACK|_BLACK;
break;
case 30 : color &= ~LGREY;
color |= BLACK;
break;
case 31 : color &= ~LGREY;
color |= RED;
break;
case 32 : color &= ~LGREY;
color |= GREEN;
break;
case 33 : color &= ~LGREY;
color |= BROWN;
break;
case 34 : color &= ~LGREY;
color |= BLUE;
break;
case 35 : color &= ~LGREY;
color |= MAGENTA;
break;
case 36 : color &= ~LGREY;
color |= CYAN;
break;
case 37 : color |= LGREY;
break;
case 40 : color &= ~_LGREY;
color |= _BLACK;
break;
case 41 : color &= ~_LGREY;
color |= _RED;
break;
case 42 : color &= ~_LGREY;
color |= _GREEN;
break;
case 43 : color &= ~_LGREY;
color |= _BROWN;
break;
case 44 : color &= ~_LGREY;
color |= _BLUE;
break;
case 45 : color &= ~_LGREY;
color |= _MAGENTA;
break;
case 46 : color &= ~_LGREY;
color |= _CYAN;
break;
case 47 : color |= _LGREY;
default :
break;
}
if(ch[c]==';')
c++;
}
break;
// save cursor position
case 's' : saverow=row;
savecol=col;
break;
// restore cursor position
case 'u' : row=saverow;
col=savecol;
break;
// default
default : break;
}
goto getseq;
}
if(item==13) // carriage return ?
{
col=1; // go far left
goto getone; // and get next item
}
if(item==10) // line feed ?
{
row+=1; // go to next line
goto getone; // and get next item
}
// if nothing special: display it !
WVprtc(win,row-1,col-1,color,(ChrT)item);
updposn:
col++; // increase column
if(col>VidWid) // if out-of-bounds
{ // wrap to next line
col=1;
row++;
if(row-1>=VidDep) // if next line does not exist
row--; // don't increase line
}
goto getseq; // and get another chr or seq
}