1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "npfile.h"
#include "npstringarray.h"
#include "npgroup.h"
#include "npnode.h"
#include "nptree.h"
#include "npcollections.h"
void NP_Collections::fork_browser()
{
char buffer[ 1024 ];
NP_File config;
snprintf( buffer, sizeof buffer, "%s/.peruser4-config", getenv( "HOME" ));
if ( config.openr( buffer ))
{
config.print_error();
return;
}
char *browser = NULL;
int i = 3;
while( i-- )
{
if (( browser = config.get_string()) == NULL )
{
config.print_error();
config.close();
return;
}
}
if ( strtok( browser, "\n" ) == NULL )
return;
int running = 0;
if ( strstr( browser, "netscape" ) != NULL )
{
FILE *file;
if (( file = popen( "ps aux", "r" )) == NULL )
{
perror( "popen" );
return;
}
while( fgets( buffer, sizeof buffer, file ) != NULL )
if ( strstr( buffer, "netscape" ))
{
running = 1;
break;
}
pclose( file );
if ( running )
switch( fork() )
{
case -1:
perror( "fork" );
break;
case 0:
close( ConnectionNumber( gdk_display ));
execlp( browser, browser,
"-remote", "openURL(http://peruser.netpedia.net)",
"-raise", NULL );
perror( "execlp" );
_exit( 1 );
break;
default:
break;
}
else
switch( fork() )
{
case -1:
perror( "fork" );
break;
case 0:
close( ConnectionNumber( gdk_display ));
execlp( browser, browser, "http://peruser.netpedia.net", NULL );
perror( "execlp" );
_exit( 1 );
break;
}
}
config.close();
return;
}
|