reload.c
./ddance/src/reload.c · 5.9 KB
From the archive ddance-linux.tar.bz2
Download the archive « Back to the archive contents
/****************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/****************************************************************************
* ROM 2.4 is copyright 1993-1998 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@hypercube.org) *
* Gabrielle Taylor (gtaylor@hypercube.org) *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************/
/****************************************************************************
* Demon's Dance MUD, and source code are property of Eric Goetschalckx *
* By compiling this code, you agree to include the following in your *
* login screen: *
* Derivative of Demon's Dance, by Enzo/Stan *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#elif defined(WIN32)
#include <sys/types.h>
#include <time.h>
#define NOCRYPT
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "magic.h"
#include "recycle.h"
#include "tables.h"
#include "lookup.h"
#include "arena.h"
bool free_helps( CHAR_DATA *ch, char *arg )
{
char buf[MAX_STRING_LENGTH];
HELP_DATA *h, *h_next;
HELP_DATA *prev = NULL;
bool found = FALSE;
prev = help_first;
for ( h = help_first; h; h = h_next )
{
h_next = h->next;
if ( !str_cmp( h->keyword, arg ) )
{
free_string( h->keyword );
free_string( h->text );
if ( h == help_first )
help_first = h->next;
else
prev->next = h->next;
if ( h == help_last )
help_last = prev;
/*free_mem( h, sizeof(*h) );*/
found = TRUE;
}
prev = h;
}
if ( !found )
{
sprintf( buf, "Help entry %s not found.\n\r", arg );
send_to_char( buf, ch );
return FALSE;
}
return TRUE;
}
bool read_entry( CHAR_DATA *ch, FILE *fp, char *filename, char *arg )
{
char buf[MAX_STRING_LENGTH];
HELP_DATA *new;
HELP_DATA *debug;
char *test_keyword = 0;
char *test_text = 0;
int test_level = 0;
if ( fread_letter( fp ) != '#' )
{
sprintf( buf, "read_entry: # not in %s.\n\r", filename );
send_to_char( buf, ch );
return FALSE;
}
fread_word( fp ); /* read the word HELPS */
new = alloc_mem( sizeof(*new) );
new->next = NULL;
for ( ; ; )
{
test_level = fread_number( fp );
test_keyword = fread_string( fp );
if ( !str_cmp( test_keyword, "$" )) /* end of file */
{
free_string( test_keyword );
free_string( test_text );
free_mem( new, sizeof(*new) );
return FALSE;
}
test_text = fread_string( fp );
if ( !str_cmp( test_keyword, arg )) /* match */
{
new->keyword = test_keyword;
new->level = test_level;
new->text = test_text;
debug = help_last;
if ( help_last )
help_last->next = new;
help_last = new;
sprintf( buf, "entry %s updated.\n\r", new->keyword );
send_to_char( buf, ch );
free_mem(new, sizeof(*new));
return TRUE;
}
else
{
free_string( test_keyword );
free_string( test_text );
}
}
free_mem(new, sizeof(*new));
return FALSE;
}
void do_reload( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
char buf[MAX_STRING_LENGTH];
FILE *fp;
bool found = FALSE;
int i;
/* in order of 'importance' */
char *helpfile[2] = {
"../area/help.are","../area/rom.are",
};
argument = one_argument( argument, arg );
if ( arg[0] == '\0' )
{
send_to_char( "Usage: reload <help-keyword>\n\r", ch );
return;
}
/* remove help entry from the list */
if ( !free_helps( ch, arg ))
return;
/* here we go */
fclose( fpReserve );
for ( i = 0; i < 9; i++ )
{
if ( ( fp = fopen( helpfile[i], "r" ) ) == NULL )
{
sprintf( buf, "do_reload: couldn't open %s.\n\r", helpfile[i] );
send_to_char( buf, ch );
}
else
{
if ( ( found = read_entry( ch, fp, helpfile[i], arg ) ) == TRUE )
{
fclose( fp );
break;
}
fclose( fp );
}
}
fpReserve = fopen( NULL_FILE, "r" );
return;
}