home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / slurp103.zip / HISTORY.C < prev    next >
C/C++ Source or Header  |  1992-12-20  |  1KB  |  100 lines

  1. /*
  2.  * history - handle a news history file
  3.  *
  4.  * Copyright (C) 1992 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.  * 1.00  30 Sep 92  SH  Initial coding.
  14.  *
  15.  */
  16.  
  17. #include "slurp.h"
  18.  
  19. #ifdef DBM
  20.   #undef NULL
  21.   #include <dbm.h>
  22.   #undef NULL
  23.   #define NULL 0
  24. #endif
  25.  
  26. #ifdef DBZ
  27.   #include <dbz.h>
  28.   #define DBM
  29. #endif
  30.  
  31. #ifdef NDBM
  32.   #include <ndbm.h>
  33.   #include <fcntl.h>
  34.   static DBM *db = NULL;
  35. #endif
  36.  
  37.  
  38. /*
  39.  * open_history - Open history file
  40.  */
  41.  
  42.     int
  43. open_history ()
  44.     {
  45. #ifdef DBM
  46.     if (dbminit (HISTORY_FILE) < 0)
  47.         return (1);
  48. #endif
  49.  
  50. #ifdef NDBM
  51.      if ((db = dbm_open (HISTORY_FILE, O_RDONLY, 0)) == NULL)
  52.         return (1);
  53. #endif
  54.  
  55.     return (0);
  56.     }
  57.  
  58.  
  59. /*
  60.  * close_history - Close history file
  61.  */
  62.  
  63.     void
  64. close_history ()
  65.     {
  66. #ifdef DBM
  67.     (void) dbmclose ();
  68. #endif
  69.  
  70. #ifdef NDBM
  71.      dbm_close (db);
  72. #endif
  73.     }
  74.  
  75.  
  76. /*
  77.  * Determine if message id already exists in the history file
  78.  */
  79.  
  80.     int
  81. check_id (char *message_id)
  82.     {
  83.     datum k, d;
  84.  
  85. /* Now check for presence with dbm/ndbm */
  86.  
  87.     k.dptr = message_id;
  88.     k.dsize = strlen (message_id) + 1;
  89.  
  90. #ifdef DBM
  91.     d = fetch (k);
  92. #else
  93.      d = dbm_fetch (db, k);
  94. #endif
  95.  
  96.     return (d.dptr == NULL);
  97.     }
  98.  
  99. /* END-OF-FILE */
  100.