/////////////////////////////////// // dispatcher. Called from main() ///////// int Diff(PWScore &core, const UserArgs &ua) { CompareData current, comparison, conflicts, identical; PWScore otherCore; const StringX otherSafe{std2stringx(ua.opArg)}; CItemData::FieldBits safeFields{ua.fields}; for( auto ft: diff_fields ) { if (ua.fields.test(ft) && CItemData::IsTextField(ft)) { safeFields.set(ft); } } safeFields.reset(CItem::RMTIME); int status = OpenCore(otherCore, otherSafe); if ( status == PWScore::SUCCESS ) { constexpr bool treatWhitespacesAsEmpty = false; core.Compare( &otherCore, safeFields, ua.subset.valid(), treatWhitespacesAsEmpty, ua.subset.value, ua.subset.field, ua.subset.rule, current, comparison, conflicts, identical); switch (ua.dfmt) { case UserArgs::DiffFmt::Unified: unified_diff(core, otherCore, current, comparison, conflicts, identical); break; case UserArgs::DiffFmt::Context: context_diff(core, otherCore, current, comparison, conflicts, identical); break; case UserArgs::DiffFmt::SideBySide: sidebyside_diff(core, otherCore, current, comparison, conflicts, identical, safeFields, ua.colwidth); break; default: assert(false); break; } otherCore.UnlockFile(otherSafe.c_str()); } return status; }
int main(int argc, char *argv[]) { UserArgs ua; if (!parseArgs(argc, argv, ua)) { usage(argv[0]); return 1; } PWScore core; if (!pws_os::FileExists(ua.safe.c_str())) { cerr << argv[1] << " - file not found" << endl; return 2; } wstring wpk; cout << "Enter Password: "******"CheckPasskey returned: " << status_text(status) << endl; goto done; } { CUTF8Conv conv; const char *user = getlogin() != NULL ? getlogin() : "unknown"; StringX locker; if (!conv.FromUTF8((const unsigned char *)user, strlen(user), locker)) { cerr << "Could not convert user " << user << " to StringX" << endl; return 2; } stringT lk(locker.c_str()); if (!core.LockFile(ua.safe.c_str(), lk)) { wcout << L"Couldn't lock file " << ua.safe << L": locked by " << locker << endl; status = -1; goto done; } } // Since we may be writing the same file we're reading, // it behooves us to set the Current File and use its' related // functions core.SetCurFile(ua.safe); status = core.ReadCurFile(pk); if (status != PWScore::SUCCESS) { cout << "ReadFile returned: " << status_text(status) << endl; goto done; } if (ua.ImpExp == UserArgs::Export) { CItemData::FieldBits all(~0L); int N; if (ua.Format == UserArgs::XML) { status = core.WriteXMLFile(ua.fname, all, L"", 0, 0, L' ', N); } else { // export text status = core.WritePlaintextFile(ua.fname, all, L"", 0, 0, L' ', N); } } else { // Import if (ua.Format == UserArgs::XML) { status = ImportXML(core, ua.fname); } else { // import text status = ImportText(core, ua.fname); } if (status == PWScore::SUCCESS) status = core.WriteCurFile(); } if (status != PWScore::SUCCESS) { cout << "Operation returned status: " << status_text(status) << endl; goto done; } done: core.UnlockFile(ua.safe.c_str()); return status; }