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

📄 si_misc.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) Ericsson Mobile Communications AB, 2000.
 * Licensed to AU-System AB.
 * All rights reserved.
 *
 * This software is covered by the license agreement between
 * the end user and AU-System AB, and may be used and copied
 * only in accordance with the terms of the said agreement.
 *
 * Neither Ericsson Mobile Communications AB nor AU-System AB
 * assumes any responsibility or liability for any errors or inaccuracies in
 * this software, or any consequential, incidental or indirect damage arising
 * out of the use of the Generic WAP Client software.
 */
/*********
History
-------
990525 (KHN) Corrigendum WAG-WMLScript-29 implemented.
               Behaviour of an URL call with a float argument when it
               is an integer only device.
990526 (KHN) Corrigendum WAG-WMLScript Standard Libraries-31
               String.format() behaviour in some cases.
990623 (KHN) The formatting of values from a specifier
               (used by the library function String.format) has been corrected
               on a number of details.
               * "%.f" now gives precision 0
               * a float with less significands than is to be printed is now
                  printed correct.
               * Whitespace in a specifier is not allowed.
               (function: parseFormatSpecifier)
990825 (KHN) Changed so that the parsing of float in String.format is done
               using sprintf.
               (function: parseFormatSpecifier)
991207 (KHN) WAP 1.2 update:
                SEC-18-Jun-1999-5 String.format on devices that doesn't support floating-point.
                Change: %f specifier when not supporting float => invalid.
000126 (KHN) Corrected the underlying function that performs the task of finding substrings. 
                The error was that if searching for example "BCD" in the "aaBBCD" 
                string resultet in no match.
000502 (KHN) Removed a warning found by GBU.
000802 (KHN) Changed to a safer sprintf calling style.
000808 (KHN) WAP 1.2.1 update:
                CR WMLSL-IBM-20000315-FormatConversion
                If doing a %d but the value is float then do Float.int() conversion first.
010108 (NKE) Rewritten FindSubstrings; "abac" didn't match "ababac".

**********/
#include "si_misc.h"


#include "si_types.h"
#include "si_int.h"

#ifdef HAS_FLOAT
  #include "si_float.h"
#endif

#include "url.h"
#include "wmlif.h"
#include "ansilibs.h"



/*==========================================
  FindSubstrings
============================================

---Purpose: 
To find the positions in str were the subStr is located.
The positions is returned as a single linked list.
It is also possible to onlyfind the first substring match. 
This is done by calling the function with the argument findAll set to FALSE.

---Params:
str               the string which is to be examined for sub string matches
subStr            the str that is to be found
findAll           if TRUE all substring matches are reported, else only the first match

---Return:
pstructStrFind    the first element in the list of found positions were the substring was found
NULL              the operation failed due to the variables were not of string type.

------------------------------------------------------------------------*/
pstructStrFind FindSubstrings( pstructVar str, pstructVar subStr, BOOL findAll )
{
	pstructStrFind  result = NULL;
	pstructStrFind  prev   = NULL;
	pstructStrFind  curr;
	UINT32          i;
	UINT32          j;

	if ( (VCR_OK != Var_Convert( str, typeString )) || (VCR_OK != Var_Convert( subStr, typeString )))
		return NULL;

	if (str->theStringLen > 0 && subStr->theStringLen > 0) 
		for (i = 0; i <= str->theStringLen - subStr->theStringLen; i++) 
			for (j = 0; str->val.theString[i+j] == subStr->val.theString[j]; j++)
				if (j == subStr->theStringLen - 1) {
					curr = NEWSTRUCT( structStrFind );
					curr->next = NULL;
					curr->data = NULL;
					curr->endPos = 0;
					curr->subStrPos = i;
					
					if (! findAll)
						return curr;

					i += j;
					if (prev == NULL) {
						prev = curr;
						result = curr;
					} else {
						prev->next = curr;
						prev = curr;
					}
					break;
				}
	
	if (result == NULL) { /* No match found */
		result = NEWSTRUCT( structStrFind );
		result->subStrPos = -1;
		result->next = NULL;
		result->data = NULL;
		result->endPos = 0;
	}

	return result;
}



VOID StrFind_Delete( pstructStrFind *pThis ) 
{
	if (*pThis != NULL) 
	{
		if ((*pThis)->next == NULL) 
		{
			DEALLOC( &((*pThis)->data) );
			DEALLOC( pThis );
		}
		else
		{
			StrFind_Delete( &((*pThis)->next) );
			DEALLOC( &((*pThis)->data) );
			DEALLOC( pThis );
		}
	}
}


/**/
BOOL IsNumberChar(WCHAR aChar)
{
/* NOTE!!! This function does not return true for ".","e" or "E"
if HAS_FLOAT is 0 */
#ifdef HAS_FLOAT
	return (	((aChar >= '0') && (aChar <= '9')) ||
						(aChar == '+') ||
						(aChar == '-') ||
						(aChar == '.') ||
						(aChar == 'e') ||
						(aChar == 'E'));
#else
	return (	((aChar >= '0') && (aChar <= '9')) ||
						(aChar == '+') ||
						(aChar == '-'));
#endif
}


BOOL IsWhitespaceChar(WCHAR aChar)
{
	return ( ((aChar >= CHAR_HORIZONTAL_TAB) && (aChar <= CHAR_CARRIAGE_RETURN))
  				 || (aChar == CHAR_SPACE) );
}


BOOL IsInvalidStartChar(WCHAR aChar)
{
	return ( aChar == 'i' );
}


BOOL IsTrueStartChar(WCHAR aChar)
{
	return ( aChar == 't' );
}


BOOL IsFalseStartChar(WCHAR aChar)
{
	return ( aChar == 'f' );
}


BOOL IsSingleQuoteChar(WCHAR aChar)
{
	return ( aChar == '\'' );
}


BOOL IsDoubleQuoteChar(WCHAR aChar)
{
	return ( aChar == '"' );
}


BOOL IsFirstFunctionNameChar(WCHAR aChar)
{
	return (	((aChar >= 'a') && (aChar <= 'z')) ||
						((aChar >= 'A') && (aChar <= 'Z')) ||
						(aChar == '_') );
}


BOOL IsFunctionNameChar(WCHAR aChar)
{
	return (	((aChar >= 'a') && (aChar <= 'z')) ||
						((aChar >= 'A') && (aChar <= 'Z')) ||
						(aChar == '_') || 
						((aChar >= '0') && (aChar <= '9')));
}


BOOL IsEndParathesisChar(WCHAR aChar)
{
	return ( aChar == ')' );
}


BOOL IsCommaChar(WCHAR aChar)
{
	return ( aChar == ',' );
}


BOOL IsEscapeChar(WCHAR aChar)
{
	return ( aChar == '\\' ); /* '\' */
}


INT32 GetSingleEscapeChar(WCHAR aChar)
{
	if ((aChar == '\\') ||	/* \ */
			(aChar == '/')	||	/* / */
			(aChar == '\'') ||	/* ' */
			(aChar == '"')			/* " */)
	{
		return aChar;
	}
	else if (aChar == 'b')
	{
		return 0x08;
	}
	else if (aChar == 'f')
	{
		return 0x0C;
	}
	else if (aChar == 'n')
	{
		return 0x0A;
	}
	else if (aChar == 'r')
	{
		return 0x0D;
	}
	else if (aChar == 't')
	{
		return 0x09;
	}
	else
	{
		return -1;
	}
}


INT8 GetHexValueFromChar( WCHAR aChar )
{
	if ((aChar >= '0') && (aChar <= '9'))
	{
		return (aChar - '0');
	}
	else if ((aChar >= 'a') && (aChar <= 'f'))
	{
		return (aChar - 'a' + 10);
	}
	else if ((aChar >= 'A') && (aChar <= 'F'))
	{
		return (aChar - 'A' + 10);
	}
	else
	{
		return -1;
	}
}

INT8 GetOctalValueFromChar( WCHAR aChar )
{
	if ((aChar >= '0') && (aChar <= '7'))
	{
		return (aChar - '0');
	}
	else
	{
		return -1;
	}
}


typedef enum
{
	esc_none,
	esc_octal,
	esc_hex,
	esc_unicode

} enumEscType;

pstructEscapeSeq GetEscapedChar( WCHAR *argString, UINT32 *strPos, UINT32 argstrLen )
{
	UINT32							startPos = (*strPos) - 1;
	
	pstructEscapeSeq		result = NULL;
	BOOL								done = FALSE;
	BOOL								error	= FALSE;
	enumEscType					escType	= esc_none;
	UINT32							nbrOfChars = 0;
	WCHAR								theResultChar = 0;

	INT8								val;

	WCHAR								aChar = 0;

	while ((*strPos < argstrLen) && (!done))
	{
		aChar = argString[ *strPos ];	
		switch (escType)
		{
			case esc_none:
				if (GetSingleEscapeChar(aChar) != -1 )
				{
					theResultChar = (UINT16)GetSingleEscapeChar(aChar);
					(*strPos)++;
					done = TRUE;
				}
				else if (aChar == 'x')
				{
					(*strPos)++;
					escType = esc_hex;
				}
				else if (aChar == 'u')
				{
					(*strPos)++;
					escType = esc_unicode;
				}
				else /* octal */
				{
					escType = esc_octal;
				}
				break;
			case esc_octal:
				if ((val = GetOctalValueFromChar(aChar)) != -1)
				{
					theResultChar = theResultChar << 3;
					theResultChar += val;
					(*strPos)++;
					nbrOfChars++;
					if (nbrOfChars == 3)
					{
						done = TRUE;
						if (theResultChar > 0xFF)
						{
							error = TRUE;
						}
					}
				}
				else
				{
					done = TRUE;
					if (nbrOfChars == 0)
					{
						error = TRUE;
					}
				}
				break;
			case esc_hex:
				if ((val = GetHexValueFromChar(aChar)) != -1)
				{
					theResultChar = theResultChar << 4;
					theResultChar += val;
					(*strPos)++;
					nbrOfChars++;
					if (nbrOfChars == 2)
					{
						done = TRUE;
					}
				}
				else
				{
					done = TRUE;
					error = TRUE;
				}

⌨️ 快捷键说明

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