D Eloquence Library

SAMPLE PROGRAM

/*
   sample.c

   compile: cc sample.c -o sample -l eloq
   usage  : sample database password
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <eloqdb.h>

#define ABS(a) ((a)<0?-(a):(a))

int dbid;
int status[10];

main(argc, argv)
int argc;
char *argv[];
{
   int i;
   struct {
      int count;
      int setno[MAX_SET_CNT];
   } set_list;

   if(argc < 3) {
      fprintf(stderr, "usage: %s data_base password\\n", argv[0]);
      exit(2);
   }

   dbid = idb_open(argv[1], argv[2], 9, status);
   errorhandler("opening database");

   idb_info(dbid, 0, 203, status, &set_list);
   errorhandler("info 203");
   for (i = 0 ; i < set_list.count; i++)
      set_info(set_list[i]);

   wrapup(0);
}

set_info(setno)
int setno;
{
   union info info;

   setno = ABS(setno);
   idb_info(dbid, &setno, 202, status, &info);
   errorhandler("info 202");
   printf("%16.16s %02d %c %6d %8d %8d\\n",
            info.set.name, setno, info.set.type, info.set.rec_len,
            info.set.capacity, info.set.entries);
}

wrapup(cond)
int cond;
{
   idb_exit();
   exit(cond);
}

errorhandler(action)
char *action;
{
   char tmp[80];

   if(status[0] != S_OK)
   {
      fprintf(stderr, "Status error #%d while %s\\n", status[0], action);

      if(idb_error(status, tmp, NULL) == S_OK)
         fprintf(stderr, "%s\\n", tmp);
      wrapup(1);
   }
}

Eloquence Database Manual - 19 DEC 2002