home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / index.lzh / IDELETE.C < prev    next >
Text File  |  1988-02-02  |  2KB  |  53 lines

  1. /*
  2.  * IDELETE.C - delete a record
  3.  *
  4.  *                      Copyright (c) 1987, Jim Mischel
  5.  *
  6.  * Modifications:
  7.  *
  8.  * 08/13/87 - jim - initial coding
  9.  * 02/02/88 - jim - having some trouble changing thread pointers.  So, until
  10.  *                  I can get it fixed, the routine just flags the record
  11.  *                  as deleted and lets the other routines worry about
  12.  *                  checking for deleted records.
  13.  */
  14.  
  15. #include "inxdefs.h"
  16.  
  17. /*
  18.  * idelete() - remove the current record from the data stream.  The data
  19.  * record is not actually removed from the file and the index record is not
  20.  * removed from the index file.  The index pointers are adjusted so that
  21.  * they skip over the index for this record.
  22.  * Returns 0 if successful, error status otherwise.  If the key at 'source'
  23.  * is not the same as the key in the current data record, I_INVKEY is
  24.  * returned and no action is taken.  Since the only integrity check
  25.  * made is a simple key comparison, if duplicate keys are permitted, it
  26.  * is possible to delete the wrong record.
  27.  */
  28. int idelete(void *d, void *src)
  29. {
  30.   register df_rec *db_control = (df_rec *)d;
  31.   char *source = (char *)src;
  32.  
  33.   /* see if record has already been deleted */
  34.   if (db_control->df_flags & DF_DELETE)
  35.     return(ierror(I_INVKEY));
  36.  
  37.   /* see if keys are equal */
  38.   if ((*db_control->df_cmp)((source+db_control->df_key_offset),
  39.                             db_control->df_key_ptr))
  40.     return(ierror(I_INVKEY));           /* error: keys not equal */
  41.  
  42.   /*
  43.    * Since I've been having problems adjusting node pointers,
  44.    * I'll just flag the record as deleted and let all the other
  45.    * routines worry about handling deleted records.
  46.    */
  47.   db_control->df_inx_buff.if_flags |= DELETED_REC;
  48.   if (iwrite_inx(db_control,&db_control->df_inx_buff,db_control->df_inx_ptr))
  49.     return(ierrno);
  50.   db_control->df_flags |= DF_DELETE;    /* flag record as deleted */
  51.   return(0);
  52. } /* idelete */
  53.