?? rvstdio.c
字號(hào):
/************************************************************************
File Name : rvstdio.c
Description :
************************************************************************
Copyright (c) 2001 RADVISION Inc. and RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Inc. and RADVISION Ltd.. No part of this document may be
reproduced in any form whatsoever without written prior approval by
RADVISION Inc. or RADVISION Ltd..
RADVISION Inc. and RADVISION Ltd. reserve the right to revise this
publication and make changes without obligation to notify any person of
such revisions or changes.
***********************************************************************/
#include "rvstdio.h"
/* Lets make error codes a little easier to type */
#define RvStdioErrorCode(_e) RvErrorCode(RV_ERROR_LIBCODE_CCORE, RV_CCORE_MODULE_STDIO, (_e))
/*$
{function:
{name: RvStdioInit}
{superpackage: Stdio}
{description:
{p: Initializes the stdio module. }
}
{proto: RvStatus RvStdioInit(void);}
{returns: RV_OK if successful, error code if not.}
}
$*/
RvStatus RvStdioInit(void)
{
RvStatus ret = RV_OK;
return ret;
}
/*$
{function:
{name: RvStdioEnd}
{superpackage: Stdio }
{description:
{p: De-initializes the stdio module.}
}
{proto: RvStatus RvStdioEnd(void);}
{returns: RV_OK if successful, error code if not.}
}
$*/
RvStatus RvStdioEnd(void)
{
RvStatus ret = RV_OK;
return ret;
}
#if (RV_STDIO_TYPE == RV_STDIO_WINCE_DEBUG)
#define MULTIBYTE_MAX_LENGTH 1024
RVCOREAPI RvInt RVCALLCONV RvOutputDebugPrintf(const RvChar* format, ...)
{
RvStatus ret = RV_OK;
va_list arg;
static RvChar str[MULTIBYTE_MAX_LENGTH];
static WCHAR strwc[MULTIBYTE_MAX_LENGTH];
RvInt stringlen;
va_start(arg, format);
stringlen = vsprintf(str, format, arg);
va_end(arg);
/* We have to convert the (multibyte) string to wide-character-string */
MultiByteToWideChar(CP_ACP, 0, str, stringlen, strwc, stringlen);
strwc[stringlen] = (WCHAR)0;
OutputDebugString(strwc);
return ret;
}
#endif
/* Standard char operations for old WinCE versions */
#if (RV_OS_TYPE == RV_OS_TYPE_WINCE) && (RV_OS_VERSION == RV_OS_WINCE_2_11)
void CharToWChar(RvChar CharIn, WCHAR * wCharOut)
{
MultiByteToWideChar(CP_ACP, 0, &CharIn, 1, wCharOut, 1);
}
RVCOREAPI RvInt RVCALLCONV __cdecl isupper(RvInt CharIn)
{
WCHAR wChar;
RvChar c;
c = (RvChar)CharIn;
CharToWChar(c, &wChar);
return iswupper(wChar);
}
RVCOREAPI RvInt RVCALLCONV __cdecl islower(RvInt CharIn)
{
WCHAR wChar;
RvChar c;
c = (RvChar)CharIn;
CharToWChar(c, &wChar);
return iswlower(wChar);
}
RVCOREAPI RvInt RVCALLCONV __cdecl isspace(RvInt CharIn)
{
WCHAR wChar;
RvChar c;
c = (RvChar)CharIn;
CharToWChar(c, &wChar);
return iswspace(wChar);
}
RVCOREAPI RvInt RVCALLCONV __cdecl isdigit(RvInt CharIn)
{
WCHAR wChar;
RvChar c;
c = (RvChar)CharIn;
CharToWChar(c, &wChar);
return iswdigit(wChar);
}
RVCOREAPI RvInt RVCALLCONV __cdecl isalnum(RvInt CharIn)
{
WCHAR wChar;
RvChar c;
c = (RvChar)CharIn;
CharToWChar(c, &wChar);
return iswalnum(wChar);
}
RVCOREAPI RvSize_t RVCALLCONV __cdecl strspn(const RvChar * s1, const RvChar * s2)
{
RvChar * srchs2;
RvInt len;
for (len = 0; *s1; s1++, len++)
{
for (srchs2 = (RvChar *)s2; *srchs2; srchs2++)
if (*s1 == *srchs2)
break;
if (*srchs2 == 0)
break;
}
return len;
}
#endif
#if (RV_STDIO_TYPE == RV_STDIO_STUB)
/**********************************************************************
* ANSI stdio implementations
**********************************************************************/
static RvInt RvVfscanf(RvFILE* stream, const RvChar* format, va_list arg);
/*$
{function:
{name: RvFprintf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI fprintf style function.}}
{proto: RvInt RvFprintf(RvFILE* stream, const RvChar* format, ...);}
{params:
{param: {n: stream} {d: The stream to which to write}}
{param: {n: format} {d: A fprintf style format string.}}
{param: {n: ...} {d: A variable argument list.}}
}
{returns: The number of characters written, or negative if an error occured.}
}
$*/
RVCOREAPI RvInt RVCALLCONV RvFprintf(RvFILE* stream, const RvChar* format, ...)
{
RvInt ret;
va_list arg;
va_start(arg, format);
ret = RvVfprintf(stream, format, arg);
va_end(arg);
return ret;
}
/*$
{function:
{name: RvPrintf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI printf style function.}}
{proto: RvInt RvPrintf(const RvChar* format, ...);}
{params:
{param: {n: format} {d: A fprintf style format string.}}
{param: {n: ...} {d: A variable argument list.}}
}
{returns: The number of characters written, or negative if an error occured.}
}
$*/
RVCOREAPI RvInt RVCALLCONV RvPrintf(const RvChar* format, ...)
{
RvInt ret;
va_list arg;
va_start(arg, format);
ret = RvVfprintf(RvStdout, format, arg);
va_end(arg);
return ret;
}
/*$
{function:
{name: RvVprintf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI vprintf style function.}}
{proto: RvInt RvVprintf(const RvChar* format, va_list arg);}
{params:
{param: {n: format} {d: A fprintf style format string.}}
{param: {n: arg} {d: A variable argument list.}}
}
{returns: The number of characters written, or negative if an error occured.}
}
$*/
RVCOREAPI RvInt RVCALLCONV RvVprintf(const RvChar* format, va_list arg)
{
return RvVfprintf(RvStdout, format, arg);
}
/*$
{function:
{name: RvFscanf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI fscanf style function.}}
{proto: RvInt RvFscanf(RvFILE* stream, const RvChar* format, ...);}
{params:
{param: {n: stream} {d: The stream from which to read input.}}
{param: {n: format} {d: A sscanf style format string.}}
{param: {n: ...} {d: A variable argument list.}}
}
{returns: The number input items converted, or RvEOF if an error occured.}
}
$*/
RvInt RvFscanf(RvFILE* stream, const RvChar* format, ...)
{
RvInt ret;
va_list arg;
va_start(arg, format);
ret = RvVfscanf(stream, format, arg);
va_end(arg);
return ret;
}
/*$
{function:
{name: RvScanf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI scanf style function.}}
{proto: RvInt RvScanf(const RvChar* format, ...);}
{params:
{param: {n: format} {d: A sscanf style format string.}}
{param: {n: ...} {d: A variable argument list.}}
}
{returns: The number input items converted, or RvEOF if an error occured.}
}
$*/
RvInt RvScanf(const RvChar* format, ...)
{
RvInt ret;
va_list arg;
va_start(arg, format);
ret = RvVfscanf(RvStdout, format, arg);
va_end(arg);
return ret;
}
/* Character Input ans Output Functions */
RvInt RvGetchar(void)
{
return RvGetc(RvStdin);
}
RvInt RvPutchar(RvInt c)
{
return RvPutc(c,RvStdout);
}
/**********************************************************************
* ANSI stdio stubs that do nothing
**********************************************************************/
/*$
{function:
{name: RvFopen}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI fopen style function.}}
{proto: RvFILE* RvFopen(const RvChar* filename, const RvChar* mode);}
{params:
{param: {n: filename} {d: The name of the file to open}}
{param: {n: mode} {d: The mode in which to open the file.}}
}
{returns: A handle to the opened file stream, or NULL if an error occured.}
}
$*/
RvFILE* RvFopen(const RvChar* filename, const RvChar* mode)
{
return NULL;
}
RvFILE* RvFreopen(const RvChar* filename, const RvChar* mode, RvFILE* stream)
{
return NULL;
}
RvInt RvFlush(RvFILE* stream)
{
return RvEOF;
}
/*$
{function:
{name: RvFclose}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI fclose style function.}}
{proto: RvInt RvFclose(RvFILE* stream);}
{params:
{param: {n: stream} {d: The handle to the file stream to close}}
}
{returns: Zero if successful, or RvEOF if an error occured.}
}
$*/
RvInt RvFclose(RvFILE* stream)
{
return RvEOF;
}
RvInt RvRemove(const RvChar* filename)
{
return -1;
}
RvInt RvRename(const RvChar* oldname, const RvChar* newname)
{
return -1;
}
RvFILE* RvTmpfile(void)
{
return NULL;
}
RvChar* RvTmpnam(RvChar s[RvL_tmpnam])
{
return NULL;
}
RvInt RvSetvbuf(RvFILE stream, RvChar* buf, RvInt mode, RvSize_t size)
{
return -1;
}
void RvSetbuf(RvFILE stream, RvChar* buf)
{
}
/*$
{function:
{name: RvVfprintf}
{superpackage: Stdio}
{description:
{p: This function implements an ANSI vfprintf style function.}}
{proto: RvInt RvVfprintf(RvFILE* stream, const RvChar* format, va_list arg);}
{params:
{param: {n: stream} {d: The stream to which to write}}
{param: {n: format} {d: A vfprintf style format string.}}
{param: {n: arg} {d: A variable argument list.}}
}
{returns: The number of characters written, or negative if an error occured.}
}
$*/
RVCOREAPI RvInt RVCALLCONV RvVfprintf(RvFILE* stream, const RvChar* format, va_list arg)
{
return -1;
}
/* Non-Ansi Formatted Input */
static RvInt RvVfscanf(RvFILE* stream, const RvChar* format, va_list arg)
{
return -1;
}
/* Character Input ans Output Functions */
RvInt RvFgetc(RvFILE* stream)
{
return RvEOF;
}
RvChar* RvFgets(RvChar* s, RvInt n, RvFILE* stream)
{
return NULL;
}
RvInt RvFputc(RvInt c, RvFILE* stream)
{
return RvEOF;
}
RvInt RvFputs(const RvChar* s, RvFILE* stream)
{
return RvEOF;
}
RvInt RvGetc(RvFILE* stream)
{
return RvEOF;
}
RvChar* RvGets(RvChar* s)
{
return NULL;
}
RvInt RvPutc(RvInt c, RvFILE* stream)
{
return RvEOF;
}
RvInt RvPuts(const RvChar* s, RvFILE* stream)
{
return RvEOF;
}
RvInt RvUngetc(RvInt c, RvFILE* stream)
{
return RvEOF;
}
/* Direct Input and Output Functions */
RvSize_t RvFread(void* ptr, RvSize_t size, RvSize_t nobj, RvFILE* stream)
{
return 0;
}
RvSize_t RvFwrite(const void* ptr, RvSize_t size, RvSize_t nobj, RvFILE* stream)
{
return 0;
}
/* File Positioning Functions */
RvInt RvFseek(RvFILE* stream, long offset, RvInt origin)
{
return -1;
}
long RvFtell(RvFILE* stream)
{
return -1L;
}
void RvRewind(RvFILE* stream)
{
}
RvInt RvFgetpos(RvFILE* stream, RvFpos_t* ptr)
{
return -1;
}
RvInt RvFsetpos(RvFILE* stream, const RvFpos_t* ptr)
{
return -1;
}
/* Error Functions */
void RvClearerror(RvFILE* stream)
{
}
RvInt RvFeof(RvFILE* stream)
{
return -1;
}
RvInt RvFerror(RvFILE* stream)
{
return -1;
}
void RvPerror(const RvChar* s)
{
}
#endif /* (RV_STDIO_TYPE == RV_STDIO_STUB) */
/* Binary search function */
RVCOREAPI void* RVCALLCONV RvBsearch(
const void* key,
const void* base,
RvSize_t numOfElements,
RvSize_t elementSize,
RvInt (*compareFunc)(const void* key, const void* ))
{
RvUint8 *lo = (RvUint8 *)base;
RvUint8 *hi = (RvUint8 *)base + (numOfElements - 1) * elementSize;
RvUint8 *mid;
unsigned int half;
int result;
while (lo <= hi)
{
half = numOfElements / 2;
if (half)
{
mid = lo + (numOfElements & 1 ? half : (half - 1)) * elementSize;
result = (*compareFunc)(key,mid);
if (!result)
return(mid);
else if (result < 0)
{
hi = mid - elementSize;
numOfElements = numOfElements & 1 ? half : half-1;
}
else
{
lo = mid + elementSize;
numOfElements = half;
}
}
else if (numOfElements)
return((*compareFunc)(key,lo) ? NULL : lo);
else
break;
}
return NULL;
}
/* 64bit arithmetic operations */
#if (RV_OS_TYPE == RV_OS_TYPE_PSOS) && (RV_OS_VERSION == RV_OS_PSOS_2_0)
#define get64MSB( a ) ((RvInt32)((a >> 16) >> 16))
#define get64LSB( a ) ((RvInt32)(a & 0x00000000ffffffff))
#define set64MSB( a ) ((RvInt64)(((a << 16) << 16) & 0xffffffff00000000))
RVCOREAPI RvInt64 RVCALLCONV Rv64Multiply(RvInt64 num1, RvInt64 num2)
{
RvInt64 result;
RvUint32 num1MSB = get64MSB( num1 );
RvUint32 num1LSB = get64LSB( num1 );
RvUint32 num2MSB = get64MSB( num2 );
RvUint32 num2LSB = get64LSB( num2 );
/* Basically the product of 2 64bit number is a 128bit number...
but, nevermind the overflow ... */
/* overflow = set128MSB(num1MSB * num2MSB) */
result = set64MSB( (num1MSB * num2LSB) + (num2MSB * num1LSB) ) + (num1LSB * num2MSB); /* +overflow */
return result;
}
RVCOREAPI RvInt32 RVCALLCONV Rv64Modulu(RvInt64 num1, RvInt64 num2)
{
ldiv_t lres;
lres = ldiv(num1, num2);
return (RvInt32)lres.rem;
}
RVCOREAPI RvInt64 RVCALLCONV Rv64Divide(RvInt64 num1, RvInt64 num2)
{
ldiv_t lres;
lres = ldiv(num1, num2);
return (RvInt64)lres.quot;
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -