1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/***************************************************************************
* *
* Squish Developers Kit Source, Version 2.00 *
* Copyright 1989-1994 by SCI Communications. All rights reserved. *
* *
* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE *
* SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN. IF YOU DO NOT *
* FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU *
* DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT *
* ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO *
* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH *
* DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
* ABLE TO REACH WITH THE AUTHOR. *
* *
* You can contact the author at one of the address listed below: *
* *
* Scott Dudley FidoNet 1:249/106 *
* 777 Downing St. Internet sjd@f106.n249.z1.fidonet.org *
* Kingston, Ont. CompuServe >INTERNET:sjd@f106.n249.z1.fidonet.org *
* Canada K7M 5N3 BBS 1-613-634-3058, V.32bis *
* *
***************************************************************************/
/*
#pragma off(unreferenced)
static char rcs_id[]="$Id: sq_misc.c,v 1.8 2003/01/15 05:41:19 stas_degteff Exp $";
#pragma on(unreferenced)
*/
#define MSGAPI_HANDLERS
#define MSGAPI_NO_OLD_TYPES
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include "compiler.h"
#ifdef HAS_IO_H
# include <io.h>
#endif
#ifdef HAS_SHARE_H
#include <share.h>
#endif
#ifdef HAS_MALLOC_H
#include <malloc.h>
#endif
#include "prog.h"
#include "old_msg.h"
#include "msgapi.h"
#include "api_sq.h"
#include "api_sqp.h"
#include "apidebug.h"
#include "unused.h"
/* Set the "current position" pointer in a message handle */
sword _XPENTRY apiSquishSetCurPos(HMSG hmsg, dword dwOfs)
{
if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
return -1;
hmsg->cur_pos=dwOfs;
return 0;
}
/* Return the current read position within a message */
dword _XPENTRY apiSquishGetCurPos(HMSG hmsg)
{
if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
return (dword)-1;
return hmsg->cur_pos;
}
/* Return the length of the text body of this message */
dword _XPENTRY apiSquishGetTextLen(HMSG hmsg)
{
if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
return (dword)-1L;
return hmsg->sqhRead.msg_length - XMSG_SIZE - hmsg->sqhRead.clen;
}
/* Return the length of this message's control information */
dword _XPENTRY apiSquishGetCtrlLen(HMSG hmsg)
{
if (MsgInvalidHmsg(hmsg) || !_SquishReadMode(hmsg))
return (dword)-1L;
return hmsg->sqhRead.clen;
}
/* Return the number of the high water marker */
dword _XPENTRY apiSquishGetHighWater(HAREA ha)
{
if (MsgInvalidHarea(ha))
return (dword)-1L;
return apiSquishUidToMsgn(ha, ha->high_water, UID_PREV);
}
/* Set the high water marker for this area */
sword _XPENTRY apiSquishSetHighWater(HAREA ha, dword dwMsg)
{
if (MsgInvalidHarea(ha))
return -1;
/* Make sure that the message exists */
if (dwMsg > ha->num_msg)
{
msgapierr=MERR_NOENT;
return -1;
}
if (!_SquishExclusiveBegin(ha))
return -1;
ha->high_water=apiSquishMsgnToUid(ha, dwMsg);
if (!_SquishExclusiveEnd(ha))
{
return -1;
}
return 0;
}
/* Function to set the highest/skip message numbers for a *.SQ? base */
void _XPENTRY apiSquishSetMaxMsg(HAREA ha, dword dwMaxMsgs, dword dwSkipMsgs, dword dwMaxDays)
{
if (MsgInvalidHarea(ha))
return;
/* Update base only if max msg settings have changed */
if ((dwMaxMsgs != (dword)-1L && dwMaxMsgs != Sqd->dwMaxMsg) ||
(dwSkipMsgs != (dword)-1L && dwSkipMsgs != Sqd->wSkipMsg) ||
(dwMaxDays != (dword)-1L && dwMaxDays != Sqd->wMaxDays))
{
if (!_SquishExclusiveBegin(ha))
{
return;
}
if (dwMaxMsgs != (dword)-1L)
Sqd->dwMaxMsg=dwMaxMsgs;
if (dwSkipMsgs != (dword)-1L)
Sqd->wSkipMsg=(word)dwSkipMsgs;
if (dwMaxDays != (dword)-1L)
Sqd->wMaxDays=(word)dwMaxDays;
(void)_SquishExclusiveEnd(ha);
}
}
void _XPENTRY apiSquishGetMaxMsg(HAREA ha, dword *dwMaxMsgs, dword *dwSkipMsgs, dword *dwMaxDays)
{
if (MsgInvalidHarea(ha))
return;
if (dwMaxMsgs)
*dwMaxMsgs = Sqd->dwMaxMsg;
if (dwSkipMsgs)
*dwSkipMsgs = (dword) Sqd->wSkipMsg;
if (dwMaxDays)
*dwMaxDays = (dword) Sqd->wMaxDays;
}
/* Hash function used for calculating the hashes in the .sqi file */
dword _XPENTRY SquishHash(byte *f)
{
dword hash=0, g;
while (*f)
{
hash=(hash << 4) + (dword)tolower(*f);
if ((g=(hash & 0xf0000000L)) != 0L)
{
hash |= g >> 24;
hash |= g;
}
f++;
}
/* Strip off high bit */
return (hash & 0x7fffffffLu);
}
|