?? main.c
字號:
}
}
else if( (strncmp(wordBuffer,"else",4)==0) ) {
if( _i_SkipAllIfMacro ) {
_if_ParseStatus = PARSE_MACRO_IFDEF_WAIT_ENDIF_MASK ;
} else
{
if( !findDefineTok(_strDefineName) ) {
Process_IfMacro() ;
}
else
{
_i_SkipAllIfMacro = 1 ;
}
_if_ParseStatus = PARSE_MACRO_IFDEF_WAIT_ENDIF_MASK ;
}
}
else if( (strncmp(wordBuffer,"elif",4)==0) ) {
Process_IfMacro() ;
_if_ParseStatus = PARSE_MACRO_IFDEF_WAIT_ENDIF_MASK ;
}
else if( strncmp(wordBuffer,"define",6)==0) {
_if_ParseStatus = PARSE_MACRO_DEFINE_MASK ;
}
else if( strncmp(wordBuffer,"endif",5)==0) {
_iNest_if_macro-- ;
if( _iNest_if_macro == 0 ) {
return 1 ;
}
_if_ParseStatus = PARSE_MACRO_IFDEF_WAIT_ENDIF_MASK ;
}
else if( strncmp(wordBuffer,"include",7)==0) {
_if_ParseStatus = PARSE_MACRO_INCLUDE_FILE_MASK;
}
break ;
} ;
}
}
int ProcessConfigFile()
{
struct _IF_MARCO_PARAM _if_macro_param ;
while(1) {
if( _head_configfile[_iFileCounter].leadOfconfigBuffer >= _head_configfile[_iFileCounter].sizeOfconfigBuffer ) {
if( !GetConfigFile() ) return 0 ;
}
if( !GetWordFromConfigFile() ) {
return 0 ;
}
switch( _iParseStatus ) {
case PARSE_NULL :
if( strncmp(wordBuffer,"#",1)==0) {
_iParseStatus = PARSE_MACRO_MASK ;
}
break ;
case PARSE_MACRO_MASK :
if( strncmp(wordBuffer,"if",2)==0) {
Process_IfMacro() ;
_iParseStatus = PARSE_NULL ;
}
else if( strncmp(wordBuffer,"define",6)==0) {
_iParseStatus = PARSE_MACRO_DEFINE_MASK ;
}
else if( strncmp(wordBuffer,"include",7)==0) {
_iParseStatus = PARSE_MACRO_INCLUDE_FILE_MASK;
}
break ;
case PARSE_MACRO_INCLUDE_FILE_MASK:
_iFileCounter++ ;
ProcessFileName(wordBuffer) ;
_head_configfile[_iFileCounter].configFile = fopen(wordBuffer,"r");
_iParseStatus = PARSE_NULL ;
break ;
case PARSE_MACRO_DEFINE_MASK :
if( !findDefineTok(wordBuffer) ) {
_defineToks[defineTokLast].Value = -1 ;
strcpy(_defineToks[defineTokLast].Name,wordBuffer) ;
pLastDefineTok = &_defineToks[defineTokLast] ;
defineTokLast++ ;
}
_iParseStatus = PARSE_MACRO_DEFINE_VALUE_MASK ;
break ;
case PARSE_MACRO_DEFINE_VALUE_MASK :
if( strncmp(wordBuffer,"#",1)==0) {
_iParseStatus = PARSE_MACRO_MASK ;
break ;
}
else if( wordBuffer[0] != 0 ) {
pLastDefineTok->Value = atoi(wordBuffer) ;
_iParseStatus = PARSE_NULL ;
}
break ;
}
}
}
unsigned char _Char2Hex(char p)
{
if( p >= '0' && p <= '9' ) {
return p - '0' ;
}
if( p >= 'A' && p <= 'F' ) {
return p - 'A' + 0x0A ;
}
if( p >= 'a' && p <= 'f' ) {
return p - 'a' + 0x0A ;
}
return -1 ;
}
#if defined(GBK_DOT_SIZE_16) || defined(GBK_DOT_SIZE_12)
long int HZK_offset(int _hzCode)
{
int _hzHigh ;
int _hzLow ;
int X,Y,Z,M ;
long int offset ;
int _hzM ;
_hzHigh = _hzCode & 0xFF00 ;
_hzHigh >>= 8 ;
_hzHigh &= 0xFF ;
_hzLow = _hzCode & 0x00FF ;
if( _hzLow > 0xA0 ) {
M = 0x5E ;
Y = _hzLow - 0xA1 ;
if( _hzHigh > 0xA0 ) {
X = _hzHigh - 0xA1 ;
Z = 0 ;
}
else {
X = _hzHigh - 0x81 ;
Z = 0x2284 ;
}
} else {
M = 0x60 ;
if( _hzLow > 0x7F )
Y = _hzLow - 0x41 ;
else
Y = _hzLow - 0x40 ;
if( _hzHigh > 0xA0 ) {
X = _hzHigh - 0xA1 ;
Z = 0x3a44 ;
}
else {
X = _hzHigh - 0x81 ;
Z = 0x2e44 ;
}
}
offset = X*M + Y + Z ;
offset *= HZK_DOT_WIDTH ;
return offset ;
}
#endif // defined(GBK_DOT_SIZE_16)
#if defined(HZK_DOT_SIZE_16)
long int HZK_offset(int _hzCode)
{
int _hzHigh ;
long int offset ;
_hzCode -= 0xA1A1 ;
_hzHigh = _hzCode & 0xFF00 ;
_hzHigh >>= 8 ;
_hzHigh *= 94 ;
_hzCode &= 0xFF ;
_hzCode += _hzHigh ;
offset = _hzCode ;
offset *= HZK_DOT_WIDTH ;
return offset ;
}
#endif // defined(HZK_DOT_SIZE_16)
#if defined(HZK_DOT_SIZE_12)
long int HZK_offset(int _hzCode)
{
int _hzHigh ;
long int offset ;
_hzCode -= 0xA1A1 ;
_hzHigh = _hzCode & 0xFF00 ;
_hzHigh >>= 8 ;
_hzHigh *= 94 ;
_hzCode &= 0xFF ;
_hzCode += _hzHigh ;
offset = _hzCode ;
offset *= HZK_DOT_WIDTH ;
return offset ;
}
#endif // defined(HZK_DOT_SIZE_12)
#if defined(FREETYPE2_DOT_SIZE_9)
void OutOneHZ(FT_Face *face,unsigned int unicode,
FILE *_c_hz_code_file,
FILE *_h_hz_code_file
) // using freetype2 to get bitmap
{
FT_UInt glyph_index;
int row, pixel;
int bi,bj , bMask ;
char _hzk_code[200] ;
char _buffer[128] ;
int _hzTemp,_hzNdx ;
int _hzByteSize ;
int _hzBitIndex ;
glyph_index = FT_Get_Char_Index((*face), unicode);
if(glyph_index == 0) {
printf("freetype2 font can not found char! unicode as .%d.",unicode) ;
return ;
}
if(FT_Load_Glyph((*face),glyph_index,FT_LOAD_DEFAULT)){
printf("freetype2 font can not load glyph ! unicode as .%d.",unicode) ;
return ;
}
// if(FT_Render_Glyph((*face)->glyph,FT_RENDER_MODE_MONO)){
// printf("freetype2 font can not load render glyph ! unicode as .%d.",unicode) ;
// return ;
// }
_hzByteSize = (*face)->glyph->bitmap.width / 8 ;
if( (*face)->glyph->bitmap.width % 8 ) {
_hzByteSize++ ;
}
for(bi=0;bi<HZK_DOT_WIDTH;bi++) _hzk_code[bi] = 0 ;
bi = 0 ;
bMask = 0x80 ;
_hzBitIndex = 0 ;
for(row = 0; row < (*face)->glyph->bitmap.rows; ++row){
for(pixel = 0; pixel < (*face)->glyph->bitmap_left; ++pixel) {
printf("_");
bMask >>= 1 ;
if( bMask == 0 ) {
bMask = 0x80 ;
bi++ ;
}
_hzBitIndex++ ;
if( _hzBitIndex >= (*face)->glyph->bitmap.width ) {
bi++ ;
bMask = 0x80 ;
_hzBitIndex = 0 ;
}
}
for(pixel = 0; pixel < (*face)->glyph->bitmap.width; ++pixel){
if( (*face)->glyph->bitmap.buffer
[row * (*face)->glyph->bitmap.pitch +
pixel/8] & (0xC0 >> (pixel % 8))) {
_hzk_code[bi] |= bMask ;
}
bMask >>= 1 ;
if( bMask == 0 ) {
bMask = 0x80 ;
bi++ ;
}
_hzBitIndex++ ;
if( _hzBitIndex >= (*face)->glyph->bitmap.width ) {
bi++ ;
bMask = 0x80 ;
_hzBitIndex = 0 ;
}
//printf("%c", ((*face)->glyph->bitmap.buffer
// [row * (*face)->glyph->bitmap.pitch +
// pixel/8] & (0xC0 >> (pixel % 8)))?'#':'_');
}
//printf("\n");
}
sprintf(_buffer,"{") ;
fwrite(_buffer, 1, strlen(_buffer), _c_hz_code_file);
_hzNdx=0 ;
while(_hzNdx<bi) {
_hzTemp = _hzk_code[_hzNdx++] & 0xFF ;
sprintf(_buffer,"0x%2X,",_hzTemp) ;
if( _buffer[2] == ' ' ) _buffer[2] = '0' ;
fwrite(_buffer, 1, strlen(_buffer), _c_hz_code_file);
// printf("%s",_buffer) ;
if( _hzNdx % 8 == 0 ) {
sprintf(_buffer,"\n ") ;
fwrite(_buffer, 1, strlen(_buffer), _c_hz_code_file);
// printf("%s",_buffer) ;
}
}
}
/*
所謂“utf-8”只是UCS Transformation Format,只是UNICODE的一種表現形式,不等同于UNICODE,一般漢字在UNICODE中為兩個(雙)字節表示,而我們看到實際保存的文檔確是三個字節表示一個漢字的,看看下表:
U-00000000 - U-0000007F: 0xxxxxxx
U-00000080 - U-000007FF: 110xxxxx 10xxxxxx
U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
UTF-8是一種變長度的表達方式,一般UNICODE為雙字節(指UCS2)但為了與以前的ASCII碼兼容,ASCII為一個字節,于是就想出了這種方法,在ASCII碼的范圍用一個字節表示,超出ASCII碼的范圍就用多字節表示,這就形成了我們上面看到的UTF-8的表示方法,這樣的好處是當UNICODE文檔中只有ASCII碼時,保存的文檔都為一個字節,所以就是普通的ASCII文檔無異,讀入的時候也是如此,所以能與以前的ASCII 文檔兼容。
至于大于ASCII碼的,就會由上面的第一字節的前幾位表示該unicode字符的長度,比如110xxxxxx前三位的二進制表示告訴我們這是個 2BYTE的UNICODE字符;1110xxxx是個三位的UNICODE字符,依此類推,而首字節后面的字節都是以10開頭,見上面這是為了與 ASCII碼開頭的0區分告訴我們這是個多字節UTF-8編碼的后續位。看上面的編碼,我們將上面的x部分重新連起來組成的數值就是實際的UNICODE 碼值了(排除10組成的標志位)。
下面是個我寫的從UTF-8轉換到UNICODE真實值的程序,
編譯方法:
gcc utf82unicode.cpp -o utf82unicode -lstdc++
使用方法:
比如一個漢字‘新’字,它的UTF-8編碼為:E696B0,為了知道他的實際UNICODE編碼,執行如下程序,
./utf82unicode E696B0
unicode: 65B0
上面程序的輸出結果告訴我們UTF8:E696B0 對應UNICODE:65B0。
*/
int Utf8ToUSC2( char *src_utf8, char *dest_usc2)
{
if( (src_utf8[0] & 0xF0) == 0xE0 ) // utf8 has 3 bytes
{ // U-0800 - U-FFFF: 1110xxxx 10xxxxxx 10xxxxxx
dest_usc2[0] = (src_utf8[0] & 0x0F) << 4 ;
dest_usc2[0] |= (src_utf8[1] & 0x3C) >> 2 ;
dest_usc2[1] = (src_utf8[1] & 0x03) << 6 ;
dest_usc2[1] |= (src_utf8[2] & 0x3F) ;
// UartDump(dest_usc2,2) ;
return 3 ;
}
else if( (src_utf8[0] & 0xE0) == 0xC0 ) // utf8 has 2 bytes
{ // U-0080 - U-07FF: 110xxxxx 10xxxxxx
dest_usc2[1] = (src_utf8[1] & 0x3F) ;
dest_usc2[1] |= (src_utf8[0] & 0x03) << 6 ;
dest_usc2[0] = (src_utf8[0] & 0x1C) >> 2 ;
// UartDump(dest_usc2,2) ;
return 2 ;
}
else { // U-0000 - U-007F: 0xxxxxxx
dest_usc2[0] = (src_utf8[0] & 0x7F) ;
dest_usc2[1] = 0x00 ;
// UartDump(dest_usc2,2) ;
return 1 ;
}
}
unsigned int convertUnicode(iconv_t _hzIconv,unsigned int gbkCode)
{
char inbuf[5] ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -