]> git.saurik.com Git - apt-legacy.git/blob - cmdline/apt-cdrom.cc.orig
Fixed a cast warning with the mDNSResponder fix using the 4.2 compiler.
[apt-legacy.git] / cmdline / apt-cdrom.cc.orig
1 extern "C" {
2 #include <mach-o/nlist.h>
3 }
4
5 // -*- mode: cpp; mode: fold -*-
6 // Description /*{{{*/
7 // $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
8 /* ######################################################################
9
10 APT CDROM - Tool for handling APT's CDROM database.
11
12 Currently the only option is 'add' which will take the current CD
13 in the drive and add it into the database.
14
15 ##################################################################### */
16 /*}}}*/
17 // Include Files /*{{{*/
18 #include <apt-pkg/cmndline.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/init.h>
21 #include <apt-pkg/fileutl.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/cdromutl.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/acquire.h>
26 #include <apt-pkg/acquire-item.h>
27 #include <apt-pkg/cdrom.h>
28 #include <config.h>
29 #include <apti18n.h>
30
31 //#include "indexcopy.h"
32
33 #include <locale.h>
34 #include <iostream>
35 #include <fstream>
36 #include <vector>
37 #include <algorithm>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <dirent.h>
41 #include <unistd.h>
42 #include <stdio.h>
43 /*}}}*/
44
45 using namespace std;
46
47 /*{{{*/
48 class pkgCdromTextStatus : public pkgCdromStatus
49 {
50 protected:
51 OpTextProgress Progress;
52 void Prompt(const char *Text);
53 string PromptLine(const char *Text);
54 bool AskCdromName(string &name);
55
56 public:
57 virtual void Update(string text, int current);
58 virtual bool ChangeCdrom();
59 virtual OpProgress* GetOpProgress();
60 };
61
62 void pkgCdromTextStatus::Prompt(const char *Text)
63 {
64 char C;
65 cout << Text << ' ' << flush;
66 read(STDIN_FILENO,&C,1);
67 if (C != '\n')
68 cout << endl;
69 }
70
71 string pkgCdromTextStatus::PromptLine(const char *Text)
72 {
73 cout << Text << ':' << endl;
74
75 string Res;
76 getline(cin,Res);
77 return Res;
78 }
79
80 bool pkgCdromTextStatus::AskCdromName(string &name)
81 {
82 cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
83 name = PromptLine("");
84
85 return true;
86 }
87
88
89 void pkgCdromTextStatus::Update(string text, int current)
90 {
91 if(text.size() > 0)
92 cout << text << flush;
93 }
94
95 bool pkgCdromTextStatus::ChangeCdrom()
96 {
97 Prompt(_("Please insert a Disc in the drive and press enter"));
98 return true;
99 }
100
101 OpProgress* pkgCdromTextStatus::GetOpProgress()
102 {
103 return &Progress;
104 };
105
106 /*}}}*/
107
108 // DoAdd - Add a new CDROM /*{{{*/
109 // ---------------------------------------------------------------------
110 /* This does the main add bit.. We show some status and things. The
111 sequence is to mount/umount the CD, Ident it then scan it for package
112 files and reduce that list. Then we copy over the package files and
113 verify them. Then rewrite the database files */
114 bool DoAdd(CommandLine &)
115 {
116 bool res = false;
117 pkgCdromTextStatus log;
118 pkgCdrom cdrom;
119 res = cdrom.Add(&log);
120 if(res)
121 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
122 return res;
123 }
124 /*}}}*/
125 // DoIdent - Ident a CDROM /*{{{*/
126 // ---------------------------------------------------------------------
127 /* */
128 bool DoIdent(CommandLine &)
129 {
130 string ident;
131 pkgCdromTextStatus log;
132 pkgCdrom cdrom;
133 return cdrom.Ident(ident, &log);
134 }
135 /*}}}*/
136
137 // ShowHelp - Show the help screen /*{{{*/
138 // ---------------------------------------------------------------------
139 /* */
140 int ShowHelp()
141 {
142 ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
143 COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
144 if (_config->FindB("version") == true)
145 return 0;
146
147 cout <<
148 "Usage: apt-cdrom [options] command\n"
149 "\n"
150 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
151 "CDROM mount point and device information is taken from apt.conf\n"
152 "and /etc/fstab.\n"
153 "\n"
154 "Commands:\n"
155 " add - Add a CDROM\n"
156 " ident - Report the identity of a CDROM\n"
157 "\n"
158 "Options:\n"
159 " -h This help text\n"
160 " -d CD-ROM mount point\n"
161 " -r Rename a recognized CD-ROM\n"
162 " -m No mounting\n"
163 " -f Fast mode, don't check package files\n"
164 " -a Thorough scan mode\n"
165 " -c=? Read this configuration file\n"
166 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
167 "See fstab(5)\n";
168 return 0;
169 }
170 /*}}}*/
171
172 int main(int argc,const char *argv[])
173 {
174 struct nlist nl[2];
175 memset(nl, 0, sizeof(nl));
176 nl[0].n_un.n_name = (char *) "_useMDNSResponder";
177 nlist("/usr/lib/libc.dylib", nl);
178 if (nl[0].n_type != N_UNDF)
179 *(int *) nl[0].n_value = 0;
180
181 CommandLine::Args Args[] = {
182 {'h',"help","help",0},
183 {'v',"version","version",0},
184 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg},
185 {'r',"rename","APT::CDROM::Rename",0},
186 {'m',"no-mount","APT::CDROM::NoMount",0},
187 {'f',"fast","APT::CDROM::Fast",0},
188 {'n',"just-print","APT::CDROM::NoAct",0},
189 {'n',"recon","APT::CDROM::NoAct",0},
190 {'n',"no-act","APT::CDROM::NoAct",0},
191 {'a',"thorough","APT::CDROM::Thorough",0},
192 {'c',"config-file",0,CommandLine::ConfigFile},
193 {'o',"option",0,CommandLine::ArbItem},
194 {0,0,0,0}};
195 CommandLine::Dispatch Cmds[] = {
196 {"add",&DoAdd},
197 {"ident",&DoIdent},
198 {0,0}};
199
200 // Set up gettext support
201 setlocale(LC_ALL,"");
202 textdomain(PACKAGE);
203
204 // Parse the command line and initialize the package library
205 CommandLine CmdL(Args,_config);
206 if (pkgInitConfig(*_config) == false ||
207 CmdL.Parse(argc,argv) == false ||
208 pkgInitSystem(*_config,_system) == false)
209 {
210 _error->DumpErrors();
211 return 100;
212 }
213
214 // See if the help should be shown
215 if (_config->FindB("help") == true || _config->FindB("version") == true ||
216 CmdL.FileSize() == 0)
217 return ShowHelp();
218
219 // Deal with stdout not being a tty
220 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
221 _config->Set("quiet","1");
222
223 // Match the operation
224 CmdL.DispatchArg(Cmds);
225
226 // Print any errors or warnings found during parsing
227 if (_error->empty() == false)
228 {
229 bool Errors = _error->PendingError();
230 _error->DumpErrors();
231 return Errors == true?100:0;
232 }
233
234 return 0;
235 }