kd_delete.c
/* this isn't particularly efficient, but deletes aren't all that common. */
this isn't particularly efficient, but deletes aren't all that common.
this isn ' t particularly efficient but deletes aren ' t all that common .
int delete_word_from_worddb(void *e, void *c)
{
   words_elem *we = (words_elem *) e;
   dwfw_state *s = (dwfw_state *) c;
   unsigned char word[256];
   DBC *cursor;
   DBT key, data;
   int i, ret;
   memset(&key, 0, sizeof(key));
   memset(&data, 0, sizeof(data));
   for (i=0; i<we->len && i < sizeof(word); i++)
      word[i] = tolower((we->ptr)[i]);
   key.data = (void *) word;
   key.size = (size_t) we->len;
   data.data = s->entry;
   data.size = 12;
   ret = (*(worddb->cursor))(worddb, s->tid, &cursor, 0);
   if (ret && (ret != DB_NOTFOUND)) {
      s->err->fatal = 1;
      s->err->str = "database read error creating worddb cursor for delete";
      fail();
   }
   if ((ret = (*(cursor->c_get))(cursor, &key, &data, DB_GET_BOTH))) {
     (*(cursor->c_close))(cursor);
     fflush (stdout);
     fprintf(stderr,
	     "warning:  consistency error reading worddb for delete: %.*s not found\n",
	     (int) we->len, we->ptr);
     return (1);
   }
   for (;
	ret == 0;
	ret = (*(cursor->c_get))(cursor, &key, &data, DB_NEXT_DUP)) {
      if (memcmp(data.data, s->entry, 12) != 0)
	 break;
      if ((ret = (*(cursor->c_del))(cursor, 0)))
	 break;
   }
   (*(cursor->c_close))(cursor);
   if (ret && (ret != DB_NOTFOUND)) {
      s->err->fatal = 1;
      sprintf(s->err->buf,
	      "error reading worddb entry for delete (errno = %d)", ret);
      fail();
   }
   return(1);
}
int delete_word_from_worddb ( void * e , void * c ) { words_elem * we = ( words_elem * ) e ; dwfw_state * s = ( dwfw_state * ) c ; unsigned char word [ 256 ] ; DBC * cursor ; DBT key , data ; int i , ret ; memset ( & key , 0 , sizeof ( key ) ) ; memset ( & data , 0 , sizeof ( data ) ) ; for ( i = 0 ; i < we -> len && i < sizeof ( word ) ; i ++ ) word [ i ] = tolower ( ( we -> ptr ) [ i ] ) ; key . data = ( void * ) word ; key . size = ( size_t ) we -> len ; data . data = s -> entry ; data . size = 12 ; ret = ( * ( worddb -> cursor ) ) ( worddb , s -> tid , & cursor , 0 ) ; if ( ret && ( ret != DB_NOTFOUND ) ) { s -> err -> fatal = 1 ; s -> err -> str = " " ; fail ( ) ; } if ( ( ret = ( * ( cursor -> c_get ) ) ( cursor , & key , & data , DB_GET_BOTH ) ) ) { ( * ( cursor -> c_close ) ) ( cursor ) ; fflush ( stdout ) ; fprintf ( stderr , " \n " , ( int ) we -> len , we -> ptr ) ; return ( 1 ) ; } for ( ; ret == 0 ; ret = ( * ( cursor -> c_get ) ) ( cursor , & key , & data , DB_NEXT_DUP ) ) { if ( memcmp ( data . data , s -> entry , 12 ) != 0 ) break ; if ( ( ret = ( * ( cursor -> c_del ) ) ( cursor , 0 ) ) ) break ; } ( * ( cursor -> c_close ) ) ( cursor ) ; if ( ret && ( ret != DB_NOTFOUND ) ) { s -> err -> fatal = 1 ; sprintf ( s -> err -> buf , " " , ret ) ; fail ( ) ; } return ( 1 ) ; }
this isn't particularly efficient, but deletes aren't all that common.
this isn ' t particularly efficient but deletes aren ' t all that common .
/* We can't pass non-fatal error messages back, so we have to print
	them ourselves.  This should be OK since only pksclient does
	deletions. */ /* loop over the matching entries, deleting as we go.  Normally, there
      can be only one matching entry, but there was once a bug which
      would leave extra matches around */