source: trunk/MagicSoft/Mars/showlog.cc@ 4778

Last change on this file since 4778 was 4756, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 1.9 KB
Line 
1#include <errno.h>
2#include <fstream>
3
4#include "MArgs.h"
5
6#include "MLog.h"
7#include "MLogManip.h"
8
9using namespace std;
10
11static void Usage()
12{
13 gLog << endl;
14 gLog << "Sorry the usage is:" << endl;
15 gLog << " showlog [options] filename" << endl;
16 gLog << " or" << endl;
17 gLog << " showlog [options] < filename" << endl << endl;
18 gLog << " -?, -h, --help This help" << endl << endl;
19 gLog << endl;
20 gLog << " This program converts colored output made with ansi codes" << endl;
21 gLog << " (like it is done by MLog) and redirected into a file back" << endl;
22 gLog << " into colored output." << endl << endl;
23 gLog << " It cannot be used to get rid of the Ansi codes. To display" << endl;
24 gLog << " colored output with less use the option -R, eg." << endl;
25 gLog << " less -R logfile.log" << endl << endl;
26}
27
28// FIXME: Enhance this tool with a converter to HTMl, etc.
29// Add option for 'no-colors'
30int main(int argc, char **argv)
31{
32 MArgs arg(argc, argv);
33
34 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
35 {
36 Usage();
37 return -1;
38 }
39
40 if (arg.GetNumOptions()>0)
41 {
42 gLog << warn << "WARNING - Unknown commandline options..." << endl;
43 arg.Print("options");
44 gLog << endl;
45 }
46
47 //
48 // check for the right usage of the program
49 //
50 if (arg.GetNumArguments()>1)
51 {
52 Usage();
53 return -1;
54 }
55
56 // casts necessary for gcc 2.95.3
57 istream *in = arg.GetNumArguments()==1 ? (istream*)new ifstream(arg.GetArgumentStr(0)) : (istream*)&cin;
58 if (!*in)
59 {
60 gLog << "Cannot open file " << arg.GetArgumentStr(0) << ": " << strerror(errno) << endl;
61 return -1;
62 }
63
64 TString s;
65 while (1)
66 {
67 s.ReadLine(*in);
68 if (!*in)
69 break;
70
71 s.ReplaceAll("", "\033");
72 gLog << s << endl;
73 }
74
75 if (in!=&cin)
76 delete in;
77
78 return 0;
79}
Note: See TracBrowser for help on using the repository browser.