コード例 #1
0
ファイル: strfn.cpp プロジェクト: sina-ht/enfle
// Convert archived names and comments to Unicode.
// Allows user to select a code page in GUI.
void ArcCharToWide(const char *Src,wchar *Dest,size_t DestSize,ACTW_ENCODING Encoding)
{
#if defined(_WIN_ALL) // Console Windows RAR.
  if (Encoding==ACTW_UTF8)
    UtfToWide(Src,Dest,DestSize);
  else
  {
    Array<char> NameA;
    if (Encoding==ACTW_OEM)
    {
      NameA.Alloc(DestSize+1);
      IntToExt(Src,&NameA[0],NameA.Size());
      Src=&NameA[0];
    }
    CharToWide(Src,Dest,DestSize);
  }
#else // RAR for Unix.
  if (Encoding==ACTW_UTF8)
    UtfToWide(Src,Dest,DestSize);
  else
    CharToWide(Src,Dest,DestSize);
#endif
  // Ensure that we return a zero terminate string for security reason.
  // While [Jni]CharToWide might already do it, be protected in case of future
  // changes in these functions.
  if (DestSize>0)
    Dest[DestSize-1]=0;
}
コード例 #2
0
ファイル: iconv_ut.cpp プロジェクト: Mirocow/balancer
static void TestIconv(const Stroka& utf8, const Stroka& other, ECharset enc) {
    Wtroka wide0 = CharToWide(utf8, CODES_UTF8);
    Wtroka wide1 = CharToWide(other, enc);

    UNIT_ASSERT(wide0 == wide1);

    Stroka temp = WideToChar(wide0, CODES_UTF8);
    UNIT_ASSERT(temp == utf8);

    temp = WideToChar(wide0, enc);
    UNIT_ASSERT(temp == other);

    temp = Recode(enc, CODES_UTF8, other);
    UNIT_ASSERT(temp == utf8);

    temp = Recode(CODES_UTF8, enc, utf8);
    UNIT_ASSERT(temp == other);

    size_t read = 0;
    size_t written = 0;

    RECODE_RESULT res = RecodeToUnicode(enc, other.c_str(), wide1.begin(), other.size(), wide1.size(), read, written);
    UNIT_ASSERT(res == RECODE_OK);
    UNIT_ASSERT(read == other.size());
    UNIT_ASSERT(written == wide1.size());
    UNIT_ASSERT(wide0 == wide1);

    res = RecodeFromUnicode(enc, wide0.c_str(), temp.begin(), wide0.size(), temp.size(), read, written);
    UNIT_ASSERT(res == RECODE_OK);
    UNIT_ASSERT(read == wide0.size());
    UNIT_ASSERT(written == other.size());
    UNIT_ASSERT(temp == other);
}
コード例 #3
0
ファイル: filefn.cpp プロジェクト: zachberger/UnRarX
void ConvertNameToFull(const wchar *Src,wchar *Dest)
{
  if (Src==NULL || *Src==0)
  {
    *Dest=0;
    return;
  }
#ifdef _WIN_32
  if (WinNT())
  {
    wchar FullName[NM],*NamePtr;
    if (GetFullPathNameW(Src,sizeof(FullName)/sizeof(FullName[0]),FullName,&NamePtr))
      strcpyw(Dest,FullName);
    else
      if (Src!=Dest)
        strcpyw(Dest,Src);
  }
  else
  {
    char AnsiName[NM];
    WideToChar(Src,AnsiName);
    ConvertNameToFull(AnsiName,AnsiName);
    CharToWide(AnsiName,Dest);
  }
#else
  char AnsiName[NM];
  WideToChar(Src,AnsiName);
  ConvertNameToFull(AnsiName,AnsiName);
  CharToWide(AnsiName,Dest);
#endif
}
コード例 #4
0
void CDocListRetrieverFromDisc::FillDocInfo(SDocumentAttribtes& attrs)
{
    Stroka strFilePath = m_SmartFileFind.GetFoundFilePath(m_iCurPath);

    Stroka strURL;
    if (strFilePath == m_strSearchDir) {
        TStringBuf left, right;
        PathHelper::Split(strFilePath, left, right);
        strURL = ToString(right);
    } else
        strURL = strFilePath.substr(m_strSearchDir.size());

    if (strURL.empty())
        ythrow yexception() << "Can't build url for file \"" << strFilePath
                              << "\" with searchdir \"" << m_strSearchDir << "\".";

    TransformBackSlash(strURL);

    attrs.m_strUrl = strURL;

    Stroka strTime;
    if (stroka(m_strLTM) == "file") {
        CTime lw_time = m_SmartFileFind.GetFoundFileInfo(m_iCurPath).m_LastWriteTime;
        strTime = lw_time.Format("%d.%m.%Y %H:%M:%S");
    }

    if (strTime.empty())
        strTime = m_strStartTime;

    attrs.m_strTitle = CharToWide(strTime);
    attrs.m_strSource = strURL;
    attrs.m_strTitle = CharToWide(attrs.m_strSource);     // ??? rewriting
}
コード例 #5
0
ファイル: cmddata.cpp プロジェクト: DreamingPiggy/xreader-hg
int CommandData::IsProcessFile(FileHeader &NewLhd,bool *ExactMatch,int MatchType)
{
  if (strlen(NewLhd.FileName)>=NM || wcslen(NewLhd.FileNameW)>=NM)
    return(0);
  bool Dir=(NewLhd.Flags & LHD_WINDOWMASK)==LHD_DIRECTORY;
  if (ExclCheck(NewLhd.FileName,Dir,false,true))
    return(0);
#ifndef SFX_MODULE
  if (TimeCheck(NewLhd.mtime))
    return(0);
  if ((NewLhd.FileAttr & ExclFileAttr)!=0 || InclAttrSet && (NewLhd.FileAttr & InclFileAttr)==0)
    return(0);
  if (!Dir && SizeCheck(NewLhd.FullUnpSize))
    return(0);
#endif
  char *ArgName;
  wchar *ArgNameW;
  FileArgs->Rewind();
  for (int StringCount=1;FileArgs->GetString(&ArgName,&ArgNameW);StringCount++)
  {
#ifndef SFX_MODULE
    bool Unicode=(NewLhd.Flags & LHD_UNICODE) || ArgNameW!=NULL && *ArgNameW!=0;
    if (Unicode)
    {
      wchar NameW[NM],ArgW[NM],*NamePtr=NewLhd.FileNameW;
      bool CorrectUnicode=true;
      if (ArgNameW==NULL || *ArgNameW==0)
      {
        if (!CharToWide(ArgName,ArgW) || *ArgW==0)
          CorrectUnicode=false;
        ArgNameW=ArgW;
      }
      if ((NewLhd.Flags & LHD_UNICODE)==0)
      {
        if (!CharToWide(NewLhd.FileName,NameW) || *NameW==0)
          CorrectUnicode=false;
        NamePtr=NameW;
      }
      if (CmpName(ArgNameW,NamePtr,MatchType))
      {
        if (ExactMatch!=NULL)
          *ExactMatch=wcsicompc(ArgNameW,NamePtr)==0;
        return(StringCount);
      }
      if (CorrectUnicode)
        continue;
    }
#endif
    if (CmpName(ArgName,NewLhd.FileName,MatchType))
    {
      if (ExactMatch!=NULL)
        *ExactMatch=stricompc(ArgName,NewLhd.FileName)==0;
      return(StringCount);
    }
  }
  return(0);
}
コード例 #6
0
ファイル: cmddata.cpp プロジェクト: ProfDrLuigi/zanka
int CommandData::IsProcessFile(FileHeader &NewLhd,bool *ExactMatch,int MatchType)
{
  if (strlen(NewLhd.FileName)>=NM || strlenw(NewLhd.FileNameW)>=NM)
    return(0);
  if (ExclCheck(NewLhd.FileName,false))
    return(0);
#ifndef SFX_MODULE
  if (TimeCheck(NewLhd.mtime))
    return(0);
#endif
  char *ArgName;
  wchar *ArgNameW;
  FileArgs->Rewind();
  for (int StringCount=1;FileArgs->GetString(&ArgName,&ArgNameW);StringCount++)
  {
#ifndef SFX_MODULE
    bool Unicode=(NewLhd.Flags & LHD_UNICODE) || ArgNameW!=NULL;
    if (Unicode)
    {
      wchar NameW[NM],ArgW[NM],*NamePtr=NewLhd.FileNameW;
      if (ArgNameW==NULL)
      {
        CharToWide(ArgName,ArgW);
        ArgNameW=ArgW;
      }
      if ((NewLhd.Flags & LHD_UNICODE)==0)
      {
        CharToWide(NewLhd.FileName,NameW);
        NamePtr=NameW;
      }
      if (CmpName(ArgNameW,NamePtr,MatchType))
      {
        if (ExactMatch!=NULL)
          *ExactMatch=stricompcw(ArgNameW,NamePtr)==0;
        return(StringCount);
      }
      continue;
    }
#endif
    if (CmpName(ArgName,NewLhd.FileName,MatchType))
    {
      if (ExactMatch!=NULL)
        *ExactMatch=stricompc(ArgName,NewLhd.FileName)==0;
      return(StringCount);
    }
  }
  return(0);
}
コード例 #7
0
ファイル: pathfn.cpp プロジェクト: KyleSanderson/mpc-hc
void MakeNameUsable(char *Name,bool Extended)
{
#ifdef _WIN_ALL
  // In Windows we also need to convert characters not defined in current
  // code page. This double conversion changes them to '?', which is
  // catched by code below.
  size_t NameLength=strlen(Name);
  wchar NameW[NM];
  CharToWide(Name,NameW,ASIZE(NameW));
  WideToChar(NameW,Name,NameLength+1);
  Name[NameLength]=0;
#endif
  for (char *s=Name;*s!=0;s=charnext(s))
  {
    if (strchr(Extended ? "?*<>|\"":"?*",*s)!=NULL || Extended && (byte)*s<32)
      *s='_';
#ifdef _EMX
    if (*s=='=')
      *s='_';
#endif
#ifndef _UNIX
    if (s-Name>1 && *s==':')
      *s='_';
    // Remove ' ' and '.' before path separator, but allow .\ and ..\.
    if ((*s==' ' || *s=='.' && s>Name && !IsPathDiv(s[-1]) && s[-1]!='.') && IsPathDiv(s[1]))
      *s='_';
#endif
  }
}
コード例 #8
0
ファイル: sentence.cpp プロジェクト: dubrousky/tomita-parser
bool CSentence::GetWSLemmaString(Wtroka& sLemmas, const CWordSequence& ws, bool bLem) const
{
    sLemmas = ws.GetCapitalizedLemma();

    if (bLem)
        return !sLemmas.empty();

    if (sLemmas.empty())
        for (int j = ws.FirstWord(); j <= ws.LastWord(); j++) {
            if (!sLemmas.empty())
                sLemmas += ' ';
            sLemmas += getWord(j)->GetOriginalText();
        }

    static const Wtroka trim_chars = CharToWide(" \"\'");
    TWtringBuf res = sLemmas;
    while (!res.empty() && trim_chars.find(res[0]) != TWtringBuf::npos)
        res.Skip(1);
    while (!res.empty() && trim_chars.find(res.back()) != TWtringBuf::npos)
        res.Chop(1);

    if (sLemmas.size() != res.size())
        sLemmas = ::ToWtring(res);

    return true;
}
コード例 #9
0
ファイル: find.cpp プロジェクト: LubosD/fatrat-unpack
void FindFile::SetMask(const char *FindMask)
{
  strcpy(FindFile::FindMask,FindMask);
  if (*FindMaskW==0)
    CharToWide(FindMask,FindMaskW);
  FirstCall=true;
}
コード例 #10
0
bool TParserBase::RecodeToUtf8(Stroka& text)
{
    if (Encoding == CODES_UNKNOWN) {
        if (!IsStringASCII(~text, ~text + +text)) {
            AddError(Substitute("Unknown encoding: \"$0\".", text));
            return false;
        }

    } else if (Encoding == CODES_UTF8) {
        if (!IsUtf(text)) {
            AddError(Substitute("Invalid utf8: \"$0\".", text));
            return false;
        }

    } else {
        try {
            CharToWide(text, RecodeBuffer, Encoding);
            WideToUTF8(RecodeBuffer, text);
        } catch (yexception&) {
            AddError(Substitute("Cannot recode from $0 to utf8: \"$1\".", NameByCharset(Encoding), text));
            return false;
        }
    }

    return true;
}
コード例 #11
0
ファイル: find.cpp プロジェクト: LubosD/fatrat-unpack
bool FindFile::FastFind(const char *FindMask,const wchar *FindMaskW,struct FindData *fd,bool GetSymLink)
{
  fd->Error=false;
#ifndef _UNIX
  if (IsWildcard(FindMask,FindMaskW))
    return(false);
#endif    
#ifdef _WIN_32
  HANDLE hFind=Win32Find(INVALID_HANDLE_VALUE,FindMask,FindMaskW,fd);
  if (hFind==INVALID_HANDLE_VALUE)
    return(false);
  FindClose(hFind);
#else
  struct stat st;
  if (GetSymLink)
  {
#ifdef SAVE_LINKS
    if (lstat(FindMask,&st)!=0)
#else
    if (stat(FindMask,&st)!=0)
#endif
    {
      fd->Error=(errno!=ENOENT);
      return(false);
    }
  }
  else
    if (stat(FindMask,&st)!=0)
    {
      fd->Error=(errno!=ENOENT);
      return(false);
    }
#ifdef _DJGPP
  fd->FileAttr=_chmod(FindMask,0);
#elif defined(_EMX)
  fd->FileAttr=st.st_attr;
#else
  fd->FileAttr=st.st_mode;
#endif
  fd->IsDir=IsDir(st.st_mode);
  fd->Size=st.st_size;
  fd->mtime=st.st_mtime;
  fd->atime=st.st_atime;
  fd->ctime=st.st_ctime;
  fd->FileTime=fd->mtime.GetDos();
  strcpy(fd->Name,FindMask);

  *fd->NameW=0;
#ifdef _APPLE
  if (!LowAscii(fd->Name))
    UtfToWide(fd->Name,fd->NameW,sizeof(fd->NameW));
#elif defined(UNICODE_SUPPORTED)
  if (!LowAscii(fd->Name) && UnicodeEnabled())
    CharToWide(fd->Name,fd->NameW);
#endif
#endif
  fd->Flags=0;
  fd->IsDir=IsDir(fd->FileAttr);
  return(true);
}
コード例 #12
0
ファイル: arccmt.cpp プロジェクト: php/pecl-file_formats-rar
size_t Archive::ReadCommentData(Array<byte> *CmtData,Array<wchar> *CmtDataW)
{
  bool Unicode=SubHead.SubFlags & SUBHEAD_FLAGS_CMT_UNICODE;
  if (!ReadSubData(CmtData,NULL))
    return(0);
  size_t CmtSize=CmtData->Size();
  if (Unicode)
  {
    CmtSize/=2;
    Array<wchar> DataW(CmtSize+1);
    RawToWide(CmtData->Addr(),DataW.Addr(),CmtSize);
    DataW[CmtSize]=0;
    size_t DestSize=CmtSize*4;
    CmtData->Alloc(DestSize+1);
    WideToChar(DataW.Addr(),(char *)CmtData->Addr(),DestSize);
    (*CmtData)[DestSize]=0;
    CmtSize=strlen((char *)CmtData->Addr());
    CmtData->Alloc(CmtSize);
    if (CmtDataW!=NULL)
    {
      *CmtDataW=DataW;
      CmtDataW->Alloc(CmtSize);
    }
  }
  else
    if (CmtDataW!=NULL)
    {
      CmtData->Push(0);
      CmtDataW->Alloc(CmtSize+1);
      CharToWide((char *)CmtData->Addr(),CmtDataW->Addr(),CmtSize+1);
      CmtData->Alloc(CmtSize);
      CmtDataW->Alloc(wcslen(CmtDataW->Addr()));
    }
  return(CmtSize);
}
コード例 #13
0
ファイル: consio.cpp プロジェクト: BSzili/aros-stuff
static void GetPasswordText(wchar *Str,uint MaxLength)
{
  if (MaxLength==0)
    return;
#ifdef _WIN_ALL
  HANDLE hConIn=GetStdHandle(STD_INPUT_HANDLE);
  HANDLE hConOut=GetStdHandle(STD_OUTPUT_HANDLE);
  DWORD ConInMode,ConOutMode;
  DWORD Read=0;
  GetConsoleMode(hConIn,&ConInMode);
  GetConsoleMode(hConOut,&ConOutMode);
  SetConsoleMode(hConIn,ENABLE_LINE_INPUT);
  SetConsoleMode(hConOut,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT);

  ReadConsole(hConIn,Str,MaxLength-1,&Read,NULL);
  Str[Read]=0;
  SetConsoleMode(hConIn,ConInMode);
  SetConsoleMode(hConOut,ConOutMode);
#else
  char StrA[MAXPASSWORD];
#if defined(_EMX) || defined (__VMS) || defined(__AROS__)
  fgets(StrA,ASIZE(StrA)-1,stdin);
#elif defined(__sun)
  strncpyz(StrA,getpassphrase(""),ASIZE(StrA));
#else
  strncpyz(StrA,getpass(""),ASIZE(StrA));
#endif
  CharToWide(StrA,Str,MaxLength);
  cleandata(StrA,sizeof(StrA));
#endif
  Str[MaxLength-1]=0;
  RemoveLF(Str);
}
コード例 #14
0
ファイル: sutil.cpp プロジェクト: jjiezheng/arachnid
void  normalizeFQN(const wchar_t *source,wchar_t *dest)
{
  char scratch[512];
  WideToChar(source,scratch,512);
  char temp[512];
  normalizeFQN(scratch,temp);
  CharToWide(temp,dest,512);
}
コード例 #15
0
ファイル: find.cpp プロジェクト: brianwoo/cm11_grouper
void FindFile::SetMask(const char *FindMask)
{
  strcpy(FindFile::FindMask,NullToEmpty(FindMask));
#ifndef __BIONIC__
  if (*FindMaskW==0)
    CharToWide(FindMask,FindMaskW);
#endif
  FirstCall=true;
}
コード例 #16
0
ファイル: unicode.cpp プロジェクト: artifexor/stream-unrar
bool CharToWide(const char *Src,wchar *Dest,size_t DestSize)
{
  bool RetCode=true;
  *Dest=0; // Set 'Dest' to zero just in case the conversion will fail.

#ifdef _WIN_ALL
  if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0)
    RetCode=false;

