Mercurial > ~darius > hgwebdir.cgi > paradise_server
diff src/tool-heraldry.c @ 8:0836fb919dfa
First entry of Paradise Server 2.9 patch 10 Beta
author | darius |
---|---|
date | Sat, 06 Dec 1997 04:37:05 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tool-heraldry.c Sat Dec 06 04:37:05 1997 +0000 @@ -0,0 +1,100 @@ +/*-------------------------------------------------------------------------- +NETREK II -- Paradise + +Permission to use, copy, modify, and distribute this software and its +documentation, or any derivative works thereof, for any NON-COMMERCIAL +purpose and without fee is hereby granted, provided that this copyright +notice appear in all copies. No representations are made about the +suitability of this software for any purpose. This software is provided +"as is" without express or implied warranty. + + Xtrek Copyright 1986 Chris Guthrie + Netrek (Xtrek II) Copyright 1989 Kevin P. Smith + Scott Silvey + Paradise II (Netrek II) Copyright 1993 Larry Denys + Kurt Olsen + Brandon Gillespie +--------------------------------------------------------------------------*/ + +/* + * Robert Forsman + * + * Scans the score file for royalty. + */ + +#include "config.h" + +#include <stdio.h> +#include <sys/types.h> +#include <sys/file.h> +#include <pwd.h> +#include "defs.h" +#include "struct.h" +#include "data.h" + + +struct person +{ + int royal; + char name[16]; + struct person *next; +}; + +int +compare_people(a, b) + struct person *a, *b; +{ + if (a->royal > b->royal) + return 1; + else + return -1; +} + +int +main(argc, argv) + int argc; + char **argv; +{ + struct statentry plstats; + struct person *head = 0; + int royalty; + + printf("Reading players file from stdin..."); + while (1 == fread(&plstats, sizeof(plstats), 1, stdin)) + { + if (plstats.stats.st_royal > 0) + { + /* royalty! insert into linked list. */ + struct person **scan; + struct person *dude; + dude = (struct person *) malloc(sizeof(*dude)); + dude->royal = plstats.stats.st_royal; + strncpy(dude->name, plstats.name, sizeof(dude->name)); + for (scan = &head; + *scan && 0 > compare_people(dude, *scan); + scan = &(*scan)->next) + ; + dude->next = *scan; + *scan = dude; + } + } + printf("done.\n"); + + + royalty = -1; + while (head) + { + struct person *temp; + if (royalty != head->royal) + { + royalty = head->royal; + printf("%s:\n", royal[royalty].name); + } + printf(" %s\n", head->name); + temp = head; + head = head->next; + free(temp); + } + + exit(0); +}