mb_set_inputer |
status_t mb_set_inputer( mb_interpreter_t* s, mb_input_func_t pHandler )
Set the input handler. To remove the handler, supply NULL. This format uses the standard handler format.
typedef int (*mb_input_func_t)( char* pBuffer, int nBufSize, const char* pVarName );
Example
///////////////////////////////////////////////////////////////////////////// // static void _setup_basic_interpreter( mb_interpreter_t* s, CConsoleCmdLineInfo::RUN_E eEnvironment ) { // MyBASIC Environments defined from 0 (ENV_NONE) to 6 (ENV_MAXGRAPH) so we need to convert // If we're not running, set environment to ENV_NONE. This is the same as running in cmd window
int nEnvironment = eEnvironment > CConsoleCmdLineInfo::eNORUN ? int( eEnvironment ) - 1 : ENV_NONE;
mb_set_environment( s, nEnvironment ); mb_set_error_handler( s, _on_error ); mb_set_inputer( s, _getstring ); mb_set_printer( s, _printstring ); mb_set_check_keyboard_handler( s, _check_keyboard ); } endfunc
///////////////////////////////////////////////////////////////////////////// // static int _getstring( char* pStr, int nLen, const char* pVarName ) { if ( mb_get_environment( g_bas ) == ENV_WINDOWS ) { return MB2Console_Input( pStr, nLen, pVarName ); } else { // Must have room for at least terminator
if ( nLen == 0 ) return 0;
// Make room for '\0'
nLen--;
int c; int n = 0;
do { c = getchar();
if ( c == '\n' ) break; if ( n == nLen ) break;
pStr[n++] = c; } enddo
pStr[n] = 0;
return strlen( pStr ); } endif
return 0; } endfunc
|