ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Spectre/Spectre.cpp
(Generate patch)

Comparing trunk/Spectre/Spectre.cpp (file contents):
Revision 175 by douglas, 2003-06-09T21:03:18-07:00 vs.
Revision 176 by douglas, 2003-07-05T17:36:35-07:00

# Line 10 | Line 10
10  
11   string program;
12   string programName = "Spectre Samba Mounter";
13 < string programVersion = "1.0alpha";
13 > string programVersion = "1.0beta";
14   bool debug = false;
15  
16   Config config;
17  
18 + int spectre(vector<string>& args);
19 + void automake(set<string>& makes);
20 + void automake(set<string>& makes, ipstream& pin);
21 + void automount(set<string>& mounts);
22 + void configure();
23 +
24   int main(int argc, char* argv[])
25   {
26 <        program = argv[0];
26 >        vector<string> args(argc);
27 >
28 >        for (int index = 0; index < argc; index++)
29 >        {
30 >                args[index] = argv[index];
31 >        }
32 >
33 >        return spectre(args);
34 > }
35 >
36 > int spectre(vector<string>& args)
37 > {
38 >        program = args[0];
39  
40   #include "configure.h"
41  
42          bool make = false;
43          bool mount = false;
44 +        bool automake = false;
45 +        bool automount = false;
46  
47          set<string> makes;
48          set<string> mounts;
49          
50 <        for (int index = 1; index < argc; index++)
50 >        for (int index = 1; index < args.size(); index++)
51          {
52 <                string arg = argv[index];
33 <
34 <                if (arg == "-help")
52 >                if (args[index] == "-help")
53                  {
54                          usage();
55                          return 0;
56                  }
57 <                else if (arg == "-version")
57 >                else if (args[index] == "-version")
58                  {
59                          version();
60                          return 0;
61                  }
62 <                else if (arg == "-make")
62 >                else if (args[index] == "-make")
63                  {
64                          if (!make) make = true;
65                          
66 <                        if (++index < argc)
66 >                        if (++index < args.size())
67                          {
68 <                                makes.insert(argv[index]);
68 >                                makes.insert(args[index]);
69                          }
70                          else
71                          {
# Line 56 | Line 74 | int main(int argc, char* argv[])
74                                  return 1;
75                          }
76                  }
77 <                else if (arg == "-mount")
77 >                else if (args[index] == "-mount")
78                  {
79                          if (!mount) mount = true;
80  
81 <                        if (++index < argc)
81 >                        if (++index < args.size())
82                          {
83 <                                mounts.insert(argv[index]);
83 >                                mounts.insert(args[index]);
84                          }
85                          else
86                          {
# Line 71 | Line 89 | int main(int argc, char* argv[])
89                                  return 1;
90                          }
91                  }
92 <                else if (arg == "-D")
92 >                else if (args[index] == "-automake")
93 >                {
94 >                        if (!automake) automake = true;
95 >                }
96 >                else if (args[index] == "-automount")
97 >                {
98 >                        if (!automount) automount = true;
99 >                }
100 >                else if (args[index] == "-D")
101                  {
102                          if (!debug)
103                          {
# Line 81 | Line 107 | int main(int argc, char* argv[])
107                  }
108          }
109  
110 <        if (!make && !mount)
110 >        if (!make && !mount && !automake && !automount)
111          {
112                  usage();
113                  return 0;
# Line 109 | Line 135 | int main(int argc, char* argv[])
135                  }
136  
137                  cerr << (mount ? "}\n" : "")
138 +                        << "automake = " << automake << "\n"
139 +                        << "automount = " << automount << "\n"
140                          << "config.install = " << config.install << "\n";
141          }
142  
# Line 116 | Line 144 | int main(int argc, char* argv[])
144  
145          if (debug)
146          {
147 <                cerr << "config.smbclient = " << config.smbclient << "\n"
147 >                cerr << "config.findsmb = " << config.findsmb << "\n"
148 >                        << "config.smbclient = " << config.smbclient << "\n"
149                          << "config.mount = " << config.mount << "\n"
150                          << "config.root = " << config.root << "\n"
151                          << (!config.hosts.empty() ? "config.hosts = {\n" : "");
# Line 130 | Line 159 | int main(int argc, char* argv[])
159                  cerr << (!config.hosts.empty() ? "}\n" : "");
160          }
161  
162 <        if (make)
162 >        if (automake) ::automake(makes);
163 >
164 >        if (make || automake)
165          {
166                  for (set<string>::iterator itor = makes.begin(); itor != makes.end();
167                          itor++)
# Line 141 | Line 172 | int main(int argc, char* argv[])
172                  }
173          }
174  
175 <        if (mount)
175 >        if (automount) ::automount(mounts);
176 >
177 >        if (mount || automount)
178          {
179                  for (set<string>::iterator itor = mounts.begin(); itor != mounts.end();
180                          itor++)
# Line 173 | Line 206 | string platform()
206  
207   void usage()
208   {
209 <        cout << "Usage: " << program << " [-make host ...] [-mount host ...] [-D] "
210 <                << "[-version] [-help]\n"
209 >        string tab(8 + program.length(), ' ');
210 >
211 >        cout << "Usage: " << program << " [-make host ...] [-mount host ...]\n"
212 >                << tab << "[-automake] [-automount]\n"
213 >                << tab << "[-D] [-version] [-help]\n"
214                  << "Options:\n"
215                  << "  -make host        Make the mount tree for host\n"
216                  << "  -mount host       Mount the shares on host to its tree\n"
217 +                << "  -automake         Automagically make the mount tree\n"
218 +                << "  -automount        Automagically mount shares to the tree\n"
219                  << "  -D                Display debug information\n"
220                  << "  -version          Display version information and exit\n"
221                  << "  -help             Display this message and exit\n";
# Line 191 | Line 229 | void version()
229                  << "   (http://computers.douglasthrift.net/).\n";
230   }
231  
232 + void automake(set<string>& makes)
233 + {
234 +        vector<string> args;
235 +
236 +        args.push_back("spectre");
237 +        
238 +        ipstream findsmb(config.findsmb, args);
239 +
240 +        if (debug) cerr << "findsmb = {\n";
241 +
242 +        for (unsigned index = 0; index < 5; index++)
243 +        {
244 +                string line;
245 +
246 +                getline(findsmb, line);
247 +
248 +                if (debug) cerr << line << "\n";
249 +        }
250 +
251 +        automake(makes, findsmb);
252 +
253 +        if (debug) cerr << "}\n";
254 +
255 +        findsmb.close();
256 +
257 +        if (debug)
258 +        {
259 +                cerr << "makes = {\n";
260 +
261 +                for (set<string>::iterator itor = makes.begin(); itor != makes.end();
262 +                        itor++)
263 +                {
264 +                        cerr << "   " << *itor << "\n";
265 +                }
266 +
267 +                cerr << "}\n";
268 +        }
269 + }
270 +
271 + void automake(set<string>& makes, ipstream& pin)
272 + {
273 +        while (pin.good())
274 +        {
275 +                if (!isdigit(pin.peek())) break;
276 +
277 +                char ip[17];
278 +                char host[16];
279 +                string info;
280 +
281 +                pin.get(ip, 17);
282 +                pin.ignore();
283 +                pin.get(host, 16);
284 +                getline(pin, info);
285 +
286 +                if (debug) cerr << ip << "\t" << host << info << "\n";
287 +
288 +                strip(host);
289 +
290 +                makes.insert(tolower(host));
291 +        }
292 +
293 +        string line;
294 +
295 +        getline(pin, line);
296 +
297 +        if (debug) cerr << line << "\n";
298 +
299 +        if (line != "")
300 +        {
301 +                cerr << program << ": Unknown error\n";
302 +        }
303 + }
304 +
305 + void automount(set<string>& mounts)
306 + {
307 + }
308 +
309   void configure()
310   {
311          string conf = config.install + "/conf/spectre.conf";
# Line 213 | Line 328 | void configure()
328                  {
329                          // ignore
330                  }
331 +                else if (line.find("findsmb=") == 0)
332 +                {
333 +                        config.findsmb = line.substr(8);
334 +                }
335                  else if (line.find("smbclient=") == 0)
336                  {
337                          config.smbclient = line.substr(10);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines