home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / gopher / gopher1.01 / gopherd / NeXTindex.c < prev    next >
C/C++ Source or Header  |  1992-06-03  |  3KB  |  115 lines

  1. /*
  2.  * index interface to the NeXT text indexing routines.
  3.  */
  4.  
  5. #include <sys/stat.h>
  6. #include "text/wftable.h"
  7. #include "text/ix.h"
  8.  
  9. #include "gopherd.h"
  10.  
  11. int
  12. myInterruptRoutine()
  13. {
  14.      /* for now, always return 0 so the search is not interrupted */
  15.      return(0);
  16. }
  17.  
  18. void
  19. NeXTIndexQuery(sockfd, SearchWords, ZIndexDirectory, DatabaseNm, INDEXHost, INDEXPort)
  20.   int sockfd;
  21.   char *SearchWords;
  22.   char *ZIndexDirectory;
  23.   char *DatabaseNm;  /*** Not used by the next indexer... ***/
  24.   char *INDEXHost;
  25.   int INDEXPort;
  26. {
  27.      unsigned long i;
  28.      char *cp;
  29.      int j;
  30.      Index *workingIndex;
  31.      RefList theRefList;
  32.      RefList *ptrtheRefList;
  33.      Reference *MyReference;
  34.      FileCell *f;
  35.      char tempstr[40];
  36.      char outputline[1024];
  37.      GopherObj *gs;
  38.      GopherDirObj *gd;
  39.  
  40.      gs = GSnew();
  41.      gd = GDnew(32);
  42.  
  43.      if (DEBUG) {
  44.       printf("Nextindexer called: Search %s, Indexdir %s\n", SearchWords, ZIndexDirectory);
  45.      }
  46.  
  47.      /*** Try to open the index a couple of times ***/
  48.      for (j=0; j< 4; j++) {
  49.       workingIndex = ixOpen( ZIndexDirectory, "r" );
  50.       if (workingIndex != NULL)
  51.            break;
  52.       else
  53.            usleep (50);
  54.      }
  55.  
  56.      if ( workingIndex != 0 ) {
  57.       theRefList = ixIndexQuery(workingIndex, SearchWords, ixSearchByFullWord,
  58.                     ixMatchContent, ixLiteralString,
  59.                     (myInterruptRoutine));
  60.  
  61.       for( i=0; i < theRefList.n; i++ ){
  62.            MyReference = &(theRefList.r[i]);
  63.            f = (*MyReference).f;
  64.            
  65.            /*** The Selector String ***/
  66.            /*** So far we only index text files, so put a 0 in front ***/
  67.  
  68.            if (strstr((*f).file, ".cache") != NULL) {
  69.             continue;
  70.            }
  71.            
  72.            GSsetType(gs, '0');
  73.            /*** Process the description field, remove any crud, replace
  74.                     with spaces. ***/
  75.                {
  76.             char *moo = f->desc;
  77.             while (*moo != '\0') {
  78.                 if (!isprint(*moo))
  79.                     *moo = ' ';
  80.                 moo++;
  81.             }
  82.         }
  83.         
  84.            GSsetTitle(gs, (f->desc)+1);
  85.            GSsetHost(gs, INDEXHost);
  86.            GSsetPort(gs, INDEXPort);
  87.            
  88.            sprintf(outputline, "0/%s", f->file);
  89.            if (MacIndex)
  90.             GSsetPath(gs, f->file);
  91.            else
  92.                    GSsetPath(gs, outputline);
  93.            GSsetWeight(gs, (int)(MyReference->weight * 1000.0));
  94.            GDaddGS(gd, gs);
  95.       }
  96.  
  97.       if (UsingHTML)
  98.            GDtoNetHTML(gd, sockfd);
  99.       else
  100.            GDtoNet(gd, sockfd);
  101.  
  102.       writestring(sockfd, ".\r\n");
  103.       
  104.      }
  105.      else {
  106.       fprintf(stderr,"can't open working index\n" );
  107.      }
  108.  
  109.      GSdestroy(gs);
  110.      GDdestroy(gd);
  111.      
  112.      /* all done.... close the index file */
  113. }
  114.  
  115.