]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
   1 // -*- mode: cpp; mode: fold -*- 
   3 // $Id: apt-config.cc,v 1.11 2003/01/11 07:18:44 jgg Exp $ 
   4 /* ###################################################################### 
   6    APT Config - Program to manipulate APT configuration files 
   8    This program will parse a config file and then do something with it. 
  11      shell - Shell mode. After this a series of word pairs should occur. 
  12              The first is the environment var to set and the second is 
  13              the key to set it from. Use like:  
  14  eval `apt-config shell QMode apt::QMode` 
  16    ##################################################################### */ 
  18 // Include Files                                                        /*{{{*/ 
  21 #include <apt-pkg/cmndline.h> 
  22 #include <apt-pkg/error.h> 
  23 #include <apt-pkg/init.h> 
  24 #include <apt-pkg/strutl.h> 
  25 #include <apt-pkg/configuration.h> 
  26 #include <apt-pkg/aptconfiguration.h> 
  27 #include <apt-pkg/pkgsystem.h> 
  34 #include <apt-private/private-cmndline.h> 
  40 // DoShell - Handle the shell command                                   /*{{{*/ 
  41 // --------------------------------------------------------------------- 
  43 static bool DoShell(CommandLine 
&CmdL
) 
  45    for (const char **I 
= CmdL
.FileList 
+ 1; *I 
!= 0; I 
+= 2) 
  47       if (I
[1] == 0 || strlen(I
[1]) == 0) 
  48          return _error
->Error(_("Arguments not in pairs")); 
  51       if (key
.end()[-1] == '/') // old directory format 
  54       if (_config
->ExistsAny(key
.c_str())) 
  56                  SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
; 
  63 // DoDump - Dump the configuration space                                /*{{{*/ 
  64 // --------------------------------------------------------------------- 
  66 static bool DoDump(CommandLine 
&CmdL
) 
  68    bool const empty 
= _config
->FindB("APT::Config::Dump::EmptyValue", true); 
  69    std::string 
const format 
= _config
->Find("APT::Config::Dump::Format", "%f \"%v\";\n"); 
  70    if (CmdL
.FileSize() == 1) 
  71       _config
->Dump(cout
, NULL
, format
.c_str(), empty
); 
  73       for (const char **I 
= CmdL
.FileList 
+ 1; *I 
!= 0; ++I
) 
  74          _config
->Dump(cout
, *I
, format
.c_str(), empty
); 
  78 // ShowHelp - Show the help screen                                      /*{{{*/ 
  79 // --------------------------------------------------------------------- 
  81 static bool ShowHelp(CommandLine 
&) 
  83    ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
, 
  84             COMMON_ARCH
,__DATE__
,__TIME__
); 
  85    if (_config
->FindB("version") == true) 
  89     _("Usage: apt-config [options] command\n" 
  91       "apt-config is a simple tool to read the APT config file\n" 
  94       "   shell - Shell mode\n" 
  95       "   dump - Show the configuration\n" 
  98       "  -h   This help text.\n"  
  99       "  -c=? Read this configuration file\n"  
 100       "  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"); 
 104 int main(int argc
,const char *argv
[])                                   /*{{{*/ 
 106    CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
}, 
 111    std::vector
<CommandLine::Args
> Args 
= getCommandArgs("apt-config", CommandLine::GetCommand(Cmds
, argc
, argv
)); 
 113    // Set up gettext support 
 114    setlocale(LC_ALL
,""); 
 117    // Parse the command line and initialize the package library 
 119    ParseCommandLine(CmdL
, Cmds
, Args
.data(), &_config
, &_system
, argc
, argv
, ShowHelp
); 
 121    std::vector
<std::string
> const langs 
= APT::Configuration::getLanguages(true); 
 122    _config
->Clear("Acquire::Languages"); 
 123    for (std::vector
<std::string
>::const_iterator l 
= langs
.begin(); l 
!= langs
.end(); ++l
) 
 124       _config
->Set("Acquire::Languages::", *l
); 
 126    std::vector
<std::string
> const archs 
= APT::Configuration::getArchitectures(); 
 127    _config
->Clear("APT::Architectures"); 
 128    for (std::vector
<std::string
>::const_iterator a 
= archs
.begin(); a 
!= archs
.end(); ++a
) 
 129       _config
->Set("APT::Architectures::", *a
); 
 131    std::vector
<APT::Configuration::Compressor
> const compressors 
= APT::Configuration::getCompressors(); 
 132    _config
->Clear("APT::Compressor"); 
 133    string conf 
= "APT::Compressor::"; 
 134    for (std::vector
<APT::Configuration::Compressor
>::const_iterator c 
= compressors
.begin(); c 
!= compressors
.end(); ++c
) 
 136       string comp 
= conf 
+ c
->Name 
+ "::"; 
 137       _config
->Set(comp 
+ "Name", c
->Name
); 
 138       _config
->Set(comp 
+ "Extension", c
->Extension
); 
 139       _config
->Set(comp 
+ "Binary", c
->Binary
); 
 140       _config
->Set(std::string(comp 
+ "Cost").c_str(), c
->Cost
); 
 141       for (std::vector
<std::string
>::const_iterator a 
= c
->CompressArgs
.begin(); a 
!= c
->CompressArgs
.end(); ++a
) 
 142          _config
->Set(comp 
+ "CompressArg::", *a
); 
 143       for (std::vector
<std::string
>::const_iterator a 
= c
->UncompressArgs
.begin(); a 
!= c
->UncompressArgs
.end(); ++a
) 
 144          _config
->Set(comp 
+ "UncompressArg::", *a
); 
 147    std::vector
<std::string
> const profiles 
= APT::Configuration::getBuildProfiles(); 
 148    _config
->Clear("APT::Build-Profiles"); 
 149    for (std::vector
<std::string
>::const_iterator p 
= profiles
.begin(); p 
!= profiles
.end(); ++p
) 
 150       _config
->Set("APT::Build-Profiles::", *p
); 
 152    // Match the operation 
 153    CmdL
.DispatchArg(Cmds
); 
 155    // Print any errors or warnings found during parsing 
 156    if (_error
->empty() == false) 
 158       bool Errors 
= _error
->PendingError(); 
 159       _error
->DumpErrors(); 
 160       return Errors 
== true?100:0;