diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 2004-05-07 01:13:29 -0400 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 2004-05-07 01:13:29 -0400 |
commit | d326f24d169154673717129098ff4554a673f178 (patch) | |
tree | 7229f817b10bcdb82f8df2b6af3a3acc792a762d /WWW/Library/Implementation/HTVMS_WaisProt.c | |
parent | 2cd8e80bfe2792ce8999a26b34384598f58e3889 (diff) | |
download | lynx-snapshots-d326f24d169154673717129098ff4554a673f178.tar.gz |
snapshot of project "lynx", label v2-8-6dev_3
Diffstat (limited to 'WWW/Library/Implementation/HTVMS_WaisProt.c')
-rw-r--r-- | WWW/Library/Implementation/HTVMS_WaisProt.c | 3627 |
1 files changed, 1796 insertions, 1831 deletions
diff --git a/WWW/Library/Implementation/HTVMS_WaisProt.c b/WWW/Library/Implementation/HTVMS_WaisProt.c index 62a36a50..fbd24867 100644 --- a/WWW/Library/Implementation/HTVMS_WaisProt.c +++ b/WWW/Library/Implementation/HTVMS_WaisProt.c @@ -1,30 +1,30 @@ /* HTVMS_WAISProt.c -** -** Adaptation for Lynx by F.Macrides (macrides@sci.wfeb.edu) -** -** 31-May-1994 FM Initial version. -** -**----------------------------------------------------------------------*/ + * + * Adaptation for Lynx by F.Macrides (macrides@sci.wfeb.edu) + * + * 31-May-1994 FM Initial version. + * + *----------------------------------------------------------------------*/ /* -** Routines originally from WProt.c -- FM -** -**----------------------------------------------------------------------*/ + * Routines originally from WProt.c -- FM + * + *----------------------------------------------------------------------*/ /* WIDE AREA INFORMATION SERVER SOFTWARE: - No guarantees or restrictions. See the readme file for the full standard - disclaimer. - - 3.26.90 Harry Morris, morris@think.com - 3.30.90 Harry Morris - - removed chunk code from WAISSearchAPDU, - - added makeWAISQueryType1Query() and readWAISType1Query() which replace - makeWAISQueryTerms() and makeWAISQueryDocs(). - 4.11.90 HWM - generalized conditional includes (see c-dialect.h) - - renamed makeWAISType1Query() to makeWAISTextQuery() - renamed readWAISType1Query() to readWAISTextQuery() - 5.29.90 TS - fixed bug in makeWAISQueryDocs - added CSTFreeWAISFoo functions -*/ + * No guarantees or restrictions. See the readme file for the full standard + * disclaimer. + + * 3.26.90 Harry Morris, morris@think.com + * 3.30.90 Harry Morris + * - removed chunk code from WAISSearchAPDU, + * - added makeWAISQueryType1Query() and readWAISType1Query() which replace + * makeWAISQueryTerms() and makeWAISQueryDocs(). + * 4.11.90 HWM - generalized conditional includes (see c-dialect.h) + * - renamed makeWAISType1Query() to makeWAISTextQuery() + * renamed readWAISType1Query() to readWAISTextQuery() + * 5.29.90 TS - fixed bug in makeWAISQueryDocs + * added CSTFreeWAISFoo functions + */ #define _C_WAIS_protocol_ @@ -37,7 +37,6 @@ #include <LYLeaks.h> - /* very rough estimates of the size of an object */ #define DefWAISInitResponseSize (size_t)200 #define DefWAISSearchSize (size_t)3000 @@ -55,41 +54,35 @@ if (*len > 0) \ *len -= header_len; -/*----------------------------------------------------------------------*/ +#define S_MALLOC(type) (type*)s_malloc(sizeof(type)) +#define S_MALLOC2(type) (type*)s_malloc(sizeof(type) * 2) -static unsigned long userInfoTagSize (data_tag tag, - unsigned long length); +#define S_REALLOC2(type, ptr, num) (type*)s_realloc((char*)ptr, (sizeof(type) * (num + 2))) -static unsigned long -userInfoTagSize(tag,length) -data_tag tag; -unsigned long length; +/*----------------------------------------------------------------------*/ + +static unsigned long userInfoTagSize(data_tag tag, + unsigned long length) /* return the number of bytes required to write the user info tag and length */ { - unsigned long size; + unsigned long size; - /* calculate bytes required to represent tag. max tag is 16K */ - size = writtenCompressedIntSize(tag); - size += writtenCompressedIntSize(length); + /* calculate bytes required to represent tag. max tag is 16K */ + size = writtenCompressedIntSize(tag); + size += writtenCompressedIntSize(length); - return(size); + return (size); } /*----------------------------------------------------------------------*/ -static char* writeUserInfoHeader PARAMS((data_tag tag,long infoSize, - long estHeaderSize,char* buffer, - long* len)); - -static char* -writeUserInfoHeader(tag,infoSize,estHeaderSize,buffer,len) -data_tag tag; -long infoSize; -long estHeaderSize; -char* buffer; -long* len; +static char *writeUserInfoHeader(data_tag tag, + long infoSize, + long estHeaderSize, + char *buffer, + long *len) /* write the tag and size, making sure the info fits. return the true end of the info (after adjustment) note that the argument infoSize includes estHeaderSize. Note that the argument len is the number of bytes remaining @@ -98,787 +91,762 @@ long* len; do that writing. */ { - long dummyLen = 100; /* plenty of space for a tag and size */ - char* buf = buffer; - long realSize = infoSize - estHeaderSize; - long realHeaderSize = userInfoTagSize(tag,realSize); + long dummyLen = 100; /* plenty of space for a tag and size */ + char *buf = buffer; + long realSize = infoSize - estHeaderSize; + long realHeaderSize = userInfoTagSize(tag, realSize); - if (buffer == NULL || *len == 0) - return(NULL); + if (buffer == NULL || *len == 0) + return (NULL); - /* write the tag */ - buf = writeTag(tag,buf,&dummyLen); + /* write the tag */ + buf = writeTag(tag, buf, &dummyLen); - /* see if the if the header size was correct. if not, - we have to shift the info to fit the real header size */ - if (estHeaderSize != realHeaderSize) - { /* make sure there is enough space */ - CHECK_FOR_SPACE_LEFT(realHeaderSize - estHeaderSize,len); - memmove(buffer + realHeaderSize,buffer + estHeaderSize,(size_t)(realSize)); + /* see if the if the header size was correct. if not, + we have to shift the info to fit the real header size */ + if (estHeaderSize != realHeaderSize) { /* make sure there is enough space */ + CHECK_FOR_SPACE_LEFT(realHeaderSize - estHeaderSize, len); + memmove(buffer + realHeaderSize, buffer + estHeaderSize, (size_t) (realSize)); } - /* write the size */ - writeCompressedInteger(realSize,buf,&dummyLen); + /* write the size */ + writeCompressedInteger(realSize, buf, &dummyLen); - /* return the true end of buffer */ - return(buffer + realHeaderSize + realSize); + /* return the true end of buffer */ + return (buffer + realHeaderSize + realSize); } /*----------------------------------------------------------------------*/ -static char* readUserInfoHeader (data_tag* tag,unsigned long* num, - char* buffer); - -static char* -readUserInfoHeader(tag,num,buffer) -data_tag* tag; -unsigned long* num; -char* buffer; +static char *readUserInfoHeader(data_tag *tag, + unsigned long *num, + char *buffer) /* read the tag and size */ { - char* buf = buffer; - buf = readTag(tag,buf); - buf = readCompressedInteger(num,buf); - return(buf); + char *buf = buffer; + + buf = readTag(tag, buf); + buf = readCompressedInteger(num, buf); + return (buf); } /*----------------------------------------------------------------------*/ -WAISInitResponse* -makeWAISInitResponse(chunkCode, - chunkIDLen, - chunkMarker, - highlightMarker, - deHighlightMarker, - newLineChars) -long chunkCode; -long chunkIDLen; -char* chunkMarker; -char* highlightMarker; -char* deHighlightMarker; -char* newLineChars; +WAISInitResponse *makeWAISInitResponse(long chunkCode, + long chunkIDLen, + char *chunkMarker, + char *highlightMarker, + char *deHighlightMarker, + char *newLineChars) /* create a WAIS init response object */ { - WAISInitResponse* init = (WAISInitResponse*)s_malloc((size_t)sizeof(WAISInitResponse)); + WAISInitResponse *init = S_MALLOC(WAISInitResponse); - init->ChunkCode = chunkCode; /* note: none are copied! */ - init->ChunkIDLength = chunkIDLen; - init->ChunkMarker = chunkMarker; - init->HighlightMarker = highlightMarker; - init->DeHighlightMarker = deHighlightMarker; - init->NewlineCharacters = newLineChars; + init->ChunkCode = chunkCode; /* note: none are copied! */ + init->ChunkIDLength = chunkIDLen; + init->ChunkMarker = chunkMarker; + init->HighlightMarker = highlightMarker; + init->DeHighlightMarker = deHighlightMarker; + init->NewlineCharacters = newLineChars; - return(init); + return (init); } /*----------------------------------------------------------------------*/ -void -freeWAISInitResponse(init) -WAISInitResponse* init; +void freeWAISInitResponse(WAISInitResponse *init) /* free an object made with makeWAISInitResponse */ { - s_free(init->ChunkMarker); - s_free(init->HighlightMarker); - s_free(init->DeHighlightMarker); - s_free(init->NewlineCharacters); - s_free(init); + s_free(init->ChunkMarker); + s_free(init->HighlightMarker); + s_free(init->DeHighlightMarker); + s_free(init->NewlineCharacters); + s_free(init); } /*----------------------------------------------------------------------*/ -char* -writeInitResponseInfo(init,buffer,len) -InitResponseAPDU* init; -char* buffer; -long* len; +char *writeInitResponseInfo(InitResponseAPDU *init, + char *buffer, + long *len) /* write an init response object */ { - unsigned long header_len = userInfoTagSize(DT_UserInformationLength, - DefWAISInitResponseSize); - char* buf = buffer + header_len; - WAISInitResponse* info = (WAISInitResponse*)init->UserInformationField; - unsigned long size; + unsigned long header_len = userInfoTagSize(DT_UserInformationLength, + DefWAISInitResponseSize); + char *buf = buffer + header_len; + WAISInitResponse *info = (WAISInitResponse *) init->UserInformationField; + unsigned long size; - RESERVE_SPACE_FOR_WAIS_HEADER(len); + RESERVE_SPACE_FOR_WAIS_HEADER(len); - buf = writeNum(info->ChunkCode,DT_ChunkCode,buf,len); - buf = writeNum(info->ChunkIDLength,DT_ChunkIDLength,buf,len); - buf = writeString(info->ChunkMarker,DT_ChunkMarker,buf,len); - buf = writeString(info->HighlightMarker,DT_HighlightMarker,buf,len); - buf = writeString(info->DeHighlightMarker,DT_DeHighlightMarker,buf,len); - buf = writeString(info->NewlineCharacters,DT_NewlineCharacters,buf,len); + buf = writeNum(info->ChunkCode, DT_ChunkCode, buf, len); + buf = writeNum(info->ChunkIDLength, DT_ChunkIDLength, buf, len); + buf = writeString(info->ChunkMarker, DT_ChunkMarker, buf, len); + buf = writeString(info->HighlightMarker, DT_HighlightMarker, buf, len); + buf = writeString(info->DeHighlightMarker, DT_DeHighlightMarker, buf, len); + buf = writeString(info->NewlineCharacters, DT_NewlineCharacters, buf, len); - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_UserInformationLength,size,header_len,buffer,len); + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_UserInformationLength, + size, + header_len, + buffer, + len); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -char* -readInitResponseInfo(info,buffer) -void** info; -char* buffer; +char *readInitResponseInfo(void **info, + char *buffer) /* read an init response object */ { - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - long chunkCode,chunkIDLen; - data_tag tag1; - char* chunkMarker = NULL; - char* highlightMarker = NULL; - char* deHighlightMarker = NULL; - char* newLineChars = NULL; + char *buf = buffer; + unsigned long size; + unsigned long headerSize; + long chunkCode, chunkIDLen; + data_tag tag1; + char *chunkMarker = NULL; + char *highlightMarker = NULL; + char *deHighlightMarker = NULL; + char *newLineChars = NULL; + + chunkCode = chunkIDLen = UNUSED; - chunkCode = chunkIDLen = UNUSED; + buf = readUserInfoHeader(&tag1, &size, buf); + headerSize = buf - buffer; - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; + while (buf < (buffer + size + headerSize)) { + data_tag tag = peekTag(buf); - while (buf < (buffer + size + headerSize)) - { data_tag tag = peekTag(buf); - switch (tag) - { case DT_ChunkCode: - buf = readNum(&chunkCode,buf); + switch (tag) { + case DT_ChunkCode: + buf = readNum(&chunkCode, buf); break; - case DT_ChunkIDLength: - buf = readNum(&chunkIDLen,buf); + case DT_ChunkIDLength: + buf = readNum(&chunkIDLen, buf); break; - case DT_ChunkMarker: - buf = readString(&chunkMarker,buf); + case DT_ChunkMarker: + buf = readString(&chunkMarker, buf); break; - case DT_HighlightMarker: - buf = readString(&highlightMarker,buf); + case DT_HighlightMarker: + buf = readString(&highlightMarker, buf); break; - case DT_DeHighlightMarker: - buf = readString(&deHighlightMarker,buf); + case DT_DeHighlightMarker: + buf = readString(&deHighlightMarker, buf); break; - case DT_NewlineCharacters: - buf = readString(&newLineChars,buf); + case DT_NewlineCharacters: + buf = readString(&newLineChars, buf); break; - default: + default: s_free(highlightMarker); s_free(deHighlightMarker); s_free(newLineChars); REPORT_READ_ERROR(buf); break; - } + } } - *info = (void *)makeWAISInitResponse(chunkCode,chunkIDLen,chunkMarker, - highlightMarker,deHighlightMarker, - newLineChars); - return(buf); + *info = (void *) makeWAISInitResponse(chunkCode, chunkIDLen, chunkMarker, + highlightMarker, deHighlightMarker, + newLineChars); + return (buf); } /*----------------------------------------------------------------------*/ -WAISSearch* -makeWAISSearch(seedWords, - docs, - textList, - dateFactor, - beginDateRange, - endDateRange, - maxDocsRetrieved) -char* seedWords; -DocObj** docs; -char** textList; -long dateFactor; -char* beginDateRange; -char* endDateRange; -long maxDocsRetrieved; +WAISSearch *makeWAISSearch(char *seedWords, + DocObj **docs, + char **textList, + long dateFactor, + char *beginDateRange, + char *endDateRange, + long maxDocsRetrieved) /* create a type 3 query object */ { - WAISSearch* query = (WAISSearch*)s_malloc((size_t)sizeof(WAISSearch)); + WAISSearch *query = S_MALLOC(WAISSearch); - query->SeedWords = seedWords; /* not copied! */ - query->Docs = docs; /* not copied! */ - query->TextList = textList; /* not copied! */ - query->DateFactor = dateFactor; - query->BeginDateRange = beginDateRange; - query->EndDateRange = endDateRange; - query->MaxDocumentsRetrieved = maxDocsRetrieved; + query->SeedWords = seedWords; /* not copied! */ + query->Docs = docs; /* not copied! */ + query->TextList = textList; /* not copied! */ + query->DateFactor = dateFactor; + query->BeginDateRange = beginDateRange; + query->EndDateRange = endDateRange; + query->MaxDocumentsRetrieved = maxDocsRetrieved; - return(query); + return (query); } /*----------------------------------------------------------------------*/ -void -freeWAISSearch(query) -WAISSearch* query; +void freeWAISSearch(WAISSearch *query) /* destroy an object made with makeWAISSearch() */ { - void* ptr = NULL; - long i; + void *ptr = NULL; + long i; - s_free(query->SeedWords); + s_free(query->SeedWords); - if (query->Docs != NULL) - for (i = 0,ptr = (void *)query->Docs[i]; ptr != NULL; ptr = (void *)query->Docs[++i]) - freeDocObj((DocObj*)ptr); - s_free(query->Docs); + if (query->Docs != NULL) + for (i = 0, ptr = (void *) query->Docs[i]; + ptr != NULL; + ptr = (void *) query->Docs[++i]) + freeDocObj((DocObj *) ptr); + s_free(query->Docs); - if (query->TextList != NULL) /* XXX revisit when textlist is fully defined */ - for (i = 0,ptr = (void *)query->TextList[i]; ptr != NULL; ptr = (void *)query->TextList[++i]) - s_free(ptr); - s_free(query->TextList); + if (query->TextList != NULL) /* XXX revisit when textlist is fully defined */ + for (i = 0, ptr = (void *) query->TextList[i]; + ptr != NULL; + ptr = (void *) query->TextList[++i]) + s_free(ptr); + s_free(query->TextList); - s_free(query->BeginDateRange); - s_free(query->EndDateRange); - s_free(query); + s_free(query->BeginDateRange); + s_free(query->EndDateRange); + s_free(query); } /*----------------------------------------------------------------------*/ -DocObj* -makeDocObjUsingWholeDocument(docID,type) -any* docID; -char* type; +DocObj *makeDocObjUsingWholeDocument(any *docID, + char *type) /* construct a document object using byte chunks - only for use by servers */ { - DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj)); - doc->DocumentID = docID; /* not copied! */ - doc->Type = type; /* not copied! */ - doc->ChunkCode = CT_document; - return(doc); + DocObj *doc = S_MALLOC(DocObj); + + doc->DocumentID = docID; /* not copied! */ + doc->Type = type; /* not copied! */ + doc->ChunkCode = CT_document; + return (doc); } /*----------------------------------------------------------------------*/ -DocObj* -makeDocObjUsingLines(docID,type,start,end) -any* docID; -char* type; -long start; -long end; +DocObj *makeDocObjUsingLines(any *docID, + char *type, + long start, + long end) /* construct a document object using line chunks - only for use by servers */ { - DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj)); - doc->ChunkCode = CT_line; - doc->DocumentID = docID; /* not copied */ - doc->Type = type; /* not copied! */ - doc->ChunkStart.Pos = start; - doc->ChunkEnd.Pos = end; - return(doc); + DocObj *doc = S_MALLOC(DocObj); + + doc->ChunkCode = CT_line; + doc->DocumentID = docID; /* not copied */ + doc->Type = type; /* not copied! */ + doc->ChunkStart.Pos = start; + doc->ChunkEnd.Pos = end; + return (doc); } /*----------------------------------------------------------------------*/ -DocObj* -makeDocObjUsingBytes(docID,type,start,end) -any* docID; -char* type; -long start; -long end; +DocObj *makeDocObjUsingBytes(any *docID, + char *type, + long start, + long end) /* construct a document object using byte chunks - only for use by servers */ { - DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj)); - doc->ChunkCode = CT_byte; - doc->DocumentID = docID; /* not copied */ - doc->Type = type; /* not copied! */ - doc->ChunkStart.Pos = start; - doc->ChunkEnd.Pos = end; - return(doc); + DocObj *doc = S_MALLOC(DocObj); + + doc->ChunkCode = CT_byte; + doc->DocumentID = docID; /* not copied */ + doc->Type = type; /* not copied! */ + doc->ChunkStart.Pos = start; + doc->ChunkEnd.Pos = end; + return (doc); } /*----------------------------------------------------------------------*/ -DocObj* -makeDocObjUsingParagraphs(docID,type,start,end) -any* docID; -char* type; -any* start; -any* end; +DocObj *makeDocObjUsingParagraphs(any *docID, + char *type, + any *start, + any *end) /* construct a document object using byte chunks - only for use by servers */ { - DocObj* doc = (DocObj*)s_malloc((size_t)sizeof(DocObj)); - doc->ChunkCode = CT_paragraph; - doc->DocumentID = docID; /* not copied */ - doc->Type = type; - doc->ChunkStart.ID = start; - doc->ChunkEnd.ID = end; - return(doc); + DocObj *doc = S_MALLOC(DocObj); + + doc->ChunkCode = CT_paragraph; + doc->DocumentID = docID; /* not copied */ + doc->Type = type; + doc->ChunkStart.ID = start; + doc->ChunkEnd.ID = end; + return (doc); } /*----------------------------------------------------------------------*/ -void -freeDocObj(doc) -DocObj* doc; +void freeDocObj(DocObj *doc) /* free a docObj */ { - freeAny(doc->DocumentID); - s_free(doc->Type); - if (doc->ChunkCode == CT_paragraph) - { freeAny(doc->ChunkStart.ID); - freeAny(doc->ChunkEnd.ID); + freeAny(doc->DocumentID); + s_free(doc->Type); + if (doc->ChunkCode == CT_paragraph) { + freeAny(doc->ChunkStart.ID); + freeAny(doc->ChunkEnd.ID); } - s_free(doc); + s_free(doc); } /*----------------------------------------------------------------------*/ -static char* writeDocObj (DocObj* doc,char* buffer,long* len); - -static char* -writeDocObj(doc,buffer,len) -DocObj* doc; -char* buffer; -long* len; +static char *writeDocObj(DocObj *doc, + char *buffer, + long *len) /* write as little as we can about the doc obj */ { - char* buf = buffer; + char *buf = buffer; - /* we alwasy have to write the id, but its tag depends on if its a chunk */ - if (doc->ChunkCode == CT_document) - buf = writeAny(doc->DocumentID,DT_DocumentID,buf,len); - else - buf = writeAny(doc->DocumentID,DT_DocumentIDChunk,buf,len); + /* we alwasy have to write the id, but its tag depends on if its a chunk */ + if (doc->ChunkCode == CT_document) + buf = writeAny(doc->DocumentID, DT_DocumentID, buf, len); + else + buf = writeAny(doc->DocumentID, DT_DocumentIDChunk, buf, len); - if (doc->Type != NULL) - buf = writeString(doc->Type,DT_TYPE,buf,len); + if (doc->Type != NULL) + buf = writeString(doc->Type, DT_TYPE, buf, len); - switch (doc->ChunkCode) - { case CT_document: + switch (doc->ChunkCode) { + 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); + 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); + 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: + default: panic("Implementation error: unknown chuck type %ld", doc->ChunkCode); break; - } + } - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -static char* readDocObj (DocObj** doc,char* buffer); - -static char* -readDocObj(doc,buffer) -DocObj** doc; -char* buffer; +static char *readDocObj(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: + char *buf = buffer; + data_tag tag; + + *doc = S_MALLOC(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); + buf = readAny(&((*doc)->ChunkStart.ID), buf); + buf = readAny(&((*doc)->ChunkEnd.ID), buf); break; - default: + default: freeAny((*doc)->DocumentID); - if (readParagraphs) - { freeAny((*doc)->ChunkStart.ID); + 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); + } + } else { + freeAny((*doc)->DocumentID); + s_free(*doc); + REPORT_READ_ERROR(buf); } - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -char* -writeSearchInfo(query,buffer,len) -SearchAPDU* query; -char* buffer; -long* len; +char *writeSearchInfo(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); - } - } + 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; - /* XXX text list */ + RESERVE_SPACE_FOR_WAIS_HEADER(len); - 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); + buf = writeString(info->SeedWords, DT_SeedWords, buf, len); - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_UserInformationLength,size,header_len,buffer,len); + if (info->Docs != NULL) { + for (i = 0; info->Docs[i] != NULL; i++) { + buf = writeDocObj(info->Docs[i], buf, len); + } + } - return(buf); + /* 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; +char *readSearchInfo(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); + 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); + case DT_DocumentID: + case DT_DocumentIDChunk: + if (docIDs == NULL) /* create a new doc list */ + { + docIDs = S_MALLOC2(DocObj *); + } else { /* grow the doc list */ + docIDs = S_REALLOC2(DocObj *, docIDs, docs); + } + 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); + 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++] = doc; /* put it in the list */ docIDs[docs] = NULL; break; - case DT_TextList: + case DT_TextList: /* XXX */ break; - case DT_DateFactor: - buf = readNum(&dateFactor,buf); + case DT_DateFactor: + buf = readNum(&dateFactor, buf); break; - case DT_BeginDateRange: - buf = readString(&beginDateRange,buf); + case DT_BeginDateRange: + buf = readString(&beginDateRange, buf); break; - case DT_EndDateRange: - buf = readString(&endDateRange,buf); + case DT_EndDateRange: + buf = readString(&endDateRange, buf); break; - case DT_MaxDocumentsRetrieved: - buf = readNum(&maxDocsRetrieved,buf); + case DT_MaxDocumentsRetrieved: + buf = readNum(&maxDocsRetrieved, buf); break; - default: + 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); + 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); + *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; +WAISDocumentHeader *makeWAISDocumentHeader(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)); + WAISDocumentHeader *header = S_MALLOC(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; + 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); + return (header); } /*----------------------------------------------------------------------*/ -void -freeWAISDocumentHeader(header) -WAISDocumentHeader* header; - +void freeWAISDocumentHeader(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); + 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; +char *writeWAISDocumentHeader(WAISDocumentHeader *header, char *buffer, + long *len) { - unsigned long header_len = userInfoTagSize(DT_DocumentHeaderGroup , - DefWAISDocHeaderSize); - char* buf = buffer + header_len; - unsigned long size1; + 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; - RESERVE_SPACE_FOR_WAIS_HEADER(len); + 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); - 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; + 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 = 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); + 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(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 = S_REALLOC2(char *, types, numTypes); + + types[numTypes++] = type; + types[numTypes] = NULL; + size -= (buf - originalBuf); } } /* FALLTHRU */ - case DT_Source: - buf = readString(&source,buf); + case DT_Source: + buf = readString(&source, buf); break; - case DT_Date: - buf = readString(&date,buf); + case DT_Date: + buf = readString(&date, buf); break; - case DT_Headline: - buf = readString(&headline,buf); + case DT_Headline: + buf = readString(&headline, buf); break; - case DT_OriginCity: - buf = readString(&originCity,buf); + case DT_OriginCity: + buf = readString(&originCity, buf); break; - default: + default: freeAny(docID); s_free(source); s_free(date); @@ -886,348 +854,336 @@ char* buffer; s_free(originCity); REPORT_READ_ERROR(buf); break; - } + } } - *header = makeWAISDocumentHeader(docID,versionNumber,score,bestMatch, - docLength,lines,types,source,date,headline, - originCity); - return(buf); + *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; +WAISDocumentShortHeader *makeWAISDocumentShortHeader(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 = - (WAISDocumentShortHeader*)s_malloc((size_t)sizeof(WAISDocumentShortHeader)); + WAISDocumentShortHeader *header = S_MALLOC(WAISDocumentShortHeader); - header->DocumentID = docID; - header->VersionNumber = versionNumber; - header->Score = score; - header->BestMatch = bestMatch; - header->DocumentLength = docLen; - header->Lines = lines; + header->DocumentID = docID; + header->VersionNumber = versionNumber; + header->Score = score; + header->BestMatch = bestMatch; + header->DocumentLength = docLen; + header->Lines = lines; - return(header); + return (header); } /*----------------------------------------------------------------------*/ -void -freeWAISDocumentShortHeader(header) -WAISDocumentShortHeader* header; +void freeWAISDocumentShortHeader(WAISDocumentShortHeader *header) { - freeAny(header->DocumentID); - s_free(header); + freeAny(header->DocumentID); + s_free(header); } /*----------------------------------------------------------------------*/ -char* -writeWAISDocumentShortHeader(header,buffer,len) -WAISDocumentShortHeader* header; -char* buffer; -long* len; +char *writeWAISDocumentShortHeader(WAISDocumentShortHeader *header, char *buffer, + long *len) { - unsigned long header_len = userInfoTagSize(DT_DocumentShortHeaderGroup , - DefWAISShortHeaderSize); - char* buf = buffer + header_len; - unsigned long size; + unsigned long header_len = userInfoTagSize(DT_DocumentShortHeaderGroup, + DefWAISShortHeaderSize); + char *buf = buffer + header_len; + unsigned long size; - RESERVE_SPACE_FOR_WAIS_HEADER(len); + 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); + 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); - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_DocumentShortHeaderGroup,size,header_len,buffer,len); + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_DocumentShortHeaderGroup, + size, + header_len, + buffer, + len); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -char* -readWAISDocumentShortHeader(header,buffer) -WAISDocumentShortHeader** header; -char* buffer; +char *readWAISDocumentShortHeader(WAISDocumentShortHeader **header, char *buffer) { - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - data_tag tag1; - any* docID = NULL; - long versionNumber,score,bestMatch,docLength,lines; + char *buf = buffer; + unsigned long size; + unsigned long headerSize; + data_tag tag1; + any *docID = NULL; + long versionNumber, score, bestMatch, docLength, lines; - versionNumber = score = bestMatch = docLength = lines = UNUSED; + versionNumber = score = bestMatch = docLength = lines = UNUSED; - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; + 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); + 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); + case DT_VersionNumber: + buf = readNum(&versionNumber, buf); break; - case DT_Score: - buf = readNum(&score,buf); + case DT_Score: + buf = readNum(&score, buf); break; - case DT_BestMatch: - buf = readNum(&bestMatch,buf); + case DT_BestMatch: + buf = readNum(&bestMatch, buf); break; - case DT_DocumentLength: - buf = readNum(&docLength,buf); + case DT_DocumentLength: + buf = readNum(&docLength, buf); break; - case DT_Lines: - buf = readNum(&lines,buf); + case DT_Lines: + buf = readNum(&lines, buf); break; - default: + default: freeAny(docID); REPORT_READ_ERROR(buf); break; - } + } } - *header = makeWAISDocumentShortHeader(docID,versionNumber,score,bestMatch, - docLength,lines); - return(buf); -} - -/*----------------------------------------------------------------------*/ - -WAISDocumentLongHeader* -makeWAISDocumentLongHeader(docID, - versionNumber, - score, - bestMatch, - docLen, - lines, - types, - source, - date, - headline, - originCity, - stockCodes, - companyCodes, - industryCodes) -any* docID; -long versionNumber; -long score; -long bestMatch; -long docLen; -long lines; -char** types; -char* source; -char* date; -char* headline; -char* originCity; -char* stockCodes; -char* companyCodes; -char* industryCodes; + *header = makeWAISDocumentShortHeader(docID, versionNumber, score, bestMatch, + docLength, lines); + return (buf); +} + +/*----------------------------------------------------------------------*/ + +WAISDocumentLongHeader *makeWAISDocumentLongHeader(any *docID, + long versionNumber, + long score, + long bestMatch, + long docLen, + long lines, + char **types, + char *source, + char *date, + char *headline, + char *originCity, + char *stockCodes, + char *companyCodes, + char *industryCodes) /* construct a long 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. */ { - WAISDocumentLongHeader* header = - (WAISDocumentLongHeader*)s_malloc((size_t)sizeof(WAISDocumentLongHeader)); - - 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; - header->StockCodes = stockCodes; - header->CompanyCodes = companyCodes; - header->IndustryCodes = industryCodes; - - return(header); -} - -/*----------------------------------------------------------------------*/ - -void -freeWAISDocumentLongHeader(header) -WAISDocumentLongHeader* header; -{ - freeAny(header->DocumentID); - doList((void**)header->Types,fs_free); /* can't use the macro here! */ - s_free(header->Source); - s_free(header->Date); - s_free(header->Headline); - s_free(header->OriginCity); - s_free(header->StockCodes); - s_free(header->CompanyCodes); - s_free(header->IndustryCodes); - s_free(header); -} - -/*----------------------------------------------------------------------*/ - -char* -writeWAISDocumentLongHeader(header,buffer,len) -WAISDocumentLongHeader* header; -char* buffer; -long* len; -{ - unsigned long header_len = userInfoTagSize(DT_DocumentLongHeaderGroup , - DefWAISLongHeaderSize); - 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; + WAISDocumentLongHeader *header = S_MALLOC(WAISDocumentLongHeader); + + 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; + header->StockCodes = stockCodes; + header->CompanyCodes = companyCodes; + header->IndustryCodes = industryCodes; + + return (header); +} + +/*----------------------------------------------------------------------*/ + +void freeWAISDocumentLongHeader(WAISDocumentLongHeader *header) +{ + freeAny(header->DocumentID); + doList((void **) header->Types, fs_free); /* can't use the macro here! */ + s_free(header->Source); + s_free(header->Date); + s_free(header->Headline); + s_free(header->OriginCity); + s_free(header->StockCodes); + s_free(header->CompanyCodes); + s_free(header->IndustryCodes); + s_free(header); +} + +/*----------------------------------------------------------------------*/ + +char *writeWAISDocumentLongHeader(WAISDocumentLongHeader *header, char *buffer, + long *len) +{ + unsigned long header_len = userInfoTagSize(DT_DocumentLongHeaderGroup, + DefWAISLongHeaderSize); + 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 = 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); - buf = writeString(header->StockCodes,DT_StockCodes,buf,len); - buf = writeString(header->CompanyCodes,DT_CompanyCodes,buf,len); - buf = writeString(header->IndustryCodes,DT_IndustryCodes,buf,len); - - /* now write the header and size */ - size1 = buf - buffer; - buf = writeUserInfoHeader(DT_DocumentLongHeaderGroup,size1,header_len,buffer,len); - - return(buf); -} - -/*----------------------------------------------------------------------*/ - -char* -readWAISDocumentLongHeader(header,buffer) -WAISDocumentLongHeader** header; -char* buffer; -{ - char* buf = buffer; - unsigned long size1; - unsigned long headerSize; - data_tag tag1; - any* docID; - long versionNumber,score,bestMatch,docLength,lines; - char **types; - char *source,*date,*headline,*originCity,*stockCodes,*companyCodes,*industryCodes; - - docID = NULL; - versionNumber = score = bestMatch = docLength = lines = UNUSED; - types = NULL; - source = date = headline = originCity = stockCodes = companyCodes = industryCodes = NULL; - - 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); - 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); + 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); + buf = writeString(header->StockCodes, DT_StockCodes, buf, len); + buf = writeString(header->CompanyCodes, DT_CompanyCodes, buf, len); + buf = writeString(header->IndustryCodes, DT_IndustryCodes, buf, len); + + /* now write the header and size */ + size1 = buf - buffer; + buf = writeUserInfoHeader(DT_DocumentLongHeaderGroup, + size1, + header_len, + buffer, + len); + + return (buf); +} + +/*----------------------------------------------------------------------*/ + +char *readWAISDocumentLongHeader(WAISDocumentLongHeader **header, char *buffer) +{ + char *buf = buffer; + unsigned long size1; + unsigned long headerSize; + data_tag tag1; + any *docID; + long versionNumber, score, bestMatch, docLength, lines; + char **types; + char *source, *date, *headline, *originCity, *stockCodes, *companyCodes, *industryCodes; + + docID = NULL; + versionNumber = + score = + bestMatch = + docLength = + lines = UNUSED; + types = NULL; + source = + date = + headline = + originCity = + stockCodes = + companyCodes = + industryCodes = NULL; + + 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); + readCompressedInteger(&size, buf); + while (size > 0) { + char *type = NULL; + char *originalBuf = buf; + + buf = readString(&type, buf); + types = S_REALLOC2(char *, types, numTypes); + + types[numTypes++] = type; + types[numTypes] = NULL; + size -= (buf - originalBuf); } } /* FALLTHRU */ - case DT_Source: - buf = readString(&source,buf); + case DT_Source: + buf = readString(&source, buf); break; - case DT_Date: - buf = readString(&date,buf); + case DT_Date: + buf = readString(&date, buf); break; - case DT_Headline: - buf = readString(&headline,buf); + case DT_Headline: + buf = readString(&headline, buf); break; - case DT_OriginCity: - buf = readString(&originCity,buf); + case DT_OriginCity: + buf = readString(&originCity, buf); break; - case DT_StockCodes: - buf = readString(&stockCodes,buf); + case DT_StockCodes: + buf = readString(&stockCodes, buf); break; - case DT_CompanyCodes: - buf = readString(&companyCodes,buf); + case DT_CompanyCodes: + buf = readString(&companyCodes, buf); break; - case DT_IndustryCodes: - buf = readString(&industryCodes,buf); + case DT_IndustryCodes: + buf = readString(&industryCodes, buf); break; - default: + default: freeAny(docID); s_free(source); s_free(date); @@ -1238,773 +1194,831 @@ char* buffer; s_free(industryCodes); REPORT_READ_ERROR(buf); break; - } + } } - *header = makeWAISDocumentLongHeader(docID,versionNumber,score,bestMatch, - docLength,lines,types,source,date,headline, - originCity,stockCodes,companyCodes, - industryCodes); - return(buf); -} - -/*----------------------------------------------------------------------*/ - -WAISSearchResponse* -makeWAISSearchResponse(seedWordsUsed, - docHeaders, - shortHeaders, - longHeaders, - text, - headlines, - codes, - diagnostics) -char* seedWordsUsed; -WAISDocumentHeader** docHeaders; -WAISDocumentShortHeader** shortHeaders; -WAISDocumentLongHeader** longHeaders; -WAISDocumentText** text; -WAISDocumentHeadlines** headlines; -WAISDocumentCodes** codes; -diagnosticRecord** diagnostics; + *header = makeWAISDocumentLongHeader(docID, + versionNumber, + score, + bestMatch, + docLength, + lines, + types, + source, + date, + headline, + originCity, + stockCodes, + companyCodes, + industryCodes); + return (buf); +} + +/*----------------------------------------------------------------------*/ + +WAISSearchResponse * + makeWAISSearchResponse( + char *seedWordsUsed, + WAISDocumentHeader **docHeaders, + WAISDocumentShortHeader **shortHeaders, + WAISDocumentLongHeader **longHeaders, + WAISDocumentText **text, + WAISDocumentHeadlines **headlines, + WAISDocumentCodes **codes, + diagnosticRecord ** diagnostics) +{ + WAISSearchResponse *response = S_MALLOC(WAISSearchResponse); + + response->SeedWordsUsed = seedWordsUsed; + response->DocHeaders = docHeaders; + response->ShortHeaders = shortHeaders; + response->LongHeaders = longHeaders; + response->Text = text; + response->Headlines = headlines; + response->Codes = codes; + response->Diagnostics = diagnostics; + + return (response); +} + +/*----------------------------------------------------------------------*/ + +void freeWAISSearchResponse(WAISSearchResponse * response) +{ + void *ptr = NULL; + long i; + + s_free(response->SeedWordsUsed); + + if (response->DocHeaders != NULL) + for (i = 0, ptr = (void *) response->DocHeaders[i]; + ptr != NULL; + ptr = (void *) response->DocHeaders[++i]) + freeWAISDocumentHeader((WAISDocumentHeader *) ptr); + s_free(response->DocHeaders); + + if (response->ShortHeaders != NULL) + for (i = 0, ptr = (void *) response->ShortHeaders[i]; + ptr != NULL; + ptr = (void *) response->ShortHeaders[++i]) + freeWAISDocumentShortHeader((WAISDocumentShortHeader *) ptr); + s_free(response->ShortHeaders); + + if (response->LongHeaders != NULL) + for (i = 0, ptr = (void *) response->LongHeaders[i]; + ptr != NULL; + ptr = (void *) response->LongHeaders[++i]) + freeWAISDocumentLongHeader((WAISDocumentLongHeader *) ptr); + s_free(response->LongHeaders); + + if (response->Text != NULL) + for (i = 0, ptr = (void *) response->Text[i]; + ptr != NULL; + ptr = (void *) response->Text[++i]) + freeWAISDocumentText((WAISDocumentText *) ptr); + s_free(response->Text); + + if (response->Headlines != NULL) + for (i = 0, ptr = (void *) response->Headlines[i]; + ptr != NULL; + ptr = (void *) response->Headlines[++i]) + freeWAISDocumentHeadlines((WAISDocumentHeadlines *) ptr); + s_free(response->Headlines); + + if (response->Codes != NULL) + for (i = 0, ptr = (void *) response->Codes[i]; + ptr != NULL; + ptr = (void *) response->Codes[++i]) + freeWAISDocumentCodes((WAISDocumentCodes *) ptr); + s_free(response->Codes); + + if (response->Diagnostics != NULL) + for (i = 0, ptr = (void *) response->Diagnostics[i]; + ptr != NULL; + ptr = (void *) response->Diagnostics[++i]) + freeDiag((diagnosticRecord *) ptr); + s_free(response->Diagnostics); + + s_free(response); +} + +/*----------------------------------------------------------------------*/ + +char *writeSearchResponseInfo(SearchResponseAPDU *query, + char *buffer, + long *len) { - WAISSearchResponse* response = (WAISSearchResponse*)s_malloc((size_t)sizeof(WAISSearchResponse)); - - response->SeedWordsUsed = seedWordsUsed; - response->DocHeaders = docHeaders; - response->ShortHeaders = shortHeaders; - response->LongHeaders = longHeaders; - response->Text = text; - response->Headlines = headlines; - response->Codes = codes; - response->Diagnostics = diagnostics; - - return(response); -} - -/*----------------------------------------------------------------------*/ - -void -freeWAISSearchResponse(response) -WAISSearchResponse* response; -{ - void* ptr = NULL; - long i; + unsigned long header_len = userInfoTagSize(DT_UserInformationLength, + DefWAISSearchResponseSize); + char *buf = buffer + header_len; + WAISSearchResponse *info = (WAISSearchResponse *) query->DatabaseDiagnosticRecords; + unsigned long size; + void *header = NULL; + long i; + + RESERVE_SPACE_FOR_WAIS_HEADER(len); + + buf = writeString(info->SeedWordsUsed, DT_SeedWordsUsed, buf, len); + + /* write out all the headers */ + if (info->DocHeaders != NULL) { + for (i = 0, header = (void *) info->DocHeaders[i]; + header != NULL; + header = (void *) info->DocHeaders[++i]) + buf = writeWAISDocumentHeader((WAISDocumentHeader *) header, buf, len); + } - s_free(response->SeedWordsUsed); + if (info->ShortHeaders != NULL) { + for (i = 0, header = (void *) info->ShortHeaders[i]; + header != NULL; + header = (void *) info->ShortHeaders[++i]) + buf = writeWAISDocumentShortHeader((WAISDocumentShortHeader *) header, + buf, + len); + } - if (response->DocHeaders != NULL) - for (i = 0,ptr = (void *)response->DocHeaders[i]; ptr != NULL; ptr = (void *)response->DocHeaders[++i]) - freeWAISDocumentHeader((WAISDocumentHeader*)ptr); - s_free(response->DocHeaders); + if (info->LongHeaders != NULL) { + for (i = 0, header = (void *) info->LongHeaders[i]; + header != NULL; + header = (void *) info->LongHeaders[++i]) + buf = writeWAISDocumentLongHeader((WAISDocumentLongHeader *) header, + buf, + len); + } - if (response->ShortHeaders != NULL) - for (i = 0,ptr = (void *)response->ShortHeaders[i]; ptr != NULL; ptr = (void *)response->ShortHeaders[++i]) - freeWAISDocumentShortHeader((WAISDocumentShortHeader*)ptr); - s_free(response->ShortHeaders); + if (info->Text != NULL) { + for (i = 0, header = (void *) info->Text[i]; + header != NULL; + header = (void *) info->Text[++i]) + buf = writeWAISDocumentText((WAISDocumentText *) header, buf, len); + } - if (response->LongHeaders != NULL) - for (i = 0,ptr = (void *)response->LongHeaders[i]; ptr != NULL; ptr = (void *)response->LongHeaders[++i]) - freeWAISDocumentLongHeader((WAISDocumentLongHeader*)ptr); - s_free(response->LongHeaders); + if (info->Headlines != NULL) { + for (i = 0, header = (void *) info->Headlines[i]; + header != NULL; + header = (void *) info->Headlines[++i]) + buf = writeWAISDocumentHeadlines((WAISDocumentHeadlines *) header, + buf, + len); + } - if (response->Text != NULL) - for (i = 0,ptr = (void *)response->Text[i]; ptr != NULL; ptr = (void *)response->Text[++i]) - freeWAISDocumentText((WAISDocumentText*)ptr); - s_free(response->Text); + if (info->Codes != NULL) { + for (i = 0, header = (void *) info->Codes[i]; + header != NULL; + header = (void *) info->Codes[++i]) + buf = writeWAISDocumentCodes((WAISDocumentCodes *) header, buf, len); + } - if (response->Headlines != NULL) - for (i = 0,ptr = (void *)response->Headlines[i]; ptr != NULL; ptr = (void *)response->Headlines[++i]) - freeWAISDocumentHeadlines((WAISDocumentHeadlines*)ptr); - s_free(response->Headlines); - - if (response->Codes != NULL) - for (i = 0,ptr = (void *)response->Codes[i]; ptr != NULL; ptr = (void *)response->Codes[++i]) - freeWAISDocumentCodes((WAISDocumentCodes*)ptr); - s_free(response->Codes); - - if (response->Diagnostics != NULL) - for (i = 0,ptr = (void *)response->Diagnostics[i]; ptr != NULL; ptr = (void *)response->Diagnostics[++i]) - freeDiag((diagnosticRecord*)ptr); - s_free(response->Diagnostics); - - s_free(response); -} - -/*----------------------------------------------------------------------*/ - -char* -writeSearchResponseInfo(query,buffer,len) -SearchResponseAPDU* query; -char* buffer; -long* len; -{ - unsigned long header_len = userInfoTagSize(DT_UserInformationLength, - DefWAISSearchResponseSize); - char* buf = buffer + header_len; - WAISSearchResponse* info = (WAISSearchResponse*)query->DatabaseDiagnosticRecords; - unsigned long size; - void* header = NULL; - long i; - - RESERVE_SPACE_FOR_WAIS_HEADER(len); - - buf = writeString(info->SeedWordsUsed,DT_SeedWordsUsed,buf,len); - - /* write out all the headers */ - if (info->DocHeaders != NULL) - { for (i = 0,header = (void *)info->DocHeaders[i]; header != NULL; header = (void *)info->DocHeaders[++i]) - buf = writeWAISDocumentHeader((WAISDocumentHeader*)header,buf,len); - } - - if (info->ShortHeaders != NULL) - { for (i = 0,header = (void *)info->ShortHeaders[i]; header != NULL; header = (void *)info->ShortHeaders[++i]) - buf = writeWAISDocumentShortHeader((WAISDocumentShortHeader*)header,buf,len); - } - - if (info->LongHeaders != NULL) - { for (i = 0,header = (void *)info->LongHeaders[i]; header != NULL; header = (void *)info->LongHeaders[++i]) - buf = writeWAISDocumentLongHeader((WAISDocumentLongHeader*)header,buf,len); - } + if (info->Diagnostics != NULL) { + for (i = 0, header = (void *) info->Diagnostics[i]; + header != NULL; + header = (void *) info->Diagnostics[++i]) + buf = writeDiag((diagnosticRecord *) header, buf, len); + } - if (info->Text != NULL) - { for (i = 0,header = (void *)info->Text[i]; header != NULL; header = (void *)info->Text[++i]) - buf = writeWAISDocumentText((WAISDocumentText*)header,buf,len); - } + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_UserInformationLength, + size, + header_len, + buffer, + len); - if (info->Headlines != NULL) - { for (i = 0,header = (void *)info->Headlines[i]; header != NULL; header = (void *)info->Headlines[++i]) - buf = writeWAISDocumentHeadlines((WAISDocumentHeadlines*)header,buf,len); - } + return (buf); +} - if (info->Codes != NULL) - { for (i = 0,header = (void *)info->Codes[i]; header != NULL;header = (void *)info->Codes[++i]) - buf = writeWAISDocumentCodes((WAISDocumentCodes*)header,buf,len); - } +/*----------------------------------------------------------------------*/ - if (info->Diagnostics != NULL) - { for (i = 0, header = (void *)info->Diagnostics[i]; header != NULL; header = (void *)info->Diagnostics[++i]) - buf = writeDiag((diagnosticRecord*)header,buf,len); - } - - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_UserInformationLength,size,header_len,buffer,len); - - return(buf); -} - -/*----------------------------------------------------------------------*/ - -static void -cleanUpWaisSearchResponse (char* buf,char* seedWordsUsed, - WAISDocumentHeader** docHeaders, - WAISDocumentShortHeader** shortHeaders, - WAISDocumentLongHeader** longHeaders, - WAISDocumentText** text, - WAISDocumentHeadlines** headlines, - WAISDocumentCodes** codes, - diagnosticRecord**diags); - -static void -cleanUpWaisSearchResponse (buf,seedWordsUsed,docHeaders,shortHeaders, - longHeaders,text,headlines,codes,diags) -char* buf; -char* seedWordsUsed; -WAISDocumentHeader** docHeaders; -WAISDocumentShortHeader** shortHeaders; -WAISDocumentLongHeader** longHeaders; -WAISDocumentText** text; -WAISDocumentHeadlines** headlines; -WAISDocumentCodes** codes; -diagnosticRecord** diags; +static void cleanUpWaisSearchResponse(char *buf, + char *seedWordsUsed, + WAISDocumentHeader **docHeaders, + WAISDocumentShortHeader **shortHeaders, + WAISDocumentLongHeader **longHeaders, + WAISDocumentText **text, + WAISDocumentHeadlines **headlines, + WAISDocumentCodes **codes, + diagnosticRecord ** diags) /* if buf is NULL, we have just gotten a read error, and need to clean up any state we have built. If not, then everything is going fine, and we should just hang loose */ { - void* ptr = NULL; - long i; - - if (buf == NULL) - { s_free(seedWordsUsed); - if (docHeaders != NULL) - for (i = 0,ptr = (void *)docHeaders[i]; ptr != NULL; - ptr = (void *)docHeaders[++i]) - freeWAISDocumentHeader((WAISDocumentHeader*)ptr); - s_free(docHeaders); - if (shortHeaders != NULL) - for (i = 0,ptr = (void *)shortHeaders[i]; ptr != NULL; - ptr = (void *)shortHeaders[++i]) - freeWAISDocumentShortHeader((WAISDocumentShortHeader*)ptr); - s_free(shortHeaders); - if (longHeaders != NULL) - for (i = 0,ptr = (void *)longHeaders[i]; ptr != NULL; - ptr = (void *)longHeaders[++i]) - freeWAISDocumentLongHeader((WAISDocumentLongHeader*)ptr); - s_free(longHeaders); - if (text != NULL) - for (i = 0,ptr = (void *)text[i]; ptr != NULL; ptr = (void *)text[++i]) - freeWAISDocumentText((WAISDocumentText*)ptr); - s_free(text); - if (headlines != NULL) - for (i = 0,ptr = (void *)headlines[i]; ptr != NULL; - ptr = (void *)headlines[++i]) - freeWAISDocumentHeadlines((WAISDocumentHeadlines*)ptr); - s_free(headlines); - if (codes != NULL) - for (i = 0,ptr = (void *)codes[i]; ptr != NULL; - ptr = (void *)codes[++i]) - freeWAISDocumentCodes((WAISDocumentCodes*)ptr); - s_free(codes); - if (diags != NULL) - for (i = 0,ptr = (void *)diags[i]; ptr != NULL; - ptr = (void *)diags[++i]) - freeDiag((diagnosticRecord*)ptr); - s_free(diags); - } -} - -/*----------------------------------------------------------------------*/ - -char* -readSearchResponseInfo(info,buffer) -void** info; -char* buffer; -{ - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - data_tag tag1; - void* header = NULL; - WAISDocumentHeader** docHeaders = NULL; - WAISDocumentShortHeader** shortHeaders = NULL; - WAISDocumentLongHeader** longHeaders = NULL; - WAISDocumentText** text = NULL; - WAISDocumentHeadlines** headlines = NULL; - WAISDocumentCodes** codes = NULL; - long numDocHeaders,numLongHeaders,numShortHeaders,numText,numHeadlines; - long numCodes; - char* seedWordsUsed = NULL; - diagnosticRecord** diags = NULL; - diagnosticRecord* diag = NULL; - long numDiags = 0; - - numDocHeaders = numLongHeaders = numShortHeaders = numText = numHeadlines = numCodes = 0; - - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; - - while (buf < (buffer + size + headerSize)) - { data_tag tag = peekTag(buf); - switch (tag) - { case DT_SeedWordsUsed: - buf = readString(&seedWordsUsed,buf); - break; + void *ptr = NULL; + long i; + + if (buf == NULL) { + s_free(seedWordsUsed); + if (docHeaders != NULL) + for (i = 0, ptr = (void *) docHeaders[i]; ptr != NULL; + ptr = (void *) docHeaders[++i]) + freeWAISDocumentHeader((WAISDocumentHeader *) ptr); + s_free(docHeaders); + if (shortHeaders != NULL) + for (i = 0, ptr = (void *) shortHeaders[i]; ptr != NULL; + ptr = (void *) shortHeaders[++i]) + freeWAISDocumentShortHeader((WAISDocumentShortHeader *) ptr); + s_free(shortHeaders); + if (longHeaders != NULL) + for (i = 0, ptr = (void *) longHeaders[i]; ptr != NULL; + ptr = (void *) longHeaders[++i]) + freeWAISDocumentLongHeader((WAISDocumentLongHeader *) ptr); + s_free(longHeaders); + if (text != NULL) + for (i = 0, ptr = (void *) text[i]; + ptr != NULL; + ptr = (void *) text[++i]) + freeWAISDocumentText((WAISDocumentText *) ptr); + s_free(text); + if (headlines != NULL) + for (i = 0, ptr = (void *) headlines[i]; ptr != NULL; + ptr = (void *) headlines[++i]) + freeWAISDocumentHeadlines((WAISDocumentHeadlines *) ptr); + s_free(headlines); + if (codes != NULL) + for (i = 0, ptr = (void *) codes[i]; ptr != NULL; + ptr = (void *) codes[++i]) + freeWAISDocumentCodes((WAISDocumentCodes *) ptr); + s_free(codes); + if (diags != NULL) + for (i = 0, ptr = (void *) diags[i]; ptr != NULL; + ptr = (void *) diags[++i]) + freeDiag((diagnosticRecord *) ptr); + s_free(diags); + } +} + +/*----------------------------------------------------------------------*/ + +char *readSearchResponseInfo(void **info, + char *buffer) +{ + char *buf = buffer; + unsigned long size; + unsigned long headerSize; + data_tag tag1; + void *header = NULL; + WAISDocumentHeader **docHeaders = NULL; + WAISDocumentShortHeader **shortHeaders = NULL; + WAISDocumentLongHeader **longHeaders = NULL; + WAISDocumentText **text = NULL; + WAISDocumentHeadlines **headlines = NULL; + WAISDocumentCodes **codes = NULL; + long numDocHeaders, numLongHeaders, numShortHeaders, numText, numHeadlines; + long numCodes; + char *seedWordsUsed = NULL; + diagnosticRecord **diags = NULL; + diagnosticRecord *diag = NULL; + long numDiags = 0; + + numDocHeaders = + numLongHeaders = + numShortHeaders = + numText = + numHeadlines = + numCodes = 0; + + buf = readUserInfoHeader(&tag1, &size, buf); + headerSize = buf - buffer; + + while (buf < (buffer + size + headerSize)) { + data_tag tag = peekTag(buf); + + switch (tag) { + case DT_SeedWordsUsed: + buf = readString(&seedWordsUsed, buf); + break; case DT_DatabaseDiagnosticRecords: - if (diags == NULL) /* create a new diag list */ - { diags = (diagnosticRecord**)s_malloc((size_t)sizeof(diagnosticRecord*) * 2); - } - else /* grow the diag list */ - { diags = (diagnosticRecord**)s_realloc((char*)diags,(size_t)(sizeof(diagnosticRecord*) * (numDiags + 2))); - } - buf = readDiag(&diag,buf); - diags[numDiags++] = diag; /* put it in the list */ - diags[numDiags] = NULL; - break; + if (diags == NULL) /* create a new diag list */ + { + diags = S_MALLOC2(diagnosticRecord *); + } else { /* grow the diag list */ + diags = S_REALLOC2(diagnosticRecord *, diags, numDiags); + } + buf = readDiag(&diag, buf); + diags[numDiags++] = diag; /* put it in the list */ + diags[numDiags] = NULL; + break; case DT_DocumentHeaderGroup: - if (docHeaders == NULL) /* create a new header list */ - { docHeaders = (WAISDocumentHeader**)s_malloc((size_t)sizeof(WAISDocumentHeader*) * 2); - } - else /* grow the doc list */ - { docHeaders = (WAISDocumentHeader**)s_realloc((char*)docHeaders,(size_t)(sizeof(WAISDocumentHeader*) * (numDocHeaders + 2))); - } - buf = readWAISDocumentHeader((WAISDocumentHeader**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - docHeaders[numDocHeaders++] = - (WAISDocumentHeader*)header; /* put it in the list */ - docHeaders[numDocHeaders] = NULL; - break; - case DT_DocumentShortHeaderGroup: - if (shortHeaders == NULL) /* create a new header list */ - { shortHeaders = (WAISDocumentShortHeader**)s_malloc((size_t)sizeof(WAISDocumentShortHeader*) * 2); - } - else /* grow the doc list */ - { shortHeaders = (WAISDocumentShortHeader**)s_realloc((char*)shortHeaders,(size_t)(sizeof(WAISDocumentShortHeader*) * (numShortHeaders + 2))); - } - buf = readWAISDocumentShortHeader((WAISDocumentShortHeader**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - shortHeaders[numShortHeaders++] = - (WAISDocumentShortHeader*)header; /* put it in the list */ - shortHeaders[numShortHeaders] = NULL; - break; - case DT_DocumentLongHeaderGroup: - if (longHeaders == NULL) /* create a new header list */ - { longHeaders = (WAISDocumentLongHeader**)s_malloc((size_t)sizeof(WAISDocumentLongHeader*) * 2); - } - else /* grow the doc list */ - { longHeaders = (WAISDocumentLongHeader**)s_realloc((char*)longHeaders,(size_t)(sizeof(WAISDocumentLongHeader*) * (numLongHeaders + 2))); - } - buf = readWAISDocumentLongHeader((WAISDocumentLongHeader**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - longHeaders[numLongHeaders++] = - (WAISDocumentLongHeader*)header; /* put it in the list */ - longHeaders[numLongHeaders] = NULL; - break; + if (docHeaders == NULL) /* create a new header list */ + { + docHeaders = S_MALLOC2(WAISDocumentHeader *); + } else { /* grow the doc list */ + docHeaders = S_REALLOC2(WAISDocumentHeader *, docHeaders, numDocHeaders); + } + buf = readWAISDocumentHeader((WAISDocumentHeader **) &header, buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + docHeaders[numDocHeaders++] = + (WAISDocumentHeader *) header; /* put it in the list */ + docHeaders[numDocHeaders] = NULL; + break; + case DT_DocumentShortHeaderGroup: + if (shortHeaders == NULL) /* create a new header list */ + { + shortHeaders = S_MALLOC2(WAISDocumentShortHeader *); + } else { /* grow the doc list */ + shortHeaders = S_REALLOC2(WAISDocumentShortHeader *, + shortHeaders, + numShortHeaders); + } + buf = readWAISDocumentShortHeader((WAISDocumentShortHeader **) &header, + buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + shortHeaders[numShortHeaders++] = + (WAISDocumentShortHeader *) header; /* put it in the list */ + shortHeaders[numShortHeaders] = NULL; + break; + case DT_DocumentLongHeaderGroup: + if (longHeaders == NULL) /* create a new header list */ + { + longHeaders = S_MALLOC2(WAISDocumentLongHeader *); + } else { /* grow the doc list */ + longHeaders = S_REALLOC2(WAISDocumentLongHeader *, + longHeaders, + numLongHeaders); + } + buf = readWAISDocumentLongHeader((WAISDocumentLongHeader **) &header, + buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + longHeaders[numLongHeaders++] = + (WAISDocumentLongHeader *) header; /* put it in the list */ + longHeaders[numLongHeaders] = NULL; + break; case DT_DocumentTextGroup: - if (text == NULL) /* create a new list */ - { text = (WAISDocumentText**)s_malloc((size_t)sizeof(WAISDocumentText*) * 2); - } - else /* grow the list */ - { text = (WAISDocumentText**)s_realloc((char*)text,(size_t)(sizeof(WAISDocumentText*) * (numText + 2))); - } - buf = readWAISDocumentText((WAISDocumentText**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - text[numText++] = - (WAISDocumentText*)header; /* put it in the list */ - text[numText] = NULL; - break; - case DT_DocumentHeadlineGroup: - if (headlines == NULL) /* create a new list */ - { headlines = (WAISDocumentHeadlines**)s_malloc((size_t)sizeof(WAISDocumentHeadlines*) * 2); - } - else /* grow the list */ - { headlines = (WAISDocumentHeadlines**)s_realloc((char*)headlines,(size_t)(sizeof(WAISDocumentHeadlines*) * (numHeadlines + 2))); - } - buf = readWAISDocumentHeadlines((WAISDocumentHeadlines**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - headlines[numHeadlines++] = - (WAISDocumentHeadlines*)header; /* put it in the list */ - headlines[numHeadlines] = NULL; - break; - case DT_DocumentCodeGroup: - if (codes == NULL) /* create a new list */ - { codes = (WAISDocumentCodes**)s_malloc((size_t)sizeof(WAISDocumentCodes*) * 2); - } - else /* grow the list */ - { codes = (WAISDocumentCodes**)s_realloc((char*)codes,(size_t)(sizeof(WAISDocumentCodes*) * (numCodes + 2))); - } - buf = readWAISDocumentCodes((WAISDocumentCodes**)&header,buf); - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - RETURN_ON_NULL(buf); - codes[numCodes++] = - (WAISDocumentCodes*)header; /* put it in the list */ - codes[numCodes] = NULL; - break; + if (text == NULL) /* create a new list */ + { + text = S_MALLOC2(WAISDocumentText *); + } else { /* grow the list */ + text = S_REALLOC2(WAISDocumentText *, text, numText); + } + buf = readWAISDocumentText((WAISDocumentText **) &header, buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + text[numText++] = + (WAISDocumentText *) header; /* put it in the list */ + text[numText] = NULL; + break; + case DT_DocumentHeadlineGroup: + if (headlines == NULL) /* create a new list */ + { + headlines = S_MALLOC2(WAISDocumentHeadlines *); + } else { /* grow the list */ + headlines = S_REALLOC2(WAISDocumentHeadlines *, headlines, numHeadlines); + } + buf = readWAISDocumentHeadlines((WAISDocumentHeadlines **) &header, + buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + headlines[numHeadlines++] = + (WAISDocumentHeadlines *) header; /* put it in the list */ + headlines[numHeadlines] = NULL; + break; + case DT_DocumentCodeGroup: + if (codes == NULL) /* create a new list */ + { + codes = S_MALLOC2(WAISDocumentCodes *); + } else { /* grow the list */ + codes = S_REALLOC2(WAISDocumentCodes *, codes, numCodes); + } + buf = readWAISDocumentCodes((WAISDocumentCodes **) &header, buf); + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + RETURN_ON_NULL(buf); + codes[numCodes++] = + (WAISDocumentCodes *) header; /* put it in the list */ + codes[numCodes] = NULL; + break; default: - cleanUpWaisSearchResponse(buf,seedWordsUsed,docHeaders,shortHeaders,longHeaders,text,headlines,codes,diags); - REPORT_READ_ERROR(buf); - break; - } - } + cleanUpWaisSearchResponse(buf, + seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); + REPORT_READ_ERROR(buf); + break; + } + } - *info = (void *)makeWAISSearchResponse(seedWordsUsed,docHeaders,shortHeaders, - longHeaders,text,headlines,codes,diags); + *info = (void *) makeWAISSearchResponse(seedWordsUsed, + docHeaders, + shortHeaders, + longHeaders, + text, + headlines, + codes, + diags); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -WAISDocumentText* -makeWAISDocumentText(docID,versionNumber,documentText) -any* docID; -long versionNumber; -any* documentText; +WAISDocumentText *makeWAISDocumentText(any *docID, + long versionNumber, + any *documentText) { - WAISDocumentText* docText = (WAISDocumentText*)s_malloc((size_t)sizeof(WAISDocumentText)); + WAISDocumentText *docText = S_MALLOC(WAISDocumentText); - docText->DocumentID = docID; - docText->VersionNumber = versionNumber; - docText->DocumentText = documentText; + docText->DocumentID = docID; + docText->VersionNumber = versionNumber; + docText->DocumentText = documentText; - return(docText); + return (docText); } /*----------------------------------------------------------------------*/ -void -freeWAISDocumentText(docText) -WAISDocumentText* docText; +void freeWAISDocumentText(WAISDocumentText *docText) { - freeAny(docText->DocumentID); - freeAny(docText->DocumentText); - s_free(docText); + freeAny(docText->DocumentID); + freeAny(docText->DocumentText); + s_free(docText); } /*----------------------------------------------------------------------*/ -char* -writeWAISDocumentText(docText,buffer,len) -WAISDocumentText* docText; -char* buffer; -long* len; +char *writeWAISDocumentText(WAISDocumentText *docText, char *buffer, + long *len) { - unsigned long header_len = userInfoTagSize(DT_DocumentTextGroup, - DefWAISDocTextSize); - char* buf = buffer + header_len; - unsigned long size; + unsigned long header_len = userInfoTagSize(DT_DocumentTextGroup, + DefWAISDocTextSize); + char *buf = buffer + header_len; + unsigned long size; - RESERVE_SPACE_FOR_WAIS_HEADER(len); + RESERVE_SPACE_FOR_WAIS_HEADER(len); - buf = writeAny(docText->DocumentID,DT_DocumentID,buf,len); - buf = writeNum(docText->VersionNumber,DT_VersionNumber,buf,len); - buf = writeAny(docText->DocumentText,DT_DocumentText,buf,len); + buf = writeAny(docText->DocumentID, DT_DocumentID, buf, len); + buf = writeNum(docText->VersionNumber, DT_VersionNumber, buf, len); + buf = writeAny(docText->DocumentText, DT_DocumentText, buf, len); - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_DocumentTextGroup,size,header_len,buffer,len); + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_DocumentTextGroup, size, header_len, buffer, len); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -char* -readWAISDocumentText(docText,buffer) -WAISDocumentText** docText; -char* buffer; +char *readWAISDocumentText(WAISDocumentText **docText, char *buffer) { - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - data_tag tag1; - any *docID,*documentText; - long versionNumber; + char *buf = buffer; + unsigned long size; + unsigned long headerSize; + data_tag tag1; + any *docID, *documentText; + long versionNumber; + + docID = documentText = NULL; + versionNumber = UNUSED; - docID = documentText = NULL; - versionNumber = UNUSED; + buf = readUserInfoHeader(&tag1, &size, buf); + headerSize = buf - buffer; - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; + while (buf < (buffer + size + headerSize)) { + data_tag tag = peekTag(buf); - 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_DocumentText: - buf = readAny(&documentText,buf); - break; + switch (tag) { + case DT_DocumentID: + buf = readAny(&docID, buf); + break; + case DT_VersionNumber: + buf = readNum(&versionNumber, buf); + break; + case DT_DocumentText: + buf = readAny(&documentText, buf); + break; default: - freeAny(docID); - freeAny(documentText); - REPORT_READ_ERROR(buf); - break; - } - } + freeAny(docID); + freeAny(documentText); + REPORT_READ_ERROR(buf); + break; + } + } - *docText = makeWAISDocumentText(docID,versionNumber,documentText); - return(buf); + *docText = makeWAISDocumentText(docID, versionNumber, documentText); + return (buf); } /*----------------------------------------------------------------------*/ -WAISDocumentHeadlines* -makeWAISDocumentHeadlines(docID, - versionNumber, - source, - date, - headline, - originCity) -any* docID; -long versionNumber; -char* source; -char* date; -char* headline; -char* originCity; -{ - WAISDocumentHeadlines* docHeadline = - (WAISDocumentHeadlines*)s_malloc((size_t)sizeof(WAISDocumentHeadlines)); - - docHeadline->DocumentID = docID; - docHeadline->VersionNumber = versionNumber; - docHeadline->Source = source; - docHeadline->Date = date; - docHeadline->Headline = headline; - docHeadline->OriginCity = originCity; - - return(docHeadline); -} - -/*----------------------------------------------------------------------*/ - -void -freeWAISDocumentHeadlines(docHeadline) -WAISDocumentHeadlines* docHeadline; -{ - freeAny(docHeadline->DocumentID); - s_free(docHeadline->Source); - s_free(docHeadline->Date); - s_free(docHeadline->Headline); - s_free(docHeadline->OriginCity); - s_free(docHeadline); -} - -/*----------------------------------------------------------------------*/ - -char* -writeWAISDocumentHeadlines(docHeadline,buffer,len) -WAISDocumentHeadlines* docHeadline; -char* buffer; -long* len; -{ - unsigned long header_len = userInfoTagSize(DT_DocumentHeadlineGroup, - DefWAISDocHeadlineSize); - char* buf = buffer + header_len; - unsigned long size; - - RESERVE_SPACE_FOR_WAIS_HEADER(len); - - buf = writeAny(docHeadline->DocumentID,DT_DocumentID,buf,len); - buf = writeNum(docHeadline->VersionNumber,DT_VersionNumber,buf,len); - buf = writeString(docHeadline->Source,DT_Source,buf,len); - buf = writeString(docHeadline->Date,DT_Date,buf,len); - buf = writeString(docHeadline->Headline,DT_Headline,buf,len); - buf = writeString(docHeadline->OriginCity,DT_OriginCity,buf,len); - - /* now write the header and size */ - size = buf - buffer; - buf = writeUserInfoHeader(DT_DocumentHeadlineGroup,size,header_len,buffer,len); - - return(buf); -} - -/*----------------------------------------------------------------------*/ - -char* -readWAISDocumentHeadlines(docHeadline,buffer) -WAISDocumentHeadlines** docHeadline; -char* buffer; -{ - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - data_tag tag1; - any* docID; - long versionNumber; - char *source,*date,*headline,*originCity; - - docID = NULL; - versionNumber = UNUSED; - source = date = headline = originCity = NULL; - - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; +WAISDocumentHeadlines *makeWAISDocumentHeadlines(any *docID, + long versionNumber, + char *source, + char *date, + char *headline, + char *originCity) +{ + WAISDocumentHeadlines *docHeadline = S_MALLOC(WAISDocumentHeadlines); + + docHeadline->DocumentID = docID; + docHeadline->VersionNumber = versionNumber; + docHeadline->Source = source; + docHeadline->Date = date; + docHeadline->Headline = headline; + docHeadline->OriginCity = originCity; - 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_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; + return (docHeadline); +} + +/*----------------------------------------------------------------------*/ + +void freeWAISDocumentHeadlines(WAISDocumentHeadlines *docHeadline) +{ + freeAny(docHeadline->DocumentID); + s_free(docHeadline->Source); + s_free(docHeadline->Date); + s_free(docHeadline->Headline); + s_free(docHeadline->OriginCity); + s_free(docHeadline); +} + +/*----------------------------------------------------------------------*/ + +char *writeWAISDocumentHeadlines(WAISDocumentHeadlines *docHeadline, char *buffer, + long *len) +{ + unsigned long header_len = userInfoTagSize(DT_DocumentHeadlineGroup, + DefWAISDocHeadlineSize); + char *buf = buffer + header_len; + unsigned long size; + + RESERVE_SPACE_FOR_WAIS_HEADER(len); + + buf = writeAny(docHeadline->DocumentID, DT_DocumentID, buf, len); + buf = writeNum(docHeadline->VersionNumber, DT_VersionNumber, buf, len); + buf = writeString(docHeadline->Source, DT_Source, buf, len); + buf = writeString(docHeadline->Date, DT_Date, buf, len); + buf = writeString(docHeadline->Headline, DT_Headline, buf, len); + buf = writeString(docHeadline->OriginCity, DT_OriginCity, buf, len); + + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_DocumentHeadlineGroup, + size, + header_len, + buffer, + len); + + return (buf); +} + +/*----------------------------------------------------------------------*/ + +char *readWAISDocumentHeadlines(WAISDocumentHeadlines **docHeadline, char *buffer) +{ + char *buf = buffer; + unsigned long size; + unsigned long headerSize; + data_tag tag1; + any *docID; + long versionNumber; + char *source, *date, *headline, *originCity; + + docID = NULL; + versionNumber = UNUSED; + source = date = headline = originCity = 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_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; - } - } + freeAny(docID); + s_free(source); + s_free(date); + s_free(headline); + s_free(originCity); + REPORT_READ_ERROR(buf); + break; + } + } - *docHeadline = makeWAISDocumentHeadlines(docID,versionNumber,source,date, - headline,originCity); - return(buf); + *docHeadline = makeWAISDocumentHeadlines(docID, versionNumber, source, date, + headline, originCity); + return (buf); } /*----------------------------------------------------------------------*/ -WAISDocumentCodes* -makeWAISDocumentCodes(docID, - versionNumber, - stockCodes, - companyCodes, - industryCodes) -any* docID; -long versionNumber; -char* stockCodes; -char* companyCodes; -char* industryCodes; +WAISDocumentCodes *makeWAISDocumentCodes(any *docID, + long versionNumber, + char *stockCodes, + char *companyCodes, + char *industryCodes) { - WAISDocumentCodes* docCodes = (WAISDocumentCodes*)s_malloc((size_t)sizeof(WAISDocumentCodes)); + WAISDocumentCodes *docCodes = S_MALLOC(WAISDocumentCodes); - docCodes->DocumentID = docID; - docCodes->VersionNumber = versionNumber; - docCodes->StockCodes = stockCodes; - docCodes->CompanyCodes = companyCodes; - docCodes->IndustryCodes = industryCodes; + docCodes->DocumentID = docID; + docCodes->VersionNumber = versionNumber; + docCodes->StockCodes = stockCodes; + docCodes->CompanyCodes = companyCodes; + docCodes->IndustryCodes = industryCodes; - return(docCodes); + return (docCodes); } /*----------------------------------------------------------------------*/ -void -freeWAISDocumentCodes(docCodes) -WAISDocumentCodes* docCodes; +void freeWAISDocumentCodes(WAISDocumentCodes *docCodes) { - freeAny(docCodes->DocumentID); - s_free(docCodes->StockCodes); - s_free(docCodes->CompanyCodes); - s_free(docCodes->IndustryCodes); - s_free(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; +char *writeWAISDocumentCodes(WAISDocumentCodes *docCodes, + char *buffer, + long *len) { - unsigned long header_len = userInfoTagSize(DT_DocumentCodeGroup , - DefWAISDocCodeSize); - char* buf = buffer + header_len; - unsigned long size; + unsigned long header_len = userInfoTagSize(DT_DocumentCodeGroup, + DefWAISDocCodeSize); + char *buf = buffer + header_len; + unsigned long size; - RESERVE_SPACE_FOR_WAIS_HEADER(len); + 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); + 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); + /* now write the header and size */ + size = buf - buffer; + buf = writeUserInfoHeader(DT_DocumentCodeGroup, size, header_len, buffer, len); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -char* -readWAISDocumentCodes(docCodes,buffer) -WAISDocumentCodes** docCodes; -char* buffer; +char *readWAISDocumentCodes(WAISDocumentCodes **docCodes, + char *buffer) { - char* buf = buffer; - unsigned long size; - unsigned long headerSize; - data_tag tag1; - any* docID; - long versionNumber; - char *stockCodes,*companyCodes,*industryCodes; + 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; - docID = NULL; - versionNumber = UNUSED; - stockCodes = companyCodes = industryCodes = NULL; + buf = readUserInfoHeader(&tag1, &size, buf); + headerSize = buf - buffer; - buf = readUserInfoHeader(&tag1,&size,buf); - headerSize = buf - buffer; + while (buf < (buffer + size + headerSize)) { + data_tag tag = peekTag(buf); - 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; + 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; - } - } + 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); + *docCodes = makeWAISDocumentCodes(docID, versionNumber, stockCodes, + companyCodes, industryCodes); + return (buf); } /*----------------------------------------------------------------------*/ -char* -writePresentInfo(present,buffer,len) -PresentAPDU* present GCC_UNUSED; -char* buffer; -long* len GCC_UNUSED; +char *writePresentInfo(PresentAPDU * present GCC_UNUSED, char *buffer, + long *len GCC_UNUSED) { - /* The WAIS protocol doesn't use present info */ - return(buffer); + /* The WAIS protocol doesn't use present info */ + return (buffer); } /*----------------------------------------------------------------------*/ -char* -readPresentInfo(info,buffer) -void** info; -char* buffer; +char *readPresentInfo(void **info, + char *buffer) { - /* The WAIS protocol doesn't use present info */ - *info = NULL; - return(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; +char *writePresentResponseInfo(PresentResponseAPDU * response GCC_UNUSED, char *buffer, + long *len GCC_UNUSED) { - /* The WAIS protocol doesn't use presentResponse info */ - return(buffer); + /* The WAIS protocol doesn't use presentResponse info */ + return (buffer); } /*----------------------------------------------------------------------*/ -char* -readPresentResponseInfo(info,buffer) -void** info; -char* buffer; +char *readPresentResponseInfo(void **info, + char *buffer) { - /* The WAIS protocol doesn't use presentResponse info */ - *info = NULL; - return(buffer); + /* The WAIS protocol doesn't use presentResponse info */ + *info = NULL; + return (buffer); } /*----------------------------------------------------------------------*/ @@ -2046,263 +2060,246 @@ char* buffer; ( XXX return type could be in the element set) */ -static query_term** makeWAISQueryTerms (DocObj** docs); - -static query_term** -makeWAISQueryTerms(docs) -DocObj** docs; +static query_term **makeWAISQueryTerms(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); + 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 = S_REALLOC2(query_term *, terms, numTerms + 2); + + 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,LESS_THAN, - IGNORE,IGNORE,IGNORE, - IGNORE, - endChunk); + } + terms[numTerms] = NULL; + } else { /* a document fragment */ + char chunk_att[ATTRIBUTE_SIZE]; + any *startChunk = NULL; + any *endChunk = NULL; + + terms = S_REALLOC2(query_term *, terms, numTerms + 6); + + 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] = 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; + } + 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 = S_REALLOC2(query_term *, terms, numTerms); + + terms[numTerms++] = makeOperatorTerm(OR); + terms[numTerms] = NULL; } } - return(terms); + return (terms); } /*----------------------------------------------------------------------*/ -static DocObj** makeWAISQueryDocs (query_term** terms); - -static DocObj** -makeWAISQueryDocs(terms) -query_term** terms; +static DocObj **makeWAISQueryDocs(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; + query_term *docTerm = NULL; + query_term *fragmentTerm = NULL; + DocObj **docs = NULL; + DocObj *doc = NULL; + long docNum, termNum; - docNum = termNum = 0; + docNum = termNum = 0; - docs = (DocObj**)s_malloc((size_t)(sizeof(DocObj*) * 1)); - docs[docNum] = NULL; + docs = S_MALLOC(DocObj *); - /* 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 */ + 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 */ { - doc = makeDocObjUsingWholeDocument(duplicateAny(docTerm->Term), - type); -log_write("whole doc"); - termNum += startTermOffset; /* point to next term */ + startTermOffset = 3; + type = anyToString(typeTerm->Term); + } else { /* no type */ + startTermOffset = 1; + typeTerm = NULL; + type = NULL; } - docs[docNum++] = doc; /* insert the new document */ + /* grow the doc list */ + docs = S_REALLOC2(DocObj *, docs, docNum); + + /* 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] = NULL; /* keep the doc list terminated */ + 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 */ + if (terms[termNum] != NULL) + termNum++; /* skip the OR operator it necessary */ + else + break; /* we are done */ } - return(docs); + return (docs); } /*----------------------------------------------------------------------*/ -any* -makeWAISTextQuery(docs) -DocObj** docs; +any *makeWAISTextQuery(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; + any *buf = NULL; + query_term **terms = NULL; - terms = makeWAISQueryTerms(docs); - buf = writeQuery(terms); + terms = makeWAISQueryTerms(docs); + buf = writeQuery(terms); - doList((void**)terms,freeTerm); - s_free(terms); + doList((void **) terms, freeTerm); + s_free(terms); - return(buf); + return (buf); } /*----------------------------------------------------------------------*/ -DocObj** -readWAISTextQuery(buf) -any* buf; +DocObj **readWAISTextQuery(any *buf) /* given an any whose contents are type 1 queries of the WAIS sort, construct a list of the corresponding DocObjs */ { - query_term** terms = NULL; - DocObj** docs = NULL; + query_term **terms = NULL; + DocObj **docs = NULL; - terms = readQuery(buf); - docs = makeWAISQueryDocs(terms); + terms = readQuery(buf); + docs = makeWAISQueryDocs(terms); - doList((void**)terms,freeTerm); - s_free(terms); + doList((void **) terms, freeTerm); + s_free(terms); - return(docs); + return (docs); } /*----------------------------------------------------------------------*/ @@ -2315,29 +2312,23 @@ any* buf; /* caller to assign nulls to the pointer fields of the WAIS object. */ /*----------------------------------------------------------------------*/ -void -CSTFreeWAISInitResponse(init) -WAISInitResponse* init; +void CSTFreeWAISInitResponse(WAISInitResponse *init) /* free an object made with makeWAISInitResponse */ { - s_free(init); + s_free(init); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISSearch(query) -WAISSearch* query; +void CSTFreeWAISSearch(WAISSearch *query) /* destroy an object made with makeWAISSearch() */ { - s_free(query); + s_free(query); } /*----------------------------------------------------------------------*/ -void -CSTFreeDocObj(doc) -DocObj* doc; +void CSTFreeDocObj(DocObj *doc) /* free a docObj */ { s_free(doc); @@ -2345,87 +2336,71 @@ DocObj* doc; /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocumentHeader(header) -WAISDocumentHeader* header; +void CSTFreeWAISDocumentHeader(WAISDocumentHeader *header) { s_free(header); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocumentShortHeader(header) -WAISDocumentShortHeader* header; +void CSTFreeWAISDocumentShortHeader(WAISDocumentShortHeader *header) { - s_free(header); + s_free(header); } + /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocumentLongHeader(header) -WAISDocumentLongHeader* header; +void CSTFreeWAISDocumentLongHeader(WAISDocumentLongHeader *header) { - s_free(header); + s_free(header); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISSearchResponse(response) -WAISSearchResponse* response; +void CSTFreeWAISSearchResponse(WAISSearchResponse * response) { - s_free(response); + s_free(response); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocumentText(docText) -WAISDocumentText* docText; +void CSTFreeWAISDocumentText(WAISDocumentText *docText) { - s_free(docText); + s_free(docText); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocHeadlines(docHeadline) -WAISDocumentHeadlines* docHeadline; +void CSTFreeWAISDocHeadlines(WAISDocumentHeadlines *docHeadline) { - s_free(docHeadline); + s_free(docHeadline); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISDocumentCodes(docCodes) -WAISDocumentCodes* docCodes; +void CSTFreeWAISDocumentCodes(WAISDocumentCodes *docCodes) { - s_free(docCodes); + s_free(docCodes); } /*----------------------------------------------------------------------*/ -void -CSTFreeWAISTextQuery(query) -any* query; +void CSTFreeWAISTextQuery(any *query) { - freeAny(query); + freeAny(query); } /*----------------------------------------------------------------------*/ - /* -** Routines originally from WMessage.c -- FM -** -**----------------------------------------------------------------------*/ + * Routines originally from WMessage.c -- FM + * + *----------------------------------------------------------------------*/ /* WIDE AREA INFORMATION SERVER SOFTWARE - No guarantees or restrictions. See the readme file for the full standard - disclaimer. - 3.26.90 -*/ + * No guarantees or restrictions. See the readme file for the full standard + * disclaimer. + * 3.26.90 + */ /* This file is for reading and writing the wais packet header. * Morris@think.com @@ -2438,20 +2413,18 @@ any* query; /*---------------------------------------------------------------------*/ -void -readWAISPacketHeader(msgBuffer,header_struct) -char* msgBuffer; -WAISMessage *header_struct; +void readWAISPacketHeader(char *msgBuffer, + WAISMessage * header_struct) { - /* msgBuffer is a string containing at least HEADER_LENGTH bytes. */ + /* msgBuffer is a string containing at least HEADER_LENGTH bytes. */ - memmove(header_struct->msg_len,msgBuffer,(size_t)10); - header_struct->msg_type = char_downcase((unsigned long)msgBuffer[10]); - header_struct->hdr_vers = char_downcase((unsigned long)msgBuffer[11]); - memmove(header_struct->server,(void*)(msgBuffer + 12),(size_t)10); - header_struct->compression = char_downcase((unsigned long)msgBuffer[22]); - header_struct->encoding = char_downcase((unsigned long)msgBuffer[23]); - header_struct->msg_checksum = char_downcase((unsigned long)msgBuffer[24]); + memmove(header_struct->msg_len, msgBuffer, (size_t) 10); + header_struct->msg_type = char_downcase((unsigned long) msgBuffer[10]); + header_struct->hdr_vers = char_downcase((unsigned long) msgBuffer[11]); + memmove(header_struct->server, (void *) (msgBuffer + 12), (size_t) 10); + header_struct->compression = char_downcase((unsigned long) msgBuffer[22]); + header_struct->encoding = char_downcase((unsigned long) msgBuffer[23]); + header_struct->msg_checksum = char_downcase((unsigned long) msgBuffer[24]); } /*---------------------------------------------------------------------*/ @@ -2460,43 +2433,35 @@ WAISMessage *header_struct; * options for the arguments. */ -void -writeWAISPacketHeader(header, - dataLen, - type, - server, - compression, - encoding, - version) -char* header; -long dataLen; -long type; -char* server; -long compression; -long encoding; -long version; +void writeWAISPacketHeader(char *header, + long dataLen, + long type, + char *server, + long compression, + long encoding, + long version) /* Puts together the new wais before-the-z39-packet header. */ { - char lengthBuf[11]; - char serverBuf[11]; + char lengthBuf[11]; + char serverBuf[11]; + + long serverLen = strlen(server); - long serverLen = strlen(server); - if (serverLen > 10) - serverLen = 10; + if (serverLen > 10) + serverLen = 10; - sprintf(lengthBuf, "%010ld", dataLen); - strncpy(header,lengthBuf,10); + sprintf(lengthBuf, "%010ld", dataLen); + strncpy(header, lengthBuf, 10); - header[10] = type & 0xFF; - header[11] = version & 0xFF; + header[10] = type & 0xFF; + header[11] = version & 0xFF; - strncpy(serverBuf,server,serverLen); - strncpy((char*)(header + 12),serverBuf,serverLen); + strncpy(serverBuf, server, serverLen); + strncpy((char *) (header + 12), serverBuf, serverLen); - header[22] = compression & 0xFF; - header[23] = encoding & 0xFF; - header[24] = '0'; /* checkSum(header + HEADER_LENGTH,dataLen); XXX the result must be ascii */ + header[22] = compression & 0xFF; + header[23] = encoding & 0xFF; + header[24] = '0'; /* checkSum(header + HEADER_LENGTH,dataLen); XXX the result must be ascii */ } /*---------------------------------------------------------------------*/ - |