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

📄 readexcel.c

📁 mtk wap和mms代码。。适应mtk 25。26平台
💻 C
📖 第 1 页 / 共 2 页
字号:
#endif

#ifdef __MMI_BG_SOUND_EFFECT__
	#include "BGSoundDef.h"
#endif

#ifdef __MMI_UNIFIED_MESSAGE__
	#include "UnifiedMessageDef.h"
#endif
#if defined(__MMI_DOWNLOAD_AGENT__)
	#include "DLAgentResDef.h"
#endif

#ifdef __MMI_SWFLASH__
	#include "SWFlashDef.h"
#endif

#ifdef PLX_APP_SUPPORT
#include "plxdefs.h"
#include "UILibRes.h"
#ifdef __MMI_PLX_BROWSER__
#include "plxBrowDefs.h"
#endif

#ifdef __MMI_PLX_MMS__
#include "PlxMmsRes.h"
#endif
#endif

#include "enum_list.h"

//get fontres data
extern const U16 mtk_gMaxDeployedLangs;
extern const sLanguageDetails mtk_gLanguageArray[];

int *mtk_gLanguageFlag;//010405 Calvin added

//#define MAX_STRING_MAP_SIZE 45000
#include "CustDataRes.h"
const wchar_t* DELIMETER=L"\t\0";

/*
typedef struct Custom_StrMap_Search
{
	U16 nMinStrId;		//Minimum StringID defined by the developer.
	U16 nMaxStrId;		//Maximum StringID defined by the developer.
	U16 nMapIndex;		//Index of str in Custom_String_MAP.
}CUSTOM_STRMAP_SEARCH;
*/

typedef struct StrRes{
	wchar_t **Str;		//pointer array of lists to store Strings
	int *StrID;			//id pointers  of each string
	int *StrRef;		//pointers of Reference id in hash table of each string
	int MaxID;			//Maximum number of string ids
	int MaxNum;			//Maximum number of strings
	int TotalLength;
}StrRes;

typedef struct StrResSet{
	struct StrRes *strres;
	int iLang;
}StrResSet;

typedef struct HashItem{
	int pointer;		//index in string array
	struct HashItem *next;
}HashItem;


int mask_length(int val){
	int l=0,v;
	v = val/2;
	while (v>=1){
		l++;
		v=v/2;
	}
	return l;
}

int pow(int base, int index){
	int i,ret=1;
	for (i=0; i<index; i++)
		ret = ret*base;
	return ret;
}

int fmod(int denominator,int numerator){
	int ret=denominator;
	while (ret>=numerator)
		ret=ret-numerator;
	return ret;
}
/*********************************************************************
Function Name:			GetHashValue
Function Description:	Calculate the hash value of input string
Return Value:		
Function Input:
						string:		input string
						hash_rang:	the max hash value
*********************************************************************/

int GetHashValue(wchar_t *string,int hash_range){
	int length = mask_length(hash_range);
	int mask=(int)pow(2,length)-1;
	int i=0;
	long val=0;
	for (i=0;i<(int)wcslen(string);i++){
		val += ((string[i]+val*37)&mask);
	}
	val = (int)fmod(val,hash_range);
	return (int)val;
}
/*********************************************************************
Function Name:			Trans
Function Description:	Transform UCS2-encoding "\","n" to "\n"
Return Value:			
						0:			no transformation is done.
						1:			transformation is done.
Function Input:
						string:		input string
						buf:		output string
*********************************************************************/
int Trans (wchar_t *string, wchar_t *buf){
	wchar_t *p=NULL;
	const wchar_t cr[]=L"\\n";
	unsigned int i=0;
	int l=0,ret=0;
	for (i=0; i<wcslen(string); i++){
		if ( string[i]==L'\\' && string[i+1]==L'n' ){
			buf [l]='\n';
			i++;
			ret=1;
		} else buf[l]=string[i];
		l++;
	}
	buf[l]=L'\0';
	return ret;
}

/************************************************************************************

************************************************************************************/
int PreParseTable(FILE *file)
{
	return 1;	
}

