00001
00002 #include "common.h"
00003
00004 static char const rcsid[] = "$Id: scoreWindow.c,v 1.4 2004/07/16 22:42:55 baertsch Exp $";
00005
00006 int scoreWindow(char c, char *s, int size, int *score, int *start, int *end, int match, int misMatch)
00007
00008
00009
00010
00011 {
00012 int i=0, j=0, max=0, count = 0;
00013
00014 *end = 0;
00015
00016 for (i=0 ; i<size ; i++)
00017 {
00018 int prevScore = (i > 0) ? score[i-1] : 0;
00019
00020 if (toupper(s[i]) == toupper(c) )
00021 score[i] = prevScore+match;
00022 else
00023 score[i] = prevScore-misMatch;
00024 if (score[i] >= max)
00025 {
00026 max = score[i];
00027 *end = i;
00028
00029 for (j=i ; j>=0 ; j--)
00030 if (score[j] == 0)
00031 {
00032 *start = j+1;
00033 break;
00034 }
00035 }
00036 if (score[i] < 0)
00037 score[i] = 0;
00038 }
00039 assert (*end < size);
00040
00041 for (i=*start ; i<=*end ; i++)
00042 {
00043 assert (i < size);
00044 if (toupper(s[i]) == toupper(c) )
00045 count++;
00046 }
00047 return count;
00048 }