home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / gopherd / NeXTindex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-09  |  4.0 KB  |  167 lines

  1. /********************************************************************
  2.  * lindner
  3.  * 3.3
  4.  * 1993/04/09 16:24:49
  5.  * /home/mudhoney/GopherSrc/CVS/gopher+/gopherd/NeXTindex.c,v
  6.  * $Status: $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: NeXTindex.c
  14.  * index interface to the NeXT text indexing routines. 
  15.  *********************************************************************
  16.  * Revision History:
  17.  * NeXTindex.c,v
  18.  * Revision 3.3  1993/04/09  16:24:49  lindner
  19.  * Fixes for Gopher+ operation
  20.  *
  21.  * Revision 3.2  1993/03/26  19:46:49  lindner
  22.  * First crack at gopherplussing Indexing
  23.  *
  24.  * Revision 3.1.1.1  1993/02/11  18:02:50  lindner
  25.  * Gopher+1.2beta release
  26.  *
  27.  * Revision 1.1  1992/12/10  23:13:27  lindner
  28.  * gopher 1.1 release
  29.  *
  30.  *
  31.  *********************************************************************/
  32.  
  33. #include <sys/stat.h>
  34. #include "text/wftable.h"
  35. #include "text/ix.h"
  36.  
  37. #include "gopherd.h"
  38.  
  39. int
  40. myInterruptRoutine()
  41. {
  42.      /* for now, always return 0 so the search is not interrupted */
  43.      return(0);
  44. }
  45.  
  46. void
  47. NeXTIndexQuery(sockfd, SearchWords, ZIndexDirectory, DatabaseNm, INDEXHost, INDEXPort, INDEXPath, isgplus, view)
  48.   int sockfd;
  49.   char *SearchWords;
  50.   char *ZIndexDirectory;
  51.   char *DatabaseNm;  /*** Not used by the next indexer... ***/
  52.   char *INDEXHost;
  53.   int INDEXPort;
  54.   char *INDEXPath;
  55.   boolean isgplus;
  56.   char *view;
  57. {
  58.      unsigned long i;
  59.      char          *cp;
  60.      int           j;
  61.      Index         *workingIndex;
  62.      RefList       theRefList;
  63.      RefList       *ptrtheRefList;
  64.      Reference     *MyReference;
  65.      FileCell      *f;
  66.      char          tempstr[40];
  67.      char          outputline[1024];
  68.      GopherObj     *gs;
  69.      GopherDirObj  *gd;
  70.      boolean       plusdirs = FALSE;
  71.  
  72.  
  73.      if (view != NULL) {
  74.       if (strcasecmp(view, "Directory+")==0)
  75.            plusdirs = TRUE;
  76.      }
  77.  
  78.  
  79.      gs = GSnew();
  80.      gd = GDnew(32);
  81.  
  82.      if (DEBUG) {
  83.       printf("Nextindexer called: Search %s, Indexdir %s\n", SearchWords, ZIndexDirectory);
  84.      }
  85.  
  86.      /*** Try to open the index a couple of times ***/
  87.      if (!dochroot)
  88.       ZIndexDirectory = fixfile(ZIndexDirectory);
  89.  
  90.      for (j=0; j< 4; j++) {
  91.       
  92.       workingIndex = ixOpen( ZIndexDirectory, "r" );
  93.       if (workingIndex != NULL)
  94.            break;
  95.       else
  96.            usleep (50);
  97.      }
  98.  
  99.      if ( workingIndex != 0 ) {
  100.       theRefList = ixIndexQuery(workingIndex, SearchWords, ixSearchByFullWord,
  101.                     ixMatchContent, ixLiteralString,
  102.                     (myInterruptRoutine));
  103.  
  104.       for( i=0; i < theRefList.n; i++ ){
  105.            MyReference = &(theRefList.r[i]);
  106.            f = (*MyReference).f;
  107.            
  108.            /*** The Selector String ***/
  109.            /*** So far we only index text files, so put a 0 in front ***/
  110.  
  111.            if (strstr((*f).file, ".cache") != NULL) {
  112.             continue;
  113.            }
  114.            
  115.            GSsetType(gs, '0');
  116.            /*** Process the description field, remove any crud, replace
  117.                     with spaces. ***/
  118.                {
  119.             char *moo = f->desc;
  120.             while (*moo != '\0') {
  121.                 if (!isprint(*moo))
  122.                     *moo = ' ';
  123.                 moo++;
  124.             }
  125.         }
  126.         
  127.            GSsetTitle(gs, (f->desc)+1);
  128.            GSsetHost(gs, INDEXHost);
  129.            GSsetPort(gs, INDEXPort);
  130.  
  131.            cp = strstr(f->file, INDEXPath);
  132.            if (cp == NULL)
  133.             sprintf(outputline, "0/%s", f->file);
  134.            else
  135.             sprintf(outputline, "0/%s", cp);
  136.  
  137.            if (MacIndex)
  138.             GSsetPath(gs, f->file);
  139.            else
  140.                    GSsetPath(gs, outputline);
  141.            GSsetWeight(gs, (int)(MyReference->weight * 1000.0));
  142.            GDaddGS(gd, gs);
  143.       }
  144.  
  145.       if (isgplus) {
  146.            GSsendHeader(sockfd, -1);
  147.       }
  148.  
  149.       if (plusdirs)
  150.            GDplustoNet(gd, sockfd, NULL);
  151.       else
  152.            GDtoNet(gd, sockfd);
  153.  
  154.       writestring(sockfd, ".\r\n");
  155.       
  156.      }
  157.      else {
  158.       fprintf(stderr,"can't open working index\n" );
  159.      }
  160.  
  161.      GSdestroy(gs);
  162.      GDdestroy(gd);
  163.      
  164.      /* all done.... close the index file */
  165. }
  166.  
  167.