1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dsync-cdimage.cc,v 1.2 1999/12/26 06:59:00 jgg Exp $
4 /* ######################################################################
6 DSync CD Image - CD Image transfer program
8 This implements the DSync CD transfer method. This method is optimized
9 to reconstruct a CD from a mirror of the CD's contents and the original
12 ##################################################################### */
14 // Include files /*{{{*/
15 #include <dsync/cmndline.h>
16 #include <dsync/configuration.h>
17 #include <dsync/error.h>
18 #include <dsync/filelistdb.h>
19 #include <dsync/rsync-algo.h>
29 ostream c0out(cout.rdbuf());
30 ostream c1out(cout.rdbuf());
31 ostream c2out(cout.rdbuf());
32 ofstream devnull("/dev/null");
33 unsigned int ScreenWidth = 80;
36 // DoGenerate - Generate the checksum list /*{{{*/
37 // ---------------------------------------------------------------------
39 bool DoGenerate(CommandLine &CmdL)
44 // DoAggregate - Generate aggregated file records /*{{{*/
45 // ---------------------------------------------------------------------
46 /* This takes a file list with already generated rsync checksums and builds
47 aggregated file lists for each checksum record */
48 bool DoAggregate(CommandLine &CmdL)
50 if (CmdL.FileList[1] == 0)
51 return _error->Error("You must specify a file name");
54 dsMMapIO IO(CmdL.FileList[1]);
55 if (_error->PendingError() == true)
59 if (List.Step(IO) == false || List.Tag != dsFList::tHeader)
60 return _error->Error("Unable to read header");
64 while (List.Step(IO) == true)
66 if (List.Tag == dsFList::tDirStart)
74 File = List.Entity->Name;
78 if (List.Tag == dsFList::tRSyncChecksum)
80 RSyncMatch Match(List.RChk);
83 if (List.Tag == dsFList::tTrailer)
91 // ShowHelp - Show the help screen /*{{{*/
92 // ---------------------------------------------------------------------
94 bool ShowHelp(CommandLine &CmdL)
96 cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
97 " compiled on " << __DATE__ << " " << __TIME__ << endl;
100 "Usage: dsync-cdimage [options] command [file]\n"
102 "dsync-cdimage is a tool for replicating CD images from a mirror of\n"
106 " generate - Build a file+checksum index\n"
107 " help - This help text\n"
108 " verify - Compare the index against files in the current directory\n"
111 " -h This help text.\n"
112 " -q Loggable output - no progress indicator\n"
113 " -qq No output except for errors\n"
114 " -c=? Read this configuration file\n"
115 " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp\n"
116 "See the dsync-cdimage(1) and dsync.conf(5) manual\n"
117 "pages for more information." << endl;
122 int main(int argc, const char *argv[])
124 CommandLine::Args Args[] = {
125 {'h',"help","help",0},
126 {'q',"quiet","quiet",CommandLine::IntLevel},
127 {'q',"silent","quiet",CommandLine::IntLevel},
128 {'v',"verbose","verbose",CommandLine::IntLevel},
129 {'c',"config-file",0,CommandLine::ConfigFile},
130 {'o',"option",0,CommandLine::ArbItem},
132 CommandLine::Dispatch Cmds[] = {{"generate",&DoGenerate},
134 {"aggregate",&DoAggregate},
136 CommandLine CmdL(Args,_config);
137 if (CmdL.Parse(argc,argv) == false)
139 _error->DumpErrors();
143 // See if the help should be shown
144 if (_config->FindB("help") == true ||
145 CmdL.FileSize() == 0)
146 return ShowHelp(CmdL);
148 // Setup the output streams
149 c0out.rdbuf(cout.rdbuf());
150 c1out.rdbuf(cout.rdbuf());
151 c2out.rdbuf(cout.rdbuf());
152 if (_config->FindI("quiet",0) > 0)
153 c0out.rdbuf(devnull.rdbuf());
154 if (_config->FindI("quiet",0) > 1)
155 c1out.rdbuf(devnull.rdbuf());
158 /* signal(SIGWINCH,SigWinch);
161 // Match the operation
162 CmdL.DispatchArg(Cmds);
164 // Print any errors or warnings found during parsing
165 if (_error->empty() == false)
168 bool Errors = _error->PendingError();
169 _error->DumpErrors();
170 return Errors == true?100:0;