]> git.decadent.org.uk Git - dak.git/blob - tools/dsync-0.0/cmdline/dsync-cdimage.cc
use the right variable names
[dak.git] / tools / dsync-0.0 / cmdline / dsync-cdimage.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description                                                          /*{{{*/
3 // $Id: dsync-cdimage.cc,v 1.2 1999/12/26 06:59:00 jgg Exp $
4 /* ######################################################################
5
6    DSync CD Image - CD Image transfer program
7    
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
10    ISO image.
11    
12    ##################################################################### */
13                                                                         /*}}}*/
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>
20 #include <config.h>
21
22 #include <iostream>
23 #include <fstream>
24 #include <signal.h>
25 using namespace std;
26                                                                         /*}}}*/
27
28 // Externs                                                              /*{{{*/
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;
34                                                                         /*}}}*/
35
36 // DoGenerate - Generate the checksum list                              /*{{{*/
37 // ---------------------------------------------------------------------
38 /* */
39 bool DoGenerate(CommandLine &CmdL)
40 {
41    return true;
42 }
43                                                                         /*}}}*/
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)
49 {
50    if (CmdL.FileList[1] == 0)
51       return _error->Error("You must specify a file name");
52    
53    // Open the file
54    dsMMapIO IO(CmdL.FileList[1]);
55    if (_error->PendingError() == true)
56       return false;
57    
58    dsFList List;
59    if (List.Step(IO) == false || List.Tag != dsFList::tHeader)
60       return _error->Error("Unable to read header");
61    
62    string Dir;
63    string File;
64    while (List.Step(IO) == true)
65    {
66       if (List.Tag == dsFList::tDirStart)
67       {
68          Dir = List.Dir.Name;
69          continue;
70       }
71       
72       if (List.Entity != 0)
73       {
74          File = List.Entity->Name;
75          continue;
76       }
77       
78       if (List.Tag == dsFList::tRSyncChecksum)
79       {
80          RSyncMatch Match(List.RChk);
81       }
82       
83       if (List.Tag == dsFList::tTrailer)
84          break;
85    }
86    
87    return true;
88 }
89                                                                         /*}}}*/
90
91 // ShowHelp - Show the help screen                                      /*{{{*/
92 // ---------------------------------------------------------------------
93 /* */
94 bool ShowHelp(CommandLine &CmdL)
95 {
96    cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
97       " compiled on " << __DATE__ << "  " << __TIME__ << endl;
98    
99    cout << 
100       "Usage: dsync-cdimage [options] command [file]\n"
101       "\n"
102       "dsync-cdimage is a tool for replicating CD images from a mirror of\n"
103       "their contents.\n"
104       "\n"
105       "Commands:\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"
109       "\n"
110       "Options:\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;
118    return 100;
119 }
120                                                                         /*}}}*/
121
122 int main(int argc, const char *argv[])
123 {
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},
131       {0,0,0,0}};
132    CommandLine::Dispatch Cmds[] = {{"generate",&DoGenerate},
133                                    {"help",&ShowHelp},
134                                    {"aggregate",&DoAggregate},
135                                    {0,0}};
136    CommandLine CmdL(Args,_config);
137    if (CmdL.Parse(argc,argv) == false)
138    {
139       _error->DumpErrors();
140       return 100;
141    }
142    
143    // See if the help should be shown
144    if (_config->FindB("help") == true ||
145        CmdL.FileSize() == 0)
146       return ShowHelp(CmdL);   
147
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());
156
157    // Setup the signals
158 /*   signal(SIGWINCH,SigWinch);
159    SigWinch(0);*/
160    
161    // Match the operation
162    CmdL.DispatchArg(Cmds);
163    
164    // Print any errors or warnings found during parsing
165    if (_error->empty() == false)
166    {
167       
168       bool Errors = _error->PendingError();
169       _error->DumpErrors();
170       return Errors == true?100:0;
171    }
172          
173    return 0; 
174 }