#elif defined(_APPLE)
  UtfToWide(Src,Dest,DestSize);

#elif defined(MBFUNCTIONS)
  size_t ResultingSize=mbstowcs(Dest,Src,DestSize);
  if (ResultingSize==(size_t)-1)
    RetCode=false;
  if (ResultingSize==0 && *Src!=0)
    RetCode=false;

  if ((!RetCode || *Dest==0 && *Src!=0) && DestSize>NM && strlen(Src)<NM)
  {
    /* Workaround for strange Linux Unicode functions bug.
       Some of wcstombs and mbstowcs implementations in some situations
       (we are yet to find out what it depends on) can return an empty
       string and success code if buffer size value is too large.
    */
    return(CharToWide(Src,Dest,NM));
  }
#else
  if (UnicodeEnabled())
  {
#if defined(_EMX) && !defined(_DJGPP)
    int len=Min(strlen(Src)+1,DestSize-1);
    if (uni_toucs((char*)Src,len,(UniChar*)Dest,(size_t*)&DestSize)==-1 ||
        DestSize>len)
      DestSize=0;
    RetCode=false;
#endif
  }
  else
    for (int I=0;I<DestSize;I++)
    {
      Dest[I]=(wchar_t)Src[I];
      if (Src[I]==0)
        break;
    }
