home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / mbase.zip / SAMPLE.C < prev    next >
C/C++ Source or Header  |  1991-02-11  |  3KB  |  112 lines

  1. #include "stdinc.h"
  2. #include "mbase.h"
  3.  
  4. /* INDICIES:
  5.     1 -- noun
  6.     2 -- question|goodbad
  7.     3 -- question               */
  8.  
  9. static char *records[] =
  10.  { "1|aReallyGoodKWIn1|r", "2|betterKeyWordin2|r",
  11.    "10|aGoodKWordIn10|r",  "1|aRottenKWordIn1|w",
  12.    "2|nastyKeyWordin2|w",  "10|aRottenKWordIn10|w",
  13.    "2|nastyKeyWordin2|w",  "2|aGoodKeyWordIn2|r",
  14.    "1|aGoodKeyWordIn1|r",  "10|greatOnein10|r",
  15.    "0"
  16.  };
  17.  
  18. int    f;        /* Int into which to place the file # after mb_inc    */
  19. char   str[80];  /* Generic global char * into which to return records */
  20.  
  21. static int KEY = 128;  /* Encryption key to use on the file */
  22.  
  23. main ()
  24. {
  25.    int   i, func;
  26.    char  temp[80], validkey[80];
  27.  
  28.    if ((f = mb_inc ("sample", KEY)) < 0)
  29.     { printf ("Relation could not be opened.\n");
  30.       exit   (0);
  31.     };
  32.    printf ("Relation has been included -- %d.\n\n", f);
  33.  
  34.    printf ("Relation has been cleaned  -- %d.\n\n", mb_rst ("sample"));
  35.  
  36.    printf ("Adding records (If they're not there)\n");
  37.    printf ("   ('!' = already there, '.' = added)\n");
  38.  
  39.    for (i = 0; records[i][0] != '0'; i++)
  40.       printf ( (mb_add (f, records[i]) == 0) ? "." : "!" );
  41.    printf ("\n");
  42.  
  43.    printf ("Printing all words in the relation:\n");
  44.  
  45.    for (func = FIRST; mb_sel (f, 1, str, func, "") == 0; func = NEXT)
  46.       print_record ("<validkey unused>");
  47.  
  48.    printf ("\nLooking up 'greatOnein10'\n");
  49.    if (mb_sel (f, 1, str, EQUAL, "greatOnein10") == 0)
  50.       print_record ("<validkey unused>");
  51.    else
  52.       printf ("Couldn't find it.\n");
  53.  
  54.    printf ("\nPrinting all good words in question 1:\n");
  55.    strcpy (temp, "1|r|");
  56.    for (func = EQUAL; ; func = NEXT)
  57.     { if (mb_sel (f, 2, str, func, temp) != 0)  break;
  58.       if (func == EQUAL)  strcpy (validkey, mb_key (f, 2, str));
  59.       else
  60.          if (strcmp (validkey, mb_key (f, 2, str)) != 0)  break;
  61.       print_record (validkey);
  62.     };
  63.  
  64.    printf ("\nPrinting all bad words in question 2:\n");
  65.    strcpy (temp, "2|w|");
  66.    for (func = EQUAL; ; func = NEXT)
  67.     { if (mb_sel (f, 2, str, func, temp) != 0)  break;
  68.       if (func == EQUAL)  strcpy (validkey, mb_key (f, 2, str));
  69.       else
  70.          if (strcmp (validkey, mb_key (f, 2, str)) != 0)  break;
  71.       print_record (validkey);
  72.     };
  73.  
  74.    printf ("\nPrinting all words in question 10:\n");
  75.    strcpy (temp, "10|");
  76.    for (func = EQUAL; ; func = NEXT)
  77.     { if (mb_sel (f, 3, str, func, temp) != 0)  break;
  78.       if (func == EQUAL)  strcpy (validkey, mb_key (f, 3, str));
  79.       else
  80.          if (strcmp (validkey, mb_key (f, 3, str)) != 0)  break;
  81.       print_record (validkey);
  82.     };
  83.  
  84.    printf ("Relation has been closed -- %d\n", mb_rmv (f));
  85. }
  86.  
  87. print_record (extra)
  88. char         *extra;
  89. {
  90.    printf (" %s [ %s ]\n", str, extra);
  91. }
  92.  
  93. /*
  94.  
  95. LOOK UP A SPECIFIC RECORD:
  96.    mb_sel (f, idx, str, EQUAL, "comparison|");
  97.  
  98. UPDATE CURRENT RECORD:
  99.    sprintf (str, "%s", "<type in your new record value here>");
  100.    mb_upd (f, str);
  101.  
  102. DELETE CURRENT RECORD:
  103.    mb_del (f, 0);       The 0 is so you can't compile if you've confused
  104.                         mb_del with mb_rmv
  105.  
  106. RETRIEVE CURRENT RECORD:
  107.    mb_sel (f, idx, str, CURR, "");
  108.    print_record ();
  109.  
  110. */
  111.  
  112.