Source Code (Use browser search to find items of interest.)
Class Index
khelpcenter'ManParser (./kdebase/khelpcenter/kmanbrowser/man.h:81)
class ManParser
{
public:
ManParser();
~ManParser();
int readLocation(const QString& location);
const QString& location() { return m_location; }
QString page() { return m_page; }
private:
QString m_page;
QString m_location;
static int instance;
};
khelpcenter'ManParser::ManParser() (./kdebase/khelpcenter/kmanbrowser/man.cpp:218)
ManParser::ManParser()
{
QString sectList = getenv("MANSECT");
if (sectList.isEmpty())
sectList = MAN_SECTIONS;
// create the sections
if (instance == 0)
{
numSections = 0;
QString s;
int count = 0;
while (!sectList.isEmpty() || count > MAN_MAXSECTIONS)
{
count++;
s = sectList.left(sectList.find(":"));
sections[numSections++] = new ManSection(s);
if (sectList.contains(":") > 0)
sectList = sectList.remove(0, sectList.find(":")+1);
else
sectList += ":";
}
}
instance++;
}
khelpcenter'ManParser::~ManParser() (./kdebase/khelpcenter/kmanbrowser/man.cpp:248)
ManParser::~ManParser()
{
instance--;
if (instance == 0)
{
for (int i = 0; i < numSections; i++)
delete sections[i];
}
}
// read the specified page
// -----------------------
// formats allowed:
// (sec) reads a list of pages in 'sections'
// page(sec) reads the specified page from 'sections'
// page reads the specified page
//
khelpcenter'ManParser::readLocation() (./kdebase/khelpcenter/kmanbrowser/man.cpp:265)
int ManParser::readLocation(const QString& name)
{
debug( "ManParser::readLocation" );
debug( name.data() );
QString tmpName = name;
if (tmpName.at(0) == '(') // read a list of pages in this section
{
QString sec = tmpName.mid(1, tmpName.findRev(")") -1);
for (int i = 0; i < numSections; i++)
{
if (sections[i]->name() == sec)
{
sections[i]->readSection();
m_page = "";
for (ManPage *page = sections[i]->pages()->first(); page != 0; page = sections[i]->pages()->next())
{
QString buffer;
buffer = page->name();
buffer += "(";
buffer += sections[i]->name();
buffer += ")";
m_page += "<cell width=200> ";
m_page += "<A HREF=man:/" + buffer + ">";
m_page += page->name();
m_page += "</A>";
m_page += "</cell>";
}
m_location = i18n("Unix man pages - Section ");
m_location += sections[i]->name();
if (!sections[i]->description().isEmpty())
{
m_location += " - ";
m_location += sections[i]->description();
}
debug( "Schade 1" );
return 0;
}
}
debug( "Schade 2" );
return 1;
}
/*
else
{
m_location = "Error: Invalid URL";
m_page = "<br>Could not find or access URL: man:/" + name;
}
*/
else // read the specified page
{
char stdFile[ 256 ];
char errFile[ 256 ];
char sysCmd[ 256 ];
char rmanCmd [256 ];
char *ptr;
sysCmd[ 0 ] = '\0';
sprintf( stdFile, "%s/khelpcenterXXXXXX", _PATH_TMP ); // temp file
mktemp( stdFile );
sprintf( errFile, "%s/khelpcenterXXXXXX", _PATH_TMP ); // temp file
mktemp( errFile );
sprintf( rmanCmd, "%s/rman -f HTML", locate( "exe", "rman" ).data() );
debug( "==> rmanCmd = %s", rmanCmd );
// create the system cmd to read the man page
if( ( ptr = strchr( tmpName, '(' ) ) )
{
int pos = 0;
if( !strchr( tmpName, ')' ) ) return 1; // check for closing )
*ptr = '\0';
ptr++;
for( int i = 0; i < numSections; i++ ) // read which section?
{
if( !strncmp( ptr, sections[ i ]->name(),
strlen( sections[ i ]->name() ) ) )
{
pos = i;
break;
}
}
/*
if( safeCommand( sections[ pos ]->name() ) &&
safeCommand( tmpName ) )
{
sprintf( sysCmd, "man %s %s < /dev/null 2> %s | %s > %s",
sections[ pos ]->name().data(),
tmpName.data(), errFile, rmanCmd, stdFile );
}
*/
}
/*
else if( safeCommand( tmpName ) )
{
sprintf(sysCmd, "man %s < /dev/null 2> %s | %s > %s",
tmpName.data(), errFile, rmanCmd, stdFile );
}
*/
if ( sysCmd[0] == '\0' )
{
//Error.Set(ERR_WARNING, i18n("\"man\" system call failed"));
return -1;
}
// call 'man' to read man page
int status = system(sysCmd);
if (status < 0) // system returns -ve on failure
{
//Error.Set(ERR_WARNING, i18n("\"man\" system call failed"));
return 1;
}
// open the man page and parse it
QFile file( stdFile );
if( file.open( IO_ReadOnly ) )
{
//Error.Set(ERR_FATAL, i18n("Opening temporary file failed"));
return 1;
}
// if this file is very short assume the man call failed
/*
stream.seekg( 0, ios::end );
if ( stream.tellg() < 5 )
{
stream.close();
stream.open( errFile );
}
stream.seekg( 0, ios::beg );
*/
QString temp;
QTextStream text( &file );
while ( !text.eof() )
{
temp = text.readLine();
if( temp.at( temp.length() - 1) == '-' )
temp.truncate( temp.length() - 1 );
else
temp.append(' ');
}
file.close();
// posString = name;
remove( stdFile ); // don't need tmp file anymore
remove( errFile ); // don't need tmp file anymore
}
m_page = "<html><body>Manchmal funktioniert was.</body></html>";
return 0;
}