int UIAPI initmouse( int install ) { unsigned long tmp; if( install == 0 ) { return( false ); } UIData->mouse_xscale = 8; UIData->mouse_yscale = 8; if( !MouseInstalled ) { if( WaitHandle == 0 ) WaitHandle = RdosCreateWait(); RdosAddWaitForMouse( WaitHandle, &MouseEventProc ); RdosSetMouseWindow( 0, 0, 8 * 80 - 1, 8 * 25 - 1 ); RdosSetMouseMickey( 8, 8 ); } MouseOn = false; MouseInstalled = true; UIData->mouse_swapped = false; checkmouse( &MouseStatus, &MouseRow, &MouseCol, &tmp ); return( MouseInstalled ); }
void InitDebug( struct TDebug *obj, const char *Program, const char *Param, const char *StartDir ) { obj->FProgram = malloc( strlen( Program ) + 1 ); strcpy( obj->FProgram, Program ); obj->FParam = malloc( strlen( Param ) + 1 ); strcpy( obj->FParam, Param ); obj->FStartDir = malloc( strlen( StartDir ) + 1 ); strcpy( obj->FStartDir, StartDir ); obj->UserWait = RdosCreateWait(); obj->UserSignal = RdosCreateSignal(); RdosAddWaitForSignal( obj->UserWait, obj->UserSignal, obj ); obj->FSection = RdosCreateSection(); obj->ThreadList = 0; obj->ModuleList = 0; obj->CurrentThread = 0; obj->BreakList = 0; obj->FThreadChanged = FALSE; obj->FModuleChanged = FALSE; RdosCreateThread(DebugThread, "Debug device", obj, 0x4000); }
static void DebugThread( void *Param ) { int CurrModuleHandle; int WaitHandle; int thread; struct TDebug *obj = (struct TDebug *)Param; obj->FInstalled = TRUE; CurrModuleHandle = RdosGetModuleHandle(); SelfKey = RdosGetModuleFocusKey( CurrModuleHandle ); if ( SelfKey != RdosGetFocus() ) SelfKey = 0; RdosWaitMilli( 250 ); obj->FHandle = RdosSpawnDebug( obj->FProgram, obj->FParam, obj->FStartDir, 0, 0, &thread); RdosWaitMilli( 250 ); if( obj->FHandle ) { WaitHandle = RdosCreateWait(); RdosAddWaitForDebugEvent( WaitHandle, obj->FHandle, obj ); while( obj->FInstalled ) if( RdosWaitForever( WaitHandle ) ) SignalDebugData( obj ); RdosCloseWait( WaitHandle ); } else obj->FInstalled = FALSE; }
bool intern initkeyboard( void ) { if( !KeyInstalled ) { if( WaitHandle == 0 ) WaitHandle = RdosCreateWait(); RdosAddWaitForKeyboard( WaitHandle, &KeyEventProc ); } KeyInstalled = TRUE; return( true ); }
int __CBeginThread( thread_fn *start_addr, int prio, const char *thread_name, unsigned stack_size, void *arglist ) /************************************************************/ { thread_args *td; int th; int wait_handle; if( __TlsIndex == NO_INDEX ) { if( !__RdosThreadInit() ) return( -1L ); __InitMultipleThread(); } td = malloc( sizeof( *td ) ); if( td == NULL ) { _RWD_errno = ENOMEM; return( -1L ); } stack_size = __ROUND_UP_SIZE_4K( stack_size ); wait_handle = RdosCreateWait(); td->rtn = start_addr; td->argument = arglist; td->signal = RdosCreateSignal(); RdosResetSignal( td->signal ); RdosAddWaitForSignal( wait_handle, td->signal, 0 ); __create_thread(begin_thread_helper, prio, thread_name, td, stack_size); RdosWaitForever( wait_handle ); RdosFreeSignal( td->signal ); RdosCloseWait( wait_handle ); th = td->tid; free( td ); return( th ); }
void InitDebug( struct TDebug *obj, const char *Program, const char *Param, const char *StartDir ) { obj->FProgram = malloc( strlen( Program ) + 1 ); strcpy( obj->FProgram, Program ); obj->FParam = malloc( strlen( Param ) + 1 ); strcpy( obj->FParam, Param ); obj->FStartDir = malloc( strlen( StartDir ) + 1 ); strcpy( obj->FStartDir, StartDir ); obj->UserWait = RdosCreateWait(); obj->UserSignal = RdosCreateSignal(); RdosAddWaitForSignal( obj->UserWait, obj->UserSignal, obj ); obj->FSection = RdosCreateSection(); obj->ThreadList = 0; obj->ModuleList = 0; obj->CurrentThread = 0; obj->NewThread = 0; obj->BreakList = 0; obj->WatchList = 0; obj->FThreadChanged = FALSE; obj->FModuleChanged = FALSE; obj->FHandle = 0; obj->FMemoryModel = DEBUG_MEMORY_MODEL_FLAT; obj->FConfigChange = FALSE; obj->FAsyncBreak = FALSE; obj->FAsyncSel = 0; obj->FAsyncOffset = 0; obj->FWaitLoad = TRUE; RdosCreateThread( DebugThread, "Debug device", obj, 0x4000 ); }
int _dospawn( int mode, CHAR_TYPE *pgmname, CHAR_TYPE *cmdline, CHAR_TYPE *envpar, const CHAR_TYPE * const argv[] ) { int tid; int handle; int wait; int rc = -1; int fh; int len; char *p; char *drive; char *dir; char *fname; char *ext; char *envdata; char *envp; char *ep; char *options; int ok; options = __CreateInheritString(); __F_NAME(__ccmdline,__wccmdline)( pgmname, argv, cmdline, 0 ); ok = 0; len = strlen( pgmname ) + 7 + _MAX_PATH2; p = lib_malloc( len ); _splitpath2( pgmname, p + (len-_MAX_PATH2), &drive, &dir, &fname, &ext ); _makepath( p, drive, dir, fname, ext ); fh = RdosOpenFile( p, 0 ); if( fh == 0 ) { if( strlen( drive ) == 0 && strlen( dir ) == 0 ) { envdata = getenv( "PATH" ); if( envdata ) { envp = envdata; while( envp && !ok) { ep = strchr( envp, ';' ); if( ep ) { *ep = 0; ep++; } _makepath( p, "", envp, fname, ext ); fh = RdosOpenFile( pgmname, 0 ); if( fh ) { ok = 1; RdosCloseFile( fh ); } envp = ep; } } } } else { RdosCloseFile( fh ); ok = 1; } if( ok ) { handle = RdosSpawn( pgmname, cmdline, 0, envpar, options, &tid ); if( !handle ) ok = 0; } if( ok ) { if( mode == P_WAIT ) { wait = RdosCreateWait(); RdosAddWaitForProcessEnd( wait, handle, 0 ); RdosWaitForever( wait ); rc = RdosGetProcessExitCode( handle ); RdosCloseWait( wait ); } else rc = tid; RdosFreeProcessHandle( handle ); } lib_free( options ); lib_free( p ); return( rc ); }
const char *RemoteLink( const char *parms, bool server ) { unsigned short port; #ifndef __RDOS__ struct servent *sp; #endif #ifdef SERVER #if !defined( __RDOS__ ) trp_socklen length; char buff[128]; #endif _DBG_NET(("SERVER: Calling into RemoteLink\r\n")); #if defined(__NT__) || defined(__WINDOWS__) { WSADATA data; if( WSAStartup( 0x101, &data ) != 0 ) { return( TRP_ERR_unable_to_initialize_TCPIP ); } } #endif port = 0; #ifdef __RDOS__ while( isdigit( *parms ) ) { port = port * 10 + (*parms - '0'); ++parms; } if( port == 0 ) port = DEFAULT_PORT; wait_handle = RdosCreateWait( ); listen_handle = RdosCreateTcpListen( port, 1, SOCKET_BUFFER ); RdosAddWaitForTcpListen( wait_handle, listen_handle, (int)(&listen_handle) ); #else if( *parms == '\0' ) parms = "tcplink"; sp = getservbyname( parms, "tcp" ); if( sp != NULL ) { port = sp->s_port; } else { while( isdigit( *parms ) ) { port = port * 10 + (*parms - '0'); ++parms; } if( port == 0 ) port = DEFAULT_PORT; port = htons( port ); } control_socket = socket(AF_INET, SOCK_STREAM, 0); if( !IS_VALID_SOCKET( control_socket ) ) { return( TRP_ERR_unable_to_open_stream_socket ); } #ifdef GUISERVER if( *ServParms == '\0' ) { sprintf( ServParms, "%u", ntohs( port ) ); } #endif /* Name socket using wildcards */ socket_address.sin_family = AF_INET; socket_address.sin_addr.s_addr = INADDR_ANY; socket_address.sin_port = port; if( bind( control_socket, (LPSOCKADDR)&socket_address, sizeof( socket_address ) ) ) { return( TRP_ERR_unable_to_bind_stream_socket ); } /* Find out assigned port number and print it out */ length = sizeof( socket_address ); if( getsockname( control_socket, (LPSOCKADDR)&socket_address, &length ) ) { return( TRP_ERR_unable_to_get_socket_name ); } sprintf( buff, "%s%d", TRP_TCP_socket_number, ntohs( socket_address.sin_port ) ); ServMessage( buff ); _DBG_NET(("TCP: ")); _DBG_NET((buff)); _DBG_NET(("\r\n")); #ifdef LIST_INTERFACES // TODO: need rework to POSIX if_nameindex in <net/if.h> /* Find and print TCP/IP interface addresses, ignore aliases */ { struct ifi_info *ifi, *ifihead; struct sockaddr *sa; ifihead = get_ifi_info( AF_INET, false ); for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next ) { /* Ignore loopback interfaces */ if( ifi->flags & IFI_LOOP ) continue; if( (sa = ifi->ifi_addr) != NULL ) { sprintf( buff, "%s%s", TRP_TCP_ip_address, inet_ntoa( ((struct sockaddr_in *)sa)->sin_addr ) ); ServMessage( buff ); } } free_ifi_info( ifihead ); } #endif #endif _DBG_NET(("Start accepting connections\r\n")); /* Start accepting connections */ #ifndef __RDOS__ listen( control_socket, 5 ); #endif #else #ifdef __RDOS__ // Todo: handle connect #else const char *sock; char buff[128]; char *p; #if defined(__NT__) || defined(__WINDOWS__) { WSADATA data; if( WSAStartup( 0x101, &data ) != 0 ) { return( TRP_ERR_unable_to_initialize_TCPIP ); } } #endif /* get port number out of name */ p = buff; for( sock = parms; *sock != '\0'; ++sock ) { if( *sock == ':' ) { ++sock; break; } *p++ = *sock; } *p = '\0'; if( sock[0] == '\0' ) { sp = getservbyname( "tcplink", "tcp" ); } else { sp = getservbyname( sock, "tcp" ); } if( sp != NULL ) { port = sp->s_port; } else { port = 0; while( isdigit( *sock ) ) { port = port * 10 + (*sock - '0'); ++sock; } if( *sock != '\0' ) { return( TRP_ERR_unable_to_parse_port_number ); } if( port == 0 ) port = DEFAULT_PORT; port = htons( port ); } parms = buff; /* Setup for socket connect using parms specified by command line. */ socket_address.sin_family = AF_INET; /* OS/2's TCP/IP gethostbyname doesn't handle numeric addresses */ socket_address.sin_addr.s_addr = inet_addr( parms ); if( socket_address.sin_addr.s_addr == (unsigned long)-1L ) { struct hostent *hp; hp = gethostbyname( parms ); if( hp != 0 ) { memcpy( &socket_address.sin_addr, hp->h_addr, hp->h_length ); } else { return( TRP_ERR_unknown_host ); } } socket_address.sin_port = port; #endif #endif server = server; return( NULL ); }