|
a/src/query/history.cpp |
|
b/src/query/history.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: history.cpp,v 1.7 2006-09-11 12:05:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: history.cpp,v 1.8 2007-06-20 13:16:11 dockes Exp $ (C) 2005 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
29 |
|
29 |
|
30 |
#ifndef NO_NAMESPACES
|
30 |
#ifndef NO_NAMESPACES
|
31 |
using namespace std;
|
31 |
using namespace std;
|
32 |
#endif
|
32 |
#endif
|
33 |
|
33 |
|
34 |
static const char *docSubkey = "docs";
|
|
|
35 |
|
34 |
|
36 |
// Encode/decode document history entry: Unix time + base64 of fn +
|
35 |
// Encode/decode document history entry: Unix time + base64 of fn +
|
37 |
// base64 of ipath separated by a space. If ipath is not set, there
|
36 |
// base64 of ipath separated by a space. If ipath is not set, there
|
38 |
// are only 2 parts
|
37 |
// are only 2 parts
|
39 |
bool RclDHistoryEntry::encode(string& value)
|
38 |
bool RclDHistoryEntry::encode(string& value)
|
|
... |
|
... |
180 |
it != el.end(); it++)
|
179 |
it != el.end(); it++)
|
181 |
sl.push_back(it->value);
|
180 |
sl.push_back(it->value);
|
182 |
return sl;
|
181 |
return sl;
|
183 |
}
|
182 |
}
|
184 |
|
183 |
|
|
|
184 |
string RclHistory::docSubkey = "docs";
|
|
|
185 |
|
185 |
/// *************** History entries specific methods
|
186 |
/// *************** History entries specific methods
|
186 |
bool RclHistory::enterDoc(const string fn, const string ipath)
|
187 |
bool RclHistory::enterDoc(const string fn, const string ipath)
|
187 |
{
|
188 |
{
|
188 |
LOGDEB(("RclDHistory::enterDoc: [%s] [%s] into %s\n",
|
189 |
LOGDEB(("RclDHistory::enterDoc: [%s] [%s] into %s\n",
|
189 |
fn.c_str(), ipath.c_str(), m_data.getFilename().c_str()));
|
190 |
fn.c_str(), ipath.c_str(), m_data.getFilename().c_str()));
|
|
... |
|
... |
211 |
#endif
|
212 |
#endif
|
212 |
|
213 |
|
213 |
static string thisprog;
|
214 |
static string thisprog;
|
214 |
|
215 |
|
215 |
static string usage =
|
216 |
static string usage =
|
216 |
" [-e] [-s <subkey>]"
|
217 |
"trhist [opts] <filename>\n"
|
|
|
218 |
" [-s <subkey>]: specify subkey (default: RclHistory::docSubkey)\n"
|
|
|
219 |
" [-e] : erase all\n"
|
|
|
220 |
" [-a <string>] enter string (needs -s, no good for history entries\n"
|
217 |
" \n\n"
|
221 |
"\n"
|
218 |
;
|
222 |
;
|
219 |
|
223 |
|
220 |
static void
|
224 |
static void
|
221 |
Usage(void)
|
225 |
Usage(void)
|
222 |
{
|
226 |
{
|
|
... |
|
... |
225 |
}
|
229 |
}
|
226 |
|
230 |
|
227 |
static int op_flags;
|
231 |
static int op_flags;
|
228 |
#define OPT_e 0x2
|
232 |
#define OPT_e 0x2
|
229 |
#define OPT_s 0x4
|
233 |
#define OPT_s 0x4
|
|
|
234 |
#define OPT_a 0x8
|
230 |
|
235 |
|
231 |
int main(int argc, char **argv)
|
236 |
int main(int argc, char **argv)
|
232 |
{
|
237 |
{
|
233 |
string sk = "docs";
|
238 |
string sk = RclHistory::docSubkey;
|
|
|
239 |
string value;
|
234 |
|
240 |
|
235 |
thisprog = argv[0];
|
241 |
thisprog = argv[0];
|
236 |
argc--; argv++;
|
242 |
argc--; argv++;
|
237 |
|
243 |
|
238 |
while (argc > 0 && **argv == '-') {
|
244 |
while (argc > 0 && **argv == '-') {
|
|
... |
|
... |
240 |
if (!(**argv))
|
246 |
if (!(**argv))
|
241 |
/* Cas du "adb - core" */
|
247 |
/* Cas du "adb - core" */
|
242 |
Usage();
|
248 |
Usage();
|
243 |
while (**argv)
|
249 |
while (**argv)
|
244 |
switch (*(*argv)++) {
|
250 |
switch (*(*argv)++) {
|
|
|
251 |
case 'a': op_flags |= OPT_a; if (argc < 2) Usage();
|
|
|
252 |
value = *(++argv); argc--;
|
|
|
253 |
goto b1;
|
245 |
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
|
254 |
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
|
246 |
sk = *(++argv);
|
255 |
sk = *(++argv); argc--;
|
247 |
argc--;
|
|
|
248 |
goto b1;
|
256 |
goto b1;
|
249 |
case 'e': op_flags |= OPT_e; break;
|
257 |
case 'e': op_flags |= OPT_e; break;
|
250 |
default: Usage(); break;
|
258 |
default: Usage(); break;
|
251 |
}
|
259 |
}
|
252 |
b1: argc--; argv++;
|
260 |
b1: argc--; argv++;
|
253 |
}
|
261 |
}
|
254 |
if (argc != 0)
|
262 |
if (argc != 1)
|
255 |
Usage();
|
263 |
Usage();
|
|
|
264 |
string filename = *argv++;argc--;
|
256 |
|
265 |
|
257 |
RclHistory hist("toto", 5);
|
266 |
RclHistory hist(filename, 5);
|
258 |
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
267 |
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
259 |
DebugLog::setfilename("stderr");
|
268 |
DebugLog::setfilename("stderr");
|
260 |
|
269 |
|
261 |
if (op_flags & OPT_e) {
|
270 |
if (op_flags & OPT_e) {
|
262 |
hist.eraseAll(sk);
|
271 |
hist.eraseAll(sk);
|
|
|
272 |
} else if (op_flags & OPT_a) {
|
|
|
273 |
if (!(op_flags & OPT_s))
|
|
|
274 |
Usage();
|
|
|
275 |
hist.enterString(sk, value);
|
263 |
} else {
|
276 |
} else {
|
264 |
for (int i = 0; i < 10; i++) {
|
277 |
for (int i = 0; i < 10; i++) {
|
265 |
char docname[100];
|
278 |
char docname[100];
|
266 |
sprintf(docname, "A very long document document name"
|
279 |
sprintf(docname, "A very long document document name"
|
267 |
"is very long indeed and this is the end of "
|
280 |
"is very long indeed and this is the end of "
|