/*************************************************************************************************
 * qdbmtest
 * Writing test of QDBM
 *************************************************************************************************/


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

#define LOOPNUM     1000000
#define BUCETNUM    2000000
#define DBNAME      "casket.qdbm"


/* function prototypes */
int main(int argc, char **argv);


/* main routine */
int main(int argc, char **argv){
  DEPOT *depot;
  int i, len;
  char buf[32];
  if(!(depot = dpopen(DBNAME, DP_OWRITER | DP_OCREAT | DP_OTRUNC, BUCETNUM))){
    fprintf(stderr, "%s: %s: %s\n", argv[0], DBNAME, dperrmsg(dpecode));
    exit(1);
  }
  for(i = 1; i <= LOOPNUM; i++){
    len = sprintf(buf, "%08d", i);
    if(!dpput(depot, buf, len, buf, len, DP_DOVER)){
      fprintf(stderr, "%s: %s: %s\n", argv[0], DBNAME, dperrmsg(dpecode));
      break;
    }
    if(LOOPNUM > 250 && i % (LOOPNUM / 250) == 0){
      putchar('.');
      fflush(stdout);
      if(i == LOOPNUM || i % (LOOPNUM / 10) == 0){
        printf(" (%08d)\n", i);
        fflush(stdout);
      }
    }
  }
  if(!dpclose(depot)){
    fprintf(stderr, "%s: %s: %s\n", argv[0], DBNAME, dperrmsg(dpecode));
  }
  return 0;
}



/* END OF FILE */