#endif

  // We tried to return the zero terminated string if conversion is failed,
  // but it does not work well. MultiByteToWideChar returns 'failed' code
  // even if we wanted to convert only a part of string and passed DestSize
  // smaller than required for fully converted string. Such call is the valid
  // behavior in RAR code and we do not expect the empty string in this case.

  return(RetCode);
}
コード例 #17
0
ファイル: cmddata.cpp プロジェクト: abbeycode/UnrarKit
void CommandData::ParseEnvVar()
{
  char *EnvStr=getenv("RAR");
  if (EnvStr!=NULL)
  {
    Array<wchar> EnvStrW(strlen(EnvStr)+1);
    CharToWide(EnvStr,&EnvStrW[0],EnvStrW.Size());
    ProcessSwitchesString(&EnvStrW[0]);
  }
}
コード例 #18
0
bool ScanTree::PrepareMasks()
{
    ScanEntireDisk=false;
    if (!FileMasks->GetString(CurMask,CurMaskW,sizeof(CurMask)))
        return(false);
    CurMask[ASIZE(CurMask)-1]=0;
    CurMaskW[ASIZE(CurMaskW)-1]=0;
#ifdef _WIN_32
    UnixSlashToDos(CurMask);
#endif

    // We wish to scan entire disk if mask like c:\ is specified
    // regardless of recursion mode. Use c:\*.* mask when need to scan only
    // the root directory.
    ScanEntireDisk=IsDiskLetter(CurMask) && IsPathDiv(CurMask[2]) && CurMask[3]==0;

    char *Name=PointToName(CurMask);
    if (*Name==0)
        strcat(CurMask,MASKALL);
    if (Name[0]=='.' && (Name[1]==0 || Name[1]=='.' && Name[2]==0))
    {
        AddEndSlash(CurMask);
        strcat(CurMask,MASKALL);
    }
    SpecPathLength=Name-CurMask;
//  if (SpecPathLength>1)
//    SpecPathLength--;

    bool WideName=(*CurMaskW!=0);

    if (WideName)
    {
        wchar *NameW=PointToName(CurMaskW);
        if (*NameW==0)
            strcatw(CurMaskW,MASKALLW);
        if (NameW[0]=='.' && (NameW[1]==0 || NameW[1]=='.' && NameW[2]==0))
        {
            AddEndSlash(CurMaskW);
            strcatw(CurMaskW,MASKALLW);
        }
        SpecPathLengthW=NameW-CurMaskW;
    }
    else
    {
        wchar WideMask[NM];
        CharToWide(CurMask,WideMask);
        SpecPathLengthW=PointToName(WideMask)-WideMask;
    }
    Depth=0;

    strcpy(OrigCurMask,CurMask);
    strcpyw(OrigCurMaskW,CurMaskW);

    return(true);
}
コード例 #19
0
ファイル: pathfn.cpp プロジェクト: 1ibraheem/xbmc
wchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW)
{
  if (NameW!=NULL && *NameW!=0)
  {
    if (DestW!=NameW)
      strcpyw(DestW,NameW);
  }
  else
    CharToWide(Name,DestW);
  return(DestW);
}
コード例 #20
0
ファイル: word.cpp プロジェクト: Frankie-666/tomita-parser
bool CWord::IsComplexWordAsDate() const
//for treating dates like 11.06.07 as Words
{
    if (m_typ != Complex)
        return false;

    static const Wtroka allowed = CharToWide("-.\\/11234567890г");

    const Wtroka& str = GetText();
    return str.find_first_not_of(allowed) == Wtroka::npos;
}
コード例 #21
0
ファイル: strfn.cpp プロジェクト: ajnelson/bulk_extractor
const wchar* GetWide(const char *Src)
{
  const size_t MaxLength=NM;
  static __thread wchar StrTable[4][MaxLength];
  static __thread uint StrNum=0;
  if (++StrNum >= ASIZE(StrTable))
    StrNum=0;
  wchar *Str=StrTable[StrNum];
  CharToWide(Src,Str,MaxLength);
  Str[MaxLength-1]=0;
  return(Str);
}
コード例 #22
0
ファイル: win32stm.cpp プロジェクト: Akkarinage/Neoncube
void ExtractStreamsNew(Archive &Arc,char *FileName,wchar *FileNameW)
{
  if (!WinNT())
    return;

  wchar NameW[NM];
  if (FileNameW!=NULL && *FileNameW!=0)
    strcpyw(NameW,FileNameW);
  else
    CharToWide(FileName,NameW);
  wchar StreamNameW[NM+2];
  if (NameW[0]!=0 && NameW[1]==0)
  {
    strcpyw(StreamNameW,L".\\");
    strcpyw(StreamNameW+2,NameW);
  }
  else
    strcpyw(StreamNameW,NameW);

  wchar *DestName=StreamNameW+strlenw(StreamNameW);
  byte *SrcName=&Arc.SubHead.SubData[0];
  int DestSize=Arc.SubHead.SubData.Size()/2;

  if (strlenw(StreamNameW)+DestSize>=sizeof(StreamNameW)/sizeof(StreamNameW[0]))
  {
#if !defined(SILENT) && !defined(SFX_MODULE)
    Log(Arc.FileName,St(MStreamBroken),FileName);
#endif
    ErrHandler.SetErrorCode(CRC_ERROR);
    return;
  }

  RawToWide(SrcName,DestName,DestSize);
  DestName[DestSize]=0;

  FindData fd;
  bool Found=FindFile::FastFind(FileName,FileNameW,&fd);

  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
    SetFileAttr(FileName,FileNameW,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
  char StreamName[NM];
  WideToChar(StreamNameW,StreamName);
  File CurFile;
  if (CurFile.WCreate(StreamName,StreamNameW) && Arc.ReadSubData(NULL,&CurFile))
    CurFile.Close();
  File HostFile;
  if (Found && HostFile.Open(FileName,FileNameW,true,true))
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
                &fd.ftLastWriteTime);
  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
    SetFileAttr(FileName,FileNameW,fd.FileAttr);
}
コード例 #23
0
ファイル: resource.cpp プロジェクト: Tyf0n/Rar_crack
const wchar* StW(MSGID StringId)
{
    static wchar StrTable[8][512];
    static int StrNum = 0;

    if (++StrNum >= sizeof(StrTable) / sizeof(StrTable[0]))
        StrNum = 0;

    wchar* Str = StrTable[StrNum];
    *Str = 0;
    CharToWide(StringId, Str, ASIZE(StrTable[0]));
    return(Str);
}
コード例 #24
0
void TSurnamePredictor::Load(const Stroka& path, ECharset encoding)
{
    TIFStream is(path);

    TSurnameLemma lemma;
    yvector<TTempForm> paradigma;
    Stroka line;
    yvector<TStringBuf> fields;
    while (is.ReadLine(line)) {
        CustomSplit(line, ' ', fields);
        if (fields.ysize() < 2)
            continue;

        if (fields[0][0] == '-')
            fields[0] = fields[0].SubStr(1);

        if (fields[1][0] == '-')
            fields[1] = fields[1].SubStr(1);

        if (line[0] == '$') {
           SaveParadigma(lemma, paradigma);
           paradigma.clear();
           lemma.SurnameFlex = CharToWide(fields[1], encoding);
           lemma.Weight = FromString<double>(~fields[2], +fields[2]);
           continue;
        };

        if (lemma.SurnameFlex.empty())
            continue;
        if (MaxSurnameSuffixLength < fields[0].size())
            MaxSurnameSuffixLength = fields[0].size();

        TTempForm tempForm;
        tempForm.Flex = CharToWide(fields[0], encoding);
        tempForm.Grammars = HumanGrammemsToGramBitSet(CharToWide(fields[1], encoding));
        paradigma.push_back(tempForm);
    }
}
コード例 #25
0
ファイル: filefn.cpp プロジェクト: 1ibraheem/xbmc
void ConvertNameToFull(const wchar *Src,wchar *Dest)
{
  if (Src==NULL || *Src==0)
  {
    *Dest=0;
    return;
  }
#ifdef _WIN_32
#ifndef _WIN_CE
  if (WinNT())
#endif
  {
//#ifndef _WIN_CE
#if !defined(_WIN_CE) && !defined(_LINUX)
    wchar FullName[NM],*NamePtr;
    if (GetFullPathNameW(Src,sizeof(FullName)/sizeof(FullName[0]),FullName,&NamePtr))
      strcpyw(Dest,FullName);
    else
#endif
      if (Src!=Dest)
        strcpyw(Dest,Src);
  }
#ifndef _WIN_CE
  else
  {
    char AnsiName[NM];
    WideToChar(Src,AnsiName);
    ConvertNameToFull(AnsiName,AnsiName);
    CharToWide(AnsiName,Dest);
  }
#endif
#else
  char AnsiName[NM];
  WideToChar(Src,AnsiName);
  ConvertNameToFull(AnsiName,AnsiName);
  CharToWide(AnsiName,Dest);
#endif
}
コード例 #26
0
ファイル: unicode.cpp プロジェクト: hkajcy/xcode_tool
bool CharToWide(const char *Src,wchar *Dest,size_t DestSize)
{
  bool RetCode=true;
#ifdef _WIN_32
  if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0)
    RetCode=false;
