|
发表于 2006-11-10 20:29:52
|
显示全部楼层
来自 hypersrc:
[code:1]
void
RunHelper(void)
{
if ( !devhelpExists )
{
PrintStatusbar(_("*** devhelp not found"));
return;
}
if ( IsAnyMajorFunctionBusy(TRUE))
{
return;
}
else
if ( IsTextWidgetEmpty() || !ActiveModule() )
{
PrintStatusbar(_("Text widget is empty."));
return;
}
gsize textLen = 0;
gchar *pText = ActiveTextWidgetContents(&textLen);
gint cursorIdx = OffsetAtCursor();
if( cursorIdx < 0 || cursorIdx > textLen )
return;
// howto detect 'devehlp' exist?
GString *wordAtCursor = ScoopWordAtCursor(MAX_WORD_LEN,
pText,
textLen,
cursorIdx);
if ( NULL == wordAtCursor )
return;
gchar* sysargs[20]; // may be enough
sysargs[0]="devhelp";
sysargs[1]="--search";
sysargs[2]=g_strdup(wordAtCursor->str);
sysargs[3]=NULL;
/*
*run the helper and search 'str'
*/
SysExec(sysargs[0], sysargs);
g_string_free(wordAtCursor, TRUE);
return;
}
/*****************************************************************************
* Execute a program (without waiting).
*****************************************************************************/
void
SysExec( char* pFilename,
char** ppExecArgs )
{
pid_t pid;
pid = fork();
if ( pid > 0 )
{
/*
* This is the parent process.
*/
return;
}
else if ( pid == 0 )
{
/*
* This is the child process.
*/
execvp( pFilename, ppExecArgs );
/*
* exec*() isn't supposed to return.
*/
Warning( "execvp('%s') failed.", pFilename );
perror( "" );
PrintStatusbarThirds( "Failed to invoke '", pFilename, "'." );
_exit(-1); /* instead of exit() -- see GTK+ FAQ for why */
}
else /* pid < 0 */
{
Warning( "fork() failed." );
perror("");
return;
}
}
[/code:1] |
|