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

📄 mmimmstomobilesoft.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    {
        return(1);
    }
    
    if((MMS_U8)*str1==0x80&&(MMS_U8)*str2!=0x80
    	||(MMS_U8)*str1!=0x80&&(MMS_U8)*str2==0x80)
    	return(1);
    	
    	
    	if((MMS_U8)*str1==0x80&&(MMS_U8)*str2==0x80)
    	{
    		str1++;
    		str2++;
    		while(((*str1<<8)+*(str1+1)!=0)
    			&&((*str2<<8)+*(str2+1)!=0))
    		{
    			if(UNI_TOLOWER((MMS_U8)*(str1+1))!=UNI_TOLOWER((MMS_U8)*(str2+1)))
    			{
    				return(1);
    			}
    			str1+=2;
    			str2+=2;
    		}
    		if(((*str1<<8)+*(str1+1)==0)&&((*str2<<8)+*(str2+1)==0))
    		{
    			return(0);
    		}
    		else
    		{
    			return(1);
    		}
    	}
    	else
    	{
	
    /*
	* While not at the end of the string, if they ever differ
	* they are not equal.
	*/
	    while ((*str1 != '\0')&&(*str2 != '\0'))
	    {
	        if (TOLOWER((MMS_U8) *str1) != TOLOWER((MMS_U8) *str2))
	        {
	            return(1);
	        }
	        str1++;
	        str2++;
	    }
		
	    /*
		* One of the strings has ended, if they are both ended, then they
		* are equal, otherwise not.
		*/
	    if ((*str1 == '\0')&&(*str2 == '\0'))
		{
	        return(0);
		}
	    else
		{
	        return(1);
		}
	}
}

//no
//如为unicode,则num为除unicode头\x80外的字节个数
MMS_S8 	  *MMS_strncat (MMS_S8 *str,  const MMS_S8 *append, MMS_U32 num)
{
	int lenth=wstrlen(append);
	int tmplen=num;

	char *ss = NULL;
	int sizeAlloc;
	
	MMS_new( ss, sizeAlloc = lenth+2);
	if ((unsigned char)*append==0x80)
		tmplen+=1;
	if (lenth>=tmplen)
		lenth=tmplen;
	memcpy(ss,append,lenth);
	ss[lenth]=0;
	ss[lenth+1]=0;
	MMS_strcat(str,ss);

	MMS_free(ss, sizeAlloc);
	return str;
	
}
#endif

MMS_VOID MMS_free_big2(MMS_VOID *ptr,MMS_S32 size)
{
	MMS_TRACE_EVENT(("MMS_free_big2: %d",size));
	MMS_free(ptr,size);
    return;
}

MMS_VOID *MMS_malloc_big(MMS_S32 line, MMS_U32 size)
{
	MMS_VOID *address = NULL;

	MMS_TRACE_EVENT(("MMS_malloc_big: %d",size));
	
	MMS_new(address,size);
	if(g_codememalloc != EC_MMIMEM_OK)
	{
		MMS_TRACE_EVENT(("******MMS_malloc_big fail: %d!!******",g_codememalloc));
	}
	return address;
}

#if 0
MMS_VOID 	MMS_free_big(MMS_S32 line, MMS_VOID *ptr)
{
	MMS_TRACE_EVENT(("MMS_free_big: %p",ptr));
	return;
}
#endif

MMS_VOID 	MMS_memset(MMS_VOID *ptr, MMS_U8 value, MMS_U32 size)
{
	memset(ptr,value,size);
	return;
}

MMS_VOID MMS_memcpy(MMS_VOID *dptr, MMS_VOID *sptr, MMS_U32 size)
{
	memcpy(dptr,sptr,size);
	return;
}

MMS_VOID 	*MMS_remalloc(MMS_VOID *address, MMS_U16 oldsize, MMS_U16 size )
{
	MMS_VOID *address2 = NULL;

	MMS_TRACE_EVENT(("MMS_remalloc: %d, %d",oldsize,size));
#if 0	
	address2 =MMS_malloc_big(__LINE__,size);
	if(address2 == NULL)
	{	
		MMS_TRACE_EVENT(("******MMS_remalloc fail!!******"));
		MMS_free_big2(address, oldsize);
		return address2;

	}
#else
	MMS_new(address2, size);
	if(g_codememalloc != EC_MMIMEM_OK)
	{
		MMS_TRACE_EVENT(("******MMS_malloc_big fail: %d!!******",g_codememalloc));
		MMS_free(address, oldsize);
		return NULL;
	}
#endif
	
	memcpy(address2, address, oldsize);
	
	//MMS_free_big2(address, oldsize);
	MMS_free(address, size);
	return address2;
}
/*************************************************************/
/***************文件操作接口**********************************/
/*************************************************************/

//成功返回文件句柄,否则返回0
MMS_FILE MMS_fopen(MMS_S8 *filename, const MMS_S8 *option)
{
#ifdef _INNOVATION_EMULATOR_
	char fullName[254];
	MMS_FILE	fp;
    char path[128];
	
	GetCurrentDirectoryA(sizeof(path),path);
	strcat(path,"\\filesystem");
	strcat(path, filename);
	fp = fopen(path,option);
	if(fp <= 0)
		return 0;
	return fp;

#else
	MMS_FILE	fp;
	MMS_U16		style=0;

	MMS_TRACE_EVENT (("MMS_fopen(): %s %s",filename,option));
	
	if(MMS_strstr(option, "w"))
	{
		ffs_remove(filename);
		style |= FFS_O_WRONLY;
		style |= FFS_O_CREATE;
	}
	else if(MMS_strstr(option, "r"))
	{
		style |= FFS_O_RDONLY;
	}
	else if(MMS_strstr(option, "a"))
	{
		style |= FFS_O_WRONLY;
		style |= FFS_O_APPEND;
	}
	
	fp = ffs_open((const MMS_S8 *)filename, style);
	MMS_TRACE_EVENT (("MMS_fopen(): get fp=%d", fp));
	if(fp<=0)
	{
		MMS_TRACE_EVENT (("MMS_fopen:error,fp=%d", fp));
		return 0;
	}
	
	return fp; 
#endif	   
}

//成功返回1,否则0
MMS_BOOL 	MMS_fclose(MMS_FILE fp)
{
#ifdef _INNOVATION_EMULATOR_
	int ret;
	ret = fclose(fp);
	return ret;
#else
	signed char r ;

	MMS_TRACE_EVENT( ("MMS_fclose:%d", fp) );
	
	r = ffs_close(fp);
	if(r==EFFS_OK)
	{			
		return 1;
	}
	else
	{
		MMS_TRACE_EVENT( ("MMS_fclose:err! fp=%d, ret=%d", fp, r));
		return 0;
	}
#endif	
}

MMS_U32 	MMS_fread(MMS_VOID *buf, MMS_U32 size, MMS_U32 times, MMS_FILE fp)
{
#ifdef _INNOVATION_EMULATOR_
	int ret;
	ret = fread(buf,size,times,fp);
	return ret;
#else
	MMS_S32 ts;
	MMS_TRACE_EVENT(("MMS_fread: fp=%d, bytes=%d", fp, size*times));
	ts = ffs_read(fp, buf, size*times);

	MMS_TRACE_EVENT(("MMS_fread: fp=%d, get %d bytes", fp, ts));
	if(ts>0)
	{
		return (ts/size);
	}
	else
	{
		return 0;
	}
#endif	
}

MMS_U32 	MMS_fwrite(MMS_VOID *buf, MMS_U32 size, MMS_U32 times, MMS_FILE fp)
{
#ifdef _INNOVATION_EMULATOR_
	int ret;
	if(buf == NULL || size <= 0)
		return 0;

	ret = fwrite(buf,size,times,fp);
	return ret;
#else
	MMS_S32 ts;
	MMS_TRACE_EVENT(("MMS_fwrite: fp=%d, bytes=%d", fp, size*times));
	
	if(buf == NULL || size == 0)
		return 0;	

	ts = ffs_write(fp, buf, size*times);

	MMS_TRACE_EVENT(("MMS_fwrite: fp=%d, %d bytes writed", fp, ts));
	
	if(ts>0)
	{
		return (ts/size);
	}
	else
	{
		MMS_TRACE_EVENT(("MMS_fwrite: err! fp=%d, ret=%d", fp, ts));
		return 0;
	}
#endif 	
}

MMS_S32 	MMS_fseek(MMS_FILE fp, MMS_S32 size, MMS_S32 base)
{
#ifdef _INNOVATION_EMULATOR_
	int ret;
	ret = fseek(fp, size, base);
	return ret;
#else	
	MMS_S32 i;
	MMS_TRACE_EVENT(("MMS_fseek: fp=%d, sz=%d, base=%d", fp, size, base));
	i = ffs_seek(fp, size, base);
	return i;
#endif		
}

MMS_S32 	MMS_ftell(MMS_FILE fp)
{
#ifdef _INNOVATION_EMULATOR_
	int ret;
	ret = ftell(fp);
	return ret;
#else
	MMS_S32 i;		
	i =  MMS_fseek(fp, 0, MMS_SEEK_CUR);
	MMS_TRACE_EVENT(("MMS_ftell: fp=%d, pos=%d", fp, i));
	return i;
#endif 	
}

//成功返回1,否则返回0
MMS_S32 	MMS_deletefile(MMS_S8 *filename, MMS_S8 *path)
{
#ifdef _INNOVATION_EMULATOR_
	MMS_S8 fullname[128];
	char appPath[128];	

	if(!filename)
	{
		return 0;
	}
	GetCurrentDirectoryA(sizeof(appPath),appPath);
	strcpy(fullname,appPath);
	strcat(fullname,"\\filesystem");
	strcat(fullname,path);
	strcat(fullname,filename);	
	if(remove(fullname))
	{
		return 1;  
	}
	else
	{
		return 0;
	}

#else

	MMS_S8 fullname[MMS_FILEFULLNAME_LEN];	
	
	MMS_TRACE_EVENT(("MMS_deletefile():file \"%s\", path \"%s\"", filename, path));

	if(!filename || !path)
	{
		return 0;
	}
	MMS_TRACE_EVENT(("MMS_deletefile:%s %s ",path ,filename));

	sprintf(fullname,"%s%s", path,filename);
	
	if(EFFS_OK == ffs_remove(fullname))
	{
		MMS_TRACE_EVENT(("MMS_deletefile success "));
		return 1;  
	}
	else
	{
		MMS_TRACE_EVENT(("MMS_deletefile failed "));
		return 0;
	}
#endif 
	
}

//成功返回1,否则返回0
MMS_S32 	MMS_deletefiles(MMS_S8 *pathname)
{
#ifdef  _INNOVATION_EMULATOR_
	MMS_S8 fullname[128];
	MMS_S8 path[128];
	int len;
	WIN32_FIND_DATA FileData; 
	HANDLE hSearch; 
	BOOL fFinished = FALSE; 
	BOOL isDirectory;
	int nfiles = 0;
	int i = 0;

	GetCurrentDirectoryA(sizeof(path),path);
	strcat(path,"\\filesystem");
	strcat(path, pathname);
	strcpy(fullname, path, strlen(path));
	strcat(fullname, "*.*");
	
	hSearch = FindFirstFileA(fullname, &FileData); 
	if (hSearch == INVALID_HANDLE_VALUE) 
	{ 
		return;
	} 
	  
	while (!fFinished) 
	{
		if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0x00)
		{
			if(FileData.cFileName[0] != 0)
			{
				strcpy(fullname, path, strlen(path));
				strcat(fullname, FileData.cFileName);				
                remove(fullname);				
				nfiles ++;
			}
		}
		
		if (!FindNextFileA(hSearch, &FileData)) 
		{
			fFinished = TRUE; 
		}
	}	
	FindClose(hSearch );
				  
#else 
	T_FFS_DIR  sDir;
	int len;
//	MMS_S8 path[MMS_PATHNAME_LEN];
	MMS_S8 filename[MMS_FILENAME_LEN];
	MMS_S8 fullname[MMS_FILEFULLNAME_LEN];	
	int iRet=0;
	
	MMS_TRACE_EVENT(("MMS_deletefiles():path=\"%s\"", pathname));
	//MMS_DELAY(30);
	if(!pathname)
	{
		return 0;
	}

	strcpy(fullname, pathname);
	len = strlen(fullname);
	fullname[len-1] = '\0';
	
	if((iRet=ffs_opendir(fullname, &sDir)) > 0)
	{
		strcpy(fullname, pathname);
		memset(filename, 0, sizeof(filename));
		while((iRet = ffs_readdir(&sDir, filename, sizeof(filename))) > 0 )
		{
			MMS_TRACE_EVENT(("MMS_deletefiles():file names: %s", filename));
			fullname[len] = '\0';
			strcat(fullname, filename);
			ffs_remove(fullname);
		}
		
		//rvf_delay(10);

		if(iRet < 0 )
		{
			MMS_TRACE_EVENT(("MMS_deletefiles(): delete err, ret = %d", iRet));
			return 0;
		}	
		else
			return 1;
	}
	else
	{
		MMS_TRACE_EVENT(("MMS_deletefiles():open dir err = %d", iRet));
	}	

//	rvf_delay(10);
	return 0;

#endif 
}

//return 1 if file named by filename exist, otherwise 0
MMS_S32 MMS_fstat(MMS_S8 *filename)
{
#ifdef  _INNOVATION_EMULATOR_
	char fullName[254];
	MMS_FILE	fp;
    char path[128];
	int ret;
	
	GetCurrentDirectoryA(sizeof(path),path);
	strcat(path,"\\filesystem");
	strcat(path, filename);
	fp = fopen(path,"r");
	if(fp <= 0)
		return -1;
	ret = fseek(fp, 0, SEEK_END);
	ret  = ftell(fp);
	if(ret < 0)
		return -1;
	return ret;	
#else 
	T_FFS_STAT stat;
    //stat.flags == OF_READONLY;
	if(EFFS_OK == ffs_stat(filename, &stat))
	{
		if(stat.type == OT_FILE)
		{
		   MMS_TRACE_EVENT(("MMS_fstat:the size of %s =%d", filename, stat.size));
		   return stat.size;
		}
		else
		{
		   MMS_TRACE_EVENT(("MMS_fstat: %s is derectory",filename));
		   return -1;
		}
	}
	else
	{
        MMS_TRACE_EVENT(("MMS_fstat:error when open file %s", filename));
		return -1;
	}
	
#endif
}

/*************************************************************/
/***************其它接口**************************************/
/*************************************************************/
MMS_S8 	  *MMS_itoa (MMS_U32 value,  MMS_S8 *buf, MMS_U32 radix)
{
	//long          strtol (const char *st, char **endptr, int base);
	//unsigned long strtoul(const char *st, char **endptr, int base);
	//double        strtod (const char *st, char **endptr); //stdlib.h
	if(radix == 16)
	{
		sprintf(buf, "%.6x", value);
	}
	else

⌨️ 快捷键说明

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