2000-02-25 10:15:17 +00:00
|
|
|
// This may look like C code, but it is really -*- C++ -*-
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// The Goldware Library
|
|
|
|
// Copyright (C) 1990-1999 Odinn Sorensen
|
|
|
|
// Copyright (C) 1999-2000 Alexander S. Aganichev
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library 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
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// $Id$
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Get operating system version.
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <gstrall.h>
|
|
|
|
#include <gutlmisc.h>
|
|
|
|
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
#include <windows.h>
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-29 21:51:19 +00:00
|
|
|
#if defined(__BEOS__)
|
|
|
|
#include <File.h>
|
|
|
|
#include <AppFileInfo.h>
|
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-10-05 21:58:34 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define _MAX_VNAME_LEN 13
|
|
|
|
#define _MAX_MNAME_LEN 30
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct gcpu_info
|
|
|
|
{
|
2005-10-07 12:11:50 +00:00
|
|
|
char v_name[_MAX_VNAME_LEN+1]; // vendor name
|
|
|
|
char m_name[_MAX_MNAME_LEN+1]; // model name
|
2005-10-05 21:58:34 +00:00
|
|
|
int family;
|
|
|
|
int model;
|
|
|
|
int stepping;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
static bool HaveCPUID()
|
|
|
|
{
|
|
|
|
// TO_PORT_TAG: CPUID
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
xor eax, eax
|
|
|
|
cpuid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-10-09 21:09:37 +00:00
|
|
|
|
2005-10-05 21:58:34 +00:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void cpuname(int family, int model, const char *v_name, char *m_name)
|
|
|
|
{
|
|
|
|
if (!strcmp("AuthenticAMD", v_name))
|
|
|
|
{
|
|
|
|
switch (family)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
strcpy(m_name, "AMD_486");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
strcpy(m_name, "AMD_K5");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
strcpy(m_name, "AMD_K6");
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
strcpy(m_name, "AMD_K6-2");
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
case 12:
|
|
|
|
case 13:
|
|
|
|
case 14:
|
|
|
|
case 15:
|
|
|
|
strcpy(m_name, "AMD_K6-3");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "AMD_F%dM%d", family, model);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
strcpy(m_name, "AMD_K7");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
strcpy(m_name, "AMD_K8");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "AMD_F%dM%d", family, model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp("GenuineIntel", v_name))
|
|
|
|
{
|
|
|
|
switch (family)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
strcpy(m_name, "i486DX");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcpy(m_name, "i486SX");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcpy(m_name, "i486DX2");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
strcpy(m_name, "i486SL");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
strcpy(m_name, "i486SX2");
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
strcpy(m_name, "i486DX2E");
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
strcpy(m_name, "i486DX4");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "iF%dM%d", family, model);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
strcpy(m_name, "iPentium");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
strcpy(m_name, "iP-MMX");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "iF%dM%d", family, model);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
strcpy(m_name, "iP-Pro");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
strcpy(m_name, "iP-II");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
strcpy(m_name, "iCeleron");
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
case 11:
|
|
|
|
strcpy(m_name, "iP-III");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "iF%dM%d", family, model);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
strcpy(m_name, "iP-4");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sprintf(m_name, "iF%dM%d", family, model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp("CyrixInstead", v_name))
|
|
|
|
sprintf(m_name, "CyrF%dM%d", family, model);
|
|
|
|
else if (!strcmp("CentaurHauls", v_name))
|
|
|
|
sprintf(m_name, "CenF%dM%d", family, model);
|
|
|
|
else
|
|
|
|
sprintf(m_name, "%3sF%dM%d", v_name, family, model);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void gcpuid(gcpu_info *pinfo)
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
char buff[_MAX_VNAME_LEN];
|
|
|
|
struct
|
|
|
|
{
|
2005-10-10 23:21:42 +00:00
|
|
|
dword dw0;
|
|
|
|
dword dw1;
|
|
|
|
dword dw2;
|
2005-10-07 12:11:09 +00:00
|
|
|
} dw;
|
2005-10-05 21:58:34 +00:00
|
|
|
} vendor;
|
|
|
|
|
2005-10-10 23:21:42 +00:00
|
|
|
dword standard = 0;
|
2005-10-05 21:58:34 +00:00
|
|
|
vendor.buff[_MAX_VNAME_LEN-1] = 0;
|
|
|
|
|
|
|
|
// TO_PORT_TAG: CPUID
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
// get the vendor string
|
|
|
|
xor eax, eax
|
|
|
|
cpuid
|
2005-10-09 21:09:37 +00:00
|
|
|
mov vendor.dw.dw0, ebx
|
|
|
|
mov vendor.dw.dw1, edx
|
|
|
|
mov vendor.dw.dw2, ecx
|
2005-10-05 21:58:34 +00:00
|
|
|
|
|
|
|
// get the standard bits
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov standard, eax
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
strcpy(vendor.buff, "UNKNOUN_CPU!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pinfo->family = (standard >> 8) & 0xF; // retriving family
|
|
|
|
pinfo->model = (standard >> 4) & 0xF; // retriving model
|
|
|
|
pinfo->stepping = standard & 0xF; // retriving stepping
|
|
|
|
|
|
|
|
strncpy(pinfo->v_name, vendor.buff, _MAX_VNAME_LEN);
|
|
|
|
cpuname(pinfo->family, pinfo->model, pinfo->v_name, pinfo->m_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 10:15:17 +00:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
char* ggetosstring(void) {
|
|
|
|
|
|
|
|
static char osstring[256] = "";
|
|
|
|
|
|
|
|
if(*osstring == NUL) {
|
|
|
|
|
2001-04-15 19:24:44 +00:00
|
|
|
#if defined(__UNIX__) || defined(__DJGPP__) || defined(__EMX__)
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
struct utsname info;
|
|
|
|
|
2003-04-03 14:20:58 +00:00
|
|
|
if(uname(&info) != -1) {
|
2000-02-25 10:15:17 +00:00
|
|
|
#if defined(__EMX__)
|
|
|
|
sprintf(osstring, "%s %s.%s %s", info.sysname, info.version, info.release, info.machine);
|
|
|
|
#elif defined(__DJGPP__)
|
|
|
|
sprintf(osstring, "%s %s.%s %s", info.sysname, info.release, info.version, info.machine);
|
2003-03-29 21:51:19 +00:00
|
|
|
#elif defined(__BEOS__)
|
2003-04-03 14:20:58 +00:00
|
|
|
BAppFileInfo appFileInfo;
|
|
|
|
version_info sys_ver = {0};
|
2005-10-09 21:09:37 +00:00
|
|
|
BFile file("/boot/beos/system/lib/libbe.so", B_READ_ONLY);
|
2003-04-03 14:20:58 +00:00
|
|
|
appFileInfo.SetTo(&file);
|
|
|
|
appFileInfo.GetVersionInfo(&sys_ver, B_APP_VERSION_KIND);
|
|
|
|
sprintf(osstring, "%s %s %s", info.sysname, sys_ver.short_info, info.machine);
|
|
|
|
#else
|
2000-02-25 10:15:17 +00:00
|
|
|
sprintf(osstring, "%s %s %s", info.sysname, info.release, info.machine);
|
|
|
|
#endif
|
2003-04-03 14:20:58 +00:00
|
|
|
}
|
2000-02-25 10:15:17 +00:00
|
|
|
else
|
|
|
|
strcpy(osstring, "unknown");
|
|
|
|
|
|
|
|
#elif defined (__WIN32__)
|
|
|
|
|
|
|
|
OSVERSIONINFO info;
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
char ostype[16];
|
2005-10-05 21:58:34 +00:00
|
|
|
char processor[_MAX_MNAME_LEN];
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
GetSystemInfo(&si);
|
|
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
if(GetVersionEx(&info)) {
|
|
|
|
switch(info.dwPlatformId) {
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
|
|
|
strcpy(ostype, "WinNT");
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
|
|
strcpy(ostype, "Win9x");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(ostype, "Win32s");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(*((WORD*)&si)) {
|
|
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
|
|
|
{
|
2005-10-05 21:58:34 +00:00
|
|
|
if (HaveCPUID())
|
|
|
|
{
|
|
|
|
gcpu_info pinfo;
|
|
|
|
gcpuid(&pinfo);
|
|
|
|
strcpy(processor, pinfo.m_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
if(info.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
|
|
|
cpu = si.wProcessorLevel;
|
|
|
|
else {
|
|
|
|
switch(si.dwProcessorType) {
|
2000-02-25 10:15:17 +00:00
|
|
|
case PROCESSOR_INTEL_386:
|
|
|
|
cpu = 3;
|
|
|
|
break;
|
|
|
|
case PROCESSOR_INTEL_486:
|
|
|
|
cpu = 4;
|
|
|
|
break;
|
2005-10-07 12:37:19 +00:00
|
|
|
case PROCESSOR_INTEL_PENTIUM:
|
2000-02-25 10:15:17 +00:00
|
|
|
cpu = 5;
|
2005-10-09 21:09:37 +00:00
|
|
|
case 15: /* Pentium 4 */
|
|
|
|
cpu = 7;
|
2005-10-07 12:37:19 +00:00
|
|
|
default:
|
|
|
|
cpu = 6;
|
2000-02-25 10:15:17 +00:00
|
|
|
break;
|
2005-10-05 21:58:34 +00:00
|
|
|
}
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
2005-10-07 12:37:19 +00:00
|
|
|
switch(cpu) {
|
|
|
|
case 15:
|
|
|
|
sprintf(processor, "i786");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if( cpu>9 ) cpu= cpu%10+int(cpu/10)+1;
|
|
|
|
sprintf(processor, "i%d86", cpu);
|
|
|
|
}
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-10-09 21:09:37 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_IA64:
|
|
|
|
sprintf(processor, "IA64-%d", si.wProcessorLevel);
|
|
|
|
break;
|
2000-02-25 10:15:17 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_MIPS:
|
|
|
|
sprintf(processor, "mips%d000", si.wProcessorLevel);
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_ALPHA:
|
|
|
|
sprintf(processor, "alpha%d", si.wProcessorLevel);
|
|
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_PPC:
|
|
|
|
switch(si.wProcessorLevel) {
|
|
|
|
case 1:
|
|
|
|
strcpy(processor, "ppc601");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcpy(processor, "ppc603");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
strcpy(processor, "ppc604");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
strcpy(processor, "ppc603+");
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
strcpy(processor, "ppc604+");
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
strcpy(processor, "ppc620");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(processor, "ppcXXX");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(processor, "unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
|
|
|
|
info.dwBuildNumber = info.dwBuildNumber & 0x0000ffffl;
|
|
|
|
if(info.dwPlatformId == VER_PLATFORM_WIN32_NT and *info.szCSDVersion != NUL) {
|
|
|
|
char _tmp[128];
|
|
|
|
strcpy(_tmp, info.szCSDVersion);
|
|
|
|
strchg(_tmp, ' ', '_');
|
|
|
|
sprintf(osstring, "%s %ld.%ld.%ld-%s %s", ostype, info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, _tmp, processor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sprintf(osstring, "%s %ld.%ld.%ld %s", ostype,info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, processor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(osstring, "unknown");
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#if defined(__MSDOS__)
|
|
|
|
const char* osname = "DOS";
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
const char* osname = "OS/2";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sprintf(osstring, "%s %d.%02d ix86", osname, _osmajor, _osminor);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return osstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|