home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
283_01
/
es.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-05-05
|
15KB
|
603 lines
/* es.c -- display/edit program screens, save as compilable C source text
** d.c.oshel, 4/21/88
*/
#include "ciao.h"
#include "keys.h"
#include <dos.h>
#include <signal.h>
static int screen_number = 0;
static char far *video_RAM;
static char *sname;
/* control-c mesmerizer */
static jmp_buf isis;
void iris( void )
{
longjmp(isis,-1);
}
extern unsigned read_keyboard( void (*fn) (void) ); /* Assembler! */
/*
unsigned read_keyboard( void (*fn) (void) );
{
union REGS rx;
while (!kbhit())
(*fn)();
rx.h.ah = 0;
int86(22,&rx,&rx); *//* damn int86 does NOT ignore Control-C! *//*
if (rx.h.al)
rx.h.ah = 0;
return (rx.x.ax);
}
*/
int dialogue( void )
{
char far *p;
union REGS x;
int c;
p = savescreen( &x );
defcursor();
wputs("^2");
windowbox( 21,1,59,8 );
fullscreen();
gotoxy(23,0);
wprintf("^0╡^1 %s ^0╞^2",sname);
setwindow( 21,1,59,8 );
gotoxy( 0,1 );
wputs(" ^1R^2eset screen\n");
wputs(" ^1B^2lank screen (absolute!)\n");
wputs(" ^1C^2 text file, save screen to\n");
wputs(" ^1I^2mage file, save screen to\n");
wputs(" ^1N^2ext screen, quit editing\n\n");
wputs(" Please select: ");
flush_keys();
c = keyin( screenwait );
restorescreen(p,&x);
return (c);
}
static char namebuffer[80];
int ask( void )
{
char far *p;
union REGS x;
int c;
char buffer[80];
p = savescreen( &x );
defcursor();
wputs("^2");
windowbox( 21,12,59,14 );
sprintf(buffer,"^0 Save %s? ^1Y^0/N \b\b\b\b\b",namebuffer);
c = ((59-21) - (strlen(buffer) - 11))/2;
if (c < 1) c = 1;
gotoxy( c,1 );
wputs(buffer);
bopbleet();
flush_keys();
do
{
c = keyin( screenwait );
c = isascii(c)? toupper(c) : c;
if (c == CR) c = 'Y';
}
while ( c != 'Y' && c != 'N' );
restorescreen(p,&x);
return ( c == 'Y' );
}
int ask2( void )
{
char far *p;
union REGS x;
int c;
char buffer[80];
p = savescreen( &x );
defcursor();
wputs("^2");
windowbox( 21,12,59,14 );
sprintf(buffer,"^0 Save %s? ^1Y^0/N \b\b\b\b\b",sname);
c = ((59-21) - (strlen(buffer) - 11))/2;
if (c < 1) c = 1;
gotoxy( c,1 );
wputs(buffer);
bopbleet();
flush_keys();
do
{
c = keyin( screenwait );
c = isascii(c)? toupper(c) : c;
if (c == CR) c = 'Y';
}
while ( c != 'Y' && c != 'N' );
restorescreen(p,&x);
return ( c == 'Y' );
}
void report( void )
{
char far *p;
union REGS xr;
int x,y,x1,x2,y1,y2;
x = col;
y = row;
p = savescreen(&xr);
wputs("^3");
rptchar('\xfb',1);
hidecursor();
x1 = 1;
y1 = 1;
if ( ((y >= 0) && (y <= 4)) && ((x >= 0) && (x <= 22)) )
{
x1 = 58;
}
x2 = x1 + 20;
y2 = y1 + 2;
windowbox( x1,y1,x2,y2 );
gotoxy (1,1);
wprintf("^1 Column %2d, Row %2d ^0", x,y );
flush_keys();
keyin( screenwait );
restorescreen(p,&xr);
}
void readscreen( void )
{
FILE *fp;
register int i;
union REGS x;
x.h.ah = 0x0F;
int86( 0x10, &x, &x );
/* do we have mono adapter or cga/ega? */
video_RAM = (x.h.al == 7)? ((char far *)( 0xB0000000L )) :
((char far *)( 0xB8000000L ));
if ((fp=fopen(sname,"rb")) == NULL) {
gotoxy(0,0);
rptchar(' ',2000);
windowbox( 0,0,79,24 );
fullscreen();
}
else
{
for ( i = 0; i < 4000; i++ )
{
video_RAM[i] = fgetc(fp);
if (feof(fp))
{
video_RAM[i] = 7;
}
if (ferror(fp))
{
gotoxy(0,24);
printf("READSCREEN COULD NOT READ \"%s\"\n",sname);
thurb();
exit(1);
}
}
fclose(fp);
}
}
void title( void )
{
char far *p;
union REGS x;
p = savescreen( &x );
hidecursor();
windowbox( 21,1,59,8 );
fullscreen();
gotoxy(23,0);
wprintf("^0╡^1 %s ^0╞",strupr(sname));
setwindow( 21,1,59,8 );
gotoxy( 0,7 );
wputs("^2 Screens-to-C v.1.1, by David C. Oshel ^0\n");
wputs(" ^1MicroConsulting Services^0\n");
wputs(" ^11219 Harding Ave.^0\n");
wputs(" ^1Ames, Iowa 50010^0\n");
wputs(" ^1(515) 232-8679^0\n\n");
wputs(" Press ^1any key^0 to begin, ^1Esc^0 to quit^0");
flush_keys();
keyin( screenwait );
restorescreen(p,&x);
}
void doit( void )
{
void saveit( void );
void saveit0( void );
char far *p;
union REGS x;
unsigned int c,d;
col = 39;
row = 12;
setcursize(0,rasterl);
wputs("^0");
p = savescreen(&x);
while (1)
{
gotoxy(col,row);
c = read_keyboard( screenwait );
switch (c)
{
case ESC:
d = dialogue();
switch (d)
{
case 'b':
case 'B':
restorescreen(p,&x);
gotoxy(0,0);
rptchar(' ',2000);
windowbox( 0,0,79,24 );
fullscreen();
col = 39;
row = 12;
setcursize(0,rasterl);
wputs("^0");
p = savescreen(&x);
bopbleet();
break;
case 'r':
case 'R':
restorescreen(p,&x);
p = savescreen(&x);
bopbleet();
break;
case 'c':
case 'C':
saveit();
case 'i':
case 'I':
saveit0();
case 'n':
case 'N':
case 'q':
case 'Q':
case 'x':
case 'X':
_ffree(p);
defcursor();
goto zoo;
break;
default:
break;
}
break;
case F1:
wputs("^1");
break;
case F2:
wputs("^2");
break;
case F3:
wputs("^3");
break;
case F4:
wputs("^4");
break;
case F5:
wputs("^5");
break;
case F6:
wputs("^6");
break;
case F7:
wputs("^7");
break;
case F8:
wputs("^8");
break;
case F9:
wputs("^9");
break;
case F10:
wputs("^0");
break;
case Alt_F1:
rptchar('╔',1);
++col;
if ( col > 79 ) col = 0;
break;
case Alt_F2:
rptchar('╗',1);
++row;
if ( row > 24 ) row = 0;
break;
case Alt_F3:
rptchar('═',1);
--col;
if ( col < 0 ) col = 79;
break;
case Alt_F4:
rptchar('═',1);
++col;
if ( col > 79 ) col = 0;
break;
case Alt_F5:
rptchar('║',1);
--row;
if ( row < 0 ) row = 24;