/* Applied generic patch for reporting consistency Viewperf 3.0. */
/* Scott Brickner   Mar. 10, 1995                                */
/* Fixed a bug in preprocessor symbol for GLU in GetEnvironment()*/
/* Rob Putney       Mar. 16, 1995                                */
#ifdef OS2
#define INCL_DOSMISC
#define INCL_DOSDEVIOCTL
#include <os2.h>
#ifndef QSV_NUMPROCESSORS /* should have been in bsedos.h, but isn't for some reason */
#define QSV_NUMPROCESSORS 26
#endif
#endif
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#ifndef OS2
#include <errno.h>
#include <sys/utsname.h>
#endif
#include <math.h>

#ifdef OS2
#include <GL/pgl.h>
#endif

#include "Env.h"
#include <malloc.h>
#include "aux.h"

static char *GetShortVendorName(char *input);
static int GetHostMemorySize(void);
static char *GetHostVendor(void);
static char *GetHostModel(void);
static char *GetHostCPU(void);
static char *GetHostOperatingSystem(void);
static char *GetHostOperatingSystemRelease(void);
static char *GetHostName(void);
static char *GetOpenGLClientVendor(void);
static char *GetOpenGLClientVersion(void);
static char *GetOpenGLClientExtensions(void);
static char *GetHostCPUCount(void);
static char *GetHostPrimaryCacheSize(void);
static char *GetHostSecondaryCacheSize(void);
static char *GetWindowSystem(void);
static char *GetDriverVersion(void);

#if defined(OS2)
static int GetOpenGLBufferConfig(HAB hab, PVISUALCONFIG visInfo,
                                 EnvironmentInfo *info);
static int GetOS2EnvironInfo(EnvironmentInfo *info);
struct _OEMMACHINFO {
  UCHAR mfg[ 20];
  UCHAR model[ 10];
  UCHAR ROMrev[ 10];
};
#endif


/******************************************************************************
 * 
 * StringSearch - search for pattern in string
 *  
 * Description:
 *  StringSearch returns a pointer to the first occurance of pattern found in
 *  the subject or NULL if the pattern is not found. It implements the
 *  Knuth-Morris-Pratt pattern matching algorithm. If m is the length of the
 *  pattern and n is the length of the subject, the complexity of the KMP
 *  algorithm is (m+n), much better than the (m*n) complexity of the naive
 *  nested loop algorithm. - John Dennis
 *  
 * Returns:
 *  pointer to the first occurance of pattern found the subject or NULL
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  None
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Thu Aug  4 15:49:59 1994
 *    Initial Release
 *
 *****************************************************************************/
char *
StringSearch(char *subject, char *pattern)
{
#define MAX_FLINK (256)
  int *flink, *dynamicFlink = NULL, staticFlink[MAX_FLINK];
  int patternLen = strlen(pattern);
  int subjectLen = strlen(subject);
  int found = 0;
  int i,j;

  if (patternLen > MAX_FLINK) {      /* -1 for NULL terminator */
    dynamicFlink = malloc(patternLen * sizeof(int));
    if (dynamicFlink == NULL) {
      fprintf(stderr, "malloc failure, line %d, file: %s, exiting...\n",
	      __LINE__, __FILE__);
      exit(1);
    }
    flink = dynamicFlink;
  }
  else {
    flink = staticFlink;
  }


  /* Step 1: Constuct Flowchart */
  flink[0] = -1;		       /* -1 == read next char */
  for(i = 1; i < patternLen; i++) {
    j = flink[i-1];
    while((j >= 0) && (pattern[j] != pattern[i-1])) {
      j = flink[j];
    }
    flink[i] = j+1;
  }

  /* Step 2: Scan Algorithm */
  for (i = j = 0; i < subjectLen; i++, j++) {
    while((j >= 0) && (pattern[j] != subject[i])) {
      j = flink[j];
    }
    if (j == patternLen-1) {
      found = 1;
      goto exit;
    }
  }

 exit:
  if (dynamicFlink != NULL) free(dynamicFlink);
  if (!found)
    return(NULL);
  else
    return(&subject[i-patternLen+1]);
#undef MAX_FLINK
}


/******************************************************************************
 *
 * GetShortVendorName - return short vendor string
 *  
 * Description:
 *  some vendor strings are verbose. This function will return a shortest
 *  vendor name it can given an arbitrary vendor string. The returned string
 *  is allocated with malloc, it should be freed when no longer in use. The
 *  input string is not freed or modified by this function.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetShortVendorName(char *input)
{
  int i;
  char *s1 = NULL;              /* s1 is temp work string */
  char *s2 = NULL;              /* s2 is string to return */

  /* duplicate input string so that we can modify it */
  s1 = strdup(input);
  /* upcase string */
  for (i = 0; s1[i]; i++)
    if (islower(s1[i])) s1[i] = toupper(s1[i]);

  /* return a short name if possible, some vendor names are verbose */
  if (StringSearch(s1, "DEC") ||
      StringSearch(s1, "DECWINDOWS") ||
      StringSearch(s1, "Digital Equipment Corporation") ||
      StringSearch(s1, "DigitalEquipmentCorporation"))
    s2 = strdup("DEC");
  else if (StringSearch(s1, "SGI") ||
	   StringSearch(s1, "SILCON GRAPHICS"))
    s2 = strdup("SGI");
  else if (StringSearch(s1, "IBM") ||
	   StringSearch(s1, "INTERNATIONAL BUSINESS MACHINES"))
    s2 = strdup("IBM");
  else
    s2 = strdup(s1);

  free(s1);
  return(s2);
}


