Beispiel #1
0
LocalLinkSetPtr LIBCALL BSPtoLSP(ByteStorePtr bsp)
 {
	LocalLinkSetPtr lsp;

     if (bsp == NULL)
     {
         ErrPostEx(SEV_ERROR,0,0, "Invalid parameter.");
         return NULL;
     }
     if(BSLen(bsp) == 0)
     {
         ErrPostEx(SEV_ERROR,0,0, "Byte store contains no data.");
         return NULL;
     }
     lsp = LocalLinkSetNew();
	 if(lsp == NULL)
	 {
	   ErrPostEx(SEV_ERROR,0,0, "LocalLinkSetNew failed.");
	   return NULL;
	
	 }	
	
     lsp->num = BSLen(bsp) / sizeof(DocUid);
     if ((lsp->uids = MemNew(BSLen(bsp))) == NULL)
     {
         /* platforms which can't allocate this are out of luck */
         ErrPostEx(SEV_ERROR,0,0, "Cannot allocate memory for LinkSet");
         lsp = LocalLinkSetFree(lsp);
         return NULL;
     }
     else
     {
        BSSeek (bsp, 0L, 0);
        BSRead (bsp, lsp->uids, lsp->num * sizeof (DocUid));
     }
    return lsp;
}
Beispiel #2
0
DocUid LIBCALL  ReadItem (PostingPtr pst)

{
  DocUid  rsult;

  rsult = INT4_MAX;
  if (pst != NULL && pst->uids != NULL) {
    if (pst->buffer == NULL) {
      pst->buffer = MemNew ((size_t) pst->bufsize);
      pst->count = 0;
      pst->index = 0;
    }
    if (pst->count <= 0) {
      pst->count = (Int4) BSRead (pst->uids, pst->buffer, pst->bufsize);
      pst->index = 0;
    }
    if (pst->count > 0) {
      rsult = pst->buffer [pst->index];
      (pst->index)++;
      (pst->count) -= sizeof (DocUid);
    }
  }
  return rsult;
}
Beispiel #3
0
static Int4 BEGetUidsFromQuery(CharPtr query, Uint4Ptr PNTR uids, 
                               Boolean is_na, Boolean count_only)
{
    Entrez2ReplyPtr e2ry;
    Entrez2RequestPtr  e2rq;
    E2ReplyPtr e2rp;
    Int4 count = 0, i;
    Entrez2BooleanReplyPtr e2br;
    Entrez2IdListPtr e2idlist;
    
    *uids = NULL;
    
    EntrezSetProgramName ("BLAST API");
    /* EntrezSetServer ("www.ncbi.nlm.nih.gov", 80, 
                     "/entrez/utils/entrez2server.fcgi"); */
    
    e2rq = EntrezCreateBooleanRequest (!count_only, FALSE, 
                                       is_na? "Nucleotide" : "Protein", 
                                       query, 0, 0, NULL, 0, 0);
    
    e2ry = EntrezSynchronousQuery (e2rq);
    
    if (e2ry == NULL) {
        ErrPostEx(SEV_ERROR, 0, 0, 
                  "NULL returned from EntrezSynchronousQuery()");
        return -1;
    }

    if((e2rp = e2ry->reply) == NULL) {
        ErrPostEx(SEV_ERROR, 0, 0, "Invalid ASN.1: E2ReplyPtr==NULL");
        return -1;
    }
    
    switch(e2rp->choice) {
        
    case E2Reply_error:
        ErrPostEx(SEV_ERROR, 0, 0, (CharPtr) e2rp->data.ptrvalue);
        count = -1;
        break;
    case E2Reply_eval_boolean:
        e2br = (Entrez2BooleanReplyPtr) e2rp->data.ptrvalue;
        count = e2br->count;
        if((e2idlist = e2br->uids) != NULL) {
            count = e2idlist->num;
            *uids = MemNew(sizeof(Int4)*count);
            BSSeek((ByteStorePtr) e2idlist->uids, 0, SEEK_SET);
            BSRead((ByteStorePtr) e2idlist->uids, *uids, sizeof(Int4)*count);

        }
        break;
    default:
        ErrPostEx(SEV_ERROR, 0, 0, "Invalid reply type from the server: %d", e2rp->choice);
        count = -1;
        break;
        
    }

    Entrez2ReplyFree(e2ry);
    Entrez2RequestFree(e2rq);

    return count;
}