/******************************************************************************
  sysInfo.c -- System information
  
  Author: Mark Baranowski
  Email:  requestXXX@els-software.org (remove XXX)
  Download: http://els-software.org

  Last significant change: October 27, 2004
  
  These functions are provided "as is" in the hopes that they might serve some
  higher purpose.  If you want these functions to serve some lower purpose,
  then that too is all right.  So as to keep these hopes alive you may
  freely distribute these functions so long as this header remains intact.
  You may also freely distribute modified versions of these functions so long
  as you indicate that such versions are modified and so long as you
  provide access to the unmodified original copy.
  
  Note: The most recent version of these functions may be obtained from
        http://els-software.org

  ****************************************************************************/

#include "sysdefs.h"

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>

#include "defs.h"
#include "auxil.h"
#include "sysInfo.h"

Ulong osVersion;


Ulong get_osVersion(void)
{
  Ulong release, revision, minor_rev;
  char *cp;
  struct utsname name;
  uname(&name);
  cp = name.release;
  /* Some OSes (e.g. HPUX) preface the release with letters: */
  while (*cp && !isDigit(*cp)) cp++;
  release = strtoul(cp, &cp, 10);
  if (*cp == '.') cp++;
  revision = strtoul(cp, &cp, 10);
  if (revision > 99) revision = 99;
  if (*cp == '.') cp++;
  minor_rev = strtoul(cp, &cp, 10);
  if (minor_rev > 99) minor_rev = 99;
  osVersion = release * 10000 + revision * 100 + minor_rev;
  return(osVersion);
}


void show_options(void)
{
  if (get_osVersion() > 0)
    printf("	Currently running OS version: %lu\n", osVersion);
#if defined(SUNOS)
  printf("	Compiled with SUNOS=%d\n", SUNOS);
#endif
#if defined(HPUX)
  printf("	Compiled with HPUX=%d\n", HPUX);
#endif
#if defined(LINUX)
  printf("	Compiled with LINUX=%d\n", LINUX);
#endif
#if defined(CYGWIN)
  printf("	Compiled with CYGWIN=%d\n", CYGWIN);
#endif
#if defined(FREEBSD)
  printf("	Compiled with FREEBSD=%d\n", FREEBSD);
#endif
#if defined(DARWIN)
  printf("	Compiled with DARWIN=%d\n", DARWIN);
#endif
#if defined(OSF1)
  printf("	Compiled with OSF1=%d\n", OSF1);
#endif
#if defined(AIX)
  printf("	Compiled with AIX=%d\n", AIX);
#endif
#if defined(IRIX)
  printf("	Compiled with IRIX=%d\n", IRIX);
#endif
#if defined(SCO)
  printf("	Compiled with SCO=%d\n", SCO);
#endif
#if defined(ULTRIX)
  printf("	Compiled with ULTRIX=%d\n", ULTRIX);
#endif
#if defined(DYNIX)
  printf("	Compiled with DYNIX=%d\n", DYNIX);
#endif
#if defined(SYSV_OLD)
  printf("	Compiled with SYSV_OLD=%d\n", SYSV_OLD);
#endif

#if defined(__GNUC__)
  printf("	Compiled with __GNUC__=%d\n", __GNUC__);
#else
  printf("	Compiled *without* __GNUC__\n");
#endif

#ifdef NO_ST_BLOCKS
  printf("	Compiled with NO_ST_BLOCKS\n");
#endif
#ifdef HAVE_TIMELOCAL
  printf("	Compiled with HAVE_TIMELOCAL\n");
#endif
#ifdef HAVE_TM_ZONE
  printf("	Compiled with HAVE_TM_ZONE\n");
#endif
#ifdef HAVE_ACL
  printf("	Compiled with HAVE_ACL\n");
#else
  printf("	Compiled *without* HAVE_ACL\n");
#endif
#ifdef HAVE_STAT64
  printf("	Compiled with HAVE_STAT64\n");
#else
  printf("	Compiled *without* HAVE_STAT64\n");
#endif

  return;
}
