static void UpdateItem(FarListItem *item,SmallInfoRec *data,int width) { const int InfoMsgs[]={0,mInfoCopy,mInfoMove,mInfoWipe,mInfoDel,mInfoAttr}; TCHAR SrcA[2*MAX_PATH],percent[10]; #ifdef UNICODE TCHAR* text=(TCHAR*)malloc(128*sizeof(TCHAR)); item->Text=text; #else TCHAR* text=item->Text; #endif wc2mb(data->Src,SrcA,sizeofa(SrcA)); _stprintf(percent,_T("%3ld"),data->percent); percent[3]=0; _tcscpy(text,GetMsg(InfoMsgs[data->type])); _tcscat(text,GetMsg(mInfoSep)); _tcscat(text,percent); _tcscat(text,_T("%")); _tcscat(text,GetMsg(mInfoSep)); _tcscat(text,FSF.TruncPathStr(SrcA,width)); if(data->wait) { if(data->pause) item->Flags=LIF_CHECKED|'w'; else item->Flags=LIF_CHECKED|'W'; } else if(data->Ask) item->Flags=LIF_CHECKED|'?'; else if(data->pause) item->Flags=0; else item->Flags=LIF_CHECKED|'*'; }
// Count multi-byte characters characters needed to convert utf8 from src FXint FXTextCodec::utf2mblen(const FXchar* src,FXint nsrc) const { register FXint nr,len=0; FXchar buffer[64]; FXwchar w; if(src && 0<nsrc){ do{ nr=utf2wc(w,src,nsrc); if(nr<=0) return nr; src+=nr; nsrc-=nr; len+=wc2mb(buffer,sizeof(buffer),w); } while(0<nsrc); } return len; }
// Convert utf8 characters at src to multi-byte characters at dst FXint FXTextCodec::utf2mb(FXchar* dst,FXint ndst,const FXchar* src,FXint nsrc) const { register FXint nr,nw,len=0; FXwchar w; if(dst && src && 0<nsrc){ do{ nr=utf2wc(w,src,nsrc); if(nr<=0) return nr; src+=nr; nsrc-=nr; nw=wc2mb(dst,ndst,w); if(nw<=0) return nw; len+=nw; dst+=nw; ndst-=nw; } while(0<nsrc); } return len; }
// Convert utf8 characters at src to multi-byte characters at dst FXint FXUTF16Codec::utf2mb(FXchar* dst,FXint ndst,const FXchar* src,FXint nsrc) const { register FXint nr,nw,len=0; FXwchar w; if(dst && src && 0<nsrc){ dst[0]='\xFE'; dst[1]='\xFF'; dst+=2; len+=2; while(0<nsrc){ nr=utf2wc(w,src,nsrc); if(nr<=0) return nr; src+=nr; nsrc-=nr; nw=wc2mb(dst,ndst,w); if(nw<=0) return nw; len+=nw; dst+=nw; ndst-=nw; } } return len; }
const void* __declspec(dllexport) strncvt (const void* str, int strLen, unsigned int cpFrom, unsigned int cpTo, int* len) { if (!str) return NULL; if (strLen<0) strLen = (cpFrom>=1200&&cpFrom<=1203? wcslen(str) : strlen(str)); if (cpFrom==cpTo) { if (len) *len = strLen; return str; } const void* from = NULL, *result = NULL; BOOL alloced = FALSE; switch(cpFrom){ case CP_UTF16_LE: from=str; if (len) *len = strLen; break; case CP_UTF16_LE_BOM: from = ((const wchar_t*)str) +1; strLen--; if (len) *len = strLen; break; case CP_UTF16_BE_BOM: from = ((const wchar_t*)str) +1; strLen--; case CP_UTF16_BE : if (!from) from = str; from = wcsdup(from); unicodeSwitchEndianess(from, 1+wcslen(from)); if (len) *len = strLen; alloced=TRUE; break; case CP_UTF8_BOM : from = ((const char*)str) +3; cpFrom = CP_UTF8; strLen -= 3; default : if (!from) from=str; from = mb2wc(from, strLen, cpFrom, &strLen); if (len) *len = strLen; alloced = TRUE; break; } if (!from) return NULL; switch(cpTo){ case CP_UTF16_LE: result = from; ((wchar_t*)result)[strLen]=0; alloced = FALSE; break; case CP_UTF16_LE_BOM : if (alloced) { result = from; memmove( ((wchar_t*)result)+1, ((wchar_t*)result), sizeof(wchar_t)*(1+strLen)); } else { result = malloc(sizeof(wchar_t) * (4+strLen)); memcpy( ((wchar_t*)result)+1, from, sizeof(wchar_t)*(1+strLen)); } (*((wchar_t*)result)) = 0xFEFF; ((wchar_t*)result)[++strLen] = 0; if (len) *len = strLen; alloced = FALSE; break; case CP_UTF16_BE : result = (alloced? from : wcsdup(from)); unicodeSwitchEndianess(result, 3+wcslen(result)); alloced = FALSE; ((wchar_t*)result)[strLen] = 0; if (len) *len = strLen; break; case CP_UTF16_BE_BOM : if (alloced) { result = from; memmove( ((wchar_t*)result)+1, ((wchar_t*)result), sizeof(wchar_t)*(1+strLen)); } else { result = malloc(sizeof(wchar_t) * (4+strLen)); memcpy(((wchar_t*)result)+1, from, sizeof(wchar_t)*(1+strLen)); } (*(((wchar_t*)result))) = 0xFEFF; ((wchar_t*)result)[++strLen] = 0; unicodeSwitchEndianess(result, 3+strLen); if (len) *len = strLen; alloced = FALSE; break; case CP_UTF8_BOM : result = wc2mb(from, strLen, CP_UTF8, &strLen); memmove( ((const char*)result)+3, ((const char*)result), 1+strLen); memcpy(result, "\xEF\xBB\xBF", 3); if (len) (*len) = strLen+3; break; default : result = wc2mb(from, strLen, cpTo, &strLen); if (len) *len = strLen; break; } if (alloced) free(from); return result; }
const char* toEncoding (const wchar_t* unicode, int targetEncoding) { if (!unicode) return NULL; if (strptr) free(strptr); strptr = wc2mb(unicode, targetEncoding); return strptr; }