File: NeXTindex.c

package info (click to toggle)
gopher 2.3-2
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,364 kB
  • ctags: 2,030
  • sloc: ansic: 22,451; perl: 1,950; sh: 1,510; makefile: 397; asm: 1
file content (191 lines) | stat: -rw-r--r-- 4,789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/********************************************************************
 * $Author: lindner $
 * $Revision: 3.14 $
 * $Date: 1995/09/26 04:59:43 $
 * $Source: /home/arcwelder/GopherSrc/CVS/gopher+/gopherd/NeXTindex.c,v $
 * $State: Exp $
 *
 * Paul Lindner, University of Minnesota CIS.
 *
 * Copyright 1991, 1992 by the Regents of the University of Minnesota
 * see the file "Copyright" in the distribution for conditions of use.
 *********************************************************************
 * MODULE: NeXTindex.c
 * index interface to the NeXT text indexing routines. 
 *********************************************************************
 * Revision History:
 * $Log: NeXTindex.c,v $
 * Revision 3.14  1995/09/26  04:59:43  lindner
 * Fix abort routines, change to Die/Warn hash over access routines..
 *
 * Revision 3.13  1995/09/25  05:02:30  lindner
 * Convert to ANSI C
 *
 * Revision 3.12  1995/02/20  23:36:49  lindner
 * Fix for searches
 *
 * Revision 3.11  1995/02/11  06:18:57  lindner
 * Rid the world of MacIndex
 *
 * Revision 3.10  1994/10/24  22:16:53  lindner
 * Fix for printf error message
 *
 * Revision 3.9  1994/06/29  05:25:27  lindner
 * Add Gticket
 *
 * Revision 3.8  1993/11/02  06:02:38  lindner
 * HTML Mods
 *
 * Revision 3.7  1993/09/22  05:40:40  lindner
 * Remove extra fixfile() call
 *
 * Revision 3.6  1993/09/11  04:41:14  lindner
 * Don't fork for localhost mindex databases
 *
 * Revision 3.5  1993/07/27  05:27:35  lindner
 * Mondo Debug overhaul from Mitra
 *
 * Revision 3.4  1993/07/26  15:31:09  lindner
 * mods for application/gopher-menu
 *
 * Revision 3.3  1993/04/09  16:24:49  lindner
 * Fixes for Gopher+ operation
 *
 * Revision 3.2  1993/03/26  19:46:49  lindner
 * First crack at gopherplussing Indexing
 *
 * Revision 3.1.1.1  1993/02/11  18:02:50  lindner
 * Gopher+1.2beta release
 *
 * Revision 1.1  1992/12/10  23:13:27  lindner
 * gopher 1.1 release
 *
 *
 *********************************************************************/

#include <sys/stat.h>
#include "text/wftable.h"
#include "text/ix.h"

#include "gopherd.h"
#include "Debug.h"

static int
myInterruptRoutine()
{
     /* for now, always return 0 so the search is not interrupted */
     return(0);
}

void
NeXTIndexQuery(int sockfd,
  char *SearchWords,
  char *ZIndexDirectory,
  char *DatabaseNm,  /*** Not used by the next indexer... ***/
  char *INDEXHost,
  int INDEXPort,
  char *INDEXPath,
  boolean isgplus,
  char *view)
{
     unsigned long i;
     char          *cp;
     int           j;
     Index         *workingIndex;
     RefList       theRefList;
     RefList       *ptrtheRefList;
     Reference     *MyReference;
     FileCell      *f;
     char          tempstr[40];
     char          outputline[1024];
     GopherObj     *gs;
     GopherDirObj  *gd;
     boolean       plusdirs = FALSE;


     if (view != NULL) {
	  if (strcasecmp(view, "application/gopher+-menu")==0)
	       plusdirs = TRUE;
     }


     gs = GSnew();
     gd = GDnew(32);

     Debug("Nextindexer called: Search %s,", SearchWords);
     Debug(" Indexdir %s\r\n", ZIndexDirectory);


     for (j=0; j< 4; j++) {
	  
	  workingIndex = ixOpen( ZIndexDirectory, "r" );
	  if (workingIndex != NULL)
	       break;
	  else
	       usleep (50);
     }

     if ( workingIndex != 0 ) {
	  theRefList = ixIndexQuery(workingIndex, SearchWords, ixSearchByFullWord,
				    ixMatchContent, ixLiteralString,
				    (myInterruptRoutine));

	  for( i=0; i < theRefList.n; i++ ){
	       MyReference = &(theRefList.r[i]);
	       f = (*MyReference).f;
	       
	       /*** The Selector String ***/
	       /*** So far we only index text files, so put a 0 in front ***/

	       if (strstr((*f).file, ".cache") != NULL) {
		    continue;
	       }
	       
	       GSsetType(gs, '0');
	       /*** Process the description field, remove any crud, replace
                    with spaces. ***/
               {
			char *moo = f->desc;
			while (*moo != '\0') {
				if (!isprint(*moo))
					*moo = ' ';
				moo++;
			}
		}
		
	       GSsetTitle(gs, (f->desc)+1);
	       GSsetHost(gs, INDEXHost);
	       GSsetPort(gs, INDEXPort);

	       cp = strstr(f->file, INDEXPath);
	       if (cp == NULL)
		    sprintf(outputline, "0/%s", f->file);
	       else
		    sprintf(outputline, "0/%s", cp);

	       GSsetPath(gs, outputline);
	       GSsetWeight(gs, (int)(MyReference->weight * 1000.0));
	       GDaddGS(gd, gs);
	  }

	  if (isgplus) {
	       GSsendHeader(sockfd, -1);
	  }

	  if (plusdirs)
	       GDplustoNet(gd, sockfd, NULL, Gticket);
	  else
	       GDtoNet(gd, sockfd, GSFORM_G0, Gticket, NULL);

     }
     else {

	  Die(sockfd, 500, "can't open working index" );
     }

     GSdestroy(gs);
     GDdestroy(gd);
     
     /* all done.... close the index file */
}