X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/57722714255118560c98b3245413ff5f693b993c..5b1997c095acf183077ec49b2a8cbb1174e3c280:/cmdline/apt-sortpkgs.cc diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index 171b0ba13..12ef8dda0 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -12,21 +12,26 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include #include #include #include +#include +#include + +#include -#include -#include - #include #include +#include +#include +#include -#include -#include +#include /*}}}*/ using namespace std; @@ -59,7 +64,7 @@ struct PkgName /*{{{*/ // DoIt - Sort a single file /*{{{*/ // --------------------------------------------------------------------- /* */ -bool DoIt(string InFile) +static bool DoIt(string InFile) { FileFd Fd(InFile,FileFd::ReadOnly); pkgTagFile Tags(&Fd); @@ -103,10 +108,12 @@ bool DoIt(string InFile) const char **Order = TFRewritePackageOrder; if (Source == true) Order = TFRewriteSourceOrder; - + // Emit + FileFd stdoutfd; + stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false); unsigned char *Buffer = new unsigned char[Largest+1]; - for (vector::iterator I = List.begin(); I != List.end(); I++) + for (vector::iterator I = List.begin(); I != List.end(); ++I) { // Read in the Record. if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer,I->Length) == false) @@ -114,8 +121,8 @@ bool DoIt(string InFile) delete [] Buffer; return false; } - - Buffer[I->Length] = '\n'; + + Buffer[I->Length] = '\n'; if (Section.Scan((char *)Buffer,I->Length+1) == false) { delete [] Buffer; @@ -123,15 +130,13 @@ bool DoIt(string InFile) } // Sort the section - if (TFRewrite(stdout,Section,Order,0) == false) + if (Section.Write(stdoutfd, Order) == false || stdoutfd.Write("\n", 1) == false) { delete [] Buffer; return _error->Error("Internal error, failed to sort fields"); } - - fputc('\n',stdout); } - + delete [] Buffer; return true; } @@ -139,12 +144,11 @@ bool DoIt(string InFile) // ShowHelp - Show the help text /*{{{*/ // --------------------------------------------------------------------- /* */ -int ShowHelp() +static bool ShowHelp(CommandLine &) { - ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION, - COMMON_ARCH,__DATE__,__TIME__); + ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); if (_config->FindB("version") == true) - return 0; + return true; cout << _("Usage: apt-sortpkgs [options] file1 [file2 ...]\n" @@ -158,7 +162,7 @@ int ShowHelp() " -c=? Read this configuration file\n" " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"); - return 0; + return true; } /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ @@ -176,19 +180,9 @@ int main(int argc,const char *argv[]) /*{{{*/ textdomain(PACKAGE); // Parse the command line and initialize the package library - CommandLine CmdL(Args,_config); - if (pkgInitConfig(*_config) == false || - CmdL.Parse(argc,argv) == false || - pkgInitSystem(*_config,_system) == false) - { - _error->DumpErrors(); - return 100; - } - - // See if the help should be shown - if (_config->FindB("help") == true || - CmdL.FileSize() == 0) - return ShowHelp(); + CommandLine::Dispatch Cmds[] = {{NULL, NULL}}; + CommandLine CmdL; + ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp); // Match the operation for (unsigned int I = 0; I != CmdL.FileSize(); I++)