MAN.C
LIB3/GLOBAL/MAN.C · 3.5 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
/*
* The help module.
* This will (should) give help on the required thingy.
* modified for New Moon on 6/25/93 by prophet@itsa.ucsf.edu
* 93-09-27 Bannor - Added -v option to show man file path names.
* Added "No man/help found fail message.
*/
#include "help.h"
#include "nroff.h"
#define CROSS_REF "/doc/cross_ref"
#define CRE_POWERS "/doc/Help/creator/Powers/*"
#define CRE_TOOLS "/doc/Help/creator/Tools/*"
#define creator_dirs ({ \
"/doc/Help/lfun/", "/doc/Help/efun/",\
"/doc/Help/creator/", "/doc/Help/create/", "/doc/Help/driver/lpc/types/",\
"/doc/Help/mudlib/", "/doc/Help/driver/applies/", \
"/doc/Help/driver/concepts/", "/doc/Help/driver/lpc/constructs/", \
"/doc/Help/driver/efuns/conglom/" })
string search_man( string str )
/* checks to see if the file has been nroff'd, returns the
* path/filename of the man file */
{
if( this_player()->query_creator() &&
file_size( CNROFF_DIR + str + ".o" ) > 0 )
{
return CNROFF_DIR + str;
}
} /* search_man() */
string create_man( string str )
/* checks creator status and looks for .o copy of <arg> */
{
int i;
mixed cross_ref;
if( this_player()->query_creator() )
for( i = 0; i < sizeof( creator_dirs ); i++ )
if( file_size( creator_dirs[ i ] + str ) > 0 )
{
NROFF_HAND->create_chelp( creator_dirs[ i ], str );
return CNROFF_DIR + str;
/*
return creator_dirs[ i ] + str;
*/
}
cross_ref = read_file( CROSS_REF );
cross_ref = explode( cross_ref, "%" );
if( (i = member_array( str, cross_ref )) == -1 )
return 0;
return extract( cross_ref[ i + 1 ], 0, strlen( cross_ref[ i + 1 ] ) - 2 );
/* use extract, not explode */
} /* create_man() */
string search_man_dirs( string str )
/* searchs creator man dirs for the file str. Returns the
* path to str.
*/
{
int i;
mixed cross_ref;
if( this_player()->query_creator() )
for( i = 0; i < sizeof( creator_dirs ); i++ )
if( file_size( creator_dirs[ i ] + str ) > 0 )
return creator_dirs[ i ] + str;
} /* search_man_dirs() */
int do_man( string str )
{
string filen, s;
string topic;
int give_file_name;
if( !str )
{
printf( "Powers:\n%-#*s\n", ( int ) this_player()->query_cols(),
implode ( delete( get_dir( CRE_POWERS ), 0, 2 ), "\n" ) );
printf( "\nTools:\n%-#*s\n", ( int ) this_player()->query_cols(),
implode ( delete( get_dir( CRE_TOOLS ), 0, 2 ), "\n" ) );
write( "\nUsage : man {-v} <topic>\n" );
return 1;
}
give_file_name = 0;
if( sscanf( str, "-v %s", topic ) == 1 )
{
give_file_name = 1;
write( "%^BOLD%^Man file is: " + search_man_dirs( topic ) +
".%^RESET%^\n" );
}
else
topic = str;
filen = search_man( topic );
if( !filen )
filen = create_man( topic );
if( !filen )
{
filen = HELP_OBJECT->HELP_COMMAND( topic );
if( !filen )
write( "No man or help page found on: " + topic + ".\n" );
return 1;
}
if( give_file_name )
write( "%^BOLD%^Nroff file is: " + filen + ".%^RESET%^\n" );
filen = (string)NROFF_HAND->cat_file( filen, 1 );
if( !filen )
{
filen = create_man( topic );
filen = (string)NROFF_HAND->cat_file( filen );
}
if( !filen )
{
notify_fail( "Manual file broken. Please tell a creator.\n" );
log_file( "MANU_FILES", "Manu file " + topic + " broken.\n" );
return 0;
}
this_player()->more_string( filen );
return 1;
} /* do_man() */