📄 filename.c
字号:
//**********************************************************************
//FileName : fileName.c
//Created by : ZhengYanbo
//Created Date : 09/09/2005
//Version : v1.1
//Last modified: 2007.5.2, for printing file name to pc
//**********************************************************************
#include "fileName.h"
#include "type.h"
#include "global_def.h"
#include "fat.h"
//**********************************************************************
// This function is used to convert an Unicode to a GB2312
// code. Unicode table is stored in harddisk or CF Card.
// Return GBcode if succeed,or return its unicode.
// Unicode: low byte first here!
// For mega162 cpu: and sectorBuffer is 512 bytes, 2007.5.2
word Unicode2GB(word unicode)
//**********************************************************************
{
byte i;
UNICODE_TAB *p; word trueCode;
trueCode=(unicode>>8) & 0x00FF;
trueCode=((unicode<<8) & 0xFF00) | trueCode;
if(trueCode>0x00a3) //unicode start at 0x00a4
{
//Load first cluster of UNICODE.BIN
currentCluster=tableStartCluster;
readPos=0; sectorPos=0;
filePos=0;
do { //search a matched GBcode in the UNICODE.BIN file
read_a_sector_file(sectorBuffer.data);
//please notice: sectorBuffer is 512 bytes
p=(UNICODE_TAB *) sectorBuffer.data; //init pointer
for(i=0; i<128; i++)
{//Total Unicode:7446, sectorBuffer holds 128 GBcodes only
if(p->unicode==unicode)
{ //matched
trueCode=p->GBcode;
return(trueCode);
}
else p++;
}//for(i=0; i<128; i++)
}//do-while loop
while(filePos < tableFileSize);
}
return unicode; //can't find
}
//**********************************************************************
//This function can convert an unicode string to GB string.
//do the proccess for chinese character displaying.
//This function is written for filename conversion.
void file_name_to_GB(void)
//**********************************************************************
{
unsigned int *p; unsigned char i=0;
unsigned char length;
length=(FILE_NAME_LENGTH>>1)-1;
p=(unsigned int *)fileName; //init pointer
while(((*p)!=0)&&(i<length)) {*p=Unicode2GB(*p); p++; i++; }
}
//**********************************************************************
byte get_string_word_length(byte *string)
//**********************************************************************
{
byte length;
word *p;
p=(unsigned int *)string;
length=0;
while((*p)!=0) {length++; p++; }
return length;
}
void fileNameInsertSpace(void)
{
byte len; byte i;
len=get_string_word_length(fileName);
len = len << 1; //len * 2
i = 0;
while(i < len){if(fileName[i] == 0) fileName[i] = ' ', i++;};
}
//**********************************************************************
void string_array(byte *string)
//**********************************************************************
{ byte ascNum;
byte newpos,offset;
byte length;
newpos=0; ascNum=0; //clear ascii code number
offset=0; //p pointer offset
length=get_string_word_length(string);
length=length<<1; //word length-->byte length
do
{
if(string[offset]!=0)
{ if(string[offset]>0x7F)
{ //Found GB code
if((ascNum % 2)!=0)
{ //insert 0x20
string[newpos++]=0x20;
}
ascNum=0;
}
else
{ //if its ascii code
ascNum++; //found an ascii code
}
string[newpos++]=string[offset];
offset++; //point to next byte
}
else
offset++;
}
while(offset<length); //NULL is an end sign
string[newpos]=0; //Set last char to NULL
}
/*
void print_file_name(byte *p)
{
byte i;
file_name_to_GB();
string_array(p);
while(*p != 0) USART_put_char(*p++);
}*/
void print_file_name(byte *p)
{
byte i;
file_name_to_GB();
for(i=0; i<FILE_NAME_LENGTH; i++)
{if(p[i] != 0) USART_put_char(p[i]);};
}
//end of fileName.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -