public inbox for sourcenav@sourceware.org
 help / color / mirror / Atom feed
From: khamis2@t-online.de (Khamis Abuelkomboz)
To: dgray@rsn.hp.com
Cc: sourcenav@sources.redhat.com
Subject: Re: Using Source Nav. database API
Date: Thu, 03 Jan 2002 15:58:00 -0000	[thread overview]
Message-ID: <3C34F02E.2050808@t-online.de> (raw)
In-Reply-To: <003401c194ad$05519410$2e91630f@DGRAYPC>

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);
}


      reply	other threads:[~2002-01-03 23:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-03 15:19 David Gray
2002-01-03 15:58 ` Khamis Abuelkomboz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C34F02E.2050808@t-online.de \
    --to=khamis2@t-online.de \
    --cc=dgray@rsn.hp.com \
    --cc=sourcenav@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).