| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- /*
- * Copyright (C) 2000,2001 Florian Sander
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- static void sortstats(struct stats_global *gs, int itype, int today)
- {
- int again = 1;
- struct stats_local *last, *p, *c, *n;
- int a, b, pitype;
- Context;
- Assert(gs);
- again = 1;
- last = NULL;
- if (itype < 0) {
- // switch to the special sorting function
- switch (itype) {
- case T_WPL:
- sortstats_wpl(gs, today);
- break;
- case T_VOCABLES:
- sortstats_vocables(gs, today);
- break;
- case T_WORD:
- sortstats_word(gs, today);
- break;
- case T_IDLE:
- sortstats_idle(gs, today);
- break;
- default:
- debug1("Missing sorting algorithm for \"%d\"!!!", itype);
- }
- return;
- }
- // if (itype < 0) pitype = (TOTAL_TYPES - 1) + (itype * -1);
- // not needed here
- pitype = itype;
- while ((gs->slocal[today][pitype] != last) && (again)) {
- p = NULL;
- c = gs->slocal[today][pitype];
- n = c->snext[today][pitype];
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- a = c->values[today][itype];
- b = n->values[today][itype];
- }
- if (a < b) {
- again = 1;
- c->snext[today][pitype] = n->snext[today][pitype];
- n->snext[today][pitype] = c;
- if (p == NULL)
- gs->slocal[today][pitype] = n;
- else
- p->snext[today][pitype] = n;
- }
- p = c;
- c = n;
- n = n->snext[today][pitype];
- }
- last = c;
- }
- Context;
- return;
- }
- static void sortstats_wpl(struct stats_global *gs, int today)
- {
- int again = 1;
- struct stats_local *last, *p, *c, *n;
- int a, b, pitype;
- Context;
- again = 1;
- last = NULL;
- pitype = (T_WPL * (-1)) + TOTAL_TYPES - 1;
- while ((gs->slocal[today][pitype] != last) && (again)) {
- p = NULL;
- c = gs->slocal[today][pitype];
- n = c->snext[today][pitype];
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- if (c->values[today][T_LINES] >= min_lines)
- a = (int) (((float) c->values[today][T_WORDS] / (float) c->values[today][T_LINES]) * 100.0);
- else
- a = 0;
- if (n->values[today][T_LINES] >= min_lines)
- b = (int) (((float) n->values[today][T_WORDS] / (float) n->values[today][T_LINES]) * 100.0);
- else
- b = 0;
- }
- if (a < b) {
- again = 1;
- c->snext[today][pitype] = n->snext[today][pitype];
- n->snext[today][pitype] = c;
- if (p == NULL)
- gs->slocal[today][pitype] = n;
- else
- p->snext[today][pitype] = n;
- }
- p = c;
- c = n;
- n = n->snext[today][pitype];
- }
- last = c;
- }
- Context;
- return;
- }
- static void sortstats_vocables(struct stats_global *gs, int today)
- {
- int again = 1;
- struct stats_local *last, *p, *c, *n;
- int a, b, pitype;
- Context;
- again = 1;
- last = NULL;
- countvocables(gs);
- pitype = (T_VOCABLES * (-1)) + TOTAL_TYPES - 1;
- while ((gs->slocal[today][pitype] != last) && (again)) {
- p = NULL;
- c = gs->slocal[today][pitype];
- n = c->snext[today][pitype];
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- a = c->vocables;
- b = n->vocables;
- }
- if (a < b) {
- again = 1;
- c->snext[today][pitype] = n->snext[today][pitype];
- n->snext[today][pitype] = c;
- if (p == NULL)
- gs->slocal[today][pitype] = n;
- else
- p->snext[today][pitype] = n;
- }
- p = c;
- c = n;
- n = n->snext[today][pitype];
- }
- last = c;
- }
- Context;
- return;
- }
- static void sortstats_word(struct stats_global *gs, int today)
- {
- int again = 1;
- struct stats_local *last, *p, *c, *n;
- int a, b, pitype;
- Context;
- debug1("sortstats_word: today == %d", today);
- again = 1;
- last = NULL;
- pitype = (T_WORD * (-1)) + TOTAL_TYPES - 1;
- debug1("pitype: %d", pitype);
- while ((gs->slocal[today][pitype] != last) && (again)) {
- p = NULL;
- c = gs->slocal[today][pitype];
- n = c->snext[today][pitype];
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- if (c->word)
- a = c->word->nr;
- else
- a = 0;
- if (n->word)
- b = n->word->nr;
- else
- b = 0;
- }
- if (a < b) {
- again = 1;
- c->snext[today][pitype] = n->snext[today][pitype];
- n->snext[today][pitype] = c;
- if (p == NULL)
- gs->slocal[today][pitype] = n;
- else
- p->snext[today][pitype] = n;
- }
- p = c;
- c = n;
- n = n->snext[today][pitype];
- }
- last = c;
- }
- Context;
- return;
- }
- // sort stats by idle-factor (minutes/lines)
- static void sortstats_idle(struct stats_global *gs, int today)
- {
- int again = 1;
- struct stats_local *last, *p, *c, *n;
- int a, b, pitype;
- Context;
- again = 1;
- last = NULL;
- pitype = (T_IDLE * (-1)) + TOTAL_TYPES - 1;
- while ((gs->slocal[today][pitype] != last) && (again)) {
- p = NULL;
- c = gs->slocal[today][pitype];
- n = c->snext[today][pitype];
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- if (c->values[today][T_LINES] >= min_lines)
- a = (int) (((float) c->values[today][T_MINUTES] / (float) c->values[today][T_LINES]) * 100.0);
- else
- a = 0;
- if (n->values[today][T_LINES] >= min_lines)
- b = (int) (((float) n->values[today][T_MINUTES] / (float) n->values[today][T_LINES]) * 100.0);
- else
- b = 0;
- }
- if (a < b) {
- again = 1;
- c->snext[today][pitype] = n->snext[today][pitype];
- n->snext[today][pitype] = c;
- if (p == NULL)
- gs->slocal[today][pitype] = n;
- else
- p->snext[today][pitype] = n;
- }
- p = c;
- c = n;
- n = n->snext[today][pitype];
- }
- last = c;
- }
- Context;
- return;
- }
- static void sortwordstats(locstats *ls, globstats *gs)
- {
- int again = 1;
- wordstats *last, *p, *c, *n, *tmp;
- int a, b;
- Context;
- again = 1;
- last = NULL;
- if (ls)
- tmp = ls->words;
- else
- tmp = gs->words;
- while ((tmp != last) && (again)) {
- p = NULL;
- if (ls)
- c = ls->words;
- else
- c = gs->words;
- n = c->next;
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- a = c->nr;
- b = n->nr;
- }
- if (a < b) {
- again = 1;
- c->next = n->next;
- n->next = c;
- if (p == NULL) {
- if (ls)
- ls->words = n;
- else
- gs->words = n;
- tmp = n;
- } else
- p->next = n;
- }
- p = c;
- c = n;
- n = n->next;
- }
- last = c;
- }
- Context;
- return;
- }
- static void sorthosts(struct stats_global *gs)
- {
- int again = 1;
- hoststr *last, *p, *c, *n;
- int a, b;
- Context;
- again = 1;
- last = NULL;
- while ((gs->hosts != last) && (again)) {
- p = NULL;
- c = gs->hosts;
- n = c->next;
- again = 0;
- while (n != last) {
- if (!c || !n)
- a = b = 0;
- else {
- a = c->nr;
- b = n->nr;
- }
- if (a < b) {
- again = 1;
- c->next = n->next;
- n->next = c;
- if (p == NULL)
- gs->hosts = n;
- else
- p->next = n;
- }
- p = c;
- c = n;
- n = n->next;
- }
- last = c;
- }
- Context;
- return;
- }
- static void sort_stats_alphabetically(globstats *gs)
- {
- locstats *as, *bs, *l, *last;
- int a, b, again = 1;
- char *astr, *bstr, n[2];
- Context;
- n[0] = n[1] = 0;
- last = NULL;
- while ((gs->local != last) && again) {
- again = 0;
- l = NULL;
- as = gs->local;
- bs = gs->local->next;
- while(bs) {
- if (!as)
- astr = n;
- else
- astr = as->user;
- if (!bs)
- bstr = n;
- else
- bstr = bs->user;
- a = (int) tolower(astr[0]);
- b = (int) tolower(bstr[0]);
- while ((a == b) && a && b) {
- astr++;
- bstr++;
- a = (int) tolower(astr[0]);
- b = (int) tolower(bstr[0]);
- }
- if (a > b) {
- if (!l)
- gs->local = bs;
- else
- l->next = bs;
- as->next = bs->next;
- bs->next = as;
- again = 1;
- if (l == NULL)
- gs->local = bs;
- else
- l = bs;
- }
- l = as;
- as = bs;
- bs = bs->next;
- }
- last = as;
- }
- Context;
- }
|