X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/67111687c005d470d176a2029336e4f2b5dc77de..88593886a42025d51d76051da5929b044e42efee:/cmdline/apt-sortpkgs.cc diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index fe5fe13dd..12ef8dda0 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt-sortpkgs.cc,v 1.3 2002/01/09 04:59:44 jgg Exp $ +// $Id: apt-sortpkgs.cc,v 1.5 2003/01/11 07:18:44 jgg Exp $ /* ###################################################################### APT Sort Packages - Program to sort Package and Source files @@ -12,23 +12,31 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include #include #include #include +#include +#include + +#include -#include -#include - #include #include +#include +#include +#include -#include +#include /*}}}*/ -struct PkgName +using namespace std; + +struct PkgName /*{{{*/ { string Name; string Ver; @@ -52,11 +60,11 @@ struct PkgName bool operator >(const PkgName &x) const {return Compare3(x) > 0;}; bool operator ==(const PkgName &x) const {return Compare3(x) == 0;}; }; - + /*}}}*/ // DoIt - Sort a single file /*{{{*/ // --------------------------------------------------------------------- /* */ -bool DoIt(string InFile) +static bool DoIt(string InFile) { FileFd Fd(InFile,FileFd::ReadOnly); pkgTagFile Tags(&Fd); @@ -100,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) @@ -111,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; @@ -120,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; } @@ -136,12 +144,11 @@ bool DoIt(string InFile) // ShowHelp - Show the help text /*{{{*/ // --------------------------------------------------------------------- /* */ -int ShowHelp() +static bool ShowHelp(CommandLine &) { - ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION, - COMMON_OS,COMMON_CPU,__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" @@ -153,13 +160,12 @@ int ShowHelp() " -h This help text\n" " -s Use source file sorting\n" " -c=? Read this configuration file\n" - " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"); + " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"); - return 0; + return true; } /*}}}*/ - -int main(unsigned int argc,const char *argv[]) +int main(int argc,const char *argv[]) /*{{{*/ { CommandLine::Args Args[] = { {'h',"help","help",0}, @@ -174,19 +180,9 @@ int main(unsigned 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++) @@ -203,3 +199,4 @@ int main(unsigned int argc,const char *argv[]) return 0; } + /*}}}*/