File viewhtml.c of Package arachne

/*
viewhtml.c
Author: Hayden Walles
Date: 5 October 2007
Cross-platform support for starting up a web browser.
*/

/*
    Copyright (C) 2007 Hayden Walles

    This file is part of Arachne.

    Arachne is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Arachne is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*There may be a better way to do this.*/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

static const char *Browsers[]={
  "viewhtml",
  "firefox",
  "mozilla",
  "konqueror",
  "opera"
};



int viewHtml(char *link){
  pid_t pid;
  char *bvar;
  int i;

  pid=fork();
  if(pid<0){
    return 0;
  }
  else if(pid==0){
    /*Try to exec each web browser until we run out.*/
    bvar=getenv("BROWSER");
    if(bvar!=NULL)
      execlp(bvar,bvar,link,NULL);
    
    i=0;
    while(Browsers[i]){
      execlp(Browsers[i],Browsers[i],link,NULL);
      i++;
    }

    _exit(1);
    
  }

  return 1;
    
}
openSUSE Build Service is sponsored by