home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / slurp / part02 / history.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  1.6 KB  |  107 lines

  1. /*
  2.  * history - handle a news history file
  3.  *
  4.  * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  5.  * TQM Communications, BCM Box 225, London, WC1N 3XX.
  6.  * steveh@orbital.demon.co.uk  +44 836 825962
  7.  *
  8.  * See README for more information and disclaimers
  9.  *
  10.  * Routines to open and close a C-News style history file and determine
  11.  * whether or not a particular message id exists in the history file.
  12.  *
  13.  * $Id: history.c,v 1.4 1993/02/14 14:51:59 root Exp $
  14.  *
  15.  * $Log: history.c,v $
  16.  * Revision 1.4  1993/02/14  14:51:59  root
  17.  * No changes.
  18.  *
  19.  * Revision 1.0  1992/09/92
  20.  * Initial coding.
  21.  *
  22.  */
  23.  
  24. #include "slurp.h"
  25.  
  26. #ifdef DBM
  27.   #undef NULL
  28.   #include <dbm.h>
  29.   #undef NULL
  30.   #define NULL 0
  31. #endif
  32.  
  33. #ifdef DBZ
  34.   #include <dbz.h>
  35.   #define DBM
  36. #endif
  37.  
  38. #ifdef NDBM
  39.   #include <ndbm.h>
  40.   #include <fcntl.h>
  41.   static DBM *db = NULL;
  42. #endif
  43.  
  44.  
  45. /*
  46.  * open_history - Open history file
  47.  */
  48.  
  49.     int
  50. open_history ()
  51.     {
  52. #ifdef DBM
  53.     if (dbminit (HISTORY_FILE) < 0)
  54.         return (1);
  55. #endif
  56.  
  57. #ifdef NDBM
  58.      if ((db = dbm_open (HISTORY_FILE, O_RDONLY, 0)) == NULL)
  59.         return (1);
  60. #endif
  61.  
  62.     return (0);
  63.     }
  64.  
  65.  
  66. /*
  67.  * close_history - Close history file
  68.  */
  69.  
  70.     void
  71. close_history ()
  72.     {
  73. #ifdef DBM
  74.     (void) dbmclose ();
  75. #endif
  76.  
  77. #ifdef NDBM
  78.      dbm_close (db);
  79. #endif
  80.     }
  81.  
  82.  
  83. /*
  84.  * Determine if message id already exists in the history file
  85.  */
  86.  
  87.     int
  88. check_id (char *message_id)
  89.     {
  90.     datum k, d;
  91.  
  92. /* Now check for presence with dbm/ndbm */
  93.  
  94.     k.dptr = message_id;
  95.     k.dsize = strlen (message_id) + 1;
  96.  
  97. #ifdef DBM
  98.     d = fetch (k);
  99. #else
  100.      d = dbm_fetch (db, k);
  101. #endif
  102.  
  103.     return (d.dptr == NULL);
  104.     }
  105.  
  106. /* END-OF-FILE */
  107.