/*
 * New do_help command complicated by Lam (lam@mud.org.pl) 16.2.1998
 * also telnet lac.mud.org.pl 4000 - (completely polish mud)
 *
 * This snippet works for Envy 2.2, but I think it should work on any Merc
 * derivative (although it hasn't been tested).
 *
 * My version of do_help allows shortcuts of helps, but if the shortcut fits
 * to more than one help, all the keywords are displayed.
 * If the argument fits just right, the help is displayed, but other
 * shortcuts are displayed, too.
 *
 * If you're using my code: don't forget to mention in help "help", that
 * I am the author of this command. Also, please mail me (lam@mud.org.pl) so
 * I can make more snippets for people who are looking for them. Thank you.
 *
 * Please tell me what errors did I make, to make my coding and english
 * better. Thanx again.
 *
 * installation: see the end of the file
 */
void do_help( CHAR_DATA *ch, char *arg )
{
    HELP_DATA *help;
    HELP_DATA *help_short = NULL;
    char help_short_key [MAX_INPUT_LENGTH];
    char helplist [MAX_STRING_LENGTH]; /* it could overflow... */
    char key [MAX_INPUT_LENGTH];
    char *keylist;
    bool found = FALSE;
    bool many = FALSE;

    if ( *arg == '\0' )
        arg = "summary"; /* I suggest summaryxxx or so to prevent shortcuts */

    helplist[0] = '\0';
    
    for ( help = help_first; help; help = help->next )
    {
        if ( help->level > get_trust( ch ) )
            continue;

        /* is_name sucks ;) */
        
        for ( keylist = help->keyword; ; )
        {
            keylist = one_argument( keylist, key );
            if ( key[0] == '\0' || !str_prefix( arg, key ) )
                break;
        }
        
        if ( key[0] == '\0' )
            continue;
        
        if ( !str_cmp( arg, key ) )
        {
        /* the keyword is extactly like argument */
            if ( found )
                send_to_char( "\n\r-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r\n\r", ch );

            if ( help->level >= 0 && str_cmp( arg, "imotd" ) )
            {
                send_to_char( help->keyword, ch );
                send_to_char( "\n\r", ch );
            }

            if ( help->text[0] == '.' )
                send_to_char( help->text+1, ch );
            else
                send_to_char( help->text  , ch );
            found = TRUE;
        }
        else
        {
        /* short */
            if ( !help_short && !many )
            {
                help_short = help;
                strcpy( help_short_key, key );
            }
            else
            {
                if ( help_short )
                {
                    strcat( helplist, help_short_key );
                    strcat( helplist, "\n\r" );
                    help_short = NULL;
                }
                strcat( helplist, key );
                strcat( helplist, "\n\r" );
                many = TRUE;
            }
        }
    }

    if ( !found && !many && !help_short )
    {
        send_to_char( "No help on that word.\n\r", ch );
        return;
    }
    if ( found )
    {
        if ( help_short )
        {
            /* I suggest making this line green */
            send_to_char( "\n\rThe argument is also a prefix of keyword:\n\r", ch );
            send_to_char( help_short_key, ch );
            send_to_char( "\n\r", ch );
        }
        else if ( many )
        {
            /* colour this line too */
            send_to_char( "\n\rThe argument is also a prefix of keywords:\n\r", ch );
            send_to_char( helplist, ch );
        }
    }
    else if ( help_short )
    {
        if ( help_short->level >= 0 && str_cmp( help_short_key, "imotd" ) )
        {
            send_to_char( help_short->keyword, ch );
            send_to_char( "\n\r", ch );
        }

        if ( help_short->text[0] == '.' )
            send_to_char( help_short->text+1, ch );
        else
            send_to_char( help_short->text  , ch );
    }
    else if ( many )
    {
        /* This line also should be coloured */
        send_to_char( "The word you entered is a prefix of help keywords:\n\r", ch );
        send_to_char( helplist, ch );
    }

    return;
}

/*

INSTALLATION: (Envy 2.2)

1. Insert the above function instead of original do_help in act_info.c

Now it would work, but type eg. "h c". You will see about 2 screens of text
on Envy 2.2 distribution, without any break, even if you have pagelength set
to 20 (most of your players have)... The cure for this is:
2. in comm.c in send_to_char() remove lines with if ( strlen( txt ) ) < 600 ).
Yes, you don't need to save process time :) leave only the section below else.
3. in comm.c in show_string() just below "On advise by Scott Mobley and
others" comment out or remove lines:
    *scan++ = '\n';
    *scan++ = '\r';
leave the line:
    *scan = 0;
Now you will have better working pager. If you wish, in process_output() you
may insert \n\r in front of [Please type...].

*/


/*
 =============================================================================
/   ______ _______ ____   _____   ___ __    _ ______    ____  ____   _____   /
\  |  ____|__   __|  _ \ / ____\ / _ \| \  / |  ____|  / __ \|  _ \ / ____\  \
/  | |__     | |  | |_| | |     | |_| | |\/| | |___   | |  | | |_| | |       /
/  | ___|    | |  | ___/| |   __|  _  | |  | | ____|  | |  | |  __/| |   ___ \
\  | |       | |  | |   | |___| | | | | |  | | |____  | |__| | |\ \| |___| | /
/  |_|       |_|  |_|  o \_____/|_| |_|_|  |_|______|o \____/|_| \_|\_____/  \
\                                                                            /
 ============================================================================

------------------------------------------------------------------------------
ftp://ftp.game.org/pub/mud      FTP.GAME.ORG      http://www.game.org/ftpsite/
------------------------------------------------------------------------------

  This file came from FTP.GAME.ORG, the ultimate source for MUD resources.

------------------------------------------------------------------------------

*/