/************************************************************************************

************************************************************************************/
void UCS2ASCII (char *w_in, char *a_out){
	int i=0;
	while ( w_in[i]!='\0' || w_in[i+1]!='\0'  ){
		a_out[i>>1] = w_in[i];
		i+=2;
	}
	a_out[i>>1]='\0';
	i=i>>1;
	i--;
	while (i>=0)
	{
		if ( a_out[i]==0x0D ){
			a_out[i]='\0';
			break;
		}
		else i--;
		
	}
}

/************************************************************************************
Function Name:			ifLanguageUsed
Function Description:		Decide if the translated language should be used for
				string resource, according to SSC string.
Return Value:			-1: The language is not used.
				>=0: The index in FontRes
Function Input:			ssc_ref:     SSC string defined in ref_list.txt
************************************************************************************/
int ifLanguageUsed( wchar_t* ssc_ref)
{
	int i =0;
	char ascii_ssc[10];
	UCS2ASCII ((char*)ssc_ref,ascii_ssc);
	for ( i=0; i<mtk_gMaxDeployedLangs; i++ )
	{
		if ( strcmp ( mtk_gLanguageArray[i].aLangSSC, ascii_ssc ) ==0 )
		{
			return i;
		}
	}
	return -1;
}

/*********************************************************************
Function Name:			GetStrResList
Function Description:	Generate a non-duplicate string list from input file, using hash table
Return Value:			Number of all strings
Function Input:
						file:		input file contains string lists
						result:		non-duplicate string list
*********************************************************************/

int GetStrResList (FILE *file, StrResSet *result){
	FILE *f=file;
	struct HashItem **ht=NULL,*extra=NULL,*temp=NULL;
	struct StrRes *strres=NULL;
	wchar_t tmp0[1024], *tmp=NULL, *tok=NULL, *buf=NULL;
	int i=0,j=0,k=0,h=0,iMaxID=-2,l=0,STRID=0;//;,*iMaxNum=NULL;
	int iLang=0;//number of languages
	int LangIndex=0;//Language index in mtk_gLanguageArray
	int hash_range=0;//the value-range of hash function
	int num=0;//number of distinct strings
	int nStringLen=0;//String Length for UCS2 ENCODING
	int order=0;
	int position=0;//the position to insert a new string
	int buffer_size;
	//Read in number of languages in the file
	fgetws(tmp0,1024,f);
	tok = wcstok(tmp0,DELIMETER);
	tok = wcstok(NULL,DELIMETER);
	iLang = _wtoi(tok);
	//number language should be from FontRes.c
	
	buffer_size=512*iLang;
	tmp=malloc(sizeof(wchar_t)*buffer_size);
	memset(tmp,buffer_size,'0');
	//Read maximum string number defined at the end of file.
	while (tmp[0]!=(wchar_t)'#' && tmp[1]!=(wchar_t)'#'){
		fgetws(tmp,buffer_size,f);
		iMaxID++;
	}
	tok = wcstok(tmp,DELIMETER);
	tok = wcstok(NULL,DELIMETER);
/*
	Number of Languages used should be referenced from FontRes.c
	strres = malloc (sizeof(struct StrRes)*iLang);
	ht = malloc(sizeof(struct HashItem*)*iLang);
*/
	strres = malloc (sizeof(struct StrRes)*mtk_gMaxDeployedLangs);
	ht = malloc (sizeof(struct HashItem*)*mtk_gMaxDeployedLangs);

	mtk_gLanguageFlag = malloc (sizeof(int)*mtk_gMaxDeployedLangs);//010405 Calvin added
	for (h=0; h<mtk_gMaxDeployedLangs; h++){
		mtk_gLanguageFlag[h]=0;
	}

	for (j=0;j<iLang;j++){
		rewind(f);//reset to the start of file
		num=0;
//skip first two row (number of languages and language description), and start from third row to read in SSC String.
		fgetws(tmp,buffer_size,f);fgetws(tmp,buffer_size,f);fgetws(tmp,buffer_size,f);
//		printf ("\n");
		tok = wcstok(tmp,DELIMETER);//INDEX
		tok = wcstok(NULL,DELIMETER);//ENUM
		tok = wcstok(NULL,DELIMETER);//MODULE NAME
		tok = wcstok(NULL,DELIMETER);//MAX LENGTH
		tok = wcstok(NULL,DELIMETER);//DESCRIPTION
//change to corresponding language column according to j
		for (k=0;k<j+1;k++){
			tok = wcstok(NULL,DELIMETER);
		}
		LangIndex = ifLanguageUsed (tok);
		
		if ( LangIndex<0 ) // The language is not used in font resource.
			continue;
		rewind(f);
		
		mtk_gLanguageFlag[LangIndex]=1;//010405 Calvin added
		
		strres[LangIndex].Str=(wchar_t**)malloc(sizeof(wchar_t*)*iMaxID);
		strres[LangIndex].StrID=(int*)malloc(sizeof(int)*iMaxID+1);
		strres[LangIndex].StrRef=(int*)malloc(sizeof(int)*iMaxID);
//Set default value
		for (l=0;l<iMaxID;l++){
			strres[LangIndex].StrID[l]=-1;
			strres[LangIndex].StrRef[l]=-1;
			strres[LangIndex].TotalLength=0;
		}

//set hash_range as maximum id times 1.1(Can be changed)
		hash_range=(int)(iMaxID*1.1);

//initialize hash table
		ht[LangIndex]=(struct HashItem*)malloc(sizeof(struct HashItem)*hash_range);
		for (k=0;k<hash_range;k++){
			ht[LangIndex][k].next=NULL;
			ht[LangIndex][k].pointer=-1;
		}
//skip first two row (number of languages and language description), and start from third row.
		fgetws(tmp,buffer_size,f);fgetws(tmp,buffer_size,f);fgetws(tmp,buffer_size,f);fgetws(tmp,buffer_size,f);

		k=0;
		i=0;//number of Ref(non-duplicate strings, excluding NULL)
		l=-1;//number of ID (all strings)
//start to read file
		while ( !feof(f) ){
//Clear the tempopary buffer
			if ( buf!=NULL ){
				tok=NULL;
				free(buf);
				buf=NULL;
			}
//The last line of file
			if (tmp[0]==(wchar_t)'#')
				break;

			l++;
//Read in ID of the string
			tok = wcstok(tmp,DELIMETER);
			tok = wcstok(NULL,DELIMETER); //skip INDEX
			tok = wcstok(NULL,DELIMETER); //skip originally existing Module Name, JL
			tok = wcstok(NULL,DELIMETER); //skip originally existing Max String Length, JL
			//STRID=_wtoi(tok);
			STRID = ENUM_VALUE_MAP[l];
//string description
			tok = wcstok(NULL,DELIMETER);
//change to corresponding language column according to j
			for (k=0;k<j+1;k++){
				tok = wcstok(NULL,DELIMETER);
				if (tok!=NULL && tok[wcslen(tok)-1]==(wchar_t)'\n'){//Remove carriage-return
					tok[wcslen(tok)-2]='\0';
				}
			}
//decise if the read-in string is " " (blank)
			if ( tok !=NULL && wcslen(tok) ==1 && tok[0] ==20 )
				tok = NULL;
//Handling NULL read-in string. Insert its id into id list, it's Ref is default value -1;
			if (tok==NULL){
				order=0;
//sorting on id ascendant
				while (order<l){
					if (STRID>strres[LangIndex].StrID[order])
						order++;
					else
						break;
				}
//insert the string into the list
				position=order;
				order=l;
				while (order>position){
					strres[LangIndex].StrRef[order]=strres[LangIndex].StrRef[order-1];
					strres[LangIndex].StrID[order]=strres[LangIndex].StrID[order-1];
					order--;
				}
				strres[LangIndex].StrID[position]=STRID;
			}
//End of handling NULL string

			if (tok!=NULL){
				//

⌨️ 快捷键说明

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