#else
#ifdef _APPLE
  UtfToWide(Src,Dest,DestSize);
#else
#ifdef MBFUNCTIONS

  size_t ResultingSize=mbstowcs(Dest,Src,DestSize);
  if (ResultingSize==(size_t)-1)
    RetCode=false;
  if (ResultingSize==0 && *Src!=0)
    RetCode=false;

  if ((!RetCode || *Dest==0 && *Src!=0) && DestSize>NM && strlen(Src)<NM)
  {
    /* Workaround for strange Linux Unicode functions bug.
       Some of wcstombs and mbstowcs implementations in some situations
       (we are yet to find out what it depends on) can return an empty
       string and success code if buffer size value is too large.
    */
    return(CharToWide(Src,Dest,NM));
  }
#else
  if (UnicodeEnabled())
  {
#if defined(_EMX) && !defined(_DJGPP)
    int len=Min(strlen(Src)+1,DestSize-1);
    if (uni_toucs((char*)Src,len,(UniChar*)Dest,(size_t*)&DestSize)==-1 ||
        DestSize>len)
      DestSize=0;
    RetCode=false;
#endif
  }
  else
    for (int I=0;I<DestSize;I++)
    {
      Dest[I]=(wchar_t)Src[I];
      if (Src[I]==0)
        break;
    }
