]>
Commit | Line | Data |
---|---|---|
854e5ff1 JF |
1 | extern "C" { |
2 | #include <mach-o/nlist.h> | |
3 | } | |
4 | ||
5 | // -*- mode: cpp; mode: fold -*- | |
6 | // Description /*{{{*/ | |
7 | // $Id: apt-config.cc,v 1.11 2003/01/11 07:18:44 jgg Exp $ | |
8 | /* ###################################################################### | |
9 | ||
10 | APT Config - Program to manipulate APT configuration files | |
11 | ||
12 | This program will parse a config file and then do something with it. | |
13 | ||
14 | Commands: | |
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` | |
19 | ||
20 | ##################################################################### */ | |
21 | /*}}}*/ | |
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> | |
27 | ||
28 | #include <config.h> | |
29 | #include <apti18n.h> | |
30 | ||
31 | #include <locale.h> | |
32 | #include <iostream> | |
33 | #include <string> | |
34 | /*}}}*/ | |
35 | using namespace std; | |
36 | ||
37 | // DoShell - Handle the shell command /*{{{*/ | |
38 | // --------------------------------------------------------------------- | |
39 | /* */ | |
40 | bool DoShell(CommandLine &CmdL) | |
41 | { | |
42 | for (const char **I = CmdL.FileList + 1; *I != 0; I += 2) | |
43 | { | |
44 | if (I[1] == 0 || strlen(I[1]) == 0) | |
45 | return _error->Error(_("Arguments not in pairs")); | |
46 | ||
47 | string key = I[1]; | |
48 | if (key.end()[-1] == '/') // old directory format | |
49 | key.append("d"); | |
50 | ||
51 | if (_config->ExistsAny(key.c_str())) | |
52 | cout << *I << "='" << | |
53 | SubstVar(_config->FindAny(key.c_str()),"'","'\\''") << '\'' << endl; | |
54 | ||
55 | } | |
56 | ||
57 | return true; | |
58 | } | |
59 | /*}}}*/ | |
60 | // DoDump - Dump the configuration space /*{{{*/ | |
61 | // --------------------------------------------------------------------- | |
62 | /* */ | |
63 | bool DoDump(CommandLine &CmdL) | |
64 | { | |
65 | _config->Dump(cout); | |
66 | return true; | |
67 | } | |
68 | /*}}}*/ | |
69 | // ShowHelp - Show the help screen /*{{{*/ | |
70 | // --------------------------------------------------------------------- | |
71 | /* */ | |
72 | int ShowHelp() | |
73 | { | |
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) | |
77 | return 0; | |
78 | ||
79 | cout << | |
80 | _("Usage: apt-config [options] command\n" | |
81 | "\n" | |
82 | "apt-config is a simple tool to read the APT config file\n" | |
83 | "\n" | |
84 | "Commands:\n" | |
85 | " shell - Shell mode\n" | |
86 | " dump - Show the configuration\n" | |
87 | "\n" | |
88 | "Options:\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"); | |
92 | return 0; | |
93 | } | |
94 | /*}}}*/ | |
95 | ||
96 | int main(int argc,const char *argv[]) | |
97 | { | |
fe23a696 | 98 | #if !defined(__ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ < 10200 |
854e5ff1 JF |
99 | struct nlist nl[2]; |
100 | memset(nl, 0, sizeof(nl)); | |
3d6f1076 | 101 | nl[0].n_un.n_name = (char *) "_useMDNSResponder"; |
854e5ff1 JF |
102 | nlist("/usr/lib/libc.dylib", nl); |
103 | if (nl[0].n_type != N_UNDF) | |
104 | *(int *) nl[0].n_value = 0; | |
fe23a696 | 105 | #endif |
854e5ff1 JF |
106 | |
107 | CommandLine::Args Args[] = { | |
108 | {'h',"help","help",0}, | |
109 | {'v',"version","version",0}, | |
110 | {'c',"config-file",0,CommandLine::ConfigFile}, | |
111 | {'o',"option",0,CommandLine::ArbItem}, | |
112 | {0,0,0,0}}; | |
113 | CommandLine::Dispatch Cmds[] = {{"shell",&DoShell}, | |
114 | {"dump",&DoDump}, | |
115 | {0,0}}; | |
116 | ||
117 | // Set up gettext support | |
118 | setlocale(LC_ALL,""); | |
119 | textdomain(PACKAGE); | |
120 | ||
121 | // Parse the command line and initialize the package library | |
122 | CommandLine CmdL(Args,_config); | |
123 | if (pkgInitConfig(*_config) == false || | |
124 | CmdL.Parse(argc,argv) == false || | |
125 | pkgInitSystem(*_config,_system) == false) | |
126 | { | |
127 | _error->DumpErrors(); | |
128 | return 100; | |
129 | } | |
130 | ||
131 | // See if the help should be shown | |
132 | if (_config->FindB("help") == true || | |
133 | CmdL.FileSize() == 0) | |
134 | return ShowHelp(); | |
135 | ||
136 | // Match the operation | |
137 | CmdL.DispatchArg(Cmds); | |
138 | ||
139 | // Print any errors or warnings found during parsing | |
140 | if (_error->empty() == false) | |
141 | { | |
142 | bool Errors = _error->PendingError(); | |
143 | _error->DumpErrors(); | |
144 | return Errors == true?100:0; | |
145 | } | |
146 | ||
147 | return 0; | |
148 | } |