home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / SQ_MISC.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  5KB  |  181 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_misc.c 1.4 1993/12/30 00:49:13 sjd Exp sjd $";
  26. #pragma on(unreferenced)
  27.  
  28. #define MSGAPI_HANDLERS
  29. #define MSGAPI_NO_OLD_TYPES
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33. #include "prog.h"
  34. #include "msgapi.h"
  35. #include "api_sq.h"
  36. #include "apidebug.h"
  37.  
  38. /* Set the "current position" pointer in a message handle */
  39.  
  40. sword MAPIENTRY SquishSetCurPos(HMSG hmsg, dword dwOfs)
  41. {
  42.   if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
  43.     return -1;
  44.  
  45.   hmsg->cur_pos=dwOfs;
  46.   return 0;
  47. }
  48.  
  49.  
  50.  
  51. /* Return the current read position within a message */
  52.  
  53. dword MAPIENTRY SquishGetCurPos(HMSG hmsg)
  54. {
  55.   if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
  56.     return (dword)-1;
  57.  
  58.   return hmsg->cur_pos;
  59. }
  60.  
  61.  
  62. /* Return the length of the text body of this message */
  63.  
  64. dword MAPIENTRY SquishGetTextLen(HMSG hmsg)
  65. {
  66.   if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
  67.     return (dword)-1L;
  68.  
  69.   return hmsg->sqhRead.msg_length - sizeof(XMSG) - hmsg->sqhRead.clen;
  70. }
  71.  
  72.  
  73.  
  74.  
  75. /* Return the length of this message's control information */
  76.  
  77. dword MAPIENTRY SquishGetCtrlLen(HMSG hmsg)
  78. {
  79.   if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
  80.     return (dword)-1L;
  81.  
  82.   return hmsg->sqhRead.clen;
  83. }
  84.  
  85.  
  86. /* Return the number of the high water marker */
  87.  
  88. dword MAPIENTRY SquishGetHighWater(HAREA ha)
  89. {
  90.   if (MsgInvalidHarea(ha))
  91.     return (dword)-1L;
  92.  
  93.   return SquishUidToMsgn(ha, ha->high_water, UID_PREV);
  94. }
  95.  
  96.  
  97.  
  98.  
  99. /* Set the high water marker for this area */
  100.  
  101. sword MAPIENTRY SquishSetHighWater(HAREA ha, dword dwMsg)
  102. {
  103.   if (MsgInvalidHarea(ha))
  104.     return -1;
  105.  
  106.   /* Make sure that the message exists */
  107.  
  108.   if (dwMsg > ha->num_msg)
  109.   {
  110.     msgapierr=MERR_NOENT;
  111.     return -1;
  112.   }
  113.  
  114.   if (!_SquishExclusiveBegin(ha))
  115.     return -1;
  116.  
  117.   ha->high_water=SquishMsgnToUid(ha, dwMsg);
  118.  
  119.   if (!_SquishExclusiveEnd(ha))
  120.     return -1;
  121.  
  122.   return 0;
  123. }
  124.  
  125.  
  126.  
  127. /* Function to set the highest/skip message numbers for a *.SQ? base */
  128.  
  129. void MAPIENTRY SquishSetMaxMsg(HAREA ha, dword dwMaxMsgs, dword dwSkipMsgs, dword dwMaxDays)
  130. {
  131.   if (MsgInvalidHarea(ha))
  132.     return;
  133.  
  134.   /* Update base only if max msg settings have changed */
  135.  
  136.   if ((dwMaxMsgs  != (dword)-1L && dwMaxMsgs  != Sqd->dwMaxMsg) ||
  137.       (dwSkipMsgs != (dword)-1L && dwSkipMsgs != Sqd->wSkipMsg) ||
  138.       (dwMaxDays  != (dword)-1L && dwMaxDays  != Sqd->wMaxDays))
  139.   {
  140.     if (!_SquishExclusiveBegin(ha))
  141.       return;
  142.  
  143.     if (dwMaxMsgs != (dword)-1L)
  144.       Sqd->dwMaxMsg=dwMaxMsgs;
  145.  
  146.     if (dwSkipMsgs != (dword)-1L)
  147.       Sqd->wSkipMsg=(word)dwSkipMsgs;
  148.  
  149.     if (dwMaxDays != (dword)-1L)
  150.       Sqd->wMaxDays=(word)dwMaxDays;
  151.  
  152.     (void)_SquishExclusiveEnd(ha);
  153.   }
  154. }
  155.  
  156.  
  157. /* Hash function used for calculating the hashes in the .sqi file */
  158.  
  159. dword MAPIENTRY SquishHash(byte OS2FAR *f)
  160. {
  161.   dword hash=0, g;
  162.   char *p;
  163.  
  164.   for (p=f; *p; p++)
  165.   {
  166.     hash=(hash << 4) + (dword)tolower(*p);
  167.  
  168.     if ((g=(hash & 0xf0000000L)) != 0L)
  169.     {
  170.       hash |= g >> 24;
  171.       hash |= g;
  172.     }
  173.   }
  174.   
  175.  
  176.   /* Strip off high bit */
  177.  
  178.   return (hash & 0x7fffffffLu);
  179. }
  180.  
  181.