#endif
#endif
#endif
  return(RetCode);
}
コード例 #27
0
ファイル: word.cpp プロジェクト: Frankie-666/tomita-parser
bool CWord::IsLatComplexWordAsCompName() const
{
    if ((m_typ != Complex && m_typ != Hyphen && m_typ != AltInitial) || !m_bUp)
        return false;

    static const Wtroka allowed = CharToWide("-1234567890qwertyuiopasdfghjklzxcvbnm.\\/");

    const Wtroka& str = GetLowerText();
    if (str.find_first_not_of(allowed) != Wtroka::npos)
        return false;
    //allow only one slash
    if (str.find('\\') != str.rfind('\\') || str.find('/') != str.rfind('/'))
        return false;
    return true;
}
コード例 #28
0
ファイル: scantree.cpp プロジェクト: BlitzMaxModules/wx.mod
bool ScanTree::PrepareMasks()
{
  if (!FileMasks->GetString(CurMask,CurMaskW,sizeof(CurMask)))
    return(false);
  CurMask[ASIZE(CurMask)-1]=0;
  CurMaskW[ASIZE(CurMaskW)-1]=0;
#ifdef _WIN_32
  UnixSlashToDos(CurMask);
#endif
  char *Name=PointToName(CurMask);
  if (*Name==0)
    strcat(CurMask,MASKALL);
  if (Name[0]=='.' && (Name[1]==0 || Name[1]=='.' && Name[2]==0))
  {
    AddEndSlash(CurMask);
    strcat(CurMask,MASKALL);
  }
  SpecPathLength=Name-CurMask;
//  if (SpecPathLength>1)
//    SpecPathLength--;

  bool WideName=(*CurMaskW!=0);

  if (WideName)
  {
    wchar *NameW=PointToName(CurMaskW);
    if (*NameW==0)
      strcatw(CurMaskW,MASKALLW);
    if (NameW[0]=='.' && (NameW[1]==0 || NameW[1]=='.' && NameW[2]==0))
    {
      AddEndSlash(CurMaskW);
      strcatw(CurMaskW,MASKALLW);
    }
    SpecPathLengthW=NameW-CurMaskW;
  }
  else
  {
    wchar WideMask[NM];
    CharToWide(CurMask,WideMask);
    SpecPathLengthW=PointToName(WideMask)-WideMask;
  }
  Depth=0;

  strcpy(OrigCurMask,CurMask);
  strcpyw(OrigCurMaskW,CurMaskW);

  return(true);
}
コード例 #29
0
ファイル: errhnd.cpp プロジェクト: MeiBlack/SARUnArchiveANY
void ErrorHandler::SysErrMsg()
{
#if !defined(SFX_MODULE) && !defined(SILENT)
#ifdef _WIN_ALL
  wchar *lpMsgBuf=NULL;
  int ErrType=GetLastError();
  if (ErrType!=0 && FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
              NULL,ErrType,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
              (LPTSTR)&lpMsgBuf,0,NULL))
  {
    wchar *CurMsg=lpMsgBuf;
    while (CurMsg!=NULL)
    {
      while (*CurMsg=='\r' || *CurMsg=='\n')
        CurMsg++;
      if (*CurMsg==0)
        break;
      wchar *EndMsg=wcschr(CurMsg,'\r');
      if (EndMsg==NULL)
        EndMsg=wcschr(CurMsg,'\n');
      if (EndMsg!=NULL)
      {
        *EndMsg=0;
        EndMsg++;
      }
      uiMsg(UIERROR_SYSERRMSG,CurMsg);
      CurMsg=EndMsg;
    }
  }
  LocalFree( lpMsgBuf );
