File: TagDate.cpp

package info (click to toggle)
cvsnt 2.5.03.2382-3.3%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 32,288 kB
  • ctags: 24,567
  • sloc: ansic: 136,648; cpp: 102,037; sh: 42,846; asm: 3,495; makefile: 1,763; ada: 1,681; perl: 1,352; pascal: 1,089; cs: 1,008; yacc: 805; python: 453; xml: 263; sql: 210; lisp: 7
file content (228 lines) | stat: -rw-r--r-- 4,484 bytes parent folder | download | duplicates (2)
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
/*
	CVSNT Generic API
    Copyright (C) 2004 Tony Hoyle and March-Hare Software Ltd

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License version 2.1 as published by the Free Software Foundation.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#include <config.h>
#include "lib/api_system.h"
#include <assert.h>
#include <sys/types.h>
#include <stdlib.h>
#include <ctype.h>
#include "lib/getdate.h"
#include "TagDate.h"

CTagDate::CTagDate(bool range)
{
	m_range = range;
}

CTagDate::~CTagDate()
{
}

bool CTagDate::AddTag(const char *tag, bool isDate /* = false */)
{
	return AddGenericTag(tag,isDate);
}

/* Add a tag or date 
 * Supports ranges as:
 *
 * tag (just tag)
 * tag.n (revision on branch)
 * tag@date (date on branch)
 * tag1:tag2  (inclusive)
 * tag1::tag2 (exclusive)
 * tag1:::tag2 (exclude tag1, include tag2)
 * <tag (before tag)
 * <=tag (tag and before tag)
 * >tag (after tag)
 * >=tag (tag and after tag)
 */
bool CTagDate::AddGenericTag(const char *tag,bool isDate)
{
	CTagDateItem item,item2;

	assert(tag && *tag);

	if(strchr(tag,':'))
	{
		if(!m_range)
			return false; /* Attempted to specify range on non-ranged tag */

		const char *p = strchr(tag,':');
		int type=0;
		std::string tag1,tag2;
		
		tag1.assign(tag,tag-p);
		while(*p==':')
		{
			p++;
			type++;
		}
		tag2.assign(p);

		if(!BreakdownTag(isDate,tag1.c_str(),item.m_tag,item.m_tagVer,item.m_date))
			return false;

		if(!BreakdownTag(isDate,tag2.c_str(),item2.m_tag,item2.m_tagVer,item2.m_date))
			return false;

		if(type==1)
			item.m_tagRangeType = trtRangeStartIncluded;
		else
			item.m_tagRangeType = trtRangeStartExcluded;
		m_list.push_back(item);

		if(type==1 || type==3)
			item2.m_tagRangeType = trtRangeEndIncluded;
		else
			item2.m_tagRangeType = trtRangeEndExcluded;
		m_list.push_back(item2);
	}
	else
	{
		if(m_range)
		{
			if(tag[0]=='<' && tag[1]=='=')
			{ 
				item.m_tagRangeType=trtLessThanOrEqual;
				tag+=2;
			}
			else if(tag[0]=='<')
			{
				item.m_tagRangeType=trtLessThan;
				tag++;
			}
			else if(tag[0]=='>' && tag[1]=='=')
			{
				item.m_tagRangeType=trtGreaterThanOrEqual;
				tag+=2;
			}
			else if(tag[0]=='>')
			{
				item.m_tagRangeType=trtGreaterThan;
				tag++;
			}
			else
				item.m_tagRangeType=trtSingle;
		}
		else
			item.m_tagRangeType=trtSingle;

		if(!BreakdownTag(isDate,tag,item.m_tag,item.m_tagVer,item.m_date))
			return false;

		m_list.push_back(item);
	}
	return true;
}

/* Deterimine if a tag is syntactically valid
 * supports (for non-dates):
 *
 * 1.2.3.4 (numeric)
 * foo (text)
 * foo.3 (specific revision on branch)
 * foo@date (specific date at branch)
 * @43346363AA234 (commit identifier)
 * 
 * for dates the generic date parser is used.
 */
bool CTagDate::BreakdownTag(bool isDate, const char *tag, cvs::string& tagName, int& tagVer, time_t& time)
{
	const char *p = tag;
	if(!isDate)
	{
		// Numeric
		if(isdigit(*p))
		{
			for(;*p;p++)
				if(!isdigit(*p) && *p!='.')
					break;
			if(*p)
				return false;
			tagName=tag;
			tagVer-=1;
			time=-1;
			return true;
		}
		// Commit identifier
		if(*p=='@')
		{
			tagName=tag;
			tagVer=-1;
			time=-1;
			return true;
		}

		// Real tag
		for(;*p;p++)
			if(!isalnum(*p) && *p!='_')
				break;
		// We allow tag.n or tag@date
		if(*p && *p!='.' && *p!='@')
			return false;
		tagName=tag;
		tagName.resize(p-tag);
		if(*p=='.')
		{
			const char *q=++p;
			if(*p)
			{
				for(;*p;p++)
					if(!isdigit(*p))
						break;
				if(*p)
					return false;
			}
			tagVer=atoi(q);
			time=-1;
		}
		else if(*p=='@')
		{
			time = get_date((char*)++p,NULL);
			if(time==(time_t)-1)
				return false;
			tagVer=-1;
		}
		else
		{
			time=-1;
			tagVer=-1;
		}
		return true;
	}
	else
	{
		time = get_date((char*)tag,NULL);
		if(time==(time_t)-1)
			return false;
		tagName="";
		tagVer=-1;
		return true;
	}
}

void CTagDateItem::GenerateDateText()
{
	if(m_date==-1)
	{
		m_dateText.resize(0);
		return;
	}
	m_dateText = ctime(&m_date);
}