Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

vdumplog.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 //
00020 // Dump the contents of a log
00021 //
00022 
00023 #include "VestaLog.H"
00024 #include <stdlib.h>
00025 extern "C" {
00026 #include <getopt.h>
00027 }
00028 
00029 using std::cin;
00030 using std::cout;
00031 using std::cerr;
00032 using std::endl;
00033 
00034 char* program_name;
00035 
00036 void
00037 Usage()
00038 {
00039     cerr << "Usage: " << program_name << " [-n lognum] [-l] [logdir]" << endl;
00040     exit(2);
00041 }
00042 
00043 int
00044 main(int argc, char* argv[]) 
00045 {
00046     int lognum = -1;
00047     bool loop = false;  // loop through logfiles >= lognum
00048     VestaLog VRLog;
00049 
00050     program_name = argv[0];
00051 
00052     int c;
00053     for (;;) {
00054         c = getopt(argc, argv, "n:l");
00055         if (c == EOF) break;
00056         switch (c) {
00057           case 'n':
00058             lognum = strtol(optarg, NULL, 0);
00059             break;
00060           case 'l':
00061             loop = true;
00062             break;
00063           case '?':
00064           default:
00065             Usage();
00066         }
00067     }
00068 
00069     char* dir;
00070     switch (argc - optind) {
00071       case 0:
00072         dir = ".";
00073         break;
00074       case 1:
00075         dir = argv[optind];
00076         break;
00077       default:
00078         Usage();
00079     }
00080 
00081     try {
00082         VRLog.open(dir, lognum, true);
00083     } catch (VestaLog::Error) {
00084         cerr << program_name << ": error opening log\n";
00085         exit(1);
00086     }
00087 
00088     for (;;) {
00089         char c;
00090 
00091         try {
00092             VRLog.get(c);
00093             cout.put(c);
00094         } catch (VestaLog::Error) {
00095             cerr << program_name << ": error getting character from log\n";
00096             exit(1);
00097         } catch (VestaLog::Eof) {
00098             if (!loop || !VRLog.nextLog()) break;
00099         }
00100     }
00101     VRLog.close();
00102 
00103     return 0;
00104 }

Generated on Mon May 8 00:48:42 2006 for Vesta by  doxygen 1.4.2