home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / SQ_KILL.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  4KB  |  122 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. #pragma off(unreferenced)
  25. static char rcs_id[]="$Id: sq_kill.c 1.2 1993/12/30 00:48:46 sjd Exp sjd $";
  26. #pragma on(unreferenced)
  27.  
  28. #define MSGAPI_HANDLERS
  29. #define MSGAPI_NO_OLD_TYPES
  30.  
  31. #include <assert.h>
  32. #include "prog.h"
  33. #include "msgapi.h"
  34. #include "api_sq.h"
  35. #include "apidebug.h"
  36.  
  37.  
  38. /* Kill the specified message number.                                       *
  39.  *                                                                          *
  40.  * This function assumes that we have exclusive access to the Squish base.  */
  41.  
  42. static sword _SquishKill(HAREA ha, dword dwMsg, SQHDR *psqh, FOFS fo)
  43. {
  44.   assert(Sqd->fHaveExclusive);
  45.  
  46.  
  47.   /* Link the existing messages over this one */
  48.  
  49.   if (psqh->prev_frame)
  50.     if (!_SquishSetFrameNext(ha, psqh->prev_frame, psqh->next_frame))
  51.       return FALSE;
  52.  
  53.   if (psqh->next_frame)
  54.     if (!_SquishSetFramePrev(ha, psqh->next_frame, psqh->prev_frame))
  55.       return FALSE;
  56.  
  57.  
  58.   /* Delete this message from the index file */
  59.  
  60.   if (!_SquishRemoveIndexEntry(Sqd->hix, dwMsg, NULL, psqh, TRUE))
  61.     return FALSE;
  62.  
  63.  
  64.   /* Finally, add the freed message to the free frame list */
  65.  
  66.   return (sword)_SquishInsertFreeChain(ha, fo, psqh);
  67. }
  68.  
  69.  
  70.  
  71. /* This function is used to delete a message from a Squish message base */
  72.  
  73. sword MAPIENTRY SquishKillMsg(HAREA ha, dword dwMsg)
  74. {
  75.   SQHDR sqh;
  76.   sword rc;
  77.   FOFS fo;
  78.  
  79.   /* Validate parameters */
  80.  
  81.   if (MsgInvalidHarea(ha))
  82.     return -1;
  83.  
  84.  
  85.   /* Make sure that the message actually exists */
  86.  
  87.   if (dwMsg==0 || dwMsg > ha->num_msg)
  88.   {
  89.     msgapierr=MERR_NOENT;
  90.     return -1;
  91.   }
  92.  
  93.   /* Get the offset of the frame to delete */
  94.  
  95.   if ((fo=_SquishGetFrameOfs(ha, dwMsg))==NULL_FRAME)
  96.     return -1;
  97.  
  98.  
  99.   /* Read that into memory */
  100.  
  101.   if (!_SquishReadHdr(ha, fo, &sqh))
  102.     return -1;
  103.  
  104.  
  105.   /* Now get exclusive access for the delete operation */
  106.  
  107.   if (!_SquishExclusiveBegin(ha))
  108.     return FALSE;
  109.  
  110.   /* Let _SquishKill to the dirty work */
  111.  
  112.   rc=_SquishKill(ha, dwMsg, &sqh, fo);
  113.  
  114.   /* Let go of the base */
  115.  
  116.   if (!_SquishExclusiveEnd(ha))
  117.     rc=FALSE;
  118.  
  119.   return rc ? 0 : -1;
  120. }
  121.  
  122.