Using Source Nav. database API

Khamis Abuelkomboz
Thu Jan 3 15:58:00 GMT 2002

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)     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"

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]);
        if (!(db = dbopen(argv[1],O_RDONLY,0644,DB_BTREE,NULL)))
                fprintf(stderr,"Could not open \"%s\",%s\n",argv[1],

        pattern = argv[2];
        len = strlen(pattern);

        if (len == 0)
   = "\0";
            key.size = 1;
   = (void *)pattern;
            key.size = len;
        for(flag = R_CURSOR;
                db->seq(db, &key,&data,flag) == 0
                && strncmp(,pattern,len) == 0
                flag = R_NEXT)
                printf("%s\t%s\n", (char *), (char *);

        exit (0);

More information about the Sourcenav mailing list