home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 December
/
PCWorld_1998-12_cd.iso
/
software
/
sybase
/
ASA
/
asa60.exe
/
data1.cab
/
cxmp_files
/
mainch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-07-27
|
3KB
|
146 lines
/* MAINCH.C Character mode specific routines for all example programs
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if !defined( UNIX ) && !defined( MAC )
#include <conio.h>
#endif
#include "example.h"
int PageSize = 16;
extern int Displaytext( int pos, char *fmt, ... )
/***********************************************/
{
va_list arg_ptr;
char buffer[ 256 ];
static int curpos = 0;
int i;
int len;
va_start( arg_ptr, fmt );
vsprintf( buffer, fmt, arg_ptr );
va_end( arg_ptr );
if( pos <= SCREEN_WIDTH ) {
for( i = 0; i < ( pos - curpos ); i++ ) {
putchar( ' ' );
curpos++;
}
len = strlen( buffer );
for( i = 0; i < len; i++, curpos++ ) {
if( buffer[ i ] == MY_NEWLINE ) {
curpos = 0;
}
if( curpos <= SCREEN_WIDTH ) {
putchar( buffer[ i ] );
}
}
} else {
curpos = 0;
}
fflush( stdout );
return( TRUE );
}
extern void Display_systemerror( char *message )
/**********************************************/
{
fprintf( stderr, message );
}
extern void Display_refresh( void )
/*********************************/
{
}
static void prompt_for_string( char *prompt, char *buff, int len )
/****************************************************************/
{
printf( "%s: ", prompt );
fflush( stdout );
fgets( buff, len, stdin );
len = strlen( buff );
if( buff[ len-1 ] == MY_NEWLINE ) {
buff[ len-1 ] = '\0';
} else {
fflush( stdin ); /* entered line longer than len */
}
}
extern void GetValue( char *prompt, char *buff, int len)
/******************************************************/
{
prompt_for_string( prompt, buff, len );
}
extern void GetTableName( char *buff, int len )
/*********************************************/
{
GetValue( "Enter table name", buff, len );
}
/* The GETCH_AVAIL macro is used below to indicate whether the getch()
function is available from CLIB with your compiler
*/
#define GETCH_AVAIL 1
#ifdef __IBMC__
#if __IBMC__ < 200
#undef GETCH_AVAIL
#endif
#endif
#if defined( UNIX ) || defined( MAC )
#undef GETCH_AVAIL
#endif
#if defined( UNIX )
char **_argv;
int main( int argc, char *argv[] )
/********************************/
#else
int main( void )
/**************/
#endif
{
int ch;
#ifdef UNIX
_argv = argv;
#endif
if( !WSQLEX_Init() ) {
return( 0 );
}
for( ; ; ) {
fprintf( stdout, "==>" );
fflush( stdout );
#ifdef GETCH_AVAIL
ch = getche();
#else
/* If your compiler does not support getche(), change
the definition of GETCH_AVAIL above */
while( (ch = getchar()) == MY_NEWLINE );
while( getchar() != MY_NEWLINE );
#endif
if( ch == EOF || ch == 'q') break;
putchar( MY_NEWLINE );
WSQLEX_Process_Command( ch );
}
putchar( MY_NEWLINE );
WSQLEX_Finish();
return( 0 );
}