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

vappendlog.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 // Append stdin to 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::cerr;
00031 using std::endl;
00032 
00033 char* program_name;
00034 
00035 void
00036 Usage()
00037 {
00038     cerr << "Usage: " << program_name << " [-n lognum] [logdir]" << endl;
00039     exit(2);
00040 }
00041 
00042 int
00043 main(int argc, char* argv[]) 
00044 {
00045     int lognum = -1;
00046     VestaLog VRLog;
00047 
00048     program_name = argv[0];
00049 
00050     int c;
00051     for (;;) {
00052         c = getopt(argc, argv, "n:");
00053         if (c == EOF) break;
00054         switch (c) {
00055           case 'n':
00056             lognum = strtol(optarg, NULL, 0);
00057             break;
00058           case '?':
00059           default:
00060             Usage();
00061         }
00062     }
00063 
00064     char* dir;
00065     switch (argc - optind) {
00066       case 0:
00067         dir = ".";
00068         break;
00069       case 1:
00070         dir = argv[optind];
00071         break;
00072       default:
00073         Usage();
00074     }
00075 
00076     try {
00077         VRLog.open(dir, lognum, false, true);
00078     } catch (VestaLog::Error) {
00079         cerr << program_name << ": error opening log\n";
00080         exit(1);
00081     }
00082 
00083     char ch;
00084 
00085     // Read past existing part of log
00086     for (;;) {
00087         try {
00088             VRLog.get(ch);
00089         } catch (VestaLog::Error) {
00090             cerr << program_name << ": error getting character from log\n";
00091             exit(1);
00092         } catch (VestaLog::Eof) {
00093             if (!VRLog.nextLog()) break;
00094         }
00095     }
00096 
00097     VRLog.loggingBegin();
00098     VRLog.start();
00099 
00100     // Append new stuff
00101     while (cin.get(ch)) {
00102         try {
00103             VRLog.put(ch);
00104         } catch (VestaLog::Error) {
00105             cerr << program_name << ": error putting character to log\n";
00106             exit(1);
00107         }
00108     }
00109 
00110     VRLog.commit();
00111     VRLog.close();
00112 
00113     return 0;
00114 }

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