home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE51.TAR / mbase51 / examples / example1.c next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  1.7 KB  |  86 lines

  1. /*
  2.  * Note that, as this piece of C code doesn't actually read any
  3.  * records, there's no reason to include <example1.h> to get the
  4.  * C structure for the relation it works with.
  5.  *
  6.  */
  7.  
  8. #include <mbase.h>
  9.  
  10. /*
  11.  * PROTOTYPES -----------------------------------------------------------------
  12.  *
  13.  */
  14.  
  15.    void main XARGS( (void) );
  16.  
  17.  
  18. /*
  19.  * CODE -----------------------------------------------------------------------
  20.  *
  21.  */
  22.  
  23. void
  24. main ()
  25. {
  26.    relation *rel;
  27.    char      key[128];
  28.    long      n;
  29.  
  30.  
  31. /*
  32.  * First, try mb_tst() to see if the relation is valid; if not, display
  33.  * whatever error is appropriate and exit.  Note that mb_exit() isn't
  34.  * strictly necessary here, as no relations are open--but it's good
  35.  * practice to use it, and it won't hurt anything.
  36.  *
  37.  */
  38.  
  39.    if (mb_tst ("example1.rel") != MB_OKAY)
  40.       {
  41.       fprintf (stderr, "mb_tst() failed: %s\n", mb_error);
  42.       mb_exit (1);
  43.       }
  44.  
  45.  
  46. /*
  47.  * Now that we know the relation is valid, get an encryption key and
  48.  * open it.  The only reason mb_inc() should fail here is MB_ENCRYPT.
  49.  *
  50.  */
  51.  
  52.    printf ("encryption key : ");
  53.    gets (key);
  54.  
  55.    if ((rel = mb_inc ("example1.rel", key)) == RNULL)
  56.       {
  57.       fprintf (stderr, "mb_inc() failed: %s\n", mb_error);
  58.       mb_exit (1);
  59.       }
  60.  
  61.  
  62. /*
  63.  * Great; now that we've opened it, print out how many records are
  64.  * left, and how many of those haven't been indexed yet.
  65.  *
  66.  */
  67.  
  68.    n = mb_num (rel);
  69.    printf ("This relation has %ld %s.\n", n, (n==1) ? "record" : "records");
  70.  
  71.    n = mb_num_q (rel);
  72.    printf ("Of those, %ld %s not been indexed.\n", n, (n==1) ? "has" : "have");
  73.  
  74.  
  75. /*
  76.  * Now close the relation and leave.  Again, mb_rmv() isn't strictly necessary
  77.  * here, as mb_exit() will close all open relations...
  78.  *
  79.  */
  80.  
  81.    mb_rmv (rel);
  82.  
  83.    mb_exit (0);
  84. }
  85.  
  86.