Skip to main content.
home | support | download

Back to List Archive

changes should be done where?

From: Alain Tuezney <tuezney(at)not-real.oma.be>
Date: Tue Nov 14 2000 - 08:11:56 GMT
Hello,

Last friday I started coding changes into swish-1.3.3 but now I learn
that the latest stable version is 2.0.3.
So any changes shoud be applied to 2.0.3? .... and I thought I was
almost finished with my UseWords coding :(((

The idea is to apply a list of words ony to use when indexing youre
files, so that people searching can only find what you early introduced
in eg a UseWord.txt file similar to the StopWords.txt file

This is what I got so far :


/*****************************************************************************************/

/* 1 in file.c */
else if (c = (char *) lstrstr(line, "UseWords")) {
                        c += strlen("UseWords");
                        while (1) {
                                strcpy(value, (char *) getword(c,
&skiplen));
                                if (!skiplen || value[0] == '\0' ||
value[0] == '\n')
                                        break;
                                else {
                                        c += skiplen;
                                        if (lstrstr(value,
"SwishDefault"))
                                                readdefaultusewords();
                                        else
                                                addusehash(value);
                                }
                        }
                }
/*****************************************************************************************/

/*  2 in hash.h */
void readdefaultusewords _AP ((void));
/*****************************************************************************************/

/*  3 in hash.c */
void readdefaultusewords()
{
        int i;

        for (i = 0; defaultusewords[i] != NULL; i++)
                addusehash(defaultusewords[i]);
}

OR

void readdefaultusewords()
{
        int i;
        FILE *instream;
        char filename="/home/httpd/html/SWISH-E/swish/usewords.txt"
        char cstring[256];
        int usewordcount=0;

        if ((instream=fopen(filename,"r"))==NULL)
        {
          printf("error cannot open usewords file\n");
          fflush(stdout);
        }

        /* blah blah blah */
        while (!(feof(instream)))
        {
          fgets(cstring,instream);
          usewordcount++;
        }

        rewind(instream);

        if ((defaultusewords=(char **)malloc(usewordcount*sizeof(char
**))==NULL)
        {
          printf("memory allocation error\n");
          fflush(stdou);
        }
        i=0;
        while (!(feof(instream)))
        {
          fgets(cstring,instream);
          defaultusewords[i]=(char *)strdup(cstring);
          addusehash(defaultusewords[i]);
          i++;
        }
        fclose(instream);
}


/*****************************************************************************************/

/* 4 in swish.h */

char *defaultusewords[] = {"swish", "autoswish", "search",  NULL };
/*****************************************************************************************/

[root@alfa swish-e-1.3.3]# grep addstophash *.c *.h
/* OK became addusehash in 3 */
file.c:                                         addstophash(value);
/* OK became addusehash in 3 */ hash.c:
addstophash(defaultstopwords[i]);
/* OK became addusehash in 5 */ hash.c:void addstophash(word)
/* OK doesnt has 2 be done   */ index.c:
addstophash(ep->word);
/* OK doesnt has 2 be done   */ search.c:
addstophash(word);
/* OK became addusehash in 9 */ hash.h:void addstophash _AP ((char *));
[root@alfa swish-e-1.3.3]#
/*****************************************************************************************/

/* 5 in hash.c */
void addusehash(word)
char *word;
{
        unsigned hashval;
        struct swline *sp;

        if (isuseword(word))
                return;

        sp = (struct swline *) emalloc(sizeof(struct swline));
        sp->line = (char *) mystrdup(word);

        hashval = hash(word);
        sp->next = hashuselist[hashval];
        hashuselist[hashval] = sp;
}
/*****************************************************************************************/

[root@alfa swish-e-1.3.3]# grep hashstoplist *.c *.h
/* OK became hashuselist in 5 */ hash.c: sp->next =
hashstoplist[hashval];
/* OK became hashuselist in 5 */ hash.c: hashstoplist[hashval] = sp;
/* OK became hashuselist in 6 */ hash.c: sp = hashstoplist[hashval];
/* OK became hashuselist in 7 */ index.c:                sp =
hashstoplist[hashval];
/* OK became hashuselist in 8 */ swish.h:VAR struct swline
*hashuselist[HASHSIZE];
[root@alfa swish-e-1.3.3]#
/*****************************************************************************************/

/* 6 in hash.c */
int isuseword(word)
char *word;
{
        unsigned hashval;
        struct swline *sp;

        hashval = hash(word);
        sp = hashuselist[hashval];

        while (sp != NULL) {
                if (!strcmp(sp->line, word))
                        return 1;
                sp = sp->next;
        }
        return 0;
}
/*****************************************************************************************/

/* 7 in index.c */
/* Prints the list of usewords into the index file.
*/

void printusewords(fp)
FILE *fp;
{
        int hashval;
        struct swline *sp;

        offsets[USEWORDPOS] = ftell(fp);
        for (hashval = 0; hashval < HASHSIZE; hashval++) {
                sp = hashuselist[hashval];
                while (sp != NULL) {
                        fprintf(fp, "%s ", sp->line);
                        sp = sp->next;
                }
        }
        fprintf(fp, "\n");
}
/*****************************************************************************************/

[root@alfa swish-e-1.3.3]# grep STOPWORDPOS *.c *.h
index.c:        offsets[STOPWORDPOS] = ftell(fp);
index.c:                                if (pos == offsets[STOPWORDPOS])
{
merge.c:        limit1 = offsets[STOPWORDPOS];
merge.c:        limit2 = offsets[STOPWORDPOS];
search.c:       if (offsets[STOPWORDPOS] == ftell(fp))
search.c:                               if (offsets[STOPWORDPOS] ==
ftell(fp))
search.c:       fseek(fp, offsets[STOPWORDPOS], 0);
search.c:                               if (offsets[STOPWORDPOS] ==
ftell(fp))
swish.h:#define STOPWORDPOS MAXCHARS - 3
[root@alfa swish-e-1.3.3]#
/*****************************************************************************************/

/* 8 in swish.h */
swish.h:VAR struct swline *hashuselist[HASHSIZE];
/*****************************************************************************************/

/* 9 in swish.h */
hash.h:void addusehash _AP ((char *));
/*****************************************************************************************/

[root@alfa swish-e-1.3.3]# grep isstopword *.c *.h
check.c:        if (isstopword(word))
hash.c: if (isstopword(word) )
hash.c: if (isstopword(word))
hash.c:int isstopword(word)
index.c:                if (!isstopword(ep->word)) {
search.c:                       isstopword(pointer1->line) &&
!isrule(pointer1->line) &&
search.c:                       if (isstopword(pointer2->line) &&
!isrule(pointer2->line) &&
search.c:       if (isstopword(word) && !isrule(word))
hash.h:int isstopword _AP ((char *));
[root@alfa swish-e-1.3.3]#
Received on Tue Nov 14 08:13:30 2000