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

📄 htvms_waisprot.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 5 页
字号:
  									       headline,originCity);  return(buf);}/*----------------------------------------------------------------------*/WAISDocumentCodes*makeWAISDocumentCodes(docID,		      versionNumber,		      stockCodes,		      companyCodes,		      industryCodes)any* docID;long versionNumber;char* stockCodes;char* companyCodes;char* industryCodes;{  WAISDocumentCodes* docCodes = (WAISDocumentCodes*)s_malloc((size_t)sizeof(WAISDocumentCodes));  docCodes->DocumentID = docID;  docCodes->VersionNumber = versionNumber;  docCodes->StockCodes = stockCodes;  docCodes->CompanyCodes = companyCodes;  docCodes->IndustryCodes = industryCodes;    return(docCodes);}/*----------------------------------------------------------------------*/void freeWAISDocumentCodes(docCodes)WAISDocumentCodes* docCodes;{  freeAny(docCodes->DocumentID);  s_free(docCodes->StockCodes);  s_free(docCodes->CompanyCodes);  s_free(docCodes->IndustryCodes);  s_free(docCodes);}/*----------------------------------------------------------------------*/char* writeWAISDocumentCodes(docCodes,buffer,len)WAISDocumentCodes* docCodes;char* buffer;long* len;{  unsigned long header_len = userInfoTagSize(DT_DocumentCodeGroup ,											DefWAISDocCodeSize);  char* buf = buffer + header_len;  unsigned long size;    RESERVE_SPACE_FOR_WAIS_HEADER(len);  buf = writeAny(docCodes->DocumentID,DT_DocumentID,buf,len);  buf = writeNum(docCodes->VersionNumber,DT_VersionNumber,buf,len);  buf = writeString(docCodes->StockCodes,DT_StockCodes,buf,len);  buf = writeString(docCodes->CompanyCodes,DT_CompanyCodes,buf,len);  buf = writeString(docCodes->IndustryCodes,DT_IndustryCodes,buf,len);    /* now write the header and size */  size = buf - buffer;   buf = writeUserInfoHeader(DT_DocumentCodeGroup,size,header_len,buffer,len);  return(buf);}/*----------------------------------------------------------------------*/char* readWAISDocumentCodes(docCodes,buffer)WAISDocumentCodes** docCodes;char* buffer;{  char* buf = buffer;  unsigned long size;   unsigned long headerSize;  data_tag tag1;  any* docID;  long versionNumber;  char *stockCodes,*companyCodes,*industryCodes;    docID = NULL;  versionNumber = UNUSED;  stockCodes = companyCodes = industryCodes = NULL;    buf = readUserInfoHeader(&tag1,&size,buf);  headerSize = buf - buffer;      while (buf < (buffer + size + 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_StockCodes:  		  buf = readString(&stockCodes,buf);  		  break;  		case DT_CompanyCodes:  		  buf = readString(&companyCodes,buf);  		  break;  		case DT_IndustryCodes:  		  buf = readString(&industryCodes,buf);  		  break;        default:          freeAny(docID);          s_free(stockCodes);          s_free(companyCodes);          s_free(industryCodes);          REPORT_READ_ERROR(buf);          break;      }   }  	    *docCodes = makeWAISDocumentCodes(docID,versionNumber,stockCodes,  									companyCodes,industryCodes);  return(buf);}/*----------------------------------------------------------------------*/char* writePresentInfo(present,buffer,len)PresentAPDU* present GCC_UNUSED;char* buffer;long* len GCC_UNUSED;{  /* The WAIS protocol doesn't use present info */  return(buffer);}/*----------------------------------------------------------------------*/char* readPresentInfo(info,buffer)void** info;char* buffer;{  /* The WAIS protocol doesn't use present info */  *info = NULL;  return(buffer);}/*----------------------------------------------------------------------*/char* writePresentResponseInfo(response,buffer,len)PresentResponseAPDU* response GCC_UNUSED;char* buffer;long* len GCC_UNUSED;{  /* The WAIS protocol doesn't use presentResponse info */  return(buffer);}/*----------------------------------------------------------------------*/char* readPresentResponseInfo(info,buffer)void** info;char* buffer;{  /* The WAIS protocol doesn't use presentResponse info */  *info = NULL;  return(buffer);}/*----------------------------------------------------------------------*//* support for type 1 queries *//* new use values (for the chunk types) */#define	BYTE		"wb"#define	LINE		"wl"#define	PARAGRAPH	"wp"#define DATA_TYPE	"wt"/* WAIS supports the following semantics for type 1 queries:            1.  retrieve the header/codes from a document:            System_Control_Number = docID            Data Type = type (optional)            And     2.  retrieve a fragment of the text of a document:            System_Control_Number = docID            Data Type = type (optional)            And	    	Chunk >= start	    	And	    	Chunk < end	    	And   		Information from multiple documents may be requested by using    		groups of the above joined by:            OR   		( XXX does an OR come after every group but the first, or do they              all come at the end? )                      ( XXX return type could be in the element set)*/static query_term** makeWAISQueryTerms PARAMS((DocObj** docs));   static query_term**makeWAISQueryTerms(docs)DocObj** docs;/* given a null terminated list of docObjs, construct the appropriate   query of the form given above */{  query_term** terms = NULL;  long numTerms = 0;  DocObj* doc = NULL;  long i;  if (docs == NULL)    return((query_term**)NULL);  terms = (query_term**)s_malloc((size_t)(sizeof(query_term*) * 1));  terms[numTerms] = NULL;  /* loop through the docs making terms for them all */  for (i = 0,doc = docs[i]; doc != NULL; doc = docs[++i])    { any* type = NULL;      if (doc->Type != NULL)	type = stringToAny(doc->Type);      if (doc->ChunkCode == CT_document) /* a whole document */	{ terms = (query_term**)s_realloc((char*)terms,					  (size_t)(sizeof(query_term*) * 						   (numTerms + 3 + 1)));	  terms[numTerms++] = makeAttributeTerm(SYSTEM_CONTROL_NUMBER,						EQUAL,IGNORE,IGNORE,						IGNORE,IGNORE,doc->DocumentID);	  if (type != NULL)	   { terms[numTerms++] = makeAttributeTerm(DATA_TYPE,EQUAL,						   IGNORE,IGNORE,IGNORE,						   IGNORE,type);	     terms[numTerms++] = makeOperatorTerm(AND);           }	  terms[numTerms] = NULL;	}      else			/* a document fragment */	{	char chunk_att[ATTRIBUTE_SIZE];		any* startChunk = NULL;		any* endChunk = NULL; 		terms = (query_term**)s_realloc((char*)terms,						(size_t)(sizeof(query_term*) * 							 (numTerms + 7 + 1)));		switch (doc->ChunkCode)		  { case CT_byte:		    case CT_line:		      { char start[20],end[20];			(doc->ChunkCode == CT_byte) ?			  strncpy(chunk_att,BYTE,ATTRIBUTE_SIZE) :			strncpy(chunk_att,LINE,ATTRIBUTE_SIZE);				sprintf(start,"%ld",doc->ChunkStart.Pos);			startChunk = stringToAny(start);			sprintf(end,"%ld",doc->ChunkEnd.Pos);			endChunk = stringToAny(end);		      }		      break;		    case CT_paragraph:		      strncpy(chunk_att,PARAGRAPH,ATTRIBUTE_SIZE);		      startChunk = doc->ChunkStart.ID;		      endChunk = doc->ChunkEnd.ID;		      break;		    default:		      /* error */		      break;		    }		terms[numTerms++] = makeAttributeTerm(SYSTEM_CONTROL_NUMBER,						      EQUAL,IGNORE,IGNORE,						      IGNORE,						      IGNORE,doc->DocumentID);		if (type != NULL)		 { terms[numTerms++] = makeAttributeTerm(DATA_TYPE,EQUAL,IGNORE,							 IGNORE,IGNORE,IGNORE,							 type);		   terms[numTerms++] = makeOperatorTerm(AND);		 }		terms[numTerms++] = makeAttributeTerm(chunk_att,						      GREATER_THAN_OR_EQUAL,						      IGNORE,IGNORE,IGNORE, 						      IGNORE,						      startChunk);		terms[numTerms++] = makeOperatorTerm(AND);		terms[numTerms++] = makeAttributeTerm(chunk_att,LESS_THAN,						      IGNORE,IGNORE,IGNORE,						      IGNORE,						      endChunk);		terms[numTerms++] = makeOperatorTerm(AND);		terms[numTerms] = NULL;		if (doc->ChunkCode == CT_byte || doc->ChunkCode == CT_line)		  { freeAny(startChunk);		    freeAny(endChunk);		  }	      }            freeAny(type);           if (i != 0) /* multiple independent queries, need a disjunction */	{ terms = (query_term**)s_realloc((char*)terms,					  (size_t)(sizeof(query_term*) * 						   (numTerms + 1 + 1)));	  terms[numTerms++] = makeOperatorTerm(OR);	  terms[numTerms] = NULL;	}    }  return(terms);}/*----------------------------------------------------------------------*/static DocObj** makeWAISQueryDocs PARAMS((query_term** terms));static DocObj** makeWAISQueryDocs(terms)query_term** terms;/* given a list of terms in the form given above, convert them to    DocObjs. */{  query_term* docTerm = NULL;  query_term* fragmentTerm = NULL;  DocObj** docs = NULL;  DocObj* doc = NULL;  long docNum,termNum;  docNum = termNum = 0;    docs = (DocObj**)s_malloc((size_t)(sizeof(DocObj*) * 1));  docs[docNum] = NULL;  /* translate the terms into DocObjs */  while (true)    {	            query_term* typeTerm = NULL;      char* type = NULL;      long startTermOffset;      docTerm = terms[termNum];           if (docTerm == NULL)	break;			/* we're done converting */      typeTerm = terms[termNum + 1]; /* get the lead Term if it exists */      if (strcmp(typeTerm->Use,DATA_TYPE) == 0)	/* we do have a type */       { startTermOffset = 3;		 type = anyToString(typeTerm->Term);       }      else 				   	/* no type */       { startTermOffset = 1;	 typeTerm = NULL;	 type = NULL;       }      /* grow the doc list */      docs = (DocObj**)s_realloc((char*)docs,(size_t)(sizeof(DocObj*) * 						      (docNum + 1 + 1)));      /* figure out what kind of docObj to build - and build it */      fragmentTerm = terms[termNum + startTermOffset];      if (fragmentTerm != NULL && fragmentTerm->TermType == TT_Attribute)	{			/* build a document fragment */	  query_term* startTerm = fragmentTerm;	  query_term* endTerm = terms[termNum + startTermOffset + 2]; 	  if (strcmp(startTerm->Use,BYTE) == 0){ /* a byte chunk */	    doc = makeDocObjUsingBytes(duplicateAny(docTerm->Term),				       type,				       anyToLong(startTerm->Term),				       anyToLong(endTerm->Term));           log_write("byte");	  }else if (strcmp(startTerm->Use,LINE) == 0){ /* a line chunk */	    doc = makeDocObjUsingLines(duplicateAny(docTerm->Term),				       type,				       anyToLong(startTerm->Term),				       anyToLong(endTerm->Term));            log_write("line");	  }else{	log_write("chunk");			/* a paragraph chunk */	    doc = makeDocObjUsingParagraphs(duplicateAny(docTerm->Term),					    type,					    duplicateAny(startTerm->Term),					    duplicateAny(endTerm->Term));}	  termNum += (startTermOffset + 4);	/* point to next term */	}      else			/* build a full document */	{ 	  doc = makeDocObjUsingWholeDocument(duplicateAny(docTerm->Term),					     type);log_write("whole doc");	  termNum += startTermOffset;	/* point to next term */	}           docs[docNum++] = doc;	/* insert the new document */	       docs[docNum] = NULL;	/* keep the doc list terminated */	       if (terms[termNum] != NULL)	termNum++; /* skip the OR operator it necessary */      else	break; /* we are done */    }  return(docs);}/*----------------------------------------------------------------------*/any* makeWAISTextQuery(docs)DocObj** docs;/* given a list of DocObjs, return an any whose contents is the corresponding   type 1 query */{  any *buf = NULL;  query_term** terms = NULL;    terms = makeWAISQueryTerms(docs);  buf = writeQuery(terms);    doList((void**)terms,freeTerm);  s_free(terms);    return(buf);}/*----------------------------------------------------------------------*/DocObj** readWAISTextQuery(buf)any* buf;/* given an any whose contents are type

⌨️ 快捷键说明

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