#endif

#if defined(_UNIX) || defined(_EMX)
  if (errno!=0)
  {
    char *err=strerror(errno);
    if (err!=NULL)
    {
      wchar Msg[1024];
      CharToWide(err,Msg,ASIZE(Msg));
      uiMsg(UIERROR_SYSERRMSG,Msg);
    }
  }
#endif

#endif
}
コード例 #30
0
ファイル: extract.cpp プロジェクト: KastB/OpenCPN
void CmdExtract::ConvertDosPassword(Archive &Arc,SecPassword &DestPwd)
{
  if (Arc.Format==RARFMT15 && Arc.FileHead.HostOS==HOST_MSDOS)
  {
    // We need the password in OEM encoding if file was encrypted by
    // native RAR/DOS (not extender based). Let's make the conversion.
    wchar PlainPsw[MAXPASSWORD];
    Cmd->Password.Get(PlainPsw,ASIZE(PlainPsw));
    char PswA[MAXPASSWORD];
    CharToOemBuffW(PlainPsw,PswA,ASIZE(PswA));
    PswA[ASIZE(PswA)-1]=0;
    CharToWide(PswA,PlainPsw,ASIZE(PlainPsw));
    DestPwd.Set(PlainPsw);
    cleandata(PlainPsw,sizeof(PlainPsw));
    cleandata(PswA,sizeof(PswA));
  }
}