Right, sorry, I was getting ahead of myself. Let me repost some of the functions, they've changed a bit. There's a few other things to show, as well, I suppose...
void load_segments( FILE *fp )
{
SEG_DATA *pSeg;
char *word, line[128];
int i, j;
fgets(line, sizeof(line), fp);
word = fread_word(fp);
if (!str_cmp(word, "Segments"))
i = fread_number(fp);
else
bug("ERROR: Number of Segments not defined.", 0);
for (j = 1; j <= i; j++)
{
pSeg = alloc_perm(sizeof(pSeg));
pSeg->vnum = j;
pSeg->name = fread_string(fp);
pSeg->builders = fread_string(fp);
pSeg->seg_flags = fread_number(fp);
pSeg->credit = fread_string(fp);
if ( seg_first == NULL )
seg_first = pSeg;
if ( seg_last != NULL )
seg_last->next = pSeg;
seg_last = pSeg;
pSeg->next = NULL;
top_seg++;
}
}
That's the loading function; seg_first and seg_last are globally defined.
The listing function is the following:
void do_slist( CHAR_DATA *ch, char *argument )
{
char buf [ MAX_STRING_LENGTH ];
char result [ MAX_STRING_LENGTH*2 ]; /* May need tweaking. */
SEG_DATA *pSeg;
sprintf( result, "[%3s] [%-27s] (%-8s) [%-10s]\n\r",
"Num", "Seg Name", "Builders", "Credit" );
for ( pSeg = seg_first; pSeg; pSeg = pSeg->next )
{
sprintf( buf, "[%3d] %-29s %-5s %-12s\n\r",
pSeg->vnum,
pSeg->name,
pSeg->builders,
pSeg->credit);
strcat( result, buf );
}
send_to_char( result, ch );
return;
}
Segment structure is the following:
/*
* Segment definition. Work in progress. --Visko
*/
struct segment_data
{
SEG_DATA * next;
char * name;
char * builders;
int seg_flags;
char * credit;
int vnum;
};
Lesse, anything else....
I think that's about it for loading and displaying. If there's anything else you need, or anything obviously wrong, just post and I'll do what I can.
Thanks,
-Visko
|