1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#include <stdio.h>
#include "getopt.h"
#include <errno.h>
using namespace std;
#if defined(_MSC_VER) && _MSC_VER < 0x514 && __GNUC__<3 // VC7 and gcc 3
# include <iostream.h>
# include <fstream.h>
#else
# include <iostream>
# include <fstream>
#endif
#include "common.h"
static void yyoutput(ostream & out)
{
std::vector<CRcsFile>::const_iterator i;
for(i = gRcsFiles.begin(); i != gRcsFiles.end(); ++i)
{
const CRcsFile & rcs = *i;
rcs.print(out);
}
}
static void yygraph(const CRcsFile & rcs)
{
CRcsFile rcsFile = rcs;
rcsFile.sort();
const std::vector<CRevFile> & allrevs = rcsFile.AllRevs();
std::vector<CRevFile>::const_iterator i;
for(i = allrevs.begin(); i != allrevs.end(); ++i)
{
const CRevNumber & rev = i->RevNum();
cout << '\t' << rev.c_str() << '\n';
}
}
static void yygraph(void)
{
std::vector<CRcsFile>::const_iterator i;
for(i = gRcsFiles.begin(); i != gRcsFiles.end(); ++i)
{
const CRcsFile & rcs = *i;
yygraph(rcs);
}
}
static const char *const cmd_usage[] =
{
"CVSTREE synopsis is: cvs [cvsoptions] log [logoptions] | cvstree [cvstree options]\n",
"CVSTREE options are:\n",
" -v Verbose the output similar to cvs log (default)\n",
" -f input Input from a file\n",
" -o output Output in a file\n",
" -g Output a graph of the revisions\n",
" -1 Debug the lexer (flex output)\n",
" -2 Debug the parser (bison output)\n",
" -3 Debug both the parser and the lexer\n",
" --help,-h Print this help\n",
" --version Print the version number\n",
NULL
};
static struct option long_options[] =
{
{"help", 0, NULL, 'h'},
{"version", 0, NULL, '*'},
{0, 0, 0, 0}
};
static void usage (const char *const *cpp)
{
for (; *cpp; cpp++)
fprintf (stderr, *cpp);
exit(1);
}
int main(int argc, char **argv)
{
int c;
int option_index = 0;
bool outGraph = false;
CLogStr output;
CLogStr input;
#if qCvsDebug
yydebug = 0;
yy_flex_debug = 0;
#endif
while ((c = getopt_long
(argc, argv, "+o:f:g123vh", long_options, &option_index))
!= EOF)
{
switch (c)
{
case '1':
#if qCvsDebug
yy_flex_debug = 1;
#endif
break;
case '2':
#if qCvsDebug
yydebug = 1;
#endif
break;
case '3':
#if qCvsDebug
yydebug = 1;
yy_flex_debug = 1;
#endif
break;
case 'h':
usage (cmd_usage);
break;
case 'g':
outGraph = true;
break;
case 'v':
outGraph = false;
break;
case 'o':
output = optarg;
break;
case 'f':
input = optarg;
break;
case '*':
cerr << "Version of " << argv[0] << " is $Revision: 1.5 $\n";
exit(1);
break;
case '?':
default:
usage (cmd_usage);
}
}
argc -= optind;
argv += optind;
if (argc != 0)
usage (cmd_usage);
if(!input.empty())
{
yyin = fopen(input, "r");
if(yyin == 0L)
{
cerr << "Error while opening inputfile '" << input << "'\n";
exit(errno);
}
}
else
yyin = stdin;
yyreset();
yyrestart(yyin);
yyparse();
if(outGraph)
{
yygraph();
}
else
{
if(!output.empty())
{
ofstream out( output.c_str() );
if(!out) {
cerr << "Error while opening outputfile '" << output << "'\n";
exit(errno);
}
yyoutput(out);
}
else
yyoutput(cout);
}
if(!input.empty())
fclose(yyin);
}
|