Fix sort_scores in the acro plugin - pass the correct number of array entries
to qsort() and properly reconstruct the list. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@224 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[Changes 1.2c01]
|
||||
|
||||
* Fix timers in acro plugin, clears up some build warnings. (caf)
|
||||
* Clears up a crash and some build warnings in the acro plugin. (caf)
|
||||
|
||||
* Applied patches from jdhore to clean up the plugin building
|
||||
and installing process. (caf)
|
||||
|
||||
@@ -448,40 +448,17 @@ srec *end_vote(vrec *voters, prec *players, srec *stmp)
|
||||
return stmp;
|
||||
}
|
||||
|
||||
srec *sort_scores(srec *stmp)
|
||||
{
|
||||
int i = 0;
|
||||
srec *tmp;
|
||||
srec **sort, **ctmp;
|
||||
if (!stmp->next)
|
||||
return stmp;
|
||||
for (tmp = stmp; tmp; tmp = tmp->next)
|
||||
i++;
|
||||
ctmp = sort = (srec **)new_malloc(i*sizeof(srec *));
|
||||
put_it("START SORTING");
|
||||
put_scores(NULL, NULL, NULL, NULL, NULL);
|
||||
for (tmp = stmp; tmp; tmp = tmp->next)
|
||||
*ctmp++ = tmp;
|
||||
qsort((void *)sort, i+1, sizeof(srec *), (int (*)(const void *, const void *))comp_score);
|
||||
ctmp = sort;
|
||||
for (tmp = *ctmp++; *ctmp; ctmp++)
|
||||
tmp = tmp->next = *ctmp;
|
||||
tmp->next = NULL;
|
||||
tmp = *sort;
|
||||
new_free(&sort);
|
||||
put_scores(NULL, NULL, NULL, NULL, NULL);
|
||||
put_it("END SCORES");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Here we sort deeze babys ... The return values are "opposite" so we can
|
||||
* sort in descending order instead of ascending... Stupid declarations had
|
||||
* me going for a while, no wonder it didnt sort right at first! :)
|
||||
*/
|
||||
|
||||
int comp_score(srec **one, srec **two)
|
||||
static int comp_score(const void *a, const void *b)
|
||||
{
|
||||
srec * const *one = a;
|
||||
srec * const *two = b;
|
||||
|
||||
if ((*one)->score > (*two)->score)
|
||||
return -1;
|
||||
if ((*one)->score < (*two)->score)
|
||||
@@ -490,6 +467,41 @@ int comp_score(srec **one, srec **two)
|
||||
return strcasecmp((*one)->nick, (*two)->nick);
|
||||
}
|
||||
|
||||
srec *sort_scores(srec *stmp)
|
||||
{
|
||||
size_t n = 0;
|
||||
srec *tmp;
|
||||
srec **sort, **ctmp;
|
||||
|
||||
if (!stmp->next)
|
||||
return stmp;
|
||||
|
||||
for (tmp = stmp; tmp; tmp = tmp->next)
|
||||
n++;
|
||||
ctmp = sort = (srec **)new_malloc(n * sizeof sort[0]);
|
||||
|
||||
put_it("START SORTING");
|
||||
put_scores(NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (tmp = stmp; tmp; tmp = tmp->next)
|
||||
*ctmp++ = tmp;
|
||||
qsort(sort, n, sizeof sort[0], comp_score);
|
||||
|
||||
tmp = sort[0];
|
||||
for (ctmp = &sort[1]; ctmp < &sort[n]; ctmp++)
|
||||
{
|
||||
tmp->next = *ctmp;
|
||||
tmp = *ctmp;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
|
||||
tmp = sort[0];
|
||||
new_free(&sort);
|
||||
put_scores(NULL, NULL, NULL, NULL, NULL);
|
||||
put_it("END SCORES");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void show_acros(prec *players, char *chan)
|
||||
{
|
||||
prec *tmp;
|
||||
|
||||
@@ -104,7 +104,6 @@ prec *take_acro(grec *, prec *, char *, char *, char *);
|
||||
vrec *take_vote(grec *, vrec *, prec *, char *, char *, char *);
|
||||
srec *end_vote(vrec *, prec *, srec *);
|
||||
srec *sort_scores(srec *);
|
||||
int comp_score(srec **one, srec **two);
|
||||
void show_scores(grec *, srec *, srec *, char *);
|
||||
int warn_acro(void *, char *);
|
||||
int start_vote(void *, char *);
|
||||
|
||||
Reference in New Issue
Block a user