void load_clans (void)
{
char buf[256];
FILE *fp;
CLAN_DATA *pClan;
sprintf (buf, "%s", CLAN_FILE);
if (!(fp = fopen( buf, "r" )) )
{
logstr( LOG_BUG, "Load_clans: file not found.", 0 );
exit(1);
}
else
{
for (;;)
{
char *word;
word = feof( fp ) ? "$" : fread_word( fp );
if (!str_cmp( word, "#CLAN" ) )
{
fread_clan( fp );
break;
}
else
{
char error[MSL];
sprintf( error, "Load_clans: bad string found '%s'", word );
logstr( LOG_BUG, error, 0 );
break;
}
}
fclose( fp );
}
return;
}
case 'E':
if (!str_cmp (string, "End") )
{
fMatch = TRUE;
if (clan_first == NULL)
clan_first = pclan;
if (clan_last != NULL)
clan_last->next = pClan;
clan_last = pClan;
pClan->next = NULL;
top_clan++;
return;
}
#CLAN
Clan Loner~
Who [ {GHermit{x ] ~
Leader None~
Rank 1 Unassigned~
Rank 2 Unassigned~
Rank 3 Unassigned~
Rank 4 Unassigned~
Rank 5 Unassigned~
Rank 6 Unassigned~
Rank 7 Unassigned~
Flags C
End
#CLAN
Clan Frozen Empire~
Who [-{r={D>{CF{WE{D<{r={x-] ~
Leader Velkyr~
Rank 1 Grunt~
Rank 2 Trainee~
Rank 3 Soldier~
Rank 4 Ice Soldier~
Rank 5 Apprentice of Ice~
Rank 6 Ice Master~
Rank 7 Lord of Ice~
Flags 0
End
#CLAN
Clan Universal Defense Force~
Who [ {D>{BU{DD{WF{D<{x ] ~
Leader Oachi~
Rank 1 Recruit~
Rank 2 Trainee~
Rank 3 Apprentice~
Rank 4 Universal Defender~
Rank 5 Universal Guardian~
Rank 6 High Defender~
Rank 7 High Guardian~
Flags 0
End
$
void load_clans(void)
{
FILE *fp;
char *string;
int count = 0;
int i;
bool fMatch = FALSE;
for (i = 0; i < (1 + top_clan); i++) //MAX_CLAN; i++)
{
clan_table[i].name = "";
clan_table[i].who_name = "";
clan_table[i].leader = "";
clan_table[i].c_rank[0].rankname = "";
clan_table[i].flags = 0;
}
if (!(fp = fopen(DATA_FILE, "r")) )
{
log_string("Error: guild.dat file not found!");
exit(1);
}
for (;;)
{
string = feof(fp) ? "End" : fread_word(fp);
if (!str_cmp(string, "End"))
break;
switch (UPPER(string[0]))
{
case 'C':
top_clan++;
count++;
clan_table[count].name = fread_string(fp);
fMatch = TRUE;
break;
case 'F':
clan_table[count].flags = fread_flag( fp );
fMatch = TRUE;
break;
case 'L':
clan_table[count].leader = fread_string(fp);
fMatch = TRUE;
break;
case 'R':
if (!str_cmp(string, "CRank") || !str_cmp(string, "Rank"))
{
i = fread_number(fp);
clan_table[count].c_rank[i].rankname = fread_string(fp);
fMatch = TRUE;
}
break;
case 'W':
clan_table[count].who_name = fread_string(fp);
fMatch = TRUE;
break;
} /* end of switch */
} /* end of while (!feof) */
if (!fMatch)
{
bug("Fread_clans: no match.", 0);
fread_to_eol(fp);
}
fclose(fp);
return;
}
for (i = 0; i < (1 + top_clan); i++) //MAX_CLAN; i++)
{
clan_table[i].name = "";
clan_table[i].who_name = "";
clan_table[i].leader = "";
clan_table[i].c_rank[0].rankname = "";
clan_table[i].flags = 0;
}
This is in load_clans (void)
clan_first = NULL;
clan_last = NULL;
for (;;)
{
char *word;
word = feof( fp ) ? "$" : fread_word( fp );
if (!str_cmp( word, "#CLAN" ) )
fread_clan( fp );
else if (!str_cmp(word, "$") )
break;
else
{
char error[MSL];
sprintf( error, "Load_clans: bad string found '%s'", word );
logstr( LOG_BUG, error, 0 );
break;
}
}
fclose( fp );
This is in fread_clan (FILE *fp)
case 'E':
if (!str_cmp (string, "End") )
{
if (clan_first == NULL)
{
clan_first = pClan;
clan_last = pClan;
}
else {
clan_last->next = pClan;
}
pClan->next = NULL;
top_clan++;
fMatch = TRUE;
return;
}
break;
Before anyone criticizes, I already know im doing it wrong. This is what I have:
What im trying to figure out is if I need to allocate per clan or just all at once? Also am I writing it correctly? They are all in one file but each clan starts with #Clan and ends with End.