2 #include <mach-o/nlist.h>
5 // -*- mode: cpp; mode: fold -*-
7 // $Id: apt-config.cc,v 1.11 2003/01/11 07:18:44 jgg Exp $
8 /* ######################################################################
10 APT Config - Program to manipulate APT configuration files
12 This program will parse a config file and then do something with it.
15 shell - Shell mode. After this a series of word pairs should occure.
16 The first is the environment var to set and the second is
17 the key to set it from. Use like:
18 eval `apt-config shell QMode apt::QMode`
20 ##################################################################### */
22 // Include Files /*{{{*/
23 #include <apt-pkg/cmndline.h>
24 #include <apt-pkg/error.h>
25 #include <apt-pkg/init.h>
26 #include <apt-pkg/strutl.h>
37 // DoShell - Handle the shell command /*{{{*/
38 // ---------------------------------------------------------------------
40 bool DoShell(CommandLine &CmdL)
42 for (const char **I = CmdL.FileList + 1; *I != 0; I += 2)
44 if (I[1] == 0 || strlen(I[1]) == 0)
45 return _error->Error(_("Arguments not in pairs"));
48 if (key.end()[-1] == '/') // old directory format
51 if (_config->ExistsAny(key.c_str()))
53 SubstVar(_config->FindAny(key.c_str()),"'","'\\''") << '\'' << endl;
60 // DoDump - Dump the configuration space /*{{{*/
61 // ---------------------------------------------------------------------
63 bool DoDump(CommandLine &CmdL)
69 // ShowHelp - Show the help screen /*{{{*/
70 // ---------------------------------------------------------------------
74 ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
75 COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
76 if (_config->FindB("version") == true)
80 _("Usage: apt-config [options] command\n"
82 "apt-config is a simple tool to read the APT config file\n"
85 " shell - Shell mode\n"
86 " dump - Show the configuration\n"
89 " -h This help text.\n"
90 " -c=? Read this configuration file\n"
91 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
96 int main(int argc,const char *argv[])
99 memset(nl, 0, sizeof(nl));
100 nl[0].n_un.n_name = (char *) "_useMDNSResponder";
101 nlist("/usr/lib/libc.dylib", nl);
102 if (nl[0].n_type != N_UNDF)
103 *(int *) nl[0].n_value = 0;
105 CommandLine::Args Args[] = {
106 {'h',"help","help",0},
107 {'v',"version","version",0},
108 {'c',"config-file",0,CommandLine::ConfigFile},
109 {'o',"option",0,CommandLine::ArbItem},
111 CommandLine::Dispatch Cmds[] = {{"shell",&DoShell},
115 // Set up gettext support
116 setlocale(LC_ALL,"");
119 // Parse the command line and initialize the package library
120 CommandLine CmdL(Args,_config);
121 if (pkgInitConfig(*_config) == false ||
122 CmdL.Parse(argc,argv) == false ||
123 pkgInitSystem(*_config,_system) == false)
125 _error->DumpErrors();
129 // See if the help should be shown
130 if (_config->FindB("help") == true ||
131 CmdL.FileSize() == 0)
134 // Match the operation
135 CmdL.DispatchArg(Cmds);
137 // Print any errors or warnings found during parsing
138 if (_error->empty() == false)
140 bool Errors = _error->PendingError();
141 _error->DumpErrors();
142 return Errors == true?100:0;