#include "com_help.h"
#include "stringops.h"
#include "socket.h"

static char line [1024], output [1024];

void command_help (globals *g, player *p, char *l)
{
	FILE *f;

	#ifdef FUNCTIONS
	puts ("**command_help");
	#endif

	if (l == NULL) l = "";

	f = fopen (g->help_file, "r");
	if (f == NULL) return;

	fgets (line, 199, f);
	clipret (line);

	while (!feof(f))
	{
		if (!strncmp(line, "*****", 5) &&
			!strcmp(line + 5, l))
		{
			fgets (line, 199, f);
			clipret (line);

			while (!feof(f) && strncmp (line, "*****", 5))
			{
				sprintf (output, "w %s = %s", p->name, line);
				socket_write (g->socket, output);

				fgets (line, 199, f);
				clipret (line);
			}
		}
		else
		{
			fgets (line, 199, f);
			clipret (line);
		}
	}

	fclose (f);
}