Here's the source of a frontend written in C that I used to use with the
original SWISH 1.1 from Kevin Hughes. I'm sure (?) that it is adaptable to
SWISH-E.
All the best from,
Bill Malin
owner/webmaster
Ventura Blvd on the Web
http://www.venturablvd.com
"It's Virtual Ventura Blvd." -the L.A. Times 6-23-96
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SWISH_EXEC "/usr/bin/swish/swish"
/*---------------------------------------------------------------------------*/
static void seiPrintHeader(void)
{
printf("<html>\n<head>\n");
printf("<title>Results Of Your Search Of Virtual Ventura Blvd</title>\n");
printf("<BODY BGCOLOR=\"#9FCAF4\" TEXT=\"#000000\" LINK=\"#FF0000\"
VLINK=\"#0000FF\" ALINK=\"#FFFF00\">\n");
printf("<CENTER><IMG width=600 SRC=\"/prim_images/animcar3.gif\">\n");
printf("<TABLE width=600 cellpadding=0 cellspacing=0><TR><TD
width=365></TD><TD align=right width=100><FONT SIZE=\"4\" COLOR=\"White\">S E A
R C H</FONT></TD><TD width=10></TD><TD width=120><Font size=\"4\"
COLOR=\"white\">R E S U L T S</FONT></TD><TD width=5></TD></TR></TABLE>\n");
printf("<br><CENTER><a href=\"http://www.siteactive.com/index.html\"><img
src=\"/prim_images/banners/the-great-animation-small.gif\" width=400 height=72
border=0 alt=\"If you use it, they will come. SiteActive Web Promotion
Software\"><BR>GET SiteActive Web Promotion Software -- CLICK
HERE</a></CENTER><BR>\n");
printf("<TABLE width=600 border=0><TR><TD>\n");
} /* seiPrintHeader */
/*---------------------------------------------------------------------------*/
static void seiPrintFooter(char *returnURL)
{
printf("</TD></TR></TABLE>\n");
printf("<BR>\n");
printf("<p>\n<HR ALIGN=\"CENTER\" SIZE=\"3\" WIDTH=\"600\">\n");
printf("<FONT SIZE=\"5\"><I>Did you Find what you're looking
for?</I></FONT><BR>If not, you're welcome to <a href=\"%s\">search again</a>
or......<BR>we invite you to visit the <A
HREF=\"http://www.venturablvd.com/blvdsearch/tips.html\">Search Help</A> page
for tips on forming queries.\n", returnURL);
printf("<TABLE width=600 height=50><TR><TD></TD></TR></TABLE>\n");
printf("<TABLE width=600><TR><TD align=right><FONT SIZE=\"2\">This search
tool was built using the <A
HREF=\"http://www.eit.com/software/swish\">SWISH</A> search engine<BR>and is a
feature of <A HREF=\"http://www.venturablvd.com/vw_info.html\">Ventura Blvd on
the Web ®</A>.</FONT></TD></TR></TABLE>\n");
printf("<BR></CENTER>\n");
printf("</body>\n");
printf("</head>\n</html>\n");
} /* seiPrintFooter */
/*---------------------------------------------------------------------------*/
static int seiHexToDecimal(char first, char second)
{
int value;
first = tolower(first);
second = tolower(second);
switch (first) {
case '0': value = 16 * 0; break;
case '1': value = 16 * 1; break;
case '2': value = 16 * 2; break;
case '3': value = 16 * 3; break;
case '4': value = 16 * 4; break;
case '5': value = 16 * 5; break;
case '6': value = 16 * 6; break;
case '7': value = 16 * 7; break;
case '8': value = 16 * 8; break;
case '9': value = 16 * 9; break;
case 'a': value = 16 * 10; break;
case 'b': value = 16 * 11; break;
case 'c': value = 16 * 12; break;
case 'd': value = 16 * 13; break;
case 'e': value = 16 * 14; break;
case 'f': value = 16 * 15; break;
}
switch (second) {
case '0': value += 0; break;
case '1': value += 1; break;
case '2': value += 2; break;
case '3': value += 3; break;
case '4': value += 4; break;
case '5': value += 5; break;
case '6': value += 6; break;
case '7': value += 7; break;
case '8': value += 8; break;
case '9': value += 9; break;
case 'a': value += 10; break;
case 'b': value += 11; break;
case 'c': value += 12; break;
case 'd': value += 13; break;
case 'e': value += 14; break;
case 'f': value += 15; break;
}
return(value);
} /* seiHexToDecimal */
/*---------------------------------------------------------------------------*/
static void seiReadNameValuePair(char *thestring, char *thevalue)
{
char *cptr = NULL, *endcptr = NULL;
cptr = strstr(thestring, "=");
cptr++;
endcptr = strstr(thestring, "&");
if (endcptr) {
endcptr++;
endcptr[-1] = '\0';
}
/* copy the value of before the original string gets overwritten */
strcpy(thevalue, cptr);
if (endcptr)
strcpy(thestring, endcptr);
} /* seiReadNameValuePair */
/*---------------------------------------------------------------------------*/
static int seiReadString(char *thestring, char *substring)
{
int len;
char *cptr = NULL;
if (thestring[0] == '"') {
len = strlen(thestring);
cptr = &thestring[len-1];
while (cptr[0] != ' ')
cptr--;
}
else {
cptr = strstr(thestring, " ");
}
cptr[0] = '\0';
cptr++;
strcpy(substring, thestring);
strcpy(thestring, cptr);
} /* seiReadString */
/*---------------------------------------------------------------------------*/
void main(void)
{
char swishindex[256], keywords[512], maxresults[64];
char returnURL[1000], command[1000], thestring[2000];
char substring1[2000], substring2[2000], substring3[2000];
char *output = NULL, *cptr = NULL, *ncptr = NULL, *tempcptr;
int numchar = 10000, character;
int len, index, nindex, spacecount, done;
FILE *fp = NULL;
/* print header */
printf("Content-type: text/html%c%c",10,10);
seiPrintHeader();
sprintf(thestring, "%s", getenv("QUERY_STRING"));
sprintf(returnURL, "%s", getenv("PATH_INFO"));
nindex = 0;
len = strlen(thestring);
for (index = 0; index < len; index++) {
if (thestring[index] == '+') {
thestring[nindex++] = ' ';
}
else if (thestring[index] == '%') {
/* convert hex to decimal */
thestring[nindex++] = (char)seiHexToDecimal(thestring[index+1],
thestring[index+2]);
index+=2;
}
else {
thestring[nindex++] = thestring[index];
}
}
thestring[nindex] = '\0';
/* the order on the search form must remain constant:
swishindex, keywords, maxresults */
seiReadNameValuePair(thestring, swishindex);
strcpy(keywords, "__NOT_DEFINED__");
seiReadNameValuePair(thestring, keywords);
if (strcmp(keywords, "__NOT_DEFINED__")) {
strcpy(maxresults, "__NOT_DEFINED__");
seiReadNameValuePair(thestring, maxresults);
/* build the swish command */
if (!strcmp(maxresults, "__NOT_DEFINED__"))
sprintf(command, "%s -f %s -w %s -t HBthe %s", SWISH_EXEC, swishindex,
keywords);
else
sprintf(command, "%s -f %s -w %s -m %s", SWISH_EXEC,
swishindex, keywords, maxresults);
index = 0;
output = (char *)malloc(numchar * sizeof(char));
/* open up a pipe to the swish command */
fp = popen(command, "r");
character = fgetc(fp);
while (character != EOF) {
output[index++] = (char)character;
if (index == numchar) {
numchar *= 2;
output = (char *)realloc(output, numchar * sizeof(char));
}
character = fgetc(fp);
}
pclose(fp);
/* parse through the output line by line */
done = 0;
cptr = output;
while (cptr && !done) {
ncptr = strstr(cptr, "\n");
if (ncptr)
ncptr[0] = '\0';
/* results of swish can be-
line beginning with "#"
line beginning with "."
line beginning with "err"
line beginning with "search words:"
line beginning with relevance rank */
if (cptr[0] == '#') {
/* do something with comments? */
}
else if (cptr[0] == '.') {
done = 1;
}
else if (!strncmp(cptr, "err", 3)) {
printf("<CENTER><TABLE width=600 valign=top><TR><TD height=60><FONT
SIZE=\"5\">%s</FONT><BR></TD></TR></TABLE></CENTER>\n", cptr);
}
else if (!strncmp(cptr, "search words:", 13)) {
printf("<CENTER><TABLE width=600 valign=top><TR><TD height=60><FONT
SIZE=\"5\">%s</FONT><BR></TD></TR></TABLE></CENTER>\n", cptr);
}
else {
strcpy(thestring, cptr);
seiReadString(thestring, substring1);
seiReadString(thestring, substring2);
seiReadString(thestring, substring3);
printf("<!-- SCORE %s: <BR> --><a href = \"%s\">%s</a><BR><BR>\n",
substring1, substring2, substring3, thestring);
}
cptr = ncptr;
if (cptr)
cptr++;
}
}
else {
/* no keywords */
printf("Please specify keywords to perform search.<br>\n");
printf("__________________________________________<p>\n");
printf("search example 1: john and doe or jane<br>\n");
printf("search example 2: john and (doe or jane)<br>\n");
printf("search example 3: not (john or jane) and doe<br>\n");
printf("search example 4: j* and doe<br>\n");
}
seiPrintFooter(returnURL);
if (output) {
free(output);
output = NULL;
}
} /* main */
/*---------------------------------------------------------------------------*/
/* eof */
Received on Thu Feb 25 16:12:10 1999