/******************************************************************************
 *
 * GetHostMemorySize - Return kilobytes of memory installed on host platform
 *  
 * Description:
 *  Returns the number of kilobytes of memory installed on host platform
 *  
 * Returns:
 *  kilobytes of host platform memory
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  return 0 if unable to determine memory configuration
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Thu Aug  4 15:55:19 1994
 *    Initial Release
 *
 *****************************************************************************/
static int
GetHostMemorySize(void)
{
#if defined(__osf__)

#ifndef	GSI_PHYSMEM
#define	GSI_PHYSMEM	19	/* Amount of physical memory in KB */
#endif

  int start = 0;
  int mem = 0;
  int status;

  status = getsysinfo(GSI_PHYSMEM, &mem, sizeof(mem), &start, 0);
  if (status != 1) {
    fprintf(stderr, "Cannot read physical memory amount\n");
    return 0;
  }
  return(mem);

#elif defined(OS2)

  long mem = 0;

  DosQuerySysInfo( QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, &mem, sizeof mem);
#define HIDDEN_MEM ( 512 * 1024)
  return ( mem + 512 * 1024) / 1024;

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return 0 */
  return(0);
#endif
}


/******************************************************************************
 *
 * GetHostVendor - return string naming the system vendor
 *  
 * Description:
 *  return the name of the system vendor as a string. This is to identify
 *  manufacturer of the system. The string is allocated with malloc, it should
 *  be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostVendor(void)
{
#if defined(__osf__)
  return(strdup("DEC"));
#elif defined(OS2)

  struct _OEMMACHINFO mi;
  ULONG szmi;
ULONG rc;

  szmi = sizeof mi;
  if ( rc = DosDevIOCtl( 0, IOCTL_OEMHLP, OEMHLP_GETMACHINEINFO, 0, 0, 0,
	  &mi, szmi, &szmi))
    return strdup( "unknown");
  else
    return strdup( isalnum( mi.mfg[ 0]) ? mi.mfg : "unknown");

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetHostModel - return string naming the host model
 *  
 * Description:
 * return string identifying the host platform's model designation. The string
 * is allocated with malloc, it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostModel(void)
{
#if defined(__osf__)
/*
 * There is no system entry point that returns the name of the processor. The
 * sizer program can be run with the -c argument and it will print the model
 * and then we parse the output of sizer.
 */
  
#define MAXCMD (1024)
  FILE *inputPipe;
  int status;
  char sizerBuf[MAXCMD];
  char cmd[] = "/usr/sbin/sizer -c";
  char *modelBegin,*modelEnd;

  inputPipe= popen(cmd, "r");
  if (inputPipe == NULL) {
    fprintf(stderr, "could not open pipe for %s\n", cmd);
    return(strdup("unknown"));
  }

  fgets(sizerBuf, MAXCMD, inputPipe);
  status = pclose(inputPipe);
  if (status != 0) {
    fprintf(stderr, "cmd \"%s\" returned error %d\n", cmd, status);
    return(strdup("unknown"));
  }
  for(modelBegin = sizerBuf; *modelBegin && *modelBegin != '"'; modelBegin++);
  modelBegin++;
  for (modelEnd = modelBegin; *modelEnd && *modelEnd != '"'; modelEnd++);
  *modelEnd = 0;

  return(strdup(modelBegin));
#undef MAXCMD
#elif defined(OS2)

  struct _OEMMACHINFO mi;
  ULONG szmi;

  szmi = sizeof mi;
  if ( DosDevIOCtl( 0, IOCTL_OEMHLP, OEMHLP_GETMACHINEINFO, 0, 0, 0,
	  &mi, szmi, &szmi))
    return strdup( "unknown");
  else
    return strdup( isalnum( mi.model[ 0]) ? mi.model : "unknown");

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetHostCPU - return string naming the host CPU
 *  
 * Description:
 * return string identifying the host platform's CPU. The string
 * is allocated with malloc, it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/

static char *
GetHostCPU(void)
{
#if defined(__osf__)
/*
 * For pre OSF V3.2 systems there is no system entry point that returns the
 * name of the processor.  Post OSF V3.2 adds in the GSI_PROC_TYPE argument to
 * getsysinfo which will return the major and minor id numbers for the CPU.
 */
  
/* GSI_PROC_TYPE not defined before V3.2 BL1 */
#ifndef GSI_PROC_TYPE
#define GSI_PROC_TYPE 60
#endif

#ifndef PTYPE_MAJOR_MASK
#define PTYPE_MAJOR_MASK        0x00000000ffffffffL
#endif

#ifndef PTYPE_MINOR_SHIFT
#define PTYPE_MINOR_SHIFT       0x20
#endif

/* GSI_PROC_TYPE not defined before V3.2 BL1 */
#ifndef GSI_PROC_TYPE
#define GSI_PROC_TYPE 60
#endif

#ifndef PTYPE_MAJOR_MASK
#define PTYPE_MAJOR_MASK        0x00000000ffffffffL
#endif

#ifndef PTYPE_MINOR_SHIFT
#define PTYPE_MINOR_SHIFT       0x20
#endif

#define MAXCMD (1024)
  char procBuf[MAXCMD];
  unsigned long type, major, minor;
  int err;

  procBuf[0] = 0;
  type = 0;
  err = getsysinfo(GSI_PROC_TYPE, &type, sizeof(type), 0);
  /* should'nt check error, because call not on pre-V3.2 versions */
  if (err > 0) {
    major = type & PTYPE_MAJOR_MASK;
    minor = type >> PTYPE_MINOR_SHIFT;
    switch(major) {
    case 1:
      sprintf(&procBuf[strlen(procBuf)], "EV3");
      break;
    case 2:
      sprintf(&procBuf[strlen(procBuf)], "EV4 ");
      switch(minor) {
      case 0:
        sprintf(&procBuf[strlen(procBuf)], "Pass 2 or 2.1");
        break;
      case 1:
        sprintf(&procBuf[strlen(procBuf)], "Pass 3 (21064/150) or EV4s (21064/190)");
        break;
      default:
        sprintf(&procBuf[strlen(procBuf)], "minor processor type = %d unknown", minor);
        break;
      }
      break;
    case 3:
      sprintf(&procBuf[strlen(procBuf)], "Simulation");
      break;
    case 4:
      sprintf(&procBuf[strlen(procBuf)], "LCA Family ");
      switch(minor) {
      case 1:
        sprintf(&procBuf[strlen(procBuf)], "Pass 1 or 1.1 (21066)");
        break;
      case 2:
        sprintf(&procBuf[strlen(procBuf)], "Pass 2 (21066)");
        break;
      case 3:
        sprintf(&procBuf[strlen(procBuf)], "Pass 1 or 1.1 (21068)");
        break;
      case 4:
        sprintf(&procBuf[strlen(procBuf)], "Pass 2 (21068)");
        break;
      default:
        sprintf(&procBuf[strlen(procBuf)], "minor processor type = %d unknown", minor);
        break;
      }
      break;
    case 5:
      sprintf(&procBuf[strlen(procBuf)], "EV5 (21164)");
      break;
    case 6:
      sprintf(&procBuf[strlen(procBuf)], "EV45 (21064/xxx) ");
      switch(minor) {
      case 1:
        sprintf(&procBuf[strlen(procBuf)], "Pass 1");
        break;
      case 2:
        sprintf(&procBuf[strlen(procBuf)], "Pass 1.1");
        break;
      case 3:
        sprintf(&procBuf[strlen(procBuf)], "Pass 2");
        break;
      default:
        sprintf(&procBuf[strlen(procBuf)], "minor processor type = %d unknown", minor);
        break;
      }
      break;
    default:
      sprintf(&procBuf[strlen(procBuf)], "major processor type = %d unknown", major);
      break;
    }
  }
  else {
#ifndef OS2
    if (errno == EINVAL) {
      /* invalid argument - probably not supported in this OS release */
      sprintf(procBuf, "unknown");
    }
    else {
      sprintf(procBuf, "unable to determine processor type, getsysinfo: %s",
              strerror(errno));
    }
#endif
    
  }
  return(strdup(procBuf));
#undef MAXCMD
#elif defined(OS2)

  /*
   * Since there isn't a system call to determine the CPU type,
   * this code will try to get it from the environment variable "HOSTCPU"
   */
  PSZ p;
  if ( DosScanEnv( "HOSTCPU", &p))
    return strdup( "unknown");
  else
    return strdup( p);

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetHostCPUCount - return string indicating number of host CPU's
 *
 * Description:
 * return string indicating number of host CPU's. The string "unknown" is
 * returned if the count is not determinable. The string is allocated with
 * malloc, it should be freed when no longer in use.
 *
 * Returns:
 *  pointer to allocated string
 *
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Feb 27 14:18:41 EST 1995
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostCPUCount(void)
{
#if defined(__osf__)
  return(strdup("unknown"));
#elif defined(OS2)

  ULONG cnt = 0;
  char buf[ 16] = "unknown";

  if ( DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &cnt, sizeof cnt))
    return strdup( "unknown");
  else
  {
    sprintf( buf, "%d", cnt);
    return strdup( cnt ? buf : "unknown");
  }

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}

