00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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 }