home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / wutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-08  |  54.7 KB  |  1,917 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4. */
  5.  
  6. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  7.  
  8.  
  9. /*--------------------------------------------------------------------------
  10.  * ABSTRACT:    WAIS_TOOLS
  11.  *
  12.  * AUTHOR
  13.  *   M. Tracy Shen
  14.  *
  15.  *
  16.  *------------------------------------------------------------------------*/
  17.  
  18. #ifndef lint
  19. static char *RCSid = "$Header: /usr/users/freewais/FreeWAIS-0.1/ir/wutil.c,v 1.1 1993/02/16 15:05:35 freewais Exp $";
  20. #endif
  21.  
  22. /* Change log:
  23.  * $Log: wutil.c,v $
  24.  * Revision 1.1  1993/02/16  15:05:35  freewais
  25.  * Initial revision
  26.  *
  27.  * Revision 1.3  92/02/12  13:58:52  jonathan
  28.  * Added "$Log" so RCS will put the log message in the header
  29.  * 
  30.  * 
  31.  * ported to Unix and SaberC -brewster 7/7/90
  32.  * added in bug fixes -Tracy 11/14/90
  33.  */
  34.  
  35. /*  
  36.  * INCLUDE EXTERNAL CONSTANTS                                         
  37.  */
  38.  
  39. #include "futil.h"
  40. #include <ctype.h>
  41. #include "zprot.h"
  42. #include "zutil.h"
  43. #include "wprot.h"
  44. #include <string.h>
  45. #include "wutil.h"
  46.  
  47. #ifdef WIN32
  48. void twais_tmplt_typ3_srch_apdu(char*,long*);
  49. void dsply_doc_hdr_record(WAISDocumentHeader*);
  50. void dsply_short_hdr_record(WAISDocumentShortHeader*);
  51. #endif
  52.  
  53. /*  
  54.  * DEFINE LOCAL CONSTANTS
  55.  */
  56.  
  57.  
  58. #define CARRIAGE_RETURN 13
  59. #define LINE_FEED 10
  60. #define  ESC 27
  61. #define  DC1 17
  62. #define  DC3 19
  63. #define  ETS  3
  64.  
  65. #define FF  12
  66.  
  67.  
  68. #define INIT_CMD   1
  69. #define SEARCH_CMD 2
  70. #define EXTRACT_CMD 3
  71. #define STOP_CMD    4
  72.  
  73. #define MAX_CMD 4  /* init, query search, extract story, stop */
  74. #define MAX_BUFFER_LENGTH 10000 /* kludge -brewster */
  75.  
  76. /*
  77.  * DEFINE MACROS
  78.  */
  79.  
  80. #ifndef MIN
  81. #define MIN(a,b)  (a > b ? b : a)
  82. #endif
  83.  
  84. #define BIT(n)  (1L << n)
  85.  
  86. /*
  87.  * define global variables
  88.  */
  89.  
  90.  /* WAIS element names */
  91.     char *elm_name_tbl[] = {  ES_DocumentHeader
  92.                     ,ES_DocumentShortHeader
  93.                     ,ES_DocumentLongHeader
  94.                     ,ES_DocumentText
  95.                     ,ES_DocumentHeadline
  96.                     ,ES_DocumentCodes
  97.                     };
  98.  
  99. #ifdef TEST
  100.  
  101. twais_tmplt_typ1_srch_apdu _AP((char* buff,long* buff_len));
  102. twais_tmplt_typ3_srch_apdu _AP((char* buff,long* buff_len));
  103. dsply_doc_hdr_record _AP((WAISDocumentHeader* record));
  104. dsply_short_hdr_record _AP((WAISDocumentHeader* record));
  105.  
  106. main()
  107. {
  108.   char cmd[4096];
  109.   long cmd_len;
  110.  
  111.   printf("\n\n test template request apdu\n\n");
  112.  
  113.   do 
  114.     twais_format_req_apdu( TRUE, cmd, &cmd_len);
  115.   while ( cmd_len > 0 );
  116.  
  117.     
  118.  
  119.   printf("\n\n test formating request apdu\n\n");
  120.   do 
  121.     twais_format_req_apdu( FALSE, cmd, &cmd_len);
  122.   while ( cmd_len > 0 );
  123.  
  124.  
  125.   printf("\n\n test display init response apdu\n\n");
  126.  
  127.   twais_tmplt_init_rsp_apdu(  cmd, &cmd_len);
  128.   twais_dsply_rsp_apdu( cmd, cmd_len);
  129.  
  130.   printf("\n\n test display type3 search response apdu\n\n");
  131.   twais_tmplt_typ3_srch_rsp_apdu(  cmd, &cmd_len);
  132.   twais_dsply_rsp_apdu( cmd, cmd_len);
  133.  
  134.   printf("\n\n test display type1 search response apdu\n\n");
  135.   twais_tmplt_typ1_stry_rsp_apdu( cmd, &cmd_len);
  136.   twais_dsply_rsp_apdu( cmd, cmd_len);
  137.  
  138. }                               /* main */
  139.  
  140. #endif
  141.  
  142.  
  143. static void get_int_item _AP((char* itm_name, long *itm_val));
  144.  
  145. static void
  146. get_int_item(itm_name, itm_val)
  147. char *itm_name;
  148. long  *itm_val;
  149. {
  150.   printf("    %s (integer): ", itm_name);
  151.   scanf("%ld", itm_val);
  152. }
  153.  
  154. static void get_str_item _AP((char* itm_name,char*  itm_val));
  155.  
  156. static void
  157. get_str_item(itm_name, itm_val)
  158. char *itm_name;
  159. char *itm_val;
  160. {
  161.   printf("    %s (string): ", itm_name);
  162.   scanf("%s", itm_val);
  163. }
  164.  
  165. static void get_line_item _AP((char* itm_name,char*  itm_val));
  166.  
  167. static void
  168. get_line_item(itm_name, itm_val)
  169. char *itm_name;
  170. char *itm_val;
  171. {
  172.    
  173.   printf("    %s (one line string):\n", itm_name);
  174.   gets( itm_val);
  175.   if ( itm_val[0] == 0 )
  176.     gets(itm_val);
  177. }
  178.  
  179. static void get_req_type _AP((long* req_type));
  180.  
  181. static void
  182. get_req_type( req_type)
  183. long *req_type;
  184. {
  185.  
  186.   printf("\n\n");
  187.   printf(" request type 1)init  2)query search 3)extract story 4)stop: ");
  188.   scanf("%ld", req_type);
  189.  
  190. }                               /* get_req_type */
  191.  
  192. /*
  193.  * "twais_format_req_apdu"  This function gets request message.  It reads the
  194.  *   request message into the the specified buffer.
  195.  *   It returns the the length of the data 
  196.  *   written into the buffer as an output parameter.  
  197.  *   A zero length value indicates "end session".
  198.  *
  199.  * return values:
  200.  *  none
  201.  */
  202. void 
  203. twais_format_req_apdu(use_template,apdu_buff,len)
  204. boolean use_template;
  205. char* apdu_buff;
  206. long* len;
  207. /* use_template :  (I) flag indicating whether use template apdu */
  208. /* apdu_buff    :  (O) buffer to put apdu */
  209. /* len          :  (O) number of bytes written to the buffer */
  210. {
  211.   long req_type;
  212.  
  213.   do { 
  214.  
  215.     get_req_type( &req_type);
  216.  
  217.     switch (req_type) {
  218.     case INIT_CMD: 
  219.       *len = twais_format_init_apdu( use_template, apdu_buff);
  220.       break;
  221.     case SEARCH_CMD: 
  222.       *len = twais_format_typ3_srch_apdu( use_template, apdu_buff);
  223.       break;
  224.     case EXTRACT_CMD: 
  225.       *len = twais_format_typ1_srch_apdu( use_template,  apdu_buff);
  226.       break;
  227.     case STOP_CMD: 
  228.       *len = 0;
  229.       break;
  230.     default: 
  231.       break;
  232.     
  233.     }                           /* end switch */
  234.   }  
  235.   while ( req_type < 1 || req_type > MAX_CMD );
  236.  
  237. }                               /* twais_format_req_apdu */
  238.  
  239.  
  240.  
  241. /*
  242.  * "twais_format_init_apdu"
  243.  *   prompt user information to format an init apdu and 
  244.  *   write the apdu to the specified buffer
  245.  *
  246.  * function return:
  247.  *   number of bytes written to the buffer 
  248.  */
  249. long 
  250. twais_format_init_apdu(use_template,apdu_buff)
  251. boolean use_template;
  252. char* apdu_buff;
  253.  
  254. /* use_template :  (I) flag indicating whether use template apdu */
  255. /* apdu_buff    :  (O) buffer to put apdu */
  256. {
  257.   InitAPDU *init1;
  258.   char  *end_ptr;
  259.   long len;
  260.   long pref_msg_size;
  261.   long max_rec_size;
  262.   any refID;
  263.   char ref_id[128];
  264.  
  265.   if ( use_template ) {
  266.     twais_tmplt_init_apdu(apdu_buff, &len);
  267.     return( len);
  268.   }      
  269.  
  270.   get_int_item( "prefered message size", &pref_msg_size);
  271.   get_int_item( "maximum record size", &max_rec_size);
  272.  
  273.   get_str_item("reference id", ref_id);
  274.   refID.size = strlen(ref_id);
  275.   refID.bytes = &ref_id[0];
  276.  
  277.   init1 = makeInitAPDU(WILL_USE,WILL_NOT_USE,WILL_NOT_USE,WILL_NOT_SUPPORT,
  278.                        WILL_NOT_SUPPORT,
  279.                        pref_msg_size,
  280.                        max_rec_size, NULL,
  281.                        defaultImplementationID(),defaultImplementationName(),
  282.                        defaultImplementationVersion(), &refID,NULL);
  283.  
  284.   { long buffer_len = MAX_BUFFER_LENGTH;
  285.     end_ptr = writeInitAPDU(init1, apdu_buff, &buffer_len);
  286.   }
  287.   freeInitAPDU(init1);
  288.   len = (long)end_ptr - (long)apdu_buff;
  289.   return(len);  
  290. }                               /* twais_format_init_apdu */
  291.  
  292. /* 
  293.  * "twais_format_typ3_srch_apdu"  
  294.  *  prompt user information to form a relevance feedback search apdu and
  295.  *  write the apdu to the specified buffer
  296.  *
  297.  * function return:
  298.  *   number of bytes written to the buffer 
  299.  */
  300. long 
  301. twais_format_typ3_srch_apdu(use_template,apdu_buff)
  302. boolean use_template;
  303. char* apdu_buff;
  304.  
  305. /* use_template :  (I) flag indicating whether use template apdu */
  306. /* apdu_buff    :  (O) buffer to put apdu */
  307. {
  308.   SearchAPDU *search;
  309.   char  *end_ptr;
  310.   long len;
  311.   long small, large, medium;
  312.  
  313.   char temp_string[80];
  314.  
  315.   long num_databases, num_elmsets, i;
  316.   char **database_names_ptr;
  317.   char *database_names[11];
  318.   char database_name[10][129];
  319.   long  elm_type;
  320.   char *elm_names[21];
  321.   char elm_name[20][128];
  322.   char **elm_names_ptr = &elm_names[0];
  323.  
  324.   any refID;
  325.   char ref_id[256];
  326.   char seed_words[257];
  327.  
  328.   DocObj *DocObjs[5];
  329.  
  330.   DocObj **DocObjsPtr = 0;
  331.   long DateFactor;
  332.   char BeginDateRange[9], EndDateRange[9];
  333.   long maxDocsRetrieved;
  334.   long num, sw;
  335.   char doc_id[4][200];
  336.   any docID[4];
  337.   long ChunkCode;
  338.   any Start[4], End[4];   
  339.   char start_pos[4][10], end_pos[4][10];
  340.   long start_ipos, end_ipos;
  341.   WAISSearch *query;
  342.   long count;
  343.   for(count = 0; count < 5; count++){
  344.     DocObjs[count] = 0;         /* added by brewster */
  345.   }
  346.  
  347.   if ( use_template ) {
  348.     twais_tmplt_typ3_srch_apdu(apdu_buff, &len);
  349.     return( len);
  350.   }      
  351.  
  352.  
  353.   get_int_item("small set upper bound", &small);
  354.   get_int_item("large set lower bound", &large);
  355.   get_int_item("medium set present number", &medium);
  356.  
  357.   get_int_item("number of databases(max 10, 0 search entire databases)", &num_databases);
  358.  
  359.   if ( num_databases == 0 ) {
  360.     database_names_ptr = 0;
  361.   }
  362.  
  363.   else {
  364.     database_names_ptr = &database_names[0];
  365.     database_names[num_databases] = 0;  
  366.     for ( i=0; i < num_databases; i++ ) {
  367.       database_names[i] = &database_name[i][0];
  368.       sprintf( temp_string,"database name %ld", (i+1) );
  369.       get_str_item(temp_string, database_name[i]);
  370.     }
  371.   }
  372.  
  373.   get_int_item("number of database-element_set pairs(max 10)", &num_elmsets);
  374.  
  375.   if ( num_elmsets == 0 ) 
  376.     elm_names_ptr = 0;
  377.   else {
  378.     elm_names[num_elmsets * 2 ] = 0;
  379.     for ( i=0; i < num_elmsets; i++ ) {
  380.       elm_names[i*2] = &elm_name[i*2][0];
  381.       sprintf( temp_string,"database name %ld", (i+1) );
  382.       get_str_item(temp_string, &elm_name[i*2][0]);
  383.  
  384.       get_int_item("  element type 0)default 1)DocHeaders 2)ShortHeaders\n        3)LongHeaders 4)Text 5)HeadLines 6)Codes", 
  385.                    &elm_type);
  386.       if ( (elm_type < 1) || (elm_type > 6) )
  387.         elm_type = 1;
  388.       elm_names[i*2+1] = &elm_name[i*2+1][0];
  389.       strcpy( &elm_name[i*2+1][0], elm_name_tbl[elm_type-1]);
  390.     }
  391.   }
  392.  
  393.  
  394.   get_str_item("reference id", ref_id);
  395.   refID.size = strlen(ref_id);
  396.   refID.bytes = &ref_id[0];
  397.  
  398.   /*
  399.    * format wais search query
  400.    */
  401.   /* fill in the user information */
  402.  
  403.   get_line_item("seed_words", seed_words);
  404.   get_int_item("number of relevance feedback documents(max 4)", &num);
  405.   if ( num > 0 ) {
  406.  
  407.     if ( num > 4 )
  408.       num = 4;
  409.     DocObjsPtr = &DocObjs[0];
  410.     for ( i=0; i< num; i++) {
  411.       docID[i].bytes = &doc_id[i][0];
  412.       sprintf(temp_string, "document id %ld", (i+1));
  413.       get_str_item(temp_string, &doc_id[i][0]);
  414.       docID[i].size = strlen( &doc_id[i][0]);
  415.       get_int_item("  (1)whole story (2)part story", &sw);
  416.       if ( sw == 1) {
  417.         DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  418.       }
  419.       else {
  420.         get_int_item("  ChunkCode (1)byte (2)line (3)parag", &ChunkCode);
  421.         if ( ChunkCode == 1 ) {
  422.           get_int_item("  start position", &start_ipos);
  423.           get_int_item("  end position", &end_ipos);
  424.           DocObjs[i] = makeDocObjUsingBytes( &docID[i], NULL,
  425.                                             start_ipos, end_ipos);
  426.         }
  427.         else if ( ChunkCode == 2 ) {
  428.           get_int_item("  start position", &start_ipos);
  429.           get_int_item("  end position", &end_ipos);
  430.           DocObjs[i] = makeDocObjUsingLines( &docID[i], NULL,
  431.                                             start_ipos, end_ipos);
  432.         }
  433.         else {
  434.           get_str_item("  start position", &start_pos[i][0]);
  435.           get_str_item("  end position", &end_pos[i][0]);
  436.           Start[i].size = strlen( &start_pos[i][0]);
  437.           Start[i].bytes = &start_pos[i][0];
  438.           End[i].size = strlen( &end_pos[i][0]);
  439.           End[i].bytes = &end_pos[i][0];
  440.           DocObjs[i] = makeDocObjUsingParagraphs( &docID[i], NULL,
  441.                                                  &Start[i], &End[i]);
  442.         }
  443.       }                         /* end if-else */
  444.     }                           /* end for */
  445.   }                             /* end if */
  446.    
  447.   get_int_item("DateFactor (1-independent,2-later,3-earlier,4-range)", &DateFactor);
  448.   if ( DateFactor == 2 || DateFactor == 4) 
  449.     get_str_item("begin date  (yyyymmdd)", BeginDateRange);
  450.   else
  451.     BeginDateRange[0] = '\0';
  452.   if ( DateFactor == 3 || DateFactor == 4) 
  453.     get_str_item("end date (yyyymmdd)", EndDateRange);
  454.   else
  455.     EndDateRange[0] = '\0';
  456.  
  457.   get_int_item("max. documents retrieved", &maxDocsRetrieved);
  458.  
  459.   query = makeWAISSearch( seed_words, DocObjsPtr, 0L,
  460.                          DateFactor, BeginDateRange, EndDateRange,
  461.                          maxDocsRetrieved);
  462.  
  463.   search = makeSearchAPDU( small, large, medium, 
  464.                           1L,   /* replace indicator */
  465.                           "FOO", /* result set name */
  466.                           database_names_ptr, /* database name */   
  467.                           QT_RelevanceFeedbackQuery, /* query_type */
  468.                           elm_names_ptr, /* element name */
  469.                           &refID, query);
  470.  
  471.   {
  472.     long buffer_len = MAX_BUFFER_LENGTH;
  473.     end_ptr = writeSearchAPDU(search, apdu_buff, &buffer_len);
  474.   }
  475.   len = (long)end_ptr - (long)apdu_buff;
  476.  
  477.   i =0;
  478.   while ( DocObjs[i] != 0 ) {
  479.     CSTFreeDocObj( DocObjs[i]);
  480.     i++;
  481.   }
  482.  
  483.   CSTFreeWAISSearch(query);
  484.  
  485.   freeSearchAPDU(search);
  486.  
  487.   return(len);
  488.  
  489. }                               /* twais_format_typ3_srch_apdu */
  490.  
  491. /* 
  492.  * "twais_format_typ1_srch_apdu"  
  493.  *  prompt user information to form a text retrieval search apdu and
  494.  *  write the apdu to the specified buffer
  495.  *
  496.  * function return:
  497.  *   number of bytes written to the buffer 
  498.  */
  499. long
  500. twais_format_typ1_srch_apdu(use_template,apdu_buff)
  501. boolean use_template;
  502. char* apdu_buff;
  503.  
  504. /* use_template :  (I) flag indicating whether use template apdu */
  505. /* apdu_buff    :  (O) buffer to put apdu */
  506. {
  507.   SearchAPDU *search;
  508.   char  *end_ptr;
  509.   long len;
  510.   long small, large, medium;
  511.  
  512.   char temp_string[80];
  513.  
  514.   long num_databases, num_elmsets, i;
  515.   char **database_names_ptr;
  516.   char *database_names[11];
  517.   char database_name[10][129];
  518.   long  elm_type;
  519.   char *elm_names[21];
  520.   char elm_name[20][128];
  521.   char **elm_names_ptr = &elm_names[0];
  522.  
  523.   any refID;
  524.   char ref_id[256];
  525.  
  526.   any *query;                   /* changed by brewster from char * */
  527.   DocObj *DocObjs[11];
  528.   long num_doc;
  529.   long sw;
  530.   char doc_id[10][200];
  531.   any docID[10];
  532.   long ChunkCode;
  533.   any Start[10], End[10];   
  534.   long start_ipos, end_ipos;
  535.   char start_pos[10][10], end_pos[10][10];
  536.  
  537.   long use_text = 0;
  538.  
  539.  
  540.   if ( use_template ) {
  541.     twais_tmplt_typ1_srch_apdu(apdu_buff, &len);
  542.     return( len);
  543.   }      
  544.  
  545.  
  546.   get_int_item("small set upper bound", &small);
  547.   get_int_item("large set lower bound", &large);
  548.   get_int_item("medium set present number", &medium);
  549.  
  550.   get_int_item("number of databases(max 10, 0 search entire databases)", &num_databases);
  551.  
  552.   if ( num_databases == 0 ) {
  553.     database_names_ptr = 0;
  554.   }
  555.   else {
  556.     database_names_ptr = &database_names[0];
  557.     database_names[num_databases] = 0;  
  558.     for ( i=0; i < num_databases; i++ ) {
  559.       database_names[i] = &database_name[i][0];
  560.       sprintf(temp_string, "database name %ld", (i+1));
  561.       get_str_item( temp_string, database_name[i]);
  562.     }
  563.   }
  564.  
  565.   get_int_item("number of database-element_set pairs(max 10)", &num_elmsets);
  566.  
  567.   if ( num_elmsets == 0 ) 
  568.     elm_names_ptr = 0;
  569.   else {
  570.     elm_names[num_elmsets * 2 ] = 0;
  571.     for ( i=0; i < num_elmsets; i++ ) {
  572.       elm_names[i*2] = &elm_name[i*2][0];
  573.       sprintf( temp_string,"database name %ld", (i+1) );
  574.       get_str_item(temp_string, &elm_name[i*2][0]);
  575.  
  576.       get_int_item("  element type 0)default 1)DocHeaders 2)ShortHeaders\n        3)LongHeaders 4)Text 5)HeadLines 6)Codes", 
  577.                    &elm_type);
  578.       if ( (elm_type < 1) || (elm_type > 6) )
  579.         elm_type = 1;
  580.       if ( elm_type == 4)  use_text++;
  581.       elm_names[i*2+1] = &elm_name[i*2+1][0];
  582.       strcpy( &elm_name[i*2+1][0], elm_name_tbl[elm_type-1]);
  583.     }
  584.   }
  585.  
  586.   get_str_item("reference id", ref_id);
  587.   refID.size = strlen(ref_id);
  588.   refID.bytes = &ref_id[0];
  589.  
  590.   /*
  591.    * format type 1 query
  592.    */
  593.   get_int_item("num of documents to retrieve (max 10)", &num_doc);
  594.   if ( num_doc > 10 ) num_doc = 10;
  595.   if ( num_doc < 1 ) num_doc = 1;
  596.  
  597.   DocObjs[num_doc] = 0;
  598.  
  599.   for ( i=0; i < num_doc; i++ ) {
  600.     docID[i].bytes = &doc_id[i][0];
  601.  
  602.     sprintf( temp_string, "document id %ld", (i+1));
  603.     get_str_item(temp_string, &doc_id[i][0]);
  604.     docID[i].size = strlen( &doc_id[i][0]);
  605.         
  606.     if ( use_text == 0 )
  607.       DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  608.     else {         
  609.       get_int_item("  (1)whole story (2)part story", &sw);
  610.       if ( sw == 1) {
  611.         DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  612.       }
  613.       else {
  614.         get_int_item("  ChunkCode (1)byte (2)line (3)parag", &ChunkCode);
  615.         if ( ChunkCode == 1 ) {
  616.           get_int_item("  start position", &start_ipos);
  617.           get_int_item("  end position", &end_ipos);
  618.           DocObjs[i] = makeDocObjUsingBytes( &docID[i], NULL,
  619.                                             start_ipos, end_ipos);
  620.         }
  621.         else if ( ChunkCode == 2 ) {
  622.           get_int_item("  start position", &start_ipos);
  623.           get_int_item("  end position", &end_ipos);
  624.           DocObjs[i] = makeDocObjUsingLines( &docID[i], NULL,
  625.                                             start_ipos, end_ipos);
  626.         }
  627.         else {
  628.           get_str_item("  start position", &start_pos[i][0]);
  629.           get_str_item("  end position", &end_pos[i][0]);
  630.           Start[i].size = strlen( &start_pos[i][0]);
  631.           Start[i].bytes = &start_pos[i][0];
  632.           End[i].size = strlen( &end_pos[i][0]);
  633.           End[i].bytes = &end_pos[i][0];
  634.           DocObjs[i] = makeDocObjUsingParagraphs( &docID[i], NULL,
  635.                                                  &Start[i], &End[i]);
  636.         }
  637.       }                         /* end if-else */
  638.     }
  639.   }
  640.  
  641.   query = makeWAISTextQuery(DocObjs);   
  642.  
  643.  
  644.   search = makeSearchAPDU( small, large, medium, 
  645.                           1L,   /* replace indicator */
  646.                           "FOO", /* result set name */
  647.                           database_names_ptr, /* database name */   
  648.                           QT_TextRetrievalQuery, /* query_type */
  649.                           elm_names_ptr, /* element name */
  650.                           &refID, query);
  651.  
  652.   {
  653.     long buffer_len = MAX_BUFFER_LENGTH;
  654.     end_ptr = writeSearchAPDU(search, apdu_buff, &buffer_len);
  655.   }
  656.   len = (long)end_ptr - (long)apdu_buff;
  657.  
  658.   i =0;
  659.   while ( DocObjs[i] != 0) {
  660.     CSTFreeDocObj( DocObjs[i]);
  661.     i++;
  662.   }
  663.  
  664.   CSTFreeWAISTextQuery( query);
  665.  
  666.   freeSearchAPDU(search);
  667.  
  668.   return(len);
  669.  
  670. }                               /* twais_format_typ1_srch_apdu */
  671.  
  672. static void print_hdline _AP((char* hdline));
  673.  
  674. static void print_hdline(hdline)
  675. char *hdline;
  676. {
  677.   char buf[301];
  678.   long len, i;
  679.  
  680.   len = strlen(hdline);
  681.   if (len > 300 )
  682.     len =300;
  683.   for ( i=0; i< len; i++ )
  684.     if ( hdline[i] > 31 && hdline[i] < 127 )
  685.       buf[i] = hdline[i];
  686.     else
  687.       buf[i] = '@';         
  688.   buf[i] = 0;
  689.   printf("     Headline:  %s\n", buf);
  690. }
  691.  
  692.  
  693. static void print_any _AP((char* title,any*  any_ptr));
  694.  
  695. static void print_any( title, any_ptr)
  696. char *title;
  697. any *any_ptr;
  698. {
  699.   long i;
  700.   printf("%s", title);
  701.   if ( any_ptr ) {
  702. #ifdef WIN32
  703.     for ( i=0; i < (long)(any_ptr->size); i++)
  704. #else
  705.     for ( i=0; i < any_ptr->size; i++)
  706. #endif
  707.      { if (isprint(any_ptr->bytes[i]))
  708.          printf("%c", any_ptr->bytes[i]);
  709.        else
  710.          printf("%ld", (long)any_ptr->bytes[i]);
  711.      }
  712.     printf("\n");
  713.   } 
  714. }
  715.  
  716.  
  717.   
  718. static void dsply_long_hdr_record _AP((WAISDocumentLongHeader* record));
  719.  
  720. static void dsply_long_hdr_record(record)
  721. WAISDocumentLongHeader *record;
  722. /*
  723.  * 'dsply_long_hdr_record'
  724.  *   display one WAIS long header  record 
  725.  */
  726. {
  727.   printf(" LongHeaders\n");
  728.  
  729.   print_any("     DocumentID:  ", record->DocumentID);
  730.  
  731.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  732.  
  733.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  734.          record->Score,
  735.          record->BestMatch);
  736.  
  737.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  738.          record->DocumentLength,
  739.          record->Lines);
  740.  
  741.   if ( record->Source )
  742.     printf("     Source:  %s\n", record->Source);
  743.  
  744.   if ( record->Date )
  745.     printf("     Date:  %s\n", record->Date);
  746.  
  747.   if ( record->OriginCity)
  748.     printf("     OriginCity:  %s\n", record->OriginCity);
  749.  
  750.   if ( record->Headline)
  751. #ifdef FOR_DUM_TERM
  752.     print_hdline(record->Headline);
  753. #else
  754.   printf("     Headline:  %s\n", record->Headline);
  755. #endif
  756.  
  757.   if ( record->StockCodes)
  758.     printf("     StockCodes:  %s", record->StockCodes);
  759.  
  760.   if ( record->CompanyCodes )
  761.     printf("     CompanyCodes:  %s", record->CompanyCodes);
  762.  
  763.   if ( record->IndustryCodes)
  764.     printf("     IndustryCodes:  %s", record->IndustryCodes);
  765.  
  766.   printf("\n");
  767. }
  768. /*
  769.  * dsply_text
  770.  *  display story text
  771.  */
  772. #define TEXT_LINES_PER_PAGE 18
  773. #define  DQ_PAR_LEN   3
  774. #define  DQ_EOL_LEN   1
  775. #define  DQ_MAX_LINE_LEN  256
  776.  
  777. #define  PRINT_LINE(line, ndx, line_cnt,text_ptr,last_ptr,continue_viewing)\
  778.          line[ndx] = NULL;\
  779.          line_cnt++; \
  780.          printf("%s\n", line);\
  781.          ndx = 0;\
  782.          if ( (line_cnt == TEXT_LINES_PER_PAGE) && (text_ptr <= last_ptr)) {\
  783.             line_cnt = 0;\
  784.             printf("\n  ... more to come, enter 1 to continue or 0 to stop: ");\
  785.             scanf("%ld", &continue_viewing);\
  786.             }
  787.  
  788. #if 0
  789. /*
  790.  * try to format text
  791.  */
  792. dsply_text( size, text)
  793. long size;
  794. char *text;
  795. {
  796.   char  line[DQ_MAX_LINE_LEN +1];
  797.   char *last_ptr;
  798.   char *text_ptr;
  799.   long  ndx;
  800.   long line_cnt = 0;
  801.   long continue_viewing = 1;
  802.     
  803.   text_ptr = text;
  804.  
  805.   last_ptr = text_ptr + size;
  806.  
  807.   while ( (*text_ptr != ETS) && (text_ptr < last_ptr) ) {
  808.     if (  *text_ptr++ == ESC ) {
  809.       if (*text_ptr++ == 'k') 
  810.         break;
  811.     }
  812.   }
  813.  
  814.   if ( text_ptr >= last_ptr ) {
  815.     printf("**** ERROR in display text -- could not find text\n");
  816.     return;
  817.   }
  818.  
  819.   ndx = 0;
  820.  
  821.   while ( (continue_viewing == 1) && ( *text_ptr != ETS) &&
  822.          (text_ptr < last_ptr) ) {
  823.  
  824.     /* paragraph id -- skip */
  825.     if ( *text_ptr == ESC) {
  826.       text_ptr++;
  827.       if ( *text_ptr == 'l' )
  828.         text_ptr++;
  829.       if ( ndx > 0 ) {
  830.         PRINT_LINE(line, ndx,line_cnt,text_ptr,last_ptr,continue_viewing);  
  831.       }
  832.       ndx = DQ_PAR_LEN;
  833.       strncpy( line, text_ptr, ndx);
  834.       text_ptr += DQ_PAR_LEN;
  835.       PRINT_LINE(line, ndx,line_cnt,text_ptr,last_ptr,continue_viewing);  
  836.     }
  837.  
  838.     /* highlight & dehighlight markers -- skip */
  839.     else if ( (*text_ptr == DC1) || (*text_ptr == DC3) ) 
  840.       text_ptr++;
  841.  
  842.     /* CR -- skip and print */
  843.     else if ( *text_ptr == CARRIAGE_RETURN ) {
  844.       text_ptr += DQ_EOL_LEN;   /* CR, LF */
  845.       PRINT_LINE(line, ndx, line_cnt,text_ptr,last_ptr,continue_viewing);
  846.     }
  847.  
  848.     else {
  849.       line[ndx++] = *text_ptr++;
  850.       if ( ndx > DQ_MAX_LINE_LEN ) {
  851.         printf("**** ERROR in display text -- line too long %ld\n", ndx);
  852.         return;
  853.       }
  854.     }
  855.   }                             /* end while */
  856.  
  857.   if ( text_ptr >= last_ptr ) {
  858.     printf("**** ERROR in display text -- could not find End Of Text\n");
  859.     return;
  860.   }
  861.  
  862.   if ( ndx > 0 ) {
  863.     line[ndx] = NULL;
  864.     line_cnt++; 
  865.     printf("%s\n", line);
  866.   }
  867.  
  868.  
  869. }                               /* dsply_text */
  870. #endif
  871.  
  872. static void dsply_text _AP((long size,char* text));
  873.  
  874. static void dsply_text( size, text)
  875. long size;
  876. char *text;
  877. {
  878.   char *text_ptr, *last_ptr;
  879.   long line_cnt = 0;
  880.   long continue_viewing = 1;
  881.   char buff[3200];
  882.   long len;
  883.   char *buff_start, *buff_ptr;
  884.     
  885.   text_ptr = text;
  886.  
  887.   buff_start = &buff[0];    
  888.   buff_ptr = buff_start;
  889.   
  890.   last_ptr = text_ptr + size;
  891.  
  892.   while ( (text_ptr <= last_ptr) && (continue_viewing == 1) ) {
  893.     /* control markers */
  894.     if (  *text_ptr == ESC ) {
  895.       text_ptr++;
  896.       text_ptr++;
  897.     }
  898.     /* highlight & dehighlight markers -- skip */
  899.     else if (*text_ptr == DC1 || *text_ptr == DC3)
  900.       text_ptr++;
  901.     else if (*text_ptr == ETS)
  902.       text_ptr++;
  903.     else if ( *text_ptr == CARRIAGE_RETURN ) {
  904.       text_ptr++;               /* CR */
  905.       *buff_ptr++= CARRIAGE_RETURN;
  906.       *buff_ptr++ = LINE_FEED;
  907.       line_cnt++;
  908.       if ( (line_cnt == TEXT_LINES_PER_PAGE) && 
  909.           (text_ptr <= last_ptr)) {
  910.         len = (long)buff_ptr - (long) buff_start;
  911.         fwrite( buff_start, len, 1, stdout);
  912.         line_cnt = 0;
  913.         buff_ptr = buff_start;
  914.         printf("\n  ... more to come, enter 1 to continue or 0 to stop: ");
  915.         scanf("%ld", &continue_viewing);
  916.       }
  917.     }
  918.     else 
  919.       *buff_ptr++ = *text_ptr++;
  920.   }                             /* end while */
  921.  
  922.   if ( buff_ptr > buff_start) {
  923.     len = (long)buff_ptr - (long)buff_start;
  924.     fwrite( buff_start, len,  1, stdout);
  925.   }
  926.  
  927. }                               /* dsply_text */
  928.  
  929. static void dsply_text_record _AP((WAISDocumentText*  record));
  930.  
  931. static void dsply_text_record( record)
  932. WAISDocumentText *record;
  933. /*
  934.  * 'dsply_text_record'
  935.  *   display one WAIS text record 
  936.  */
  937. {
  938.   printf(" Text\n");
  939.   print_any("     DocumentID:  ", record->DocumentID);
  940.  
  941.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  942.   dsply_text( record->DocumentText->size,
  943.              record->DocumentText->bytes);
  944. }
  945.  
  946. static void dsply_headline_record _AP((WAISDocumentHeadlines*  record));
  947.  
  948. static void dsply_headline_record( record)
  949. WAISDocumentHeadlines *record;
  950. /*
  951.  * 'dsply_headline_record'
  952.  *   display one WAIS headline record 
  953.  */
  954. {
  955.   printf(" Headlines\n");
  956.   print_any("     DocumentID:  ", record->DocumentID);
  957.  
  958.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  959.  
  960.   if ( record->Source )
  961.     printf("     Source:  %s\n", record->Source);
  962.  
  963.   if ( record->Date )
  964.     printf("     Date:  %s\n", record->Date);
  965.  
  966.   if ( record->OriginCity)
  967.     printf("     OriginCity:  %s\n", record->OriginCity);
  968.   print_hdline(record->Headline);
  969.  
  970.   if ( record->Headline)
  971. #ifdef FOR_DUM_TERM
  972.     print_hdline(record->Headline);
  973. #else
  974.   printf("     Headline:  %s\n", record->Headline);
  975. #endif
  976. }
  977.  
  978. static void dsply_code_record _AP((WAISDocumentCodes*  record));
  979.  
  980. static void dsply_code_record( record)
  981. WAISDocumentCodes  *record;
  982. /*
  983.  * 'dsply_code_record'
  984.  *   display one WAIS code record 
  985.  */
  986. {
  987.   printf(" Codes\n");
  988.   print_any("     DocumentID:  ", record->DocumentID);
  989.  
  990.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  991.  
  992.   if ( record->StockCodes)
  993.     printf("     StockCodes:  %s", record->StockCodes);
  994.  
  995.   if ( record->CompanyCodes )
  996.     printf("     CompanyCodes:  %s", record->CompanyCodes);
  997.  
  998.   if ( record->IndustryCodes)
  999.     printf("     IndustryCodes:  %s", record->IndustryCodes);
  1000.  
  1001.   printf("\n");
  1002. }
  1003.  
  1004.  
  1005. /*
  1006.  * "twais_dsply_rsp_apdu"
  1007.  *   display response apdu on stdout
  1008.  *   the response apdu is in the specified buffer
  1009.  */
  1010. void
  1011. twais_dsply_rsp_apdu(rsp_buff, rsp_len)
  1012. char *rsp_buff;         /* (I) buffer contain response apdu */
  1013. long  rsp_len;           /* (I) number of bytes in the buffer */
  1014. {
  1015.  
  1016.   pdu_type pdu;
  1017.   pdu = peekPDUType(rsp_buff);
  1018.   switch ( pdu) {
  1019.   case initResponseAPDU:
  1020.     twais_dsply_init_rsp_apdu( rsp_buff);
  1021.     break;
  1022.   case searchResponseAPDU:
  1023.     twais_dsply_srch_rsp_apdu( rsp_buff);
  1024.     break;
  1025.  
  1026.   case initAPDU:
  1027.     twais_dsply_init_apdu( rsp_buff);
  1028.     break;
  1029.   case searchAPDU:
  1030.     twais_dsply_srch_apdu( rsp_buff);
  1031.     break;
  1032.   default:
  1033.     /* others not supported yet */
  1034.     break;
  1035.   }
  1036.  
  1037. }                               /* twais_dsply_rsp_apdu */
  1038.  
  1039.  
  1040. /*
  1041.  * "twais_dsply_init_rsp_apdu"
  1042.  *   display init response apdu on stdout
  1043.  *   the response apdu is encoded in the specified buffer
  1044.  */
  1045. void
  1046. twais_dsply_init_rsp_apdu( buffer)
  1047. char *buffer;           /* (I) buffer contain the init response apdu */
  1048. {
  1049.  
  1050.   InitResponseAPDU *response;
  1051.   WAISInitResponse *info;
  1052.   long i, len;
  1053.  
  1054.   printf("\n\n Init Response:\n");
  1055.  
  1056.   readInitResponseAPDU(&response,buffer);
  1057.  
  1058.   printf("    willSearch: %ld,  willPresent: %ld,  willDelete: %ld\n", 
  1059.          response->willSearch, 
  1060.          response->willPresent,
  1061.          response->willDelete);
  1062.   printf("    supportAccessControl: %ld,  supportResourceControl: %ld\n",
  1063.          response->supportAccessControl,
  1064.          response->supportResourceControl);
  1065.   printf("    PreferredMessageSize: %ld,  MaximumRecordSize: %ld\n",
  1066.          response->PreferredMessageSize, 
  1067.          response->MaximumRecordSize);
  1068.   if ( response->ImplementationID != 0) {
  1069.     printf("    ImplementationID: %s\n", 
  1070.            response->ImplementationID);   
  1071.   }
  1072.   if ( response->ImplementationName != 0) {
  1073.     printf("    ImplementationName: %s\n",
  1074.            response->ImplementationName);   
  1075.   }
  1076.   if ( response->ImplementationVersion != 0) {
  1077.     printf("    ImplementationVersion: %s\n",
  1078.            response->ImplementationVersion);   
  1079.   }
  1080.   if ( response->ReferenceID != 0) {
  1081.     print_any("    ReferenceID: ", response->ReferenceID);
  1082.   }
  1083.  
  1084.   if ( response->UserInformationField != 0) {
  1085.     info = (WAISInitResponse *)response->UserInformationField;
  1086.     printf("    ChunkCode: %ld,  ChunkIDLength: %ld\n",
  1087.            info->ChunkCode,
  1088.            info->ChunkIDLength);
  1089.  
  1090.     printf("    ChunkMarker: ");
  1091.     len = strlen( info->ChunkMarker);
  1092.     for ( i=0; i< len; i++)
  1093.       printf("%ld, ", info->ChunkMarker[i]);
  1094.     printf("\n");
  1095.  
  1096.     printf("    HighlightMarker: ");
  1097.     len = strlen( info->HighlightMarker);
  1098.     for ( i=0; i< len; i++)
  1099.       printf("%ld, ", info->HighlightMarker[i]);
  1100.     printf("\n");
  1101.  
  1102.     printf("    DeHighlightMarker: ");
  1103.     len = strlen( info->DeHighlightMarker);
  1104.     for ( i=0; i< len; i++)
  1105.       printf("%ld, ", info->DeHighlightMarker[i]);
  1106.     printf("\n");
  1107.  
  1108.     printf("    NewlineCharacters: ");
  1109.     len = strlen( info->NewlineCharacters);
  1110.     for ( i=0; i< len; i++)
  1111.       printf("%ld, ", info->NewlineCharacters[i]);
  1112.     printf("\n");
  1113.  
  1114.   }
  1115.   freeInitResponseAPDU( response);
  1116.  
  1117. }                               /* twais_dsply_init_rsp_apdu */
  1118.  
  1119. /*
  1120.  * "twais_dsply_init_apdu"
  1121.  *   display init apdu on stdout
  1122.  *   the apdu is in the specified buffer
  1123.  */
  1124. void
  1125. twais_dsply_init_apdu( buffer)
  1126. char *buffer;           /* (I) buffer contain the init response apdu */
  1127. {
  1128.  
  1129.   InitAPDU *init;
  1130.  
  1131.   printf("\n\n Init Request:\n");
  1132.  
  1133.   readInitAPDU(&init,buffer);
  1134.  
  1135.   printf("    willSearch: %ld,  willPresent: %ld,  willDelete: %ld\n", 
  1136.          init->willSearch, 
  1137.          init->willPresent,
  1138.          init->willDelete);
  1139.   printf("    supportAccessControl: %ld,  supportResourceControl: %ld\n",
  1140.          init->supportAccessControl,
  1141.          init->supportResourceControl);
  1142.   printf("    PreferredMessageSize: %ld,  MaximumRecordSize: %ld\n",
  1143.          init->PreferredMessageSize, 
  1144.          init->MaximumRecordSize);
  1145.  
  1146.   if ( init->IDAuthentication != 0) {
  1147.     printf("    IDAuthentication: %s\n", 
  1148.            init->IDAuthentication);   
  1149.   }
  1150.  
  1151.   if ( init->ImplementationID != 0) {
  1152.     printf("    ImplementationID: %s\n", 
  1153.            init->ImplementationID);   
  1154.   }
  1155.  
  1156.   if ( init->ImplementationName != 0) {
  1157.     printf("    ImplementationName: %s\n",
  1158.            init->ImplementationName);   
  1159.   }
  1160.  
  1161.   if ( init->ImplementationVersion != 0) {
  1162.     printf("    ImplementationVersion: %s\n",
  1163.            init->ImplementationVersion);   
  1164.   }
  1165.  
  1166.   if ( init->ReferenceID != 0) {
  1167.     print_any("    ReferenceID: ", init->ReferenceID);
  1168.   }
  1169.  
  1170.   freeInitAPDU( init);
  1171.  
  1172. }                               /* twais_dsply_init_apdu */
  1173.  
  1174. /*
  1175.  * "twais_dsply_srch_rsp_apdu"
  1176.  *   display search response apdu on stdout
  1177.  *   the response apdu is encoded in the specified buffer
  1178.  */
  1179. void
  1180. twais_dsply_srch_rsp_apdu( buffer)
  1181. char *buffer;           /* (I) buffer contain the search response apdu */
  1182. {
  1183.   SearchResponseAPDU  *response;
  1184.   WAISSearchResponse  *info;
  1185.   long continue_viewing;
  1186.   long i, k;
  1187.  
  1188.   printf("\n\n Search Response:\n");
  1189.  
  1190.   readSearchResponseAPDU(&response,buffer);
  1191.   printf("    SearchStatus:            %ld\n", response->SearchStatus); 
  1192.   printf("    ResultCount:             %ld\n", response->ResultCount); 
  1193.   printf("    NumberOfRecordsReturned: %ld\n", response->NumberOfRecordsReturned); 
  1194.   printf("    PresentStatus:           %ld\n", response->PresentStatus); 
  1195.   if ( response->ReferenceID != 0 )
  1196.     print_any("    ReferenceID:             ", response->ReferenceID);
  1197.  
  1198.   if ( response->DatabaseDiagnosticRecords != 0 ) {
  1199.     info = (WAISSearchResponse *)response->DatabaseDiagnosticRecords;
  1200.     if ( info->SeedWordsUsed != 0 )
  1201.       printf("    SeedWordsUsed:           %s\n", info->SeedWordsUsed); 
  1202.  
  1203.     i =0; 
  1204.     continue_viewing = 1; 
  1205.  
  1206.     if ( info->DocHeaders != 0 ) {
  1207.       k =0;
  1208.       while ( (continue_viewing == 1) && info->DocHeaders[k] != 0 ) {
  1209.         i++;
  1210.         printf("\n    record %2d, ", i);
  1211.         dsply_doc_hdr_record( info->DocHeaders[k++]);
  1212. #ifdef FOR_DUM_TERM
  1213.         if ( i < response->NumberOfRecordsReturned ) {
  1214.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1215.           scanf("%ld", &continue_viewing);
  1216.         }
  1217. #endif
  1218.       }
  1219.     }
  1220.  
  1221.     if ( info->ShortHeaders != 0 ) {
  1222.       k =0;
  1223.       while ( (continue_viewing == 1) && info->ShortHeaders[k] != 0 ) {
  1224.         i++;
  1225.         printf("\n    record %2d, ", i);
  1226.         dsply_short_hdr_record( info->ShortHeaders[k++]);
  1227. #ifdef FOR_DUM_TERM
  1228.         if ( i < response->NumberOfRecordsReturned ) {
  1229.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1230.           scanf("%ld", &continue_viewing);
  1231.         }
  1232. #endif
  1233.       }
  1234.     }
  1235.  
  1236.     if ( info->LongHeaders != 0 ) {
  1237.       k =0;
  1238.       while ( (continue_viewing == 1) && (info->LongHeaders[k] != 0) ) {
  1239.         i++;
  1240.         printf("\n    record %2d, ", i);
  1241.         dsply_long_hdr_record( info->LongHeaders[k++]);
  1242. #ifdef FOR_DUM_TERM
  1243.         if ( i < response->NumberOfRecordsReturned ) {
  1244.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1245.           scanf("%ld", &continue_viewing);
  1246.         }
  1247. #endif
  1248.       }
  1249.     }
  1250.  
  1251.     if ( info->Text != 0 ) {
  1252.       k =0;
  1253.       while ( (continue_viewing == 1) && (info->Text[k] != 0) ) {
  1254.         i++;
  1255.         printf("\n    record %2d, ", i);
  1256.         dsply_text_record( info->Text[k++]);
  1257. #ifdef FOR_DUM_TERM
  1258.         if ( i < response->NumberOfRecordsReturned ) {
  1259.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1260.           scanf("%ld", &continue_viewing);
  1261.         }
  1262. #endif
  1263.       }
  1264.     }
  1265.  
  1266.     if ( info->Headlines != 0 ) {
  1267.       k =0;
  1268.       while ( (continue_viewing ==1) && (info->Headlines[k] != 0) ) {
  1269.         i++;
  1270.         printf("\n    record %2d, ", i);
  1271.         dsply_headline_record( info->Headlines[k++]);
  1272. #ifdef DUM_TERM
  1273.         if ( i < response->NumberOfRecordsReturned ) {
  1274.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1275.           scanf("%ld", &continue_viewing);
  1276.         }
  1277. #endif
  1278.       }
  1279.     }
  1280.          
  1281.     if ( info->Codes != 0 ) {
  1282.       k =0;
  1283.       while ( (continue_viewing ==1) && (info->Codes[k] != 0) ) {
  1284.         i++;
  1285.         printf("\n    record %2d, ", i);
  1286.         dsply_code_record( info->Codes[k++]);
  1287. #ifdef FOR_DUM_TERM
  1288.         if ( i < response->NumberOfRecordsReturned ) {
  1289.           printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1290.           scanf("%ld", &continue_viewing);
  1291.         }
  1292. #endif
  1293.       }
  1294.     }
  1295.  
  1296.     freeWAISSearchResponse(info);         
  1297.  
  1298.   }                             /* display user info */
  1299.  
  1300.  
  1301.   freeSearchResponseAPDU( response);
  1302.  
  1303. }                               /* twais_dsply_srch_rsp_apdu */
  1304.  
  1305.  
  1306. /*
  1307.  * 'dsply_doc_hdr_record'
  1308.  *   display one WAIS document header record 
  1309.  */
  1310. #ifdef WIN32
  1311. void
  1312. #endif
  1313. dsply_doc_hdr_record( record)
  1314. WAISDocumentHeader  *record;
  1315. {
  1316.   printf(" DocHeaders\n");
  1317.   print_any("     DocumentID:  ", record->DocumentID);
  1318.  
  1319.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  1320.  
  1321.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  1322.          record->Score, record->BestMatch);
  1323.  
  1324.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  1325.          record->DocumentLength,
  1326.          record->Lines);
  1327.  
  1328.   if ( record->Source )
  1329.     printf("     Source:  %s\n", record->Source);
  1330.   if ( record->Date  )
  1331.     printf("     Date:  %s\n", record->Date);
  1332.  
  1333.   if ( record->OriginCity )
  1334.     printf("     OriginCity:  %s\n", record->OriginCity);
  1335.  
  1336.   if ( record->Headline )
  1337. #ifdef FOR_DUM_TERM
  1338.     print_hdline(record->Headline);
  1339. #else
  1340.   printf("     Headline:  %s\n", record->Headline);
  1341. #endif
  1342. }
  1343.  
  1344. /*
  1345.  * 'dsply_short_hdr_record'
  1346.  *   display one WAIS short header record 
  1347.  */
  1348. #ifdef WIN32
  1349. void
  1350. #endif
  1351. dsply_short_hdr_record( record)
  1352. WAISDocumentShortHeader  *record;
  1353. {
  1354.   printf(" ShortHeaders\n");
  1355.   print_any("     DocumentID:  ", record->DocumentID);
  1356.  
  1357.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  1358.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  1359.          record->Score, record->BestMatch);
  1360.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  1361.          record->DocumentLength,  record->Lines);
  1362. }
  1363.  
  1364. static void print_docs _AP((DocObj** docs));
  1365.  
  1366. static void print_docs( docs)
  1367. DocObj **docs;
  1368. {
  1369.   long i;
  1370.  
  1371.   for ( i=0; docs[i] !=0; i++ ) {
  1372.     printf("    Document %ld:\n", i+1 );
  1373.     print_any("     DocID: ", docs[i]->DocumentID);
  1374.     if (docs[i]->Type != NULL)
  1375.       printf("     Type: %s\n",docs[i]->Type);
  1376.     printf("     ChunkCode: %ld\n", docs[i]->ChunkCode);
  1377.     switch ( docs[i]->ChunkCode ) {
  1378.     case CT_byte:
  1379.     case CT_line:
  1380.       printf("     Range: (%ld, %ld)\n", docs[i]->ChunkStart.Pos,
  1381.              docs[i]->ChunkEnd.Pos);
  1382.       break;
  1383.     case CT_paragraph:
  1384.       print_any("     Chunk Start: ", docs[i]->ChunkStart.ID);
  1385.       print_any("     Chunk End:   ", docs[i]->ChunkEnd.ID);
  1386.       break;
  1387.     case CT_document:
  1388.     default:
  1389.       break;
  1390.     }
  1391.   }
  1392.  
  1393. }                               /* print_docs */
  1394.  
  1395.  
  1396. /*
  1397.  * "twais_dsply_srch_apdu"
  1398.  *   display search apdu on stdout
  1399.  *   the  apdu is in the specified buffer
  1400.  */
  1401. void
  1402. twais_dsply_srch_apdu( buffer)
  1403. char *buffer;           /* (I) buffer contain the search apdu */
  1404. {
  1405.   SearchAPDU  *search;
  1406.   WAISSearch  *info;
  1407.   DocObj **docs;
  1408.   any *text_search;
  1409.   long i;
  1410.  
  1411.   printf("\n\n Search Request:\n");
  1412.  
  1413.   readSearchAPDU(&search,buffer);
  1414.  
  1415.   printf("    SmallSetUpperBound:      %ld\n", search->SmallSetUpperBound); 
  1416.   printf("    LargeSetLowerBound:      %ld\n", search->LargeSetLowerBound); 
  1417.   printf("    MediumSetPresentNumber:  %ld\n", search->MediumSetPresentNumber); 
  1418.   printf("    ReplaceIndicator:        %ld\n", search->ReplaceIndicator); 
  1419.   if ( search->ResultSetName != 0 )
  1420.     printf("    ResultSetName:           %s\n", search->ResultSetName); 
  1421.   if ( search->QueryType != 0 )
  1422.     printf("    QueryType:               %s\n", search->QueryType); 
  1423.   if ( search->DatabaseNames != 0 )
  1424.     for ( i=0; search->DatabaseNames[i] != 0 ; i++ )
  1425.       printf("    Databasenames[%ld]:          %s\n", i,
  1426.              search->DatabaseNames[i]);
  1427.  
  1428.   if ( search->ElementSetNames != 0 )
  1429.     for ( i=0; search->ElementSetNames[i] != 0 ; i++ )
  1430.       printf("    ElementSetNames[%ld]:        %s\n", i,
  1431.              search->ElementSetNames[i]);
  1432.   
  1433.  
  1434.   if ( search->ReferenceID != 0 )
  1435.     print_any("    ReferenceID:             ", search->ReferenceID);
  1436.  
  1437.   if ( search->Query != 0 ) {
  1438.  
  1439.     /* type 1 */
  1440.     if ( ! strcmp( search->QueryType, QT_TextRetrievalQuery) ) {
  1441.       text_search = (any *) search->Query;
  1442.       docs = readWAISTextQuery(text_search);
  1443.       if ( docs != 0 )
  1444.         print_docs( docs);
  1445.       freeAny(text_search);
  1446.       doList((void**)docs,freeDocObj);
  1447.       s_free(docs);
  1448.     }
  1449.  
  1450.     else if ( ! strcmp( search->QueryType, QT_RelevanceFeedbackQuery) ) {
  1451.  
  1452.       info = (WAISSearch *)search->Query;
  1453.       if ( info->SeedWords != 0 )
  1454.         printf("    SeedWords:               %s\n", info->SeedWords); 
  1455.       if ( info->Docs != 0 )
  1456.         print_docs( info->Docs);
  1457.       printf("    DateFactor: %ld\n", info->DateFactor);
  1458.       if ( info->BeginDateRange )
  1459.         printf("    BeginDateRange: %s\n", info->BeginDateRange);
  1460.       if ( info->EndDateRange )
  1461.         printf("    EndDateRange:   %s\n", info->EndDateRange);
  1462.       printf("    MaxDocumentsRetrieved: %ld\n", info->MaxDocumentsRetrieved);
  1463.  
  1464.       freeWAISSearch(info);         
  1465.     }
  1466.     else {
  1467.       printf(" Unrecognized query type\n");
  1468.     }
  1469.   }
  1470.  
  1471.   freeSearchAPDU( search);
  1472.  
  1473. }                               /* twais_dsply_srch_apdu */
  1474.  
  1475.  
  1476. void twais_free_apdu(apdu_buff)
  1477. char *apdu_buff;        /* (I) buffer contain the apdu */
  1478. {
  1479.   pdu_type pdu;
  1480.  
  1481.   pdu = peekPDUType(apdu_buff);
  1482.   switch ( pdu) {
  1483.   case (initAPDU):
  1484.     freeInitAPDU((struct InitAPDU *)apdu_buff);
  1485.     break;
  1486.   case (initResponseAPDU):
  1487.     freeInitResponseAPDU((struct InitResponseAPDU *)apdu_buff);
  1488.     break;
  1489.   case (searchAPDU):
  1490.     freeSearchAPDU((struct SearchAPDU *)apdu_buff);
  1491.     break;
  1492.   case (searchResponseAPDU):
  1493.     freeSearchResponseAPDU((struct SearchResponseAPDU *)apdu_buff);
  1494.     break;
  1495.   default:
  1496.     break;
  1497.   }
  1498.   
  1499. }                               /* twais_free_apdu */
  1500.  
  1501.  
  1502. /*----------------------------------------------------------------------------*
  1503.  *  template apdus for testing purpose                                        *
  1504.  *----------------------------------------------------------------------------*/
  1505. void
  1506. twais_tmplt_init_apdu(buff, buff_len)
  1507. char *buff;             /* (O) buffer to hold the apdu */
  1508. long *buff_len;          /* (O) number of bytes written to the buffer */
  1509. {
  1510.   InitAPDU *init;
  1511.   char  *end_ptr;
  1512.   long len;
  1513.   any refID;
  1514.   refID.size = 2;
  1515.   refID.bytes = "10";
  1516.  
  1517.  
  1518.   init = makeInitAPDU(WILL_USE,WILL_NOT_USE,WILL_NOT_USE,WILL_NOT_SUPPORT,
  1519.                       WILL_NOT_SUPPORT,
  1520.                       2048L,
  1521.                       2048L, NULL,
  1522.                       defaultImplementationID(),defaultImplementationName(),
  1523.                       defaultImplementationVersion(), &refID,NULL);
  1524.   { long buffer_len = MAX_BUFFER_LENGTH;
  1525.     end_ptr = writeInitAPDU(init,buff, &buffer_len);
  1526.   }
  1527.   len = (long)end_ptr - (long)&buff[0];
  1528.   *buff_len = len;
  1529.   freeInitAPDU(init);
  1530. }                               /* twais_tmplt_init_apdu */
  1531.  
  1532.  
  1533. void
  1534. twais_tmplt_init_rsp_apdu(buff, buff_len)
  1535. char *buff;             /* (O) buffer to hold the apdu */
  1536. long *buff_len;          /* (O) number of bytes written to the buffer */
  1537. {
  1538.   WAISInitResponse *info;
  1539.   InitResponseAPDU *response;
  1540.   char  *end_ptr;
  1541.   long len;
  1542.   any refID;
  1543.   char chunk_marker[3];
  1544.   char highl_marker[2];
  1545.   char dhighl_marker[2];
  1546.   char new_line_chars[2];
  1547.   refID.size = 1;
  1548.   refID.bytes = "0";
  1549.   chunk_marker[0] = ESC;
  1550.   chunk_marker[1] = '1';
  1551.   chunk_marker[2]= 0;
  1552.   highl_marker[0] = DC1;
  1553.   highl_marker[1] = 0;
  1554.   dhighl_marker[0] = DC3;
  1555.   dhighl_marker[1] = 0;
  1556.   new_line_chars[0] = CARRIAGE_RETURN;
  1557.   new_line_chars[1] = 0;
  1558.  
  1559.   info =  makeWAISInitResponse(  CT_paragraph /* chunkCode */
  1560.                                ,3 /* chunkIDLen */
  1561.                                ,chunk_marker /* chunkMarker */
  1562.                                ,highl_marker /* highlightMarker */
  1563.                                ,dhighl_marker /* deHighlightMarker */
  1564.                                ,new_line_chars /* newLineChars */
  1565.                                );
  1566.  
  1567.   response = makeInitResponseAPDU( ACCEPT, /* result */
  1568.                                   WILL_USE,WILL_NOT_USE,WILL_NOT_USE, /* search, rsp, del */
  1569.                                   WILL_NOT_SUPPORT,WILL_NOT_SUPPORT, /* acc ctl, rsc ctl */
  1570.                                   1024L, 2048L, /* preferred msg size, max msg size */
  1571.                                   NULL, /* authentication */
  1572.                                   defaultImplementationID(),
  1573.                                   defaultImplementationName(),
  1574.                                   defaultImplementationVersion(),
  1575.                                   &refID, /* reference id */
  1576.                                   info);
  1577.   { long buffer_len = MAX_BUFFER_LENGTH;
  1578.     end_ptr = writeInitResponseAPDU(response, buff, &buffer_len);
  1579.   }
  1580.   len = (long)end_ptr - (long)&buff[0];
  1581.   *buff_len = len;
  1582.  
  1583.   CSTFreeWAISInitResponse( info);
  1584.   freeInitResponseAPDU(response);
  1585. }                               /* twais_tmplt_init_rsp_apdu */
  1586.  
  1587.  
  1588.  
  1589. void twais_tmplt_typ1_srch_apdu( buff, buff_len)
  1590. char *buff;             /* (O) buffer to hold the apdu */
  1591. long *buff_len;          /* (O) number of bytes written to the buffer */
  1592. {
  1593.  
  1594.   SearchAPDU *search1;
  1595.   char  *end_ptr;
  1596.   long len;
  1597.  
  1598.   static char *database_names[2];
  1599.   any docID;
  1600.   any refID;
  1601.  
  1602.   DocObj *DocObjs[2];
  1603.   any *query;                   /* changed from char* by brewster */
  1604.   database_names[0] = "Quest";
  1605.   database_names[1] = NULL;
  1606.   docID.size = 12;
  1607.   docID.bytes = "0000106776WJ";
  1608.   refID.size = 1;
  1609.   refID.bytes = "3";
  1610.    
  1611.   DocObjs[0] = makeDocObjUsingWholeDocument( &docID,NULL);
  1612.   DocObjs[1] = NULL;
  1613.  
  1614.   query = makeWAISTextQuery(DocObjs);   
  1615.  
  1616.   search1 = makeSearchAPDU( 10L, 16L, 15L, 
  1617.                            1L,  /* replace indicator */
  1618.                            "FOO", /* result set name */
  1619.                            database_names, /* database name */   
  1620.                            QT_TextRetrievalQuery, /* query_type */
  1621.                            0L,  /* element name */
  1622.                            &refID, /* reference ID */
  1623.                            query);
  1624.  
  1625.   {
  1626.     long buffer_len = MAX_BUFFER_LENGTH;
  1627.     end_ptr = writeSearchAPDU(  search1, buff, &buffer_len);
  1628.   }
  1629.   len = (long)end_ptr - (long)&buff[0];
  1630.   *buff_len = len;
  1631.  
  1632.   CSTFreeWAISTextQuery( query);
  1633.   freeSearchAPDU(search1);
  1634.  
  1635. }                               /* twais_tmplt_typ1_srch_apdu */
  1636.  
  1637. #if 0
  1638.  
  1639. twais_tmplt_typ3_srch_apdu( buff, buff_len)
  1640. char *buff;             /* (O) buffer to hold the apdu */
  1641. long *buff_len;          /* (O) number of bytes written to the buffer */
  1642. {
  1643.  
  1644.   SearchAPDU *search3;
  1645.   char  *end_ptr;
  1646.   static char *database_names[2];
  1647.   long len;
  1648.   any refID;
  1649.   WAISSearch *query;
  1650.   database_names[0] = "Quest"
  1651.     database_names[1] = NULL;
  1652.   refID.size = 1;
  1653.   refID.bytes = "3";
  1654.  
  1655.   query = makeWAISSearch( "Supercomputers in Taiwan", /* seed_words*/
  1656.                          0L,    /* DocObjsPtr */
  1657.                          0L,
  1658.                          1L,    /* DateFactor */
  1659.                          0L,    /* BeginDateRange */
  1660.                          0L,    /* EndDateRange */
  1661.                          10L    /* maxDocsRetrieved */
  1662.                          );
  1663.  
  1664.   search3 = makeSearchAPDU( 10L, 16L, 15L, 
  1665.                            1L,  /* replace indicator */
  1666.                            "FOO", /* result set name */
  1667.                            database_names, /* database name */   
  1668.                            QT_RelevanceFeedbackQuery, /* query_type */
  1669.                            0L,  /* element name */
  1670.                            &refID, /* reference ID */
  1671.                            query);
  1672.   {
  1673.     long buffer_len = MAX_BUFFER_LENGTH;
  1674.     end_ptr = writeSearchAPDU(  search3, buff, &buffer_len);
  1675.   }
  1676.   len = (long)end_ptr - (long)&buff[0];
  1677.   *buff_len = len;
  1678.  
  1679.   CSTFreeWAISSearch( query);
  1680.   freeSearchAPDU(search3);
  1681.  
  1682. }                               /* twais_tmplt_typ3_srch_apdu */
  1683. #endif
  1684.  
  1685.  
  1686. void twais_tmplt_typ3_srch_rsp_apdu( buff, buff_len)
  1687. char *buff;
  1688. long *buff_len;
  1689. {
  1690.  
  1691.   char  *end_ptr;
  1692.   long len;
  1693.   any refID;
  1694.  
  1695.   WAISDocumentHeader  *doc_headers[3];
  1696.   WAISSearchResponse *records;
  1697.   SearchResponseAPDU *response;
  1698.   any doc_id1;
  1699.   any doc_id2;
  1700.   refID.size = 1;
  1701.   refID.bytes = "1";
  1702.   doc_id1.size = 12;   
  1703.   doc_id1.bytes = "0000106776WJ";
  1704.   doc_id2.size = 12;
  1705.   doc_id2.bytes = "0000026870WP";
  1706.  
  1707.   doc_headers[0] = makeWAISDocumentHeader(
  1708.                                           &doc_id1, /* docID */
  1709.                                           1L, /* versionNumber */
  1710.                                           80L, /* score */
  1711.                                           1L, /* bestMatch */
  1712.                                           850L, /* docLen */
  1713.                                           200L, /* lines */
  1714.                                           NULL, /* types */
  1715.                                           "Source1", /* source */
  1716.                                           "19900115", /* date */
  1717.                                           "CRAY sells supercomputer to Taiwan", /* headline */
  1718.                                           "New York"); /* originCity */
  1719.  
  1720.  
  1721.   doc_headers[1] = makeWAISDocumentHeader(
  1722.                                           &doc_id2, /* docID */
  1723.                                           1L, /* versionNumber */
  1724.                                           60L, /* score */
  1725.                                           1L, /* bestMatch */
  1726.                                           550L, /* docLen */
  1727.                                           100L, /* lines */
  1728.                                           NULL,
  1729.                                           "Test Source", /* source */
  1730.                                           "19900110", /* date */
  1731.                                           "Test Headline", /* headline */
  1732.                                           "Test City"); /* originCity */
  1733.  
  1734.   doc_headers[2] = 0;
  1735.  
  1736.   records = makeWAISSearchResponse( "Supercomputer Taiwan" /* seedWordsUsed*/
  1737.                                    ,doc_headers /* docHeaders */
  1738.                                    ,0 ,0 ,0 ,0 /* shortHeaders, longHeaders, text, headlines */
  1739.                                    ,0 /* codes */
  1740.                                    ,NULL /* diagnostics.  KLUDGE */
  1741.                                    );
  1742.  
  1743.  
  1744.   response = makeSearchResponseAPDU( SUCCESS /* result */
  1745.                                     ,2 /* count */
  1746.                                     ,2 /* recordsReturned */
  1747.                                     ,0 /* nextPos */
  1748.                                     ,0 /* ignore resultStatus since result SUCCESS */
  1749.                                     ,SUCCESS /* presentStatus */
  1750.                                     ,&refID /* refID */
  1751.                                     ,records);
  1752.  
  1753.  
  1754.   {
  1755.     long buffer_len = MAX_BUFFER_LENGTH;
  1756.     end_ptr = writeSearchResponseAPDU(  response, buff, &buffer_len);
  1757.   }
  1758.   len = (long)end_ptr - (long)&buff[0];
  1759.   *buff_len = len;
  1760.  
  1761.   CSTFreeWAISDocumentHeader( doc_headers[0]);
  1762.  
  1763.   CSTFreeWAISDocumentHeader( doc_headers[1]);
  1764.  
  1765.   CSTFreeWAISSearchResponse( records);
  1766.   freeSearchResponseAPDU(response);
  1767.  
  1768.  
  1769. }                               /* twais_tmplt_typ3_srch_rsp_apdu */
  1770.  
  1771. #ifdef WIN32
  1772. void
  1773. #endif
  1774. twais_tmplt_typ1_stry_rsp_apdu( buff, buff_len)
  1775. char *buff;
  1776. long *buff_len;
  1777. {
  1778.  
  1779.   char  *end_ptr;
  1780.   long len;
  1781.   any refID;
  1782.  
  1783.   WAISDocumentText *doc_text[2];
  1784.   WAISSearchResponse *records;
  1785.   SearchResponseAPDU *response;
  1786.   any docID;
  1787.   any story;
  1788.   char *story_buff;
  1789.   
  1790.   FILE *fptr;
  1791.   refID.size = 1;
  1792.   refID.bytes = "1";
  1793.   docID.size = 12;
  1794.   docID.bytes = "0000106776WJ";
  1795.   doc_text[0] = 0;
  1796.   doc_text[1] = 0;
  1797.  
  1798.   fptr = s_fopen("twais_template.txt", "r");
  1799.   if (fptr == NULL ) {
  1800.     printf(" unable to open story text file \n");
  1801.     return;
  1802.   }
  1803.    
  1804.   /* read story length */
  1805.   fread((char*)&story.size, sizeof(long), 1, fptr);
  1806.   story_buff = s_malloc( story.size +1);
  1807.   if ( story_buff == NULL) {
  1808.     printf(" insufficient memory\n");
  1809.     s_fclose( fptr);
  1810.     return;
  1811.   }
  1812.  
  1813.   /* read story text */
  1814.   fread( story_buff, 1, story.size, fptr);   
  1815.   story.bytes = story_buff;
  1816.    
  1817.   doc_text[0] = makeWAISDocumentText( &docID, 1L, &story);
  1818.  
  1819.   records = makeWAISSearchResponse( 0 /* seedWordsUsed*/
  1820.                                    ,0 ,0 ,0 /* docHeaders, shortHeaders, longHeaders */
  1821.                                    ,doc_text ,0 /* text, headlines */
  1822.                                    ,0 /* codes */
  1823.                                    ,NULL /* diagnostics.  KLUDGE */
  1824.                                    );
  1825.  
  1826.  
  1827.   response = makeSearchResponseAPDU( SUCCESS /* result */
  1828.                                     ,1 /* count */
  1829.                                     ,1 /* recordsReturned */
  1830.                                     ,0 /* nextPos */
  1831.                                     ,0 /* ignore resultStatus since result SUCCESS */
  1832.                                     ,SUCCESS /* presentStatus */
  1833.                                     ,&refID /* refID */
  1834.                                     ,records);
  1835.  
  1836.  
  1837.   {
  1838.     long buffer_len = MAX_BUFFER_LENGTH;
  1839.     end_ptr = writeSearchResponseAPDU(  response, buff, &buffer_len);
  1840.   }
  1841.   len = (long)end_ptr - (long)&buff[0];
  1842.   *buff_len = len;
  1843.  
  1844.   CSTFreeWAISDocumentText( doc_text[0]);
  1845.  
  1846.   CSTFreeWAISSearchResponse( records);
  1847.  
  1848.   freeSearchResponseAPDU(response);
  1849.  
  1850.   s_free(story_buff);
  1851.   s_fclose(fptr);
  1852.  
  1853. }                               /* twais_tmplt_typ1_stry_rsp_apdu */
  1854.  
  1855. #ifdef WIN32
  1856. void
  1857. #endif
  1858. twais_tmplt_typ3_srch_apdu( buff, buff_len)
  1859. char *buff;             /* (O) buffer to hold the apdu */
  1860. long *buff_len;          /* (O) number of bytes written to the buffer */
  1861. {
  1862.  
  1863.   SearchAPDU *search3;
  1864.   char  *end_ptr;
  1865.   static char *database_names[7] = { 
  1866.     "11111111111111111111111111111111111111111111111111",
  1867.     "22222222222222222222222222222222222222222222222222",
  1868.     "33333333333333333333333333333333333333333333333333",
  1869.     "44444444444444444444444444444444444444444444444444",
  1870.     "55555555555555555555555555555555555555555555555555",
  1871.     "66666666666666666666666666666666666666666666666666",
  1872.     0};
  1873.   static char *elem_names[7] = { ES_DocumentHeader
  1874.                                    ,ES_DocumentShortHeader
  1875.                                      ,ES_DocumentLongHeader
  1876.                                        ,ES_DocumentText
  1877.                                          ,ES_DocumentHeadline
  1878.                                            ,ES_DocumentCodes
  1879.                                              ,0};
  1880.  
  1881.   long len;          
  1882.   any refID;
  1883.   WAISSearch *query;
  1884.   refID.size = 1;
  1885.   refID.bytes = "3";
  1886.  
  1887.   query = makeWAISSearch( 
  1888.                          "What is the penalities for driving without insurance",
  1889.                          0L,    /* DocObjsPtr */
  1890.                          0L,
  1891.                          1L,    /* DateFactor */
  1892.                          0L,    /* BeginDateRange */
  1893.                          0L,    /* EndDateRange */
  1894.                          10L    /* maxDocsRetrieved */
  1895.                          );
  1896.  
  1897.   search3 = makeSearchAPDU( 10L, 16L, 15L, 
  1898.                            1L,  /* replace indicator */
  1899.                            "FOO", /* result set name */
  1900.                            database_names, /* database name */   
  1901.                            QT_RelevanceFeedbackQuery, /* query_type */
  1902.                            elem_names, /* element name */
  1903.                            &refID, /* reference ID */
  1904.                            query);
  1905.   {
  1906.     long buffer_len = MAX_BUFFER_LENGTH;
  1907.     end_ptr = writeSearchAPDU(  search3, buff, &buffer_len);
  1908.   }
  1909.   len = (long)end_ptr - (long)&buff[0];
  1910.   *buff_len = len;
  1911.  
  1912.   CSTFreeWAISSearch( query);
  1913.   freeSearchAPDU(search3);
  1914.  
  1915. }                               /* twais_tmplt_typ3_srch_apdu */
  1916.  
  1917.