/******************************************************************************
 *
 * GetHostPrimaryCacheSize - return string indicating host's primary cache (KB)
 *
 * Description:
 * return string indicating the number of kilobytes of primary cache on the
 * host's CPU, or "unknown" if not determinable. The string
 * is allocated with malloc, it should be freed when no longer in use.
 *
 * Returns:
 *  pointer to allocated string
 *
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Feb 27 14:18:41 EST 1995
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostPrimaryCacheSize(void)
{
#if defined(__osf__)
  return(strdup("unknown"));
#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}

/******************************************************************************
 *
 * GetHostSecondaryCacheSize - return string indicating host's secondary cache (KB)
 *
 * Description:
 * return string indicating the number of kilobytes of secondary cache on the
 * host's CPU, or "unknown" if not determinable. The string
 * is allocated with malloc, it should be freed when no longer in use.
 *
 * Returns:
 *  pointer to allocated string
 *
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Feb 27 14:18:41 EST 1995
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostSecondaryCacheSize(void)
{
#if defined(__osf__)
  return(strdup("unknown"));
#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}

/******************************************************************************
 *
 * GetWindowSystem - return string naming the windowing system
 *
 * Description:
 * return string identifying the windowing system in use on the target
 * device. The string is allocated with malloc, it should be freed when no
 * longer in use.
 *
 * Returns:
 *  pointer to allocated string
 *
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetWindowSystem(void)
{
  char buf[128];
#if defined(XWINDOWS)
  sprintf(buf, "X Window System V%d", X_PROTOCOL);
  return(strdup(buf));
#elif defined(WIN32)
  return(strdup("Win32"));
#else
  return(strdup("unknown"));
#endif
}

/******************************************************************************
 *
 * GetDriverVersion - return string identifying the graphics driver
 *
 * Description:
 * Return string identifying the graphics driver version. If there is no
 * graphics driver than the string "NA" is returned. If a graphics driver
 * exists, but the function cannot identify it then the string "unknown" is
 * returned.  The string is allocated with malloc, it should be freed when no
 * longer in use.
 *
 * Returns:
 *  pointer to allocated string
 *
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Feb 27 15:00:18 EST 1995
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetDriverVersion(void)
{
#if defined(__osf__)
  return(strdup("unknown"));
#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}

/******************************************************************************
 *
 * GetHostOperatingSystem - return string naming the host CPU operating system
 *  
 * Description:
 *  return the type of the host operating system as a string. This is to
 *  identify what type of operating system this program is running under. The
 *  string is allocated with malloc, it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostOperatingSystem(void)
{
#if defined(__osf__)
  struct utsname uName;
  int status;

  status = uname(&uName);
  if (status < 0) {
    return(strdup("unknown"));
  }
  else {
    return(strdup(uName.sysname));
  }
#elif defined(OS2)
  return strdup( "OS/2");
#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetHostOperatingSystemRelease - return string naming operating system release
 *  
 * Description:
 *  return the release/version of the host operating system as a string. This
 *  is to identify what version of the operating system this program is
 *  running under. The string is allocated with malloc, it should be freed
 *  when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostOperatingSystemRelease(void)
{
#if defined(__osf__)
  struct utsname uName;
  int status;
  int releaseLen, versionLen;
  char *s;

  status = uname(&uName);
  if (status < 0) {
    return(strdup("unknown"));
  }
  else {
    releaseLen = strlen(uName.release);
    versionLen = strlen(uName.version);
    /* 1 extra char for space, 1 extra char for null terminator */
    s = malloc(releaseLen + versionLen + 2);
    *s = 0;
    strcpy(s, uName.release);
    strcat(s, " ");
    strcat(s, uName.version);
    return(s);
  }
