annotate src/tool-trim.c @ 16:e246e5730173

Removed useless binaries from repository...
author darius
date Wed, 24 Dec 1997 12:36:02 +0000
parents 0836fb919dfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 * Kevin P. Smith 12/05/88
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 *
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 * Modified for Paradise by Rob Forsman 1993 Cleaned up by Brandon Gillespie
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 * Sept 17 1994
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include "config.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include <stdio.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #include <sys/types.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30 #include <sys/file.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 #include <pwd.h>
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 #include "defs.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #include "data.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34 #include "struct.h"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 struct statentry player2;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 /* struct status globals; */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 struct rawdesc *output = NULL;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 char mode;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41 /* prototypes */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 void trimblanks2(char *str);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 void trimblanks(char *str);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 void usage(char *me);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 main(argc, argv)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 int argc;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 char **argv;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 int fd;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 struct statentry plstats;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 int i;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 char buf[512];
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 int harsh = 10; /* How strict we will be with player trimming */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 char *me;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 char *path;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 FILE *infile = stdin; /* these used to actually read in from the
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 * actual file, Rob changed them to
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 * stdin/out, and I don't mind them that way
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 * (it actually makes it a little easier */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 FILE *outfile = stdout;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 me = *argv;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 if (argc == 2)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 if (*argv[1] == '-')
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 usage(me);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 else
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 harsh = atoi(argv[1]);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 if (argc > 2 || harsh <= 0)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 usage(me);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 fprintf(stderr, "%s: If you do not know how to use this program, break now and type '%s -h'\n", me, me);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 i = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 while (1 == fread(&plstats, sizeof(plstats), 1, infile))
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 /* Player 0 is always saved. */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 /*
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83 * This formula reads: If (deadtime - (10 + rank^2 + playtime/2.4)*n days
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 * > 0), nuke him.
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 */
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 if (i != 0
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 && harsh < 100
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 && ((time(NULL) - plstats.stats.st_lastlogin) >
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 (10 +
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 plstats.stats.st_rank * plstats.stats.st_rank +
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 (plstats.stats.st_tticks +
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 plstats.stats.st_sbticks +
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 plstats.stats.st_wbticks +
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 plstats.stats.st_jsticks) / 2.4) * harsh * 24 * 60 * 60)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 )
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97 fprintf(stderr,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 "%-16.16s %7.2f %4d %4d %4d %4d\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 plstats.name,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 plstats.stats.st_tticks / 36000.0,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 plstats.stats.st_tplanets,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 player2.stats.st_tarmsbomb,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 player2.stats.st_tkills,
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 player2.stats.st_tlosses);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 continue;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 if (outfile)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 fwrite(&plstats, sizeof(plstats), 1, outfile);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 i++;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 exit(0);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 usage(char *me)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 int x;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 char message[][255] = {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 "\n\t'%s [n] < old-playerdb > new-playerdb'\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 "\nThis program trims a player database file. The level of niceness is\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 "determined by 'n' (default: 10). The old player database is read from stdin,\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124 "the new player database is written to stdout, a quick description of players\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 "who were removed is written to stderr. It will remove any character who\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 "has not played for n*10 days, as well as giving some other consideration\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 "to their varied statistics. The actual formula is:\n\n",
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 "\tIf (deadtime - (10 + rank^2 + playtime/2.4)*n days > 0), nuke him.\n\n"
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 };
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 fprintf(stderr, "-- NetrekII (Paradise), %s --\n", PARAVERS);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 for (x = 0; *message[x] != '\0'; x++)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 fprintf(stderr, message[x], me);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 exit(0);
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 trimblanks2(char *str)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 *str = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 str--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 while (*str == ' ')
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 *str = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 str--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 if (*str == '_')
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 *str = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 void
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 trimblanks(char *str)
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 *str = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 str--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 while (*str == ' ')
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 {
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 *str = 0;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 str--;
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 }
0836fb919dfa First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162 }