/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* 61haes_r714 src/43haes/usr/sbin/cluster/clstat/clstat_main.c 1.7       */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1990,2006              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
static char sccsid[] = "@(#)44 1.7 src/43haes/usr/sbin/cluster/clstat/clstat_main.c, hacmp.clstat, 61haes_r714 3/8/06 09:43:19";

/*
 *   COMPONENT_NAME: CLSTAT
 *
 *   FUNCTIONS: main
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>

#if !defined(__HAES__) && !defined(__HACMP__) && !defined(__HANFS__)
#error Neither __HAES__, __HACMP__, nor __HANFS__ has been defined!
#endif

#if ((defined(__HAES__)+defined(__HACMP__)+defined(__HANFS__)) > 1)
#error Detected more than one of __HAES__, __HACMP__, or __HANFS__ defined!
#endif

int main(int argc, char *argv[])
{

  typedef int	(*intFunc)();

  intFunc	Xmain;
  char	xclstatPath[MAXPATHLEN];
  char	*arg0;
  int	i;
  char *progname;

  /* Get the program name that was executed.  If it was "clstat.cgi",
   * then we will run the CGI/HTML interface.
   */
  progname = (char *)rindex(argv[0], '/');
  if (progname != NULL)
    progname++;
  else
    progname = argv[0];

#ifndef __LINUX__
  if (strcmp(progname, "clstat.cgi") == 0)
    HTMLmain();
  else if((getenv("DISPLAY") == NULL) || 
          (strcmp( argv[1], "-a") == 0) ||
	  (strcmp( argv[1], "-o") == 0) )
#endif
    TTYmain(argc, argv);
#ifndef __LINUX__
  else
    {
    char *ptr;

    strcpy(xclstatPath, argv[0]);
    ptr = (char *)strrchr(xclstatPath, '/');
    if (ptr)
      {
      ptr++;
      *ptr = '\0';
      }
    else
      {
      xclstatPath[0] = '\0';
      }

    strcat(xclstatPath, "xclstat");
    if (access(xclstatPath, X_OK))
      {
      strcpy(xclstatPath, "/usr/es/sbin/cluster/xclstat");

      }

    arg0 = argv[0];
    argv[0] = xclstatPath;

    if (Xmain = (intFunc)(load(xclstatPath, 1, NULL)))
        Xmain(argc, argv);
    else
        {
        argv[0] = arg0;
        TTYmain(argc, argv);
        }
    }
#endif
}