#elif defined(OS2)

  long sysinfo[ 3];
  DosQuerySysInfo( QSV_VERSION_MAJOR, QSV_VERSION_REVISION,
	  sysinfo, sizeof sysinfo);
  if ( sysinfo[ 0] == 20 && sysinfo[ 2] == 0)
  {
    switch ( sysinfo[ 1])
    {
     case 0:
      return strdup( "2.0");

     case 10:
      return strdup( "2.1");

     case 11:
      return strdup( "2.11");

     case 30:
      return strdup( "3.0");

     default:
      return strdup( "unknown");
    }
  }
  else
    return strdup( "unknown");

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetHostName - return string naming the host
 *  
 * Description:
 *  return the name of this host as a string. This is to identify which
 *  platform this program is running on. The string is allocated with malloc,
 *  it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetHostName(void)
{
#if defined(__osf__)
  struct utsname uName;
  int status;

  status = uname(&uName);
  if (status < 0) {
    return(strdup("unknown"));
  }
  else {
    return(strdup(uName.nodename));
  }

#elif defined(OS2)

  /*
   * OS/2 doesn't have a "hostname" concept without a network operating
   * system installed.  This code tries to get the hostname from the
   * environment variable "HOSTNAME", which happens to coincide with the
   * indicator that IBM TCP/IP for OS/2 uses.
   */
  PSZ p;
  if ( DosScanEnv( "HOSTNAME", &p))
    return strdup( "unknown");
  else
    return strdup( p);

#elif defined(some_other_os)
  /* Put your OS specfic code here */
#else
  /* no os specfic code, just return "unknown" */
  return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetDateTime - get the current month, day, year, hour, minute
 *  
 * Description:
 *  Get the current  day, month, year, hour, minute. Each is a pointer to an
 *  integer. If the pointer is NULL then no value is returned for that
 *  parameter, otherwise an assignment is made to the integer pointed to by
 *  the parameter.
 *
 *  month:  in the range [1-12] 1=January, 12=December
 *  day:    in the range [1-31]
 *  year:   as a 4 digit number, e.g. 1994
 *  hour:   in the range [0-23]
 *  min:    in the range [0-59]
 *  
 * Returns:
 *  0 for success, error code otherwise
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  return non-zero on failure
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Wed Aug 17 13:08:36 1994
 *    Initial Release
 *
 *****************************************************************************/

int
GetDateTime(int *month, int *day, int *year, int *hour, int *minute)
{
  time_t timeT;
  struct tm *timeTm;

  time(&timeT);
  timeTm = localtime(&timeT);
  if (timeTm == NULL) {
#ifndef OS2
    fprintf(stderr, "Error calling localtime: %d\n", errno);
    return(errno);
#endif
  }
  if (month)  *month  = timeTm->tm_mon + 1;
  if (day)    *day    = timeTm->tm_mday;
  if (year)   *year   = timeTm->tm_year + 1900;
  if (hour)   *hour   = timeTm->tm_hour;
  if (minute) *minute = timeTm->tm_min;
  return(0);
}


/******************************************************************************
 *
 * GetOpenGLClientVendor - return string naming the client library vendor
 *  
 * Description:
 *  return the name of the vendor supplying the OpenGL client library.  The
 *  string is allocated with malloc,it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetOpenGLClientVendor(void)
{
#if defined(XWINDOWS)
    Display *dpy;

    dpy = auxXDisplay();
#if defined(GLX_VERSION_1_1)
    return(GetShortVendorName((char *)glXQueryClientString(dpy, GLX_VENDOR)));
#else
    return(strdup("unknown"));
#endif
#elif defined(OS2)
    return(strdup("OS2"));
#else
    return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetOpenGLClientVersion - return string naming the client library version
 *  
 * Description:
 *  return the version of the OpenGL client library.  The string is allocated
 *  with malloc,it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *
 *****************************************************************************/
static char *
GetOpenGLClientVersion(void)
{
#if defined(XWINDOWS)
    Display *dpy;

    dpy = auxXDisplay();
#if defined(GLX_VERSION_1_1)
    return((char *)glXQueryClientString(dpy, GLX_VERSION));
#else
    return(strdup("1.0"));
#endif
#elif defined(OS2)
    return( strdup( glGetString( GL_VERSION)));
#elif defined(SOME_OTHER_WINDOW_SYSTEM)
    return(strdup("unknown"));
#else
    return(strdup("unknown"));
#endif
}


/******************************************************************************
 *
 * GetOpenGLClientExtensions - return string naming the client extensions
 *  
 * Description:
 *  return the extensions supported in the OpenGL client library.  The string
 *  is allocated with malloc,it should be freed when no longer in use.
 *  
 * Returns:
 *  pointer to allocated string
 *  
 * Side Effects:
 *  string allocation, string should be freed when no longer needed.
 *  
 * Errors:
 *  no errors, if function fails the string "unknown" is returned
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
 *    Initial Release
 *  Revision 1: Author: Rob Putney     Date: Fri Apr 21 09:32:00 1995
 *    Changed extension query to return None if string is NULL.
 *
 *****************************************************************************/
static char *
GetOpenGLClientExtensions(void)
{
#if defined(XWINDOWS)
    Display *dpy;

    dpy = auxXDisplay();
#if defined(GLX_VERSION_1_1)
    return((char *)glXQueryClientString(dpy, GLX_EXTENSIONS));
#else
    return(strdup("unknown"));
#endif
#elif defined(OS2)
    if(  glGetString( GL_EXTENSIONS) == NULL )
        return( "none" );
    else
        return( glGetString( GL_EXTENSIONS));
#elif defined(SOME_OTHER_WINDOW_SYSTEM)
    return(strdup("unknown"));
#else
    return(strdup("unknown"));
#endif
}



/******************************************************************************
 *
 * GetOpenGLBufferInfo - inquire the OpenGL buffer configuration
 *  
 * Description:
 *  Given a specfic rendering target and visual description, return the OpenGL
 *  buffer configuration. This information includes:
 *  
 * Returns:
 *  0 for success, error code otherwise
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  None
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Thu Aug 18 10:18:45 1994
 *    Initial Release
 *
 *****************************************************************************/

#if defined(OS2)
static int
GetOpenGLBufferConfig(HAB hab, PVISUALCONFIG  visInfo, EnvironmentInfo *info)
{
  BufferConfig *config = &info->bufConfig;
 
  config->doubleBuffer = visInfo->doubleBuffer;
  config->stereo = visInfo->stereo;
  config->rgba = visInfo->rgba;
  if (config->rgba) {
      config->redSize = visInfo->redSize;
      config->blueSize = visInfo->blueSize;
      config->greenSize = visInfo->greenSize;
      config->alphaSize = visInfo->alphaSize;

      config->accumRedSize = visInfo->accumRedSize;
      config->accumBlueSize = visInfo->accumBlueSize;
      config->accumGreenSize = visInfo->accumGreenSize;
      config->accumAlphaSize = visInfo->accumAlphaSize;
      config->indexSize = -1;
  } else {
    config->redSize = -1;
    config->greenSize = -1;
    config->blueSize = -1;
    config->alphaSize = -1;

    config->accumRedSize = -1;
    config->accumGreenSize = -1;
    config->accumBlueSize = -1;
    config->accumAlphaSize = -1;

    config->indexSize = visInfo->bufferSize;
  }
  config->depthSize = visInfo->depthSize;
  config->stencilSize = visInfo->stencilSize;
  config->auxBuffers = visInfo->auxBuffers;
  config->level = visInfo->level;


}
#elif defined(SOME_OTHER_WINDOW_SYSTEM)
#else
#error "unknown window system"
#endif


/******************************************************************************
 *
 * GetOS2EnvironInfo - Get all enironment info specfic to OS2
 *  
 * Description:
 *  
 *  
 * Returns:
 *  0 success, error code otherwise
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  errors with bad configurations
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Thu Aug 18 16:51:10 1994
 *    Initial Release
 *
 *****************************************************************************/

#if defined(OS2)
static int
GetOS2EnvironInfo(EnvironmentInfo *info)
{
  HAB hab ;
  HWND win;
  PVISUALCONFIG visualId;
  SWP winsize;
  int i, status;
  int screen;
  char buf[256];
  int glxMajorVersion, glxMinorVersion;
  

  /* Find the visualInfo given a visualId */
  hab = auxOS2HAB();
  win = auxOS2Window();
  visualId = auxGetCurrentConfig();
  if (visualId == NULL ) {
    fprintf(stderr, "Error calling XGetVisualInfo\n");
  }
  else {
    GetOpenGLBufferConfig(hab, visualId, info);
  }
  WinQueryWindowPos(win,&winsize);
  info->windowWidth = winsize.cx;
  info->windowHeight = winsize.cy;
  

  pglQueryVersion(hab, &glxMajorVersion, &glxMinorVersion);


  info->screenWidth = 0;
  info->screenHeight = 0;


  free((void *)visualId);
  return(0);
}
#elif defined(SOME_OTHER_WINDOW_SYSTEM)
#else
#error "unknown window system"
#endif



/******************************************************************************
 *
 * GetEnvironment - return info about environment test was run in
 *  
 * Description:
 *  This function fills in an environment info record with every pertinent
 *  piece of information about the condiditons under which the test was run.
 *  
 * Returns:
 *  0 success, error code otherwise
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  errors generally only with bad configurations, too many to list
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Thu Aug 18 16:52:35 1994
 *    Initial Release
 *
 *****************************************************************************/

int
GetEnvironment(EnvironmentInfo *info)
{
  GLenum windType;

  FreeEnvironmentData(info);

  GetDateTime(&info->month, &info->day, &info->year, NULL, NULL);
  info->host = GetHostName();
  info->hostOperatingSystem = GetHostOperatingSystem();
  info->hostOperatingSystemVersion = GetHostOperatingSystemRelease();
  info->hostVendor = GetHostVendor();
  info->hostModel = GetHostModel();
  info->hostCPU = GetHostCPU();
  info->hostCPUCount = GetHostCPUCount();
  info->hostMemorySize = GetHostMemorySize() / 1024; /* kilobytes to MB */
  info->glVendor = GetShortVendorName((char *)glGetString(GL_VENDOR));
  info->glVersion = strdup((char *)glGetString(GL_VERSION));
  info->glRenderer = strdup((char *)glGetString(GL_RENDERER));
  info->glExtensions = strdup((char *)glGetString(GL_EXTENSIONS));
  info->glClientVendor = GetOpenGLClientVendor();
  info->glClientVersion = GetOpenGLClientVersion();
  info->glClientExtensions = GetOpenGLClientExtensions();

#ifdef GLU_VERSION_1_1
  info->gluVersion = strdup((char *)gluGetString(GLU_VERSION));;
  info->gluExtensions = strdup((char *)gluGetString(GLU_EXTENSIONS));;
#else
  info->gluVersion = strdup("unknown");
  info->gluExtensions = strdup("unknown");
#endif

#if defined(XWINDOWS)
  GetXEnvironInfo(info);
#elif defined(OS2)
  GetOS2EnvironInfo(info);
#endif
  

  /*
   * Direct rendering is a "request", not a guarantee. We need to check the
   * direct render bit for each test because the GL context is only set up
   * in the above conditional block. If we didn't check it for each test
   * then the value for direct rendering store in the test descriptor would
   * be the "request" value, not the actual value.
   */

  windType = auxGetDisplayMode();
  if (windType & AUX_DIRECT)
    info->directRender = TRUE;
  else
    info->directRender = FALSE;
}



/******************************************************************************
 *
 * FreeEnvironmentData - frees all dynamic data in EnvironmentInfo struct
 *  
 * Description:
 *  Free all the dynamically allocated data in an EnvironmentInfo struct. Each
 *  pointer in the struct is assigned the value of NULL after its data has
 *  been freed. The struct itself is not freed.
 *  
 * Returns:
 *  void
 *  
 * Side Effects:
 *  free dynamically allocated memory
 *  
 * Errors:
 *  None
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Tue Sep 13 17:31:19 1994
 *    Initial Release
 *
 *****************************************************************************/

void
FreeEnvironmentData(EnvironmentInfo *info)
{
  if (info->host != NULL) free(info->host);
  if (info->hostOperatingSystem != NULL) free(info->hostOperatingSystem);
  if (info->hostOperatingSystemVersion != NULL) free(info->hostOperatingSystemVersion);
  if (info->hostVendor != NULL) free(info->hostVendor);
  if (info->hostModel != NULL) free(info->hostModel);
  if (info->hostCPU != NULL) free(info->hostCPU);
  if (info->hostCPUCount != NULL) free(info->hostCPUCount);
  if (info->hostPrimaryCacheSize != NULL) free(info->hostPrimaryCacheSize);
  if (info->hostSecondaryCacheSize != NULL) free(info->hostSecondaryCacheSize);
  if (info->windowSystem != NULL) free(info->windowSystem);
  if (info->driverVersion != NULL) free(info->driverVersion);
  if (info->glVendor != NULL) free(info->glVendor);
  if (info->glVersion != NULL) free(info->glVersion);
  if (info->glRenderer != NULL) free(info->glRenderer);
  if (info->glExtensions != NULL) free(info->glExtensions);
  if (info->glClientVendor != NULL) free(info->glClientVendor);
  if (info->glClientVersion != NULL) free(info->glClientVersion);
  if (info->glClientExtensions != NULL) free(info->glClientExtensions);
  if (info->gluVersion != NULL) free(info->gluVersion);
  if (info->gluExtensions != NULL) free(info->gluExtensions);
#if defined(XWINDOWS)
  if (info->display != NULL) free(info->display);
  if (info->glServerVendor != NULL) free(info->glServerVendor);
  if (info->glServerVersion != NULL) free(info->glServerVersion);
  if (info->glServerExtensions != NULL) free(info->glServerExtensions);
  if (info->glxVersion != NULL) free(info->glxVersion);
  if (info->glxExtensions != NULL) free(info->glxExtensions);
#endif
  NullEnvironmentData(info);
}


/******************************************************************************
 *
 * NullEnvironmentData - sets all dynamic data ptrs in EnvironmentInfo to NULL
 *  
 * Description:
 *  Sets all the pointers to dynamically allocated data in an EnvironmentInfo
 *  struct to NULL. The data pointed to by the pointers are not freed, use the
 *  function FreeEnvironmentData for that purpose.
 *  
 * Returns:
 *  void
 *  
 * Side Effects:
 *  None
 *  
 * Errors:
 *  None
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Tue Sep 13 17:31:19 1994
 *    Initial Release
 *
 *****************************************************************************/

void
NullEnvironmentData(EnvironmentInfo *info)
{
    info->host = NULL;
    info->hostOperatingSystem = NULL;
    info->hostOperatingSystemVersion = NULL;
    info->hostVendor = NULL;
    info->hostModel = NULL;
    info->hostCPU = NULL;
    info->hostCPUCount = NULL;
    info->hostPrimaryCacheSize = NULL;
    info->hostSecondaryCacheSize = NULL;
    info->windowSystem = NULL;
    info->driverVersion = NULL;
    info->glVendor = NULL;
    info->glVersion = NULL;
    info->glRenderer = NULL;
    info->glExtensions = NULL;
    info->glClientVendor = NULL;
    info->glClientVersion = NULL;
    info->glClientExtensions = NULL;
    info->gluVersion = NULL;
    info->gluExtensions = NULL;
#if defined(XWINDOWS)
    info->display = NULL;
    info->glServerVendor = NULL;
    info->glServerVersion = NULL;
    info->glServerExtensions = NULL;
    info->glxVersion = NULL;
    info->glxExtensions = NULL;
#endif
}



/******************************************************************************
 *
 * PrintEnvironment - print contents of EnvironmentInfo struct
 *  
 * Description:
 *  Print the contents of EnvironmentInfo struct. The stream parameter Points
 *  to a FILE structure specifying an open stream to which output will be
 *  written. The title parameter is a pointer to a string which will be output
 *  before any of the EnvironmentInfo data is output, The title string may be
 *  NULL in which case no title string will be written. The leader parameter
 *  is a pointer to a string which will be output before each field in the
 *  EnvironmentInfo struct. The nameWidth parameter is an integer parameter
 *  specifying how pad the name of each field. This can be used to cause the
 *  values to line up in a column. A positive value left justifies, a negative
 *  value right justifies. The suffix parameter is a pointer to a string which
 *  will be output after all of the EnvironmentInfo data is output, The suffix
 *  string may be NULL in which case no suffix string will be written.
 *  
 * Returns:
 *  void
 *  
 * Side Effects:
 *  file stream output
 *  
 * Errors:
 *  None
 *
 * Revision History:
 *  Revision 0: Author: John R. Dennis Date: Wed Sep 14 09:02:57 1994
 *    Initial Release
 *
 *****************************************************************************/

void
PrintEnvironment(FILE *stream, EnvironmentInfo *info, char *title,
                 char *leader, int nameWidth, char *suffix)
{
  if (title) fprintf(stream, "%s", title);

  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Month", info->month);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Day", info->day);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Year", info->year);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Host", info->host);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Operating System", info->hostOperatingSystem);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Operating System Version", info->hostOperatingSystemVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Host Vendor", info->hostVendor);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Host Model", info->hostModel);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Host CPU", info->hostCPU);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Host CPU Count", info->hostCPUCount);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Host Memory Size (MB)", info->hostMemorySize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Host Primary Cache Size (KB)", info->hostPrimaryCacheSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Host Secondary Cache Size (KB)", info->hostSecondaryCacheSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Driver Version", info->driverVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Vendor", info->glVendor);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Version", info->glVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Extensions", info->glExtensions);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Renderer", info->glRenderer);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Client Vendor", info->glClientVendor);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Client Version", info->glClientVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Client Extensions", info->glClientExtensions);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "GLU Version", info->gluVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "GLU Extensions", info->gluExtensions);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Direct Rendering", info->directRender ? "True" : "False");
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Double Buffer", info->bufConfig.doubleBuffer ? "True" : "False");
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Stereo", info->bufConfig.stereo ? "True" : "False");
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "RGBA", info->bufConfig.rgba ? "True" : "False");
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Color Index Size", info->bufConfig.indexSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Red Size", info->bufConfig.redSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Green Size", info->bufConfig.greenSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Blue Size", info->bufConfig.blueSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Alpha Size", info->bufConfig.alphaSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Accum Red Size", info->bufConfig.accumRedSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Accum Green Size", info->bufConfig.accumGreenSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Accum Blue Size", info->bufConfig.accumBlueSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Accum Alpha Size", info->bufConfig.accumAlphaSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Depth Size", info->bufConfig.depthSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Stencil Size", info->bufConfig.stencilSize);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Auxiliary Buffer Count", info->bufConfig.auxBuffers);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Frame BufferLevel", info->bufConfig.level);
#if defined(XWINDOWS)
  fprintf(stream, "%s%*s%#X\n", leader, nameWidth,
         "Visual ID", info->bufConfig.visualId);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Visual Class", 
         info->bufConfig.visualClass == StaticGray  ? "StaticGray"  :
         info->bufConfig.visualClass == GrayScale   ? "GrayScale"   :
         info->bufConfig.visualClass == StaticColor ? "StaticColor" :
         info->bufConfig.visualClass == PseudoColor ? "PseudoColor" :
         info->bufConfig.visualClass == TrueColor   ? "TrueColor"   :
         info->bufConfig.visualClass == DirectColor ? "DirectColor" :
         "unknown");
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Window Width (pixels)", info->windowWidth);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Window Height (pixels)", info->windowHeight);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Screen Width (pixels)", info->screenWidth);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Screen Height (pixels)", info->screenHeight);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Display", info->display);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Server Vendor", info->glServerVendor);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Server Version", info->glServerVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "OpenGL Server Extensions", info->glServerExtensions);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "GLX Server Version", info->glxVersion);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "GLX Server Extensions", info->glxExtensions);
  fprintf(stream, "%s%*s%d\n", leader, nameWidth,
         "Screen Number", info->screenNumber);
  fprintf(stream, "%s%*s%s\n", leader, nameWidth,
         "Shared Memory Connection",
         info->sharedMemConnection ? "True" : "False");
#endif
  if (suffix) fprintf(stream, "%s", suffix);
}

