/* ************************************************************************
Renum.c Utility for Realms of Aurealis
9/23/96 RoA v0.2 Beta
This will renumber, i say renumber all the ID NUMBERS in the player file
and crack us open a nice nifty fresh pfile. It starts with 0 and goes on
up right thru the last player in pfile.
************************************************************************* */
#include <stdio.h>
#include <ctype.h>
#include "../structures.h"
#include "../utils.h"
void renum(char *filename)
{
FILE *fl;
FILE *outfile;
struct char_file_u player;
int idnum;
char *ptr;
int badnames;
if (!(fl = fopen(filename, "r+"))) {
printf("Can't open %s.", filename);
exit(1);
}
outfile = fopen("players.new", "w");
for (idnum = 0, badnames = 0; ; )
{
fread(&player, sizeof(struct char_file_u ), 1, fl);
if (feof(fl))
{
fclose(fl);
fclose(outfile);
puts("Done.");
printf("%d characters renumbered, with %d spaced names reported.\n",
idnum, badnames);
exit(1);
}
for (ptr = player.name; *ptr; ptr++)
if (!*ptr || *ptr == ' ')
{
badnames++;
sprintf(player.name, "bad%d", badnames);
}
if (idnum == 1) /* fix chaos :) */
strcpy(player.name, "ChaosBAK");
if (idnum >= 0 && idnum <= 5) /* show 1st 5 players */
printf("[%5d] %s\n",idnum, player.name);
player.saved.idnum = idnum++;
fwrite(&player, sizeof(struct char_file_u ), 1, outfile);
}
}
int main(int argc, char *argv[])
{
if (argc != 2)
printf("Usage: %s playerfile-name\n", argv[0]);
else
renum(argv[1]);
return 1;
}