TIP: Click on subject to list as thread! ANSI
echo: public_domain
to: andrew clarke
from: Paul Edwards
date: 1995-09-10 12:35:58
subject: msgapi38 mod

Mod to api_sq.c ...


static dword EXPENTRY SquishUidToMsgn(MSG *sq, UMSGID umsgid, word type)
{
  UMSGID answer;
  word getbuf;
  size_t mn;
  size_t diff;
  int found;

  if (InvalidMh(sq))
    return 0L;

  if (umsgid==0L)
    return ((dword)0L);

  if (sq->locked)
    getbuf=FALSE;
  else
  {
    getbuf=TRUE;

    if (_SquishReadIndex(sq)==-1)
      return 0L;
  }
  
  answer=(UMSGID)0L;

  if (sq->num_msg > 0)
  {
      found = 0;
      diff = sq->num_msg / 2;
      mn = diff;
      while (!found)
      {
          if (Sqd->idxbuf[mn].umsgid == umsgid)
          {
              found = 1;
              break;
          }
          else 
          {
              if (diff == 1) break;
              if ((diff % 2) != 0)
              {
                  diff++;
              }
              diff /= 2;
              if (Sqd->idxbuf[mn].umsgid > umsgid)
              {
                  mn -= diff;
              }
              else
              {
                  mn += diff;
              }
          }
      }
      if (!found)
      {
          if (type == UID_NEXT)
          {
              if (Sqd->idxbuf[mn].umsgid >= umsgid)
              {
                  found = 1;
              }
              else if ((mn + 1) num_msg)
              {
                  mn++;
                  if (Sqd->idxbuf[mn].umsgid >= umsgid)
                  {
                      found = 1;
                  }
              }
          }
          else if (type == UID_PREV)
          {
              if (Sqd->idxbuf[mn].umsgid <= umsgid)
              {
                  found = 1;
              }
              else if (mn > 0)
              {
                  mn--;
                  if (Sqd->idxbuf[mn].umsgid <= umsgid)
                  {
                      found = 1;
                  }
              }
          }
      }
  }

  if (found)
  {
      answer = (UMSGID)(mn + 1);
  }
  else if (type != UID_EXACT)
  {      
    for (mn=0; mn num_msg; mn++)
    {
      /* Scan each element, and if we find a match, return the right value */

      if (Sqd->idxbuf[mn].umsgid==umsgid ||
          (type==UID_NEXT && Sqd->idxbuf[mn].umsgid >= umsgid) ||
          (type==UID_PREV && Sqd->idxbuf[mn].umsgid <= umsgid
&&
           Sqd->idxbuf[mn].umsgid &&
           (mn+1 >= sq->num_msg || Sqd->idxbuf[mn+1].umsgid > umsgid)))
      {
        answer=(UMSGID)(mn+1);
        break;
      }
    }
  }

  if (getbuf && Sqd->idxbuf)
  {
    farpfree(Sqd->idxbuf);
    Sqd->idxbuf=NULL;
  }

  return answer;
}
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.