]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-sortpkgs.cc
review of new/changed translatable program strings
[apt.git] / cmdline / apt-sortpkgs.cc
index 12ef8dda091c38a710537137242455fe5402b668..a4707a9745f4f8b547685cc7a6a1ea05cf31e371 100644 (file)
 #include <apt-pkg/pkgsystem.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 
 #include <vector>
 #include <algorithm>
 #include <stdio.h>
 #include <iostream>
 #include <string>
+#include <memory>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -112,91 +114,54 @@ static bool DoIt(string InFile)
    // Emit
    FileFd stdoutfd;
    stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
-   unsigned char *Buffer = new unsigned char[Largest+1];
+   auto const Buffer = std::unique_ptr<unsigned char[]>(new unsigned char[Largest+1]);
    for (vector<PkgName>::iterator I = List.begin(); I != List.end(); ++I)
    {
       // Read in the Record.
-      if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer,I->Length) == false)
-      {
-        delete [] Buffer;
+      if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer.get(),I->Length) == false)
         return false;
-      }
 
       Buffer[I->Length] = '\n';
-      if (Section.Scan((char *)Buffer,I->Length+1) == false)
-      {
-        delete [] Buffer;
+      if (Section.Scan((char *)Buffer.get(),I->Length+1) == false)
         return _error->Error("Internal error, failed to scan buffer");
-      }
 
       // Sort the section
       if (Section.Write(stdoutfd, Order) == false || stdoutfd.Write("\n", 1) == false)
-      {
-        delete [] Buffer;
         return _error->Error("Internal error, failed to sort fields");
-      }
    }
-
-   delete [] Buffer;
    return true;
 }
                                                                        /*}}}*/
-// ShowHelp - Show the help text                                       /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowHelp(CommandLine &)
+bool ShowHelp(CommandLine &)                                           /*{{{*/
 {
-   ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-   if (_config->FindB("version") == true)
-      return true;
-   
-   cout <<
+   std::cout <<
     _("Usage: apt-sortpkgs [options] file1 [file2 ...]\n"
       "\n"
-      "apt-sortpkgs is a simple tool to sort package files. The -s option is used\n"
-      "to indicate what kind of file it is.\n"
-      "\n"
-      "Options:\n"
-      "  -h   This help text\n"
-      "  -s   Use source file sorting\n"
-      "  -c=? Read this configuration file\n"
-      "  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
-
+      "apt-sortpkgs is a simple tool to sort package information files.\n"
+      "By default it sorts by binary package information, but the -s option\n"
+      "can be used to switch to source package ordering instead.\n");
    return true;
 }
                                                                        /*}}}*/
+std::vector<aptDispatchWithHelp> GetCommands()                         /*{{{*/
+{
+   return {
+      {nullptr, nullptr, nullptr}
+   };
+}
+                                                                       /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
-   CommandLine::Args Args[] = {
-      {'h',"help","help",0},
-      {'v',"version","version",0},
-      {'s',"source","APT::SortPkgs::Source",0},
-      {'c',"config-file",0,CommandLine::ConfigFile},
-      {'o',"option",0,CommandLine::ArbItem},
-      {0,0,0,0}};
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
+   InitLocale();
 
-   // Parse the command line and initialize the package library
-   CommandLine::Dispatch Cmds[] = {{NULL, NULL}};
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, APT_CMD::APT_SORTPKG, &_config, &_system, argc, argv);
 
    // Match the operation
    for (unsigned int I = 0; I != CmdL.FileSize(); I++)
       if (DoIt(CmdL.FileList[I]) == false)
         break;
-   
-   // Print any errors or warnings found during parsing
-   if (_error->empty() == false)
-   {
-      bool Errors = _error->PendingError();
-      _error->DumpErrors();
-      return Errors == true?100:0;
-   }
-   
-   return 0;   
+
+   return DispatchCommandLine(CmdL, {});
 }
                                                                        /*}}}*/