static void DumpWString(TString* s, DumpState* D) { if (s==NULL || getwstr(s)==NULL) { size_t size=0; DumpVar(size,D); } else { size_t size=s->tsv.len+1; /* include trailing '\0' */ DumpVector(getwstr(s),size,2,D); } }
// Purely user interface function. Gets and returns user input. UIASKREP_RESULT uiAskReplace(wchar *Name,size_t MaxNameSize,int64 FileSize,RarTime *FileTime,uint Flags) { bool AllowRename=(Flags & UIASKREP_F_NORENAME)==0; eprintf(St(MFileExists),Name); int Choice=0; do { Choice=Ask(St(AllowRename ? MYesNoAllRenQ : MYesNoAllQ)); } while (Choice==0); // 0 means invalid input. switch(Choice) { case 1: return UIASKREP_R_REPLACE; case 2: return UIASKREP_R_SKIP; case 3: return UIASKREP_R_REPLACEALL; case 4: return UIASKREP_R_SKIPALL; } if (AllowRename && Choice==5) { mprintf(St(MAskNewName)); if (getwstr(Name,MaxNameSize)) return UIASKREP_R_RENAME; else return UIASKREP_R_SKIP; // Process fwgets failure as if user answered 'No'. } return UIASKREP_R_CANCEL; }
static int l_wstrcmp (const TString *ls, const TString *rs) { const lua_WChar *l = getwstr(ls); size_t ll = ls->tsv.len; const lua_WChar *r = getwstr(rs); size_t lr = rs->tsv.len; for (;;) { int temp = lua_WChar_cmp(l, r); if (temp != 0) return temp; else { /* strings are equal up to a `\0' */ size_t len = lua_WChar_len(l); /* index of first `\0' in both strings */ if (len == lr) /* r is finished? */ return (len == ll) ? 0 : 1; else if (len == ll) /* l is finished? */ return -1; /* l is smaller than r (because r is not finished) */ /* both strings longer than `len'; go on comparing (after the `\0') */ len++; l += len; ll -= len; r += len; lr -= len; } } }
// Purely user interface function. Gets and returns user input. UIASKREP_RESULT uiAskReplace(wchar *Name,size_t MaxNameSize,int64 FileSize,RarTime *FileTime,uint Flags) { wchar SizeText1[20],DateStr1[50],SizeText2[20],DateStr2[50]; FindData ExistingFD; memset(&ExistingFD,0,sizeof(ExistingFD)); // In case find fails. FindFile::FastFind(Name,&ExistingFD); itoa(ExistingFD.Size,SizeText1,ASIZE(SizeText1)); ExistingFD.mtime.GetText(DateStr1,ASIZE(DateStr1),false); if (FileSize==INT64NDF || FileTime==NULL) { eprintf(L"\n"); eprintf(St(MAskOverwrite),Name); } else { itoa(FileSize,SizeText2,ASIZE(SizeText2)); FileTime->GetText(DateStr2,ASIZE(DateStr2),false); eprintf(St(MAskReplace),Name,SizeText1,DateStr1,SizeText2,DateStr2); } bool AllowRename=(Flags & UIASKREP_F_NORENAME)==0; int Choice=0; do { Choice=Ask(St(AllowRename ? MYesNoAllRenQ : MYesNoAllQ)); } while (Choice==0); // 0 means invalid input. switch(Choice) { case 1: return UIASKREP_R_REPLACE; case 2: return UIASKREP_R_SKIP; case 3: return UIASKREP_R_REPLACEALL; case 4: return UIASKREP_R_SKIPALL; } if (AllowRename && Choice==5) { mprintf(St(MAskNewName)); if (getwstr(Name,MaxNameSize)) return UIASKREP_R_RENAME; else return UIASKREP_R_SKIP; // Process fwgets failure as if user answered 'No'. } return UIASKREP_R_CANCEL; }
int Ask(const wchar *AskStr) { Alarm(); const int MaxItems=10; wchar Item[MaxItems][40]; int ItemKeyPos[MaxItems],NumItems=0; for (const wchar *NextItem=AskStr;NextItem!=NULL;NextItem=wcschr(NextItem+1,'_')) { wchar *CurItem=Item[NumItems]; wcsncpyz(CurItem,NextItem+1,ASIZE(Item[0])); wchar *EndItem=wcschr(CurItem,'_'); if (EndItem!=NULL) *EndItem=0; int KeyPos=0,CurKey; while ((CurKey=CurItem[KeyPos])!=0) { bool Found=false; for (int I=0;I<NumItems && !Found;I++) if (toupperw(Item[I][ItemKeyPos[I]])==toupperw(CurKey)) Found=true; if (!Found && CurKey!=' ') break; KeyPos++; } ItemKeyPos[NumItems]=KeyPos; NumItems++; } for (int I=0;I<NumItems;I++) { eprintf(I==0 ? (NumItems>4 ? L"\n":L" "):L", "); int KeyPos=ItemKeyPos[I]; for (int J=0;J<KeyPos;J++) eprintf(L"%c",Item[I][J]); eprintf(L"[%c]%ls",Item[I][KeyPos],&Item[I][KeyPos+1]); } eprintf(L" "); wchar Str[50]; getwstr(Str,ASIZE(Str)); wchar Ch=toupperw(Str[0]); for (int I=0;I<NumItems;I++) if (Ch==Item[I][ItemKeyPos[I]]) return I+1; return 0; }