⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htvms_waisprot.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 5 页
字号:
    { case CT_document:	/* do nothing - there is no chunk data */	break;      case CT_byte:      case CT_line:	buf = writeNum(doc->ChunkCode,DT_ChunkCode,buf,len);	buf = writeNum(doc->ChunkStart.Pos,DT_ChunkStartID,buf,len);	buf = writeNum(doc->ChunkEnd.Pos,DT_ChunkEndID,buf,len);	break;      case CT_paragraph:	buf = writeNum(doc->ChunkCode,DT_ChunkCode,buf,len);	buf = writeAny(doc->ChunkStart.ID,DT_ChunkStartID,buf,len);	buf = writeAny(doc->ChunkEnd.ID,DT_ChunkEndID,buf,len);	break;      default:	panic("Implementation error: unknown chuck type %ld",	      doc->ChunkCode);	break;      }     return(buf);}/*----------------------------------------------------------------------*/static char* readDocObj PARAMS((DocObj** doc,char* buffer));static char*readDocObj(doc,buffer)DocObj** doc;char* buffer;/* read whatever we have about the new document */{  char* buf = buffer;  data_tag tag;    *doc = (DocObj*)s_malloc((size_t)sizeof(DocObj));    tag = peekTag(buf);  buf = readAny(&((*doc)->DocumentID),buf);    if (tag == DT_DocumentID)    { (*doc)->ChunkCode = CT_document;      tag = peekTag(buf);      if (tag == DT_TYPE)	/* XXX depends on DT_TYPE != what comes next */	buf = readString(&((*doc)->Type),buf);      /* ChunkStart and ChunkEnd are undefined */    }  else if (tag == DT_DocumentIDChunk)    { boolean readParagraphs = false; /* for cleanup */      tag = peekTag(buf);      if (tag == DT_TYPE)	/* XXX depends on DT_TYPE != CT_FOO */	buf = readString(&((*doc)->Type),buf);      buf = readNum(&((*doc)->ChunkCode),buf);      switch ((*doc)->ChunkCode)	{ case CT_byte:	  case CT_line:	    buf = readNum(&((*doc)->ChunkStart.Pos),buf);	    buf = readNum(&((*doc)->ChunkEnd.Pos),buf);	    break;	  case CT_paragraph:	    readParagraphs = true;	    buf = readAny(&((*doc)->ChunkStart.ID),buf);	    buf = readAny(&((*doc)->ChunkEnd.ID),buf);	    break;	  default:	    freeAny((*doc)->DocumentID);	    if (readParagraphs)	      { freeAny((*doc)->ChunkStart.ID);		freeAny((*doc)->ChunkEnd.ID);	      }	    s_free(doc);	    REPORT_READ_ERROR(buf);	    break;	  }    }  else    { freeAny((*doc)->DocumentID);      s_free(*doc);      REPORT_READ_ERROR(buf);    }  return(buf);  }/*----------------------------------------------------------------------*/char* writeSearchInfo(query,buffer,len)SearchAPDU* query;char* buffer;long* len;/* write out a WAIS query (type 1 or 3) */{  if (strcmp(query->QueryType,QT_TextRetrievalQuery) == 0)    { return(writeAny((any*)query->Query,DT_Query,buffer,len));    }  else    { unsigned long header_len = userInfoTagSize(DT_UserInformationLength,						 DefWAISSearchSize);       char* buf = buffer + header_len;      WAISSearch* info = (WAISSearch*)query->Query;      unsigned long size;      long i;        RESERVE_SPACE_FOR_WAIS_HEADER(len);             buf = writeString(info->SeedWords,DT_SeedWords,buf,len);      if (info->Docs != NULL)      { for (i = 0; info->Docs[i] != NULL; i++)	  { buf = writeDocObj(info->Docs[i],buf,len);	  }	}         /* XXX text list */       buf = writeNum(info->DateFactor,DT_DateFactor,buf,len);      buf = writeString(info->BeginDateRange,DT_BeginDateRange,buf,len);      buf = writeString(info->EndDateRange,DT_EndDateRange,buf,len);      buf = writeNum(info->MaxDocumentsRetrieved,DT_MaxDocumentsRetrieved,buf,len);        /* now write the header and size */      size = buf - buffer;       buf = writeUserInfoHeader(DT_UserInformationLength,size,header_len,buffer,len);         return(buf);    }}/*----------------------------------------------------------------------*/char* readSearchInfo(info,buffer)void** info;char* buffer;/* read a WAIS query (type 1 or 3) */{  data_tag type = peekTag(buffer);  if (type == DT_Query)		/* this is a type 1 query */    { char* buf = buffer;      any* query = NULL;      buf = readAny(&query,buf);      *info = (void *)query;      return(buf);    }  else				/* a type 3 query */    { char* buf = buffer;      unsigned long size;       unsigned long headerSize;      data_tag tag1;      char* seedWords = NULL;      char* beginDateRange = NULL;      char* endDateRange = NULL;      long dateFactor,maxDocsRetrieved;      char** textList = NULL;       DocObj** docIDs = NULL;      DocObj* doc = NULL;      long docs = 0;      long i;      void* ptr = NULL;      dateFactor = maxDocsRetrieved = UNUSED;        buf = readUserInfoHeader(&tag1,&size,buf);      headerSize = buf - buffer;        while (buf < (buffer + size + headerSize))	{ data_tag tag = peekTag(buf);	  switch (tag)	    { case DT_SeedWords:		buf = readString(&seedWords,buf);		break;	      case DT_DocumentID:	      case DT_DocumentIDChunk:		if (docIDs == NULL) /* create a new doc list */		  { docIDs = (DocObj**)s_malloc((size_t)sizeof(DocObj*) * 2);		  }		else		/* grow the doc list */		  { docIDs = (DocObj**)s_realloc((char*)docIDs,(size_t)(sizeof(DocObj*) * (docs + 2)));		  }		buf = readDocObj(&doc,buf);		if (buf == NULL) 		  { s_free(seedWords);		    s_free(beginDateRange);		    s_free(endDateRange);		    if (docIDs != NULL)		      for (i = 0,ptr = (void *)docIDs[i]; ptr != NULL; ptr = (void *)docIDs[++i])			freeDocObj((DocObj*)ptr);		    s_free(docIDs);		    /* XXX should also free textlist when it is fully defined */		  }		RETURN_ON_NULL(buf);		docIDs[docs++] = doc; /* put it in the list */		docIDs[docs] = NULL;		break;	      case DT_TextList:		/* XXX */		break;	      case DT_DateFactor:		buf = readNum(&dateFactor,buf);		break;	      case DT_BeginDateRange:		buf = readString(&beginDateRange,buf);		break;	      case DT_EndDateRange:		buf = readString(&endDateRange,buf);		break;	      case DT_MaxDocumentsRetrieved:		buf = readNum(&maxDocsRetrieved,buf);		break;	      default:		s_free(seedWords);		s_free(beginDateRange);		s_free(endDateRange);		if (docIDs != NULL)		  for (i = 0,ptr = (void *)docIDs[i]; ptr != NULL; ptr = (void *)docIDs[++i])		    freeDocObj((DocObj*)ptr);		s_free(docIDs);		/* XXX should also free textlist when it is fully defined */		REPORT_READ_ERROR(buf);		break;	      }	}  	        *info = (void *)makeWAISSearch(seedWords,docIDs,textList,				     dateFactor,beginDateRange,endDateRange,				     maxDocsRetrieved);      return(buf);    }}/*----------------------------------------------------------------------*/WAISDocumentHeader*makeWAISDocumentHeader(docID,		       versionNumber,		       score,		       bestMatch,		       docLen,		       lines,		       types,		       source,		       date,		       headline,		       originCity)any* docID;long versionNumber;long score;long bestMatch;long docLen;long lines;char** types;char* source;char* date;char* headline;char* originCity;/* construct a standard document header, note that no fields are copied!   if the application needs to save these fields, it should copy them,   or set the field in this object to NULL before freeing it. */{  WAISDocumentHeader* header =     (WAISDocumentHeader*)s_malloc((size_t)sizeof(WAISDocumentHeader));  header->DocumentID = docID;  header->VersionNumber = versionNumber;  header->Score = score;  header->BestMatch = bestMatch;  header->DocumentLength = docLen;  header->Lines = lines;  header->Types = types;  header->Source = source;  header->Date = date;  header->Headline = headline;  header->OriginCity = originCity;    return(header);}/*----------------------------------------------------------------------*/voidfreeWAISDocumentHeader(header)WAISDocumentHeader* header;{  freeAny(header->DocumentID);  doList((void**)header->Types,fs_free); /* can't use the macro here ! */  s_free(header->Types);  s_free(header->Source);  s_free(header->Date);  s_free(header->Headline);  s_free(header->OriginCity);  s_free(header);}/*----------------------------------------------------------------------*/char*writeWAISDocumentHeader(header,buffer,len)WAISDocumentHeader* header;char* buffer;long* len;{  unsigned long header_len = userInfoTagSize(DT_DocumentHeaderGroup ,					     DefWAISDocHeaderSize);  char* buf = buffer + header_len;  unsigned long size1;    RESERVE_SPACE_FOR_WAIS_HEADER(len);     buf = writeAny(header->DocumentID,DT_DocumentID,buf,len);  buf = writeNum(header->VersionNumber,DT_VersionNumber,buf,len);  buf = writeNum(header->Score,DT_Score,buf,len);  buf = writeNum(header->BestMatch,DT_BestMatch,buf,len);  buf = writeNum(header->DocumentLength,DT_DocumentLength,buf,len);  buf = writeNum(header->Lines,DT_Lines,buf,len);  if (header->Types != NULL)    { long size;      char* ptr = NULL;      long i;      buf = writeTag(DT_TYPE_BLOCK,buf,len);      for (i = 0,size = 0,ptr = header->Types[i]; ptr != NULL; ptr = header->Types[++i])	{ long typeSize = strlen(ptr);	  size += writtenTagSize(DT_TYPE);	  size += writtenCompressedIntSize(typeSize);	  size += typeSize; 	}      buf = writeCompressedInteger((unsigned long)size,buf,len);      for (i = 0,ptr = header->Types[i]; ptr != NULL; ptr = header->Types[++i])	buf = writeString(ptr,DT_TYPE,buf,len);    }  buf = writeString(header->Source,DT_Source,buf,len);  buf = writeString(header->Date,DT_Date,buf,len);  buf = writeString(header->Headline,DT_Headline,buf,len);  buf = writeString(header->OriginCity,DT_OriginCity,buf,len);    /* now write the header and size */  size1 = buf - buffer;   buf = writeUserInfoHeader(DT_DocumentHeaderGroup,size1,header_len,buffer,len);  return(buf);}/*----------------------------------------------------------------------*/char*readWAISDocumentHeader(header,buffer)WAISDocumentHeader** header;char* buffer;{  char* buf = buffer;  unsigned long size1;   unsigned long headerSize;  data_tag tag1;  any* docID = NULL;  long versionNumber,score,bestMatch,docLength,lines;  char** types = NULL;  char *source = NULL;  char *date = NULL;  char *headline = NULL;  char *originCity = NULL;    versionNumber = score = bestMatch = docLength = lines = UNUSED;    buf = readUserInfoHeader(&tag1,&size1,buf);  headerSize = buf - buffer;      while (buf < (buffer + size1 + headerSize))    { data_tag tag = peekTag(buf);      switch (tag)	{ case DT_DocumentID:	    buf = readAny(&docID,buf);	    break;	  case DT_VersionNumber:	    buf = readNum(&versionNumber,buf);	    break;	  case DT_Score:	    buf = readNum(&score,buf);	    break;	  case DT_BestMatch:	    buf = readNum(&bestMatch,buf);	    break;	  case DT_DocumentLength:	    buf = readNum(&docLength,buf);	    break;	  case DT_Lines:	    buf = readNum(&lines,buf);	    break;	  case DT_TYPE_BLOCK:	    { unsigned long size = -1;	      long numTypes = 0;	      buf = readTag(&tag,buf);	      buf = readCompressedInteger(&size,buf);	      while (size > 0)		{ char* type = NULL;		  char* originalBuf = buf;		  buf = readString(&type,buf);		  types = (char**)s_realloc(types,(size_t)(sizeof(char*) * (numTypes + 2)));		  types[numTypes++] = type;		  types[numTypes] = NULL;		  size -= (buf - originalBuf);		}	    }	    /* FALLTHRU */	  case DT_Source:	    buf = readString(&source,buf);	    break;	  case DT_Date:	    buf = readString(&date,buf);	    break;	  case DT_Headline:	    buf = readString(&headline,buf);	    break;	  case DT_OriginCity:	    buf = readString(&originCity,buf);	    break;	  default:	    freeAny(docID);	    s_free(source);	    s_free(date);	    s_free(headline);	    s_free(originCity);	    REPORT_READ_ERROR(buf);	    break;	  }    }  	    *header = makeWAISDocumentHeader(docID,versionNumber,score,bestMatch,				   docLength,lines,types,source,date,headline,				   originCity);  return(buf);}/*----------------------------------------------------------------------*/WAISDocumentShortHeader*makeWAISDocumentShortHeader(docID,			    versionNumber,			    score,			    bestMatch,			    docLen,			    lines)any* docID;long versionNumber;long score;long bestMatch;long docLen;long lines;/* construct a short document header, note that no fields are copied!   if the application needs to save these fields, it should copy them,   or set the field in this object to NULL before freeing it. */{  WAISDocumentShortHeader* header = 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -