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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Author : Alexandre Parenteau <aubonbeurre@hotmail.com> --- March 1998
*/
/*
* LogParse.cpp : parse the cvs log output
*/
#include "stdafx.h"
#include <errno.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef WIN32
# include "wincvs.h"
# include "GraphDoc.h"
#endif /* WIN32 */
#ifdef macintosh
# include <unistd.h>
# include "MacCvsApp.h"
# include "CTreeView.h"
#endif /* macintosh */
#if qUnix
# include "UCvsDialogs.h"
# include "UCvsGraph.h"
#endif
#include "LogParse.h"
#include "CvsArgs.h"
#include "CvsLog.h"
#include "AppGlue.h"
#include "AppConsole.h"
#include "CPStr.h"
#include "getline.h"
#ifdef WIN32
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
static char THIS_FILE[] = __FILE__;
# endif
#endif /* WIN32 */
static void print(CColorConsole & out, const CRevFile & rev)
{
out << kBlue << "----------------------------" << kNormal << kNL;
out << "Revision : " << kBold << kRed << rev.RevNum().c_str() << kNormal << kNL;
if(!rev.Locker().empty())
out << "Locked by : '" << kBold << rev.Locker() << kNormal << '\'' << kNL;
out << "Date : " << kBold <<
(rev.RevTime().tm_year + 1900) << '/' <<
rev.RevTime().tm_mon << '/' <<
rev.RevTime().tm_mday << ' ' <<
rev.RevTime().tm_hour << ':' <<
rev.RevTime().tm_min << ':' <<
rev.RevTime().tm_sec << kNormal << kNL;
out << "Author : '" << kBold << rev.Author() << kNormal << '\'' << kNL;
out << "State : '" << kBold << rev.State() << kNormal << '\'' << kNL;
out << "Lines : +" << kBold << rev.ChgPos() << ' ' << rev.ChgNeg() << kNormal << kNL;
if(!rev.BranchesList().empty())
{
out << "Branches :" << kNL;
std::vector<CRevNumber>::const_iterator s;
for(s = rev.BranchesList().begin(); s != rev.BranchesList().end(); ++s)
{
const CRevNumber & branch = *s;
out << '\t' << kBold << branch.c_str() << kNormal << kNL;
}
}
out << "Description :" << kNL << kBrown << rev.DescLog() << kNormal << kNL;
}
static void print(CColorConsole & out, const CRcsFile & rcs, bool recurse = true)
{
out << "Rcs file : '" << kRed << rcs.RcsFile() << kNormal << '\'' << kNL;
out << "Working file : '" << kBold << rcs.WorkingFile() << kNormal << '\'' << kNL;
out << "Head revision : " << kBold << kRed << rcs.HeadRev().c_str() << kNormal << kNL;
out << "Branch revision : " << kBold << rcs.BranchRev().c_str() << kNormal << kNL;
out << "Locks :" << kBold << (rcs.LockStrict() ? " strict" : "") << kNormal << kNL;
std::vector<CRevNumber>::const_iterator s;
for(s = rcs.LocksList().begin(); s != rcs.LocksList().end(); ++s)
{
const CRevNumber & lock = *s;
out << '\t' << kBold << lock.c_str() << " : '" << lock.Tag() << '\'' << kNormal << kNL;
}
out << "Access :" << kNL;
std::vector<CLogStr>::const_iterator a;
for(a = rcs.AccessList().begin(); a != rcs.AccessList().end(); ++a)
{
out << "\t'" << kBold << *a << kNormal << '\'' << kNL;
}
if(!rcs.SymbolicList().empty())
{
out << "Symbolic names :" << kNL;
std::vector<CRevNumber>::const_iterator n;
for(n = rcs.SymbolicList().begin(); n != rcs.SymbolicList().end(); ++n)
{
const CRevNumber & symb = *n;
out << '\t' << kBold << symb.c_str() << " : '" << symb.Tag() << '\'' << kNormal << kNL;
}
}
out << "Keyword substitution : '" << kBold << rcs.KeywordSubst() << kNormal << '\'' << kNL;
out << "Total revisions : " << kBold << rcs.TotRevisions() << kNormal << kNL;
out << "Selected revisions : " << kBold << rcs.SelRevisions() << kNormal << kNL;
out << "Description :" << kNL << kBrown << rcs.DescLog() << kNormal << kNL;
std::vector<CRevFile>::const_iterator i;
if(recurse) for(i = rcs.AllRevs().begin(); i != rcs.AllRevs().end(); ++i)
{
print(out, *i);
}
out << kGreen << "===============================================" << kNormal << kNL;
}
static void print(CColorConsole & out, const CLogNode * node, CStr & offset)
{
out << offset;
switch(node->GetType())
{
case kNodeHeader :
{
CLogNodeHeader *header = (CLogNodeHeader *)node;
out << offset << "Rcs file : '" << kRed << (**header).RcsFile() << kNormal << '\'' << kNL;
break;
}
case kNodeBranch :
break;
case kNodeRev :
{
CLogNodeRev *rev = (CLogNodeRev *)node;
out << offset << kBold << (**rev).RevNum().c_str() << kNormal << kNL;
break;
}
case kNodeTag :
break;
}
CStr newOffset;
newOffset = offset;
newOffset << " ";
std::vector<CLogNode *>::const_iterator i;
for(i = node->Childs().begin(); i != node->Childs().end(); ++i)
{
print(out, *i, newOffset);
newOffset << ' ';
}
if(node->Next() != 0L)
{
print(out, node->Next(), offset);
}
}
void CvsLogOutput(CColorConsole & out, CLogNode *node)
{
switch(node->GetType())
{
case kNodeHeader :
{
CRcsFile & rcs = **(CLogNodeHeader *)node;
print(out, rcs, false);
break;
}
case kNodeBranch :
break;
case kNodeRev :
{
CRevFile & rev = **(CLogNodeRev *)node;
print(out, rev);
break;
}
case kNodeTag :
break;
}
}
void CvsLogParse(const char *dir, const CvsArgs & args, bool outGraph, void *defWnd)
{
// make a stream of the cvs log output
CStr tmpFile;
FILE *output;
output = launchCVS(dir, args, tmpFile);
if(output == 0L)
return;
// parse
std::vector<CRcsFile> & allRcs = CvsLogParse(output);
// maybe something went wrong or may be the user
// asked to print only the RCS names, so print the
// output directly whithout parsing../
if(allRcs.empty())
{
char *line = 0L;
size_t line_chars_allocated = 0;
int line_length;
fseek(output, SEEK_SET, 0);
while ((line_length = getline (&line, &line_chars_allocated, output)) > 0)
{
cvs_outstr(line, line_length);
cvs_outstr("\n", 1);
}
if (line_length < 0 && !feof (output))
cvs_err("Cannot read output file (error %d)\n", errno);
if(line != 0L)
free (line);
}
// close the temp file
fclose(output);
if(unlink(tmpFile) != 0)
{
cvs_err("Impossible to delete the file '%s' (error %d)",
(const char *)tmpFile, errno);
}
if(allRcs.empty())
return;
// output the result
CColorConsole out;
std::vector<CRcsFile>::iterator i;
for(i = allRcs.begin(); i != allRcs.end(); ++i)
{
CRcsFile & rcs = *i;
if(!outGraph)
print(out, rcs);
else
{
CLogNode *node = CvsLogGraph(rcs);
if(node == 0L)
{
cvs_err("Impossible to create a graph for %s\n",
(const char *)rcs.WorkingFile());
}
#ifdef WIN32
CWincvsApp* app = (CWincvsApp *)AfxGetApp();
CGraphDoc *doc;
if(defWnd != 0L)
doc = (CGraphDoc *)defWnd;
else
doc = (CGraphDoc*)app->gLogGraph->OpenDocumentFile(NULL);
doc->SetNode(node, dir);
#elif qMacCvsPP
if(defWnd != 0L)
((CTreeView *)defWnd)->SetNode(node, dir);
else
CMacCvsApp::app->NewLogTree(node, dir);
#elif qUnix
UCvsGraph * graph = new UCvsGraph(node, dir);
void *win = UCreate_GraphWindow();
UEventSendMessage(graph->GetWidID(), EV_INIT_WIDGET, kUMainWidget, win);
UEventSendMessage(graph->GetWidID(), EV_SHOW_WIDGET, UMAKEINT(kUMainWidget, 1), 0L);
#else
CStr offset;
print(out, node, offset);
delete node;
#endif
}
}
// reset the parser
CvsLogReset();
}
|