#include "escheme.h" #include "scheme.h" #include "schemeterface.h" static Scheme_Object *open_tty( int n_args, Scheme_Object* args[] ) { Scheme_Object* pReply = scheme_false; Scheme_Object* pArgName = args[ 0 ]; Scheme_Object* pArgBaud = args[ 1 ]; if( SCHEME_STRINGP( pArgName ) ) { char *pPath = SCHEME_STR_VAL( pArgName ); if( SCHEME_INTP( pArgBaud ) ) { int baud = SCHEME_INT_VAL( pArgBaud ); char *pText = ""; pText = open_port( pPath, baud ); if( pText != "" ) { pReply = scheme_make_string( pText ); } } else { pReply = scheme_make_string( "Error in open-tty: expected an int" ); } } else { pReply = scheme_make_string( "Error in open-tty: expected a string."); } return pReply; } static Scheme_Object *close_tty( int n_args, Scheme_Object* args[] ) { close_port(); return scheme_false; } static Scheme_Object *write_tty( int n_arg, Scheme_Object* args[] ) { Scheme_Object* pReply = scheme_false; Scheme_Object* pArg = args[ 0 ]; static char *pText; pText = ""; if( SCHEME_INTP( pArg ) ) { char val = SCHEME_INT_VAL( pArg ); pText = write_val( val ); } else if( SCHEME_STRINGP( pArg ) ) { pText = write_bytes( SCHEME_STR_VAL( pArg ) ); } else { pReply = scheme_make_string( "error in write-tty: expected integer or string" ); } if( *pText != '\0' ) { pReply = scheme_make_string( pText ); } return pReply; } static Scheme_Object *read_tty( int n_arg, Scheme_Object* args[] ) { Scheme_Object* pReply = scheme_false; char* pText = read_bytes(); if( *pText != '\0' ) { pReply = scheme_make_string( pText ); } return pReply; } Scheme_Object *scheme_initialize(Scheme_Env *env) { scheme_add_global( "open-tty", scheme_make_prim_w_arity( open_tty, "open-tty", 2, 2), env ); scheme_add_global( "write-tty", scheme_make_prim_w_arity( write_tty, "write-tty", 1, 1), env); scheme_add_global( "read-tty", scheme_make_prim_w_arity( read_tty, "read-tty", 0, 0), env ); scheme_add_global( "close-tty", scheme_make_prim_w_arity( close_tty, "close-tty", 0, 0), env ); return scheme_make_string( "extension includes: open-tty write-tty read-tty close-tty" ); } Scheme_Object *scheme_reload(Scheme_Env *env) { return scheme_initialize(env); /* Nothing special for reload */ } Scheme_Object *scheme_module_name() { return scheme_false; }