* Using Source Nav. database API
@ 2002-01-03 15:19 David Gray
2002-01-03 15:58 ` Khamis Abuelkomboz
0 siblings, 1 reply; 2+ messages in thread
From: David Gray @ 2002-01-03 15:19 UTC (permalink / raw)
To: sourcenav
Hi, guys,
I installed Source Nav. to help me analyze our source. It seems like a =
very powerful tool. I also need to use the database programming =
interface to extend the capabilities. I've read over the programming =
documentation several times, but still cannot get the tcl/tk or C =
interfaces to work.
I am not familiar with tcl/tk but here's what happens when I run the =
sample script shown below. =20
% pwd
/tmp_mnt/nis.home/pal/dgray/test_dev
% ls
Makefile dbqry.c legacyio_cscope tbvm
cscope_clock extract_clock legacyio_snav.proj tcl.sh
dbqry functions.sh legacyio_thtk
% cat tcl.sh
#!/bin/sh
# Replace $HOME/snavigator with the Source-Navigator
# installation directory! \
exec /opt/snav/bin/hyper "$0" "$@"
#
# Don't forget the backslash before exec!
#
set db_functions [dbopen nav_func .snprj/legacyio_snav.to RDONLY 0644 =
btree \
{cachesize=3D200000}]
puts [join [$db_functions seq -data] \n]
exit
% ll /opt/snav/bin/hyper
-rwxr-xr-x 1 root mppos 19368880 Mar 22 2001 =
/opt/snav/bin/hyper=20
% ll .snprj/legacyio_snav.to
-rw-rw---- 1 dgray mppos 259457024 Dec 4 09:57 =
.snprj/legacyio_snav.to
% tcl.sh
Error: unknown encoding "iso8859-1"
% uname -a
HP-UX bobcat B.10.20 A 9000/889 274844331 two-user license
This seems simply like some kind of setup or environmental problem.
I also compiled and linked the dbqry.c sample program. I tried various =
pattern arguments but repeatedly got no output. Is there any =
documentation on specifying the pattern argument? What is the universal =
"dump it all" pattern?
I attached the dbqry.c program below.
I am just trying to get started with the database interface but got =
stuck. I would appreciate any tips you guys can send me.
Thanks,
David Gray
Hewlett-Packard
Richardson, Texas
---------------------------- attachment -------------------------------
/*
* dbquery.c
*
* Copyright (C) 1998 Cygnus Solutions
*
* Description:
* This example shows how to query the Source-Navigator database in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include "db.h"
int
main(int argc, char *argv[])
{
DB *db;
DBT data;
DBT key;
int flag;
int len;
char *pattern;
if (argc !=3D 3)
{
printf("usage: %s database pattern\n",argv[0]);
exit(1);
}
if (!(db =3D dbopen(argv[1],O_RDONLY,0644,DB_BTREE,NULL)))
{
fprintf(stderr,"Could not open \"%s\",%s\n",argv[1],
strerror(errno));
exit(2);
}
pattern =3D argv[2];
len =3D strlen(pattern);
key.data =3D (void *)pattern;
key.size =3D len;
for(flag =3D R_CURSOR;
db->seq(db,&key,&data,flag) =3D=3D 0 &&
strncmp(key.data,pattern,len) =3D=3D 0; flag =3D R_NEXT)
{
printf("key: %s\n", (char *) key.data);
printf("data: %s\n", (char *) data.data);
}
db->close(db);
exit (0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Using Source Nav. database API
2002-01-03 15:19 Using Source Nav. database API David Gray
@ 2002-01-03 15:58 ` Khamis Abuelkomboz
0 siblings, 0 replies; 2+ messages in thread
From: Khamis Abuelkomboz @ 2002-01-03 15:58 UTC (permalink / raw)
To: dgray; +Cc: sourcenav
Your example is correct!
It works only if you specify a pattern, what the key begins with. The DB
tool does only
provide "BEGINS" functionality (maybe I'm wrong). The problem was, that
you didn't
hit any string combination, what the db key begins with :-)
However, here is your example that displays all the database contents if
you specify an
empty pattern ("").
One more tip! the SN database files contents differ from one to other.
You need to use your
example to study the contents of every file carefully.
The extensions of the databases tell you about the file is used for:
db.fil contains all symbols in a file (largest file)
db.cl contains all classes
db.f contains all files
db.fu contains all functions
...
and so on.
/*
* dbquery.c
*
* Copyright (C) 1998 Cygnus Solutions
*
* Description:
* This example shows how to query the Source-Navigator database in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include "NTunixstubs.h"
#include "db.h"
int
main(int argc, char *argv[])
{
DB *db;
DBT data;
DBT key;
int flag;
int len;
char *pattern;
if (argc != 3)
{
printf("usage: %s database pattern\n",argv[0]);
exit(1);
}
if (!(db = dbopen(argv[1],O_RDONLY,0644,DB_BTREE,NULL)))
{
fprintf(stderr,"Could not open \"%s\",%s\n",argv[1],
strerror(errno));
exit(2);
}
pattern = argv[2];
len = strlen(pattern);
if (len == 0)
{
key.data = "\0";
key.size = 1;
}
else
{
key.data = (void *)pattern;
key.size = len;
}
for(flag = R_CURSOR;
db->seq(db, &key,&data,flag) == 0
&& strncmp(key.data,pattern,len) == 0
;
flag = R_NEXT)
{
printf("%s\t%s\n", (char *) key.data, (char *) data.data);
}
db->close(db);
exit (0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-01-03 23:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-03 15:19 Using Source Nav. database API David Gray
2002-01-03 15:58 ` Khamis Abuelkomboz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).