* print selected parts of score list. * argc >= 2, with argv[0] untrustworthy (directory names, et al.), * and argv[1] starting with "-s". * caveat: some shells might allow argv elements to be arbitrarily long. */
| 1191 | * caveat: some shells might allow argv elements to be arbitrarily long. |
| 1192 | */ |
| 1193 | void |
| 1194 | prscore(int argc, char **argv) |
| 1195 | { |
| 1196 | const char **players, *player0; |
| 1197 | int i, playerct, rank; |
| 1198 | struct toptenentry *t1; |
| 1199 | FILE *rfile; |
| 1200 | char pbuf[BUFSZ], *p; |
| 1201 | unsigned ln; |
| 1202 | int uid = -1; |
| 1203 | boolean current_ver = TRUE, init_done = FALSE, match_found = FALSE; |
| 1204 | |
| 1205 | /* expect "-s" or "--scores"; "-s<anything> is accepted */ |
| 1206 | ln = (argc < 2) ? 0U |
| 1207 | : ((p = strchr(argv[1], ' ')) != 0) ? (unsigned) (p - argv[1]) |
| 1208 | : Strlen(argv[1]); |
| 1209 | if (ln < 2 || (strncmp(argv[1], "-s", 2) |
| 1210 | && strcmp(argv[1], "--scores"))) { |
| 1211 | raw_printf("prscore: bad arguments (%d)", argc); |
| 1212 | return; |
| 1213 | } |
| 1214 | |
| 1215 | rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); |
| 1216 | if (!rfile) { |
| 1217 | raw_print("Cannot open record file!"); |
| 1218 | return; |
| 1219 | } |
| 1220 | |
| 1221 | #ifdef AMIGA |
| 1222 | { |
| 1223 | extern winid amii_rawprwin; |
| 1224 | |
| 1225 | init_nhwindows(&argc, argv); |
| 1226 | amii_rawprwin = create_nhwindow(NHW_TEXT); |
| 1227 | } |
| 1228 | #endif |
| 1229 | |
| 1230 | /* If the score list isn't after a game, we never went through |
| 1231 | * initialization. */ |
| 1232 | if (wiz1_level.dlevel == 0) { |
| 1233 | dlb_init(); |
| 1234 | init_dungeons(); |
| 1235 | init_done = TRUE; |
| 1236 | } |
| 1237 | |
| 1238 | /* to get here, argv[1] either starts with "-s" or is "--scores" without |
| 1239 | trailing stuff; for "-s<anything>" treat <anything> as separate arg */ |
| 1240 | if (argv[1][1] == '-' || !argv[1][2]) { |
| 1241 | argc--; |
| 1242 | argv++; |
| 1243 | } else { /* concatenated arg string; use up "-s" but keep argc,argv */ |
| 1244 | argv[1] += 2; |
| 1245 | } |
| 1246 | /* -v doesn't take a version number arg; it means 'all versions present |
| 1247 | in the file' instead of the default of only the current version; |
| 1248 | unlike -s, we don't accept "-v<anything>" for non-empty <anything> */ |
| 1249 | if (argc > 1 && !strcmp(argv[1], "-v")) { |
| 1250 | current_ver = FALSE; |
no test coverage detected