📄 bwx_iqc.c
字号:
/*************************************************************** bwx_iqc.c Environment-dependent implementation of Bywater BASIC Interpreter for IBM PC and Compatibles using the Microsoft QuickC (tm) Compiler Copyright (c) 1993, Ted A. Campbell Bywater Software email: tcamp@delphi.com Copyright and Permissions Information: All U.S. and international rights are claimed by the author, Ted A. Campbell. This software is released under the terms of the GNU General Public License (GPL), which is distributed with this software in the file "COPYING". The GPL specifies the terms under which users may copy and use the software in this distribution. A separate license is available for commercial distribution, for information on which you should contact the author.***************************************************************//*---------------------------------------------------------------*//* NOTE: Modifications marked "JBV" were made by Jon B. Volkoff, *//* 11/1995 (eidetics@cerf.net). *//* *//* Those additionally marked with "DD" were at the suggestion of *//* Dale DePriest (daled@cadence.com). *//*---------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <setjmp.h>#include <bios.h>#include <graph.h>#include <signal.h>#include "bwbasic.h"#include "bwb_mes.h"extern int prn_col;extern jmp_buf mark;short oldfgd;long oldbgd;int reset_mode = FALSE;static int iqc_setpos( void );/*************************************************************** FUNCTION: main() DESCRIPTION: As in any C program, main() is the basic function from which the rest of the program is called. Some environments, however, provide their own main() functions (Microsoft Windows (tm) is an example). In these cases, the following code will have to be included in the initialization function that is called by the environment.***************************************************************/voidmain( int argc, char **argv ) {#if MS_CMDS struct videoconfig vc; short videomode; /* Save original foreground, background, and text position. */ _getvideoconfig( &vc ); oldfgd = _gettextcolor(); oldbgd = _getbkcolor(); if ( vc.mode != _TEXTC80 ) { if ( _setvideomode( _TEXTC80 ) == 0 ) { _getvideoconfig( &vc ); prn_xprintf( stderr, "Failed to set color video mode\n" ); } else { reset_mode = FALSE; } } else { reset_mode = FALSE; }#endif /* MS_CMDS */ bwb_init( argc, argv );#if INTERACTIVE setjmp( mark );#endif /* now set the number of colors available */ * var_findnval( co, co->array_pos ) = (bnumber) vc.numcolors; /* main program loop */ while( !feof( stdin ) ) /* condition !feof( stdin ) added in v1.11 */ { bwb_mainloop(); } }/*************************************************************** FUNCTION: bwx_signon() DESCRIPTION:***************************************************************/intbwx_signon( void ) { sprintf( bwb_ebuf, "\r%s %s\n", MES_SIGNON, VERSION ); prn_xprintf( stdout, bwb_ebuf ); sprintf( bwb_ebuf, "\r%s\n", MES_COPYRIGHT ); prn_xprintf( stdout, bwb_ebuf );#if PERMANENT_DEBUG sprintf( bwb_ebuf, "\r%s\n", "Debugging Mode" ); prn_xprintf( stdout, bwb_ebuf );#else sprintf( bwb_ebuf, "\r%s\n", MES_LANGUAGE ); prn_xprintf( stdout, bwb_ebuf );#endif return TRUE; }/*************************************************************** FUNCTION: bwx_message() DESCRIPTION:***************************************************************/intbwx_message( char *m ) {#if DEBUG _outtext( "<MES>" );#endif _outtext( m ); return TRUE; }/*************************************************************** FUNCTION: bwx_putc() DESCRIPTION:***************************************************************/extern intbwx_putc( char c ) { static char tbuf[ 2 ]; tbuf[ 0 ] = c; tbuf[ 1 ] = '\0'; _outtext( tbuf ); return TRUE; }/*************************************************************** FUNCTION: bwx_error() DESCRIPTION:***************************************************************/intbwx_errmes( char *m ) { static char tbuf[ MAXSTRINGSIZE + 1 ]; /* this memory should be permanent in case of memory overrun errors */ if (( prn_col != 1 ) && ( errfdevice == stderr )) { prn_xprintf( errfdevice, "\n" ); } if ( CURTASK number == 0 ) { sprintf( tbuf, "\n%s: %s\n", ERRD_HEADER, m ); } else { sprintf( tbuf, "\n%s %d: %s\n", ERROR_HEADER, CURTASK number, m ); }#if INTENSIVE_DEBUG prn_xprintf( stderr, "<ERR>" );#endif prn_xprintf( errfdevice, tbuf ); return TRUE; }/*************************************************************** FUNCTION: bwx_input() DESCRIPTION: As implemented here, the input facility is a hybrid of _outtext output (which allows the color to be set) and standard output (which does not). The reason is that I've found it helpful to use the DOS facility for text entry, with its backspace-delete and recognition of the SIGINT, depite the fact that its output goes to stdout.***************************************************************/intbwx_input( char *prompt, char *buffer ) {#if INTENSIVE_DEBUG prn_xprintf( stdout, "<INP>" );#endif prn_xprintf( stdout, prompt ); fgets( buffer, MAXREADLINESIZE, stdin ); prn_xprintf( stdout, "\n" ); /* let _outtext catch up */ * prn_getcol( stdout ) = 1; /* reset column */ return TRUE; }/*************************************************************** FUNCTION: bwx_terminate() DESCRIPTION:***************************************************************/voidbwx_terminate( void ) {#if MS_CMDS if ( reset_mode == TRUE ) { _setvideomode( _DEFAULTMODE ); /* Restore original foreground and background. */ _settextcolor( oldfgd ); _setbkcolor( oldbgd ); }#endif exit( 0 ); }/*************************************************************** FUNCTION: bwx_shell() DESCRIPTION:***************************************************************/#if COMMAND_SHELLextern intbwx_shell( struct bwb_line *l ) { static char *s_buffer; static int init = FALSE; static int position; /* get memory for temporary buffer if necessary */ if ( init == FALSE ) { init = TRUE; /* Revised to CALLOC pass-thru call by JBV */ if ( ( s_buffer = CALLOC( MAXSTRINGSIZE + 1, sizeof( char ) )) == NULL ) { bwb_error( err_getmem ); return FALSE; } } /* get the first element and check for a line number */#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): line buffer is <%s>.", l->buffer ); bwb_debug( bwb_ebuf );#endif position = 0; adv_element( l->buffer, &position, s_buffer ); if ( is_numconst( s_buffer ) != TRUE ) /* not a line number */ {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): no line number, command <%s>.", l->buffer ); bwb_debug( bwb_ebuf );#endif if ( system( l->buffer ) == 0 ) { iqc_setpos(); return TRUE; } else { iqc_setpos(); return FALSE; } } else /* advance past line number */ { adv_ws( l->buffer, &position ); /* advance past whitespace */#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): line number, command <%s>.", l->buffer ); bwb_debug( bwb_ebuf );#endif if ( system( &( l->buffer[ position ] ) ) == 0 ) { iqc_setpos(); return TRUE; } else { iqc_setpos(); return FALSE; } } }#endif/*************************************************************** FUNCTION: iqc_setpos() DESCRIPTION:***************************************************************/static intiqc_setpos( void ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -