⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmcons.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*COPYRIGHT (c) 1996 by Philips SemiconductorsTHIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHERPERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICEAND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWAREON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.*//*	Copyright (c) 1996 Philips Semiconductors - TriMedia. All rights reserved.FILE	tmcons.cHISTORY	:	#define TR 		Tilakraj Roy	960201 TR		Created  ( Tilakraj Roy )	961113 TR		Pulled in from ctcmon sourcesCOMMNETS	Requires RPCServ.dll & TMMan32.dll services	CleanUp - the exit function is called either when the DSP programs send back an exit code	or when tmDSPStopExecutable() is called.*/
#define USE_NEWRPC
#define USE_STATIC
#include "windows.h"#include "stdio.h"#include "fcntl.h"#include "io.h"#include "time.h"#include "sys\stat.h"#include "tmwincom.h"#include "tmman32.h"#include "verinfo.h"#include "TM1IF.h"#include "OpenDll.h"/* CONSTANTS */

#ifdef USE_DVD
#include "DVD_Ctl.h"
#endif

#define	MAX_PATH_INDEX	0x20 // maximum of 32 entries may be picked from the ini file/* TYPEDEFS */enum tStdHandles{	kLevel2StdinHandle = 0,	kLevel2StdoutHandle = 1,	kLevel2StderrHandle = 2
#ifdef USE_DVD
	,kDVDControHandle	= 0xfffffffe
#endif
};
typedef struct tagRedirectStdParam{	DWORD	Handle;	BOOL	Redirected;}	tRedirectStdParam, *tpRedirectStdParam; /* GLOBALS */tRedirectStdParam	StdInParam, StdOutParam, StdErrParam;HANDLE	Stdin, Stdout, Stderr;BOOL	fServerLoaded = FALSE;BOOL	fExitProcess = FALSE;BOOL	fTargetExited = FALSE;HANDLE	ExitObject, ThreadExitObject;DWORD	DSPNumber;DWORD	DSPHandle;/* PROTOTYPES */VOID	CleanUp ( VOID );VOID	StripCR ( PCHAR pBuffer, DWORD *BytesRead );/* IMPLEMENTATION */DWORD	ArgCountFunc ( DWORD NodeID ){	TMMAN_DSP_INFO	DSPInfo;	tmDSPGetMiscInfo ( DSPHandle, & DSPInfo ); 	return DSPInfo.ArgCount;}PCHAR *	ArgVectorFunc ( DWORD NodeID ){	TMMAN_DSP_INFO	DSPInfo;	tmDSPGetMiscInfo ( DSPHandle, & DSPInfo ); 	return (PCHAR *)DSPInfo.ArgVector;}DWORD	ExitCodeFunc ( DWORD NodeID, DWORD ExitCode ){	CHAR	szTemp[0x80];	sprintf ( szTemp, 		"\r\nTMCons : Program Exit Code [%x]", ExitCode );	fprintf(stdout, szTemp );		/* get out of this program */	fTargetExited = TRUE;	SetEvent ( ExitObject );	return 0;}// rogier's additionDWORD	OpenDllFunc( PCHAR pszFilename ){	return OpenDll_open_dll ( pszFilename, (PVOID)_open, LittleEndian );}DWORD	ReadFileFunc ( DWORD Handle, PVOID pBuffer, DWORD Count ){	DWORD	BytesRead;
#ifdef USE_DVD	if ( ( Handle == kDVDControHandle ) )
	{
		BytesRead = dvdRead ( pBuffer, Count );
		goto ReadFileFuncExit ;
	}
	
#endif
	if ( ( Handle == kLevel2StdinHandle ) )	{		if ( StdInParam.Redirected == TRUE )		{			BytesRead = _read (  StdInParam.Handle, pBuffer, Count );			goto ReadFileFuncExit ;		}		else		{			BOOL Status;			HANDLE		Objects[2];			Objects[0] =  Stdin; 			Objects[1] =  ThreadExitObject;									WaitForMultipleObjects  ( 2, Objects, FALSE, INFINITE );			if ( fExitProcess != TRUE )			{				Status = ReadFile (  Stdin, pBuffer, Count, &BytesRead,					NULL );				// perform the CRLF->LF translation here				// we just replace the CR LF with WS LF,				// so we can keep the number of bytes read 				// unchanged.            if ( GetFileType (Stdin) == FILE_TYPE_CHAR )				   StripCR ( pBuffer, &BytesRead );			}			else			{				OutputDebugString ( "\nTMCons:ReadFileFunc:Terminating\n");				Status = FALSE;				}			if ( Status != TRUE )			{				BytesRead = 0;				goto	ReadFileFuncExit;			}			else			{				goto ReadFileFuncExit ;			}		}	}	// fall through	BytesRead = _read ( Handle, pBuffer, Count );	if ( BytesRead != Count )	{		CHAR	TempString[0x80];		sprintf ( TempString, 		"READ:Handle[%x]:pBuffer[%x]:Count[%x]:Result[%x]:Status[%x]:FAIL\n",			Handle, pBuffer, Count, BytesRead, GetLastError() );		OutputDebugString ( TempString );	}ReadFileFuncExit :	return BytesRead;}DWORD	WriteFileFunc ( DWORD Handle, PVOID pBuffer, DWORD Count ){	DWORD	BytesWritten;
#ifdef USE_DVD
	if ( ( Handle == kDVDControHandle ) )
	{
		BytesWritten = dvdWrite ( pBuffer, Count );
		return BytesWritten;
	}
#endif

	if ( Handle == kLevel2StdoutHandle )	{		if ( StdOutParam.Redirected  == TRUE )		{			return _write ( StdOutParam.Handle, pBuffer, Count );		}		else		{			if ( WriteFile (  Stdout, pBuffer, Count, &BytesWritten,				NULL ) != TRUE )			{				return 0;			}			else			{				return BytesWritten;			}		}	}	// fall through	if ( Handle == kLevel2StderrHandle )	{		if (  StdErrParam.Redirected  == TRUE )		{			return _write (  StdErrParam.Handle, pBuffer, Count );		}		else		{			if ( WriteFile (  Stderr, pBuffer, Count, &BytesWritten,				NULL ) != TRUE )			{				return 0;			}			else			{				return BytesWritten;			}		}	}	BytesWritten  = _write ( Handle, pBuffer, Count );	if ( BytesWritten != Count )	{		CHAR	TempString[0x80];		sprintf ( TempString, 		"WRITE:Handle[%x]:pBuffer[%x]:Count[%x]:Result[%x]:Status[%x]:FAIL\n",			Handle, pBuffer, Count, BytesWritten, GetLastError() );		OutputDebugString ( TempString );	}	// fall through		return BytesWritten;}DWORD	FstatFunc ( DWORD Handle,  struct stat *pStat ){

#ifdef USE_DVD
	if ( ( Handle == kDVDControHandle ) )
	{
		return -1;
	}
#endif
	if ( ( Handle == kLevel2StdinHandle ) || 		( Handle == kLevel2StdoutHandle ) ||		( Handle == kLevel2StderrHandle ) )	{		pStat->st_mode	= S_IFCHR;		pStat->st_size	= 512;		return 0;	}	else	{		return _fstat ( Handle, (struct _stat *)pStat );	}}DWORD	FcntlFunc ( DWORD Handle, DWORD Command, DWORD Flags ){	if ( Command == _O_BINARY)	{		return _setmode( Handle, Command );	}	else	{		return ((DWORD)~0);	}}DWORD	IsattyFunc ( DWORD Handle ){
#ifdef USE_DVD
	if ( ( Handle == kDVDControHandle ) )
	{
		return -1;
	}
#endif

	if ( ( Handle == kLevel2StdinHandle ) || 		( Handle == kLevel2StdoutHandle ) ||		( Handle == kLevel2StderrHandle ) )	{		return 1;	}	else	{		return _isatty ( Handle );	}}DWORD	LseekFunc ( DWORD Handle, DWORD Offset, DWORD Origin ){

#ifdef USE_DVD
	if ( ( Handle == kDVDControHandle ) )
	{
		return -1;
	}
#endif

	if ( ( Handle == kLevel2StdinHandle ) || 		( Handle == kLevel2StdoutHandle ) ||		( Handle == kLevel2StderrHandle ) )	{		return (0xffffffff);	}	else	{		return _lseek ( Handle, Offset, Origin );	}}


DWORD   OpenFunc (  PCHAR PathName, DWORD Flags, DWORD Mode )
{

#ifdef USE_DVD
    if ( strcmp ( PathName, DVDCtl_FILENAME ) == 0 ) 
	{
        return kDVDControHandle;
    } 
	else 
#endif

	{
		return _open ( PathName, Flags,Mode );
    }
}

DWORD   CloseFunc (  DWORD Handle  )
{
	if (
#ifdef USE_DVD
		( Handle == kDVDControHandle ) ||
#endif
		( Handle == kLevel2StdinHandle ) || 
		( Handle == kLevel2StdoutHandle ) ||
		( Handle == kLevel2StderrHandle ) )
		
	{
		return 0;
	}

    return _close ( Handle );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -