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

📄 favnamefile.c

📁 汉字在计算机内存放分为两种情况
💻 C
字号:
#include <gendef.h>
#include "system_drv.h"
#include "simgr.h"

#include "user.h"


#include "FavNameFile.h"
static char   *databuf = NULL;
static pDATA  data = NULL;

static char      *temp;
static pFAVNAME  favp;


/*
#define _D1_
*/
#ifdef _D1_
#include "osg.h"
#endif
int  LoadFavNamesData(int size)/*将名字数据载入*/
{
	int i;
	if(databuf) free(databuf);
   
	databuf = (char *)malloc(size);
	memset(databuf,0,size);
	
	DT_NV_Read(0,databuf,size,FLASH_Bauquet);
        
      
	
	data = (pDATA)databuf;
	
	#ifdef _D1_
        {
        	 char buf[80];
          	 favp = (pFAVNAME)data->data; 
          	 FNTDrawText(202, 0, 250,   215,favp->name );
          	 sprintf(buf,"data->data[0] = 0x%x,data->nums =%d",data->data[0],data->nums);
        	 FNTDrawText(202, 0, 250,   235,buf);
        }
	#endif
	
	if(data->data[0] == SIMBOL_CHAR)
		return data->nums;  	
	free(databuf);
	databuf = NULL;
	return  0;
}
void ReleaseFavNamesData(void)/*释放名字数据*/
{
	if(databuf)
	 free(databuf);
	 
	 databuf = NULL;
}
 int GetNameByOrder(int ord,char **name)/*已索引为续得到某一名字*/
{
	
	int i;
	if(!databuf ||  ord < 0  || ord >= data->nums)
	  return -SIMBOL_CHAR;
	temp = data->data;
	favp = (pFAVNAME)temp;
	
	for(i = 0;i < data->nums ;i++)
	{  
	   if(favp->simbol != SIMBOL_CHAR)
	   {
	    *name = NULL;
	    return -SIMBOL_CHAR;
	   } 
	   if(i == ord)
	   {
	     	*name = favp->name;
	     	 return ord;
	   }else
	   {
	    	temp += sizeof(FAVNAME);
	    	temp += favp->len + 1;
	    	favp = (pFAVNAME)temp;
	   }	
	}
	
	 *name = NULL;
	return -SIMBOL_CHAR;
	
	
}

void SaveFavNames(char *sdata,int size)
{
	data = (pDATA)sdata;
	if(data->data[0] != SIMBOL_CHAR)/*简单验证一下*/
    	 return;
    	 
    	  #ifdef _D1_
        {
        	 char sbuf[40];
        	
        	 pDATA data =(pDATA)sdata; 
          	
          	 sprintf(sbuf,"data->nums =%d:data->data[0]:%x",data->nums,data->data[0]);
        	 FNTDrawText(202, 0, 250,   245,sbuf);
        	
        } 
	#endif
	
	DT_NV_Erase(FLASH_Bauquet);
        DT_NV_Write(0,data,size,FLASH_Bauquet);
}

⌨️ 快捷键说明

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