| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // Generic TX get library and OS version information |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 24-07-2005 Initial version, split off from TXUTIL |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> |
|---|
| 40 | #include <txvers.h> // TXLIB version definitions |
|---|
| 41 | |
|---|
| 42 | #if defined (LINUX) |
|---|
| 43 | #include <sys/utsname.h> |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | static char txVersion[ TXMAXTM]; // static version string |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | #if defined (DOS32) |
|---|
| 50 | static TXTM exVersion; // DOS extender version info |
|---|
| 51 | #elif defined (WIN32) |
|---|
| 52 | #elif defined (LINUX) |
|---|
| 53 | //- to be refined |
|---|
| 54 | #else |
|---|
| 55 | #define TXKVL 32000 // length of kernel to search |
|---|
| 56 | #define TXKVS "Internal revision " |
|---|
| 57 | static TXTM kernelrev = ""; // OS/2 kernel revision |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | /*****************************************************************************/ |
|---|
| 62 | // Get operatingsystem version major*minor*micro and text (Win-9x major = 1) |
|---|
| 63 | /*****************************************************************************/ |
|---|
| 64 | ULONG TxOsVersion // RET number 000000..999999 |
|---|
| 65 | ( |
|---|
| 66 | char *descr // OUT OS description or NULL |
|---|
| 67 | ) |
|---|
| 68 | { |
|---|
| 69 | ULONG rc = 0; // function return |
|---|
| 70 | TXTM text; |
|---|
| 71 | #if defined(LINUX) |
|---|
| 72 | size_t at; |
|---|
| 73 | char *env; |
|---|
| 74 | struct utsname un; |
|---|
| 75 | #else |
|---|
| 76 | double mm; // major/minor double value |
|---|
| 77 | #endif |
|---|
| 78 | ULONG major = 0; // major version component |
|---|
| 79 | ULONG minor = 0; // minor version component |
|---|
| 80 | ULONG micro = 0; // micro version component |
|---|
| 81 | |
|---|
| 82 | ENTER(); |
|---|
| 83 | |
|---|
| 84 | #if defined (WIN32) |
|---|
| 85 | { |
|---|
| 86 | OSVERSIONINFO osv; |
|---|
| 87 | BOOL win9x = FALSE; |
|---|
| 88 | |
|---|
| 89 | osv.dwOSVersionInfoSize = sizeof( OSVERSIONINFO); |
|---|
| 90 | if (GetVersionEx( &osv)) |
|---|
| 91 | { |
|---|
| 92 | major = (ULONG) osv.dwMajorVersion; |
|---|
| 93 | minor = (ULONG) osv.dwMinorVersion; |
|---|
| 94 | |
|---|
| 95 | mm = (double) (major); |
|---|
| 96 | if (minor < 10) mm += (double) ((double) minor) / 10.0; |
|---|
| 97 | else if (minor < 100) mm += (double) ((double) minor) / 100.0; |
|---|
| 98 | else mm += (double) ((double) minor) / 1000.0; |
|---|
| 99 | |
|---|
| 100 | switch (osv.dwPlatformId) |
|---|
| 101 | { |
|---|
| 102 | case VER_PLATFORM_WIN32s: strcpy( text, "Win32s API"); break; |
|---|
| 103 | case VER_PLATFORM_WIN32_NT: strcpy( text, "Unknown-NT"); |
|---|
| 104 | switch (major) |
|---|
| 105 | { |
|---|
| 106 | case 3: |
|---|
| 107 | case 4: |
|---|
| 108 | strcpy( text, "Windows-NT"); |
|---|
| 109 | break; |
|---|
| 110 | |
|---|
| 111 | case 5: |
|---|
| 112 | switch (minor) |
|---|
| 113 | { |
|---|
| 114 | case 00: strcpy( text, "WinNT-2000"); break; |
|---|
| 115 | case 01: strcpy( text, "Windows-XP"); break; |
|---|
| 116 | case 02: strcpy( text, "WinNT-2003"); break; |
|---|
| 117 | } |
|---|
| 118 | break; |
|---|
| 119 | |
|---|
| 120 | case 6: |
|---|
| 121 | strcpy( text, "Win-Vista "); |
|---|
| 122 | break; |
|---|
| 123 | } |
|---|
| 124 | if (strlen(osv.szCSDVersion) == 0) |
|---|
| 125 | { |
|---|
| 126 | strcpy( osv.szCSDVersion, "No Service Pack"); |
|---|
| 127 | } |
|---|
| 128 | break; |
|---|
| 129 | |
|---|
| 130 | default: |
|---|
| 131 | strcpy( text, "Windows-9x"); |
|---|
| 132 | win9x = TRUE; |
|---|
| 133 | break; |
|---|
| 134 | } |
|---|
| 135 | if (descr) |
|---|
| 136 | { |
|---|
| 137 | sprintf( descr, "%s %4.2lf build %lu: %s", |
|---|
| 138 | text, mm, osv.dwBuildNumber, osv.szCSDVersion); |
|---|
| 139 | } |
|---|
| 140 | if (win9x) |
|---|
| 141 | { |
|---|
| 142 | major -= 3; // make Win9x different from NT |
|---|
| 143 | } // in the return value |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | #elif defined (DOS32) |
|---|
| 147 | { |
|---|
| 148 | union REGS regs; |
|---|
| 149 | |
|---|
| 150 | TxxClearReg( regs); |
|---|
| 151 | regs.h.al = 0x00; // include OEM info |
|---|
| 152 | TxxDosInt21( regs, TXDX_DOS_GETVERSION); |
|---|
| 153 | |
|---|
| 154 | major = (ULONG) regs.h.al; |
|---|
| 155 | minor = (ULONG) regs.h.ah; |
|---|
| 156 | |
|---|
| 157 | mm = (double) (major); |
|---|
| 158 | if (minor < 10) mm += (double) ((double) minor) / 10.0; |
|---|
| 159 | else if (minor < 100) mm += (double) ((double) minor) / 100.0; |
|---|
| 160 | else mm += (double) ((double) minor) / 1000.0; |
|---|
| 161 | |
|---|
| 162 | if (descr) |
|---|
| 163 | { |
|---|
| 164 | BOOL vm86 = (strstr( txDosExtDpmiInfo(), "VM86") != NULL); |
|---|
| 165 | BOOL mmgr = (strstr( txDosExtDpmiInfo(), ": NO") == NULL); |
|---|
| 166 | |
|---|
| 167 | if (major == 20) // major version, OS/2 dosbox |
|---|
| 168 | { |
|---|
| 169 | strcpy( text, "32bit OS/2"); |
|---|
| 170 | } |
|---|
| 171 | else |
|---|
| 172 | { |
|---|
| 173 | switch (regs.h.bh) // check OEM indicator |
|---|
| 174 | { |
|---|
| 175 | case 0xff: |
|---|
| 176 | if ((mm == 5.0) && (vm86) && (!mmgr)) |
|---|
| 177 | { |
|---|
| 178 | strcpy( text, "Windows-NT/2000/XP"); |
|---|
| 179 | } |
|---|
| 180 | else if (mm >= 8.0) |
|---|
| 181 | { |
|---|
| 182 | strcpy( text, "Microsoft Windows-ME"); |
|---|
| 183 | } |
|---|
| 184 | else if (mm >= 7.0) |
|---|
| 185 | { |
|---|
| 186 | strcpy( text, "Microsoft Windows-9x"); |
|---|
| 187 | } |
|---|
| 188 | else |
|---|
| 189 | { |
|---|
| 190 | strcpy( text, "Microsoft MS-DOS"); |
|---|
| 191 | } |
|---|
| 192 | break; |
|---|
| 193 | |
|---|
| 194 | case 0x00: strcpy( text, "IBM PC-DOS"); break; |
|---|
| 195 | case 0x01: strcpy( text, "Compaq-DOS"); break; |
|---|
| 196 | case 0xee: strcpy( text, "DR-DOS"); break; |
|---|
| 197 | case 0xef: strcpy( text, "Novell-DOS"); break; |
|---|
| 198 | case 0xfd: strcpy( text, "FreeDOS"); break; |
|---|
| 199 | default: strcpy( text, "DOS, unknown OEM"); break; |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | sprintf( descr, "DOS %5.2lf %s %2.2hx: %s", |
|---|
| 203 | mm, (vm86) ? (mmgr) ? "MemMgr" : |
|---|
| 204 | "DosBox" : |
|---|
| 205 | "OemVer", regs.h.bh, text); |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | #elif defined (LINUX) |
|---|
| 209 | if (uname( &un) == -1) // get uname descriptions |
|---|
| 210 | { // only likely failure seems |
|---|
| 211 | if (descr) // systemcall not implemented |
|---|
| 212 | { |
|---|
| 213 | strcpy( descr, "Linux, old kernel! "); |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | else |
|---|
| 217 | { |
|---|
| 218 | TRACES(( "sysname : '%s'\n", un.sysname)); |
|---|
| 219 | TRACES(( "release : '%s'\n", un.release)); |
|---|
| 220 | TRACES(( "version : '%s'\n", un.version)); |
|---|
| 221 | TRACES(( "nodename: '%s'\n", un.nodename)); |
|---|
| 222 | TRACES(( "domain : '%s'\n", un.domainname)); |
|---|
| 223 | if (descr) |
|---|
| 224 | { |
|---|
| 225 | if ((env = getenv("TERM")) != NULL) |
|---|
| 226 | { |
|---|
| 227 | strcpy( text, env); |
|---|
| 228 | } |
|---|
| 229 | else |
|---|
| 230 | { |
|---|
| 231 | strcpy( text, "unknown!"); |
|---|
| 232 | } |
|---|
| 233 | if ((at = strspn( un.release, ".0123456789")) != 0) |
|---|
| 234 | { |
|---|
| 235 | un.release[at] = 0; // terminate after number |
|---|
| 236 | } |
|---|
| 237 | sprintf( descr, "%s %9s env TERM=%s ", un.sysname, un.release, text); |
|---|
| 238 | |
|---|
| 239 | } |
|---|
| 240 | sscanf( un.release, "%lu.%lu.%lu", &major, &minor, µ); |
|---|
| 241 | } |
|---|
| 242 | if (descr) |
|---|
| 243 | { |
|---|
| 244 | if ((env = getenv("LOGNAME")) != NULL) |
|---|
| 245 | { |
|---|
| 246 | strcpy( text, env); |
|---|
| 247 | } |
|---|
| 248 | else |
|---|
| 249 | { |
|---|
| 250 | strcpy( text, "someone"); |
|---|
| 251 | } |
|---|
| 252 | strcat( descr, text); |
|---|
| 253 | strcat( descr, " on "); |
|---|
| 254 | strcat( descr, un.nodename); |
|---|
| 255 | } |
|---|
| 256 | #else |
|---|
| 257 | { |
|---|
| 258 | ULONG sysinfo[QSV_VERSION_MINOR]; // major, minor, bootdrive etc |
|---|
| 259 | |
|---|
| 260 | if (DosQuerySysInfo( 1, QSV_VERSION_MINOR, sysinfo, |
|---|
| 261 | QSV_VERSION_MINOR * sizeof(ULONG)) == NO_ERROR) |
|---|
| 262 | { |
|---|
| 263 | major = sysinfo[QSV_VERSION_MAJOR -1]; |
|---|
| 264 | minor = sysinfo[QSV_VERSION_MINOR -1]; |
|---|
| 265 | |
|---|
| 266 | if (major == 20) // major version |
|---|
| 267 | { |
|---|
| 268 | switch (minor) // minor version |
|---|
| 269 | { |
|---|
| 270 | case 00: mm = 2.0; break; |
|---|
| 271 | case 10: mm = 2.1; break; |
|---|
| 272 | case 11: mm = 2.11; break; |
|---|
| 273 | case 30: mm = 3.0; break; |
|---|
| 274 | case 40: mm = 4.0; break; |
|---|
| 275 | default: mm = 4.50; break; |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | if (descr) |
|---|
| 279 | { |
|---|
| 280 | if ((strlen(kernelrev) == 0) || (TxaOption('r'))) |
|---|
| 281 | { |
|---|
| 282 | TXLN kernel; |
|---|
| 283 | FILE *fp; |
|---|
| 284 | char boot = (char) '@' + (char) sysinfo[QSV_BOOT_DRIVE-1]; |
|---|
| 285 | |
|---|
| 286 | sprintf( kernel, "%c:\\os2krnl", boot); |
|---|
| 287 | if ((fp = fopen( kernel, "rb")) == NULL) |
|---|
| 288 | { |
|---|
| 289 | strcat( kernel, "i"); // alternative (floppy) name |
|---|
| 290 | fp = fopen( kernel, "rb"); |
|---|
| 291 | } |
|---|
| 292 | if (fp != NULL) |
|---|
| 293 | { |
|---|
| 294 | BYTE *buf = TxAlloc( 1, TXKVL); |
|---|
| 295 | char *kver; |
|---|
| 296 | |
|---|
| 297 | if (buf != NULL) |
|---|
| 298 | { |
|---|
| 299 | if (fread( buf, 1, TXKVL, fp) != 0) |
|---|
| 300 | { |
|---|
| 301 | if ((kver = TxMemStr( buf, TXKVS, TXKVL)) != NULL) |
|---|
| 302 | { |
|---|
| 303 | memcpy( text, kver + strlen(TXKVS), 10); |
|---|
| 304 | text[10] = 0; |
|---|
| 305 | TRACES(( "kernel string: '%s'\n", text)); |
|---|
| 306 | |
|---|
| 307 | for (kver = text; *kver; kver++) |
|---|
| 308 | { |
|---|
| 309 | if (!isprint(*kver)) |
|---|
| 310 | { |
|---|
| 311 | *kver = 0; |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | sprintf( kernelrev, "OS2kernel: %s on drive %c:", text, boot); |
|---|
| 315 | } |
|---|
| 316 | } |
|---|
| 317 | TxFreeMem( buf); |
|---|
| 318 | } |
|---|
| 319 | fclose( fp); |
|---|
| 320 | } |
|---|
| 321 | if (strlen(kernelrev) == 0) |
|---|
| 322 | { |
|---|
| 323 | sprintf( kernelrev, |
|---|
| 324 | "Internal : %lu.%lu on drive %c:", |
|---|
| 325 | major, minor, boot); |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | if (descr) |
|---|
| 331 | { |
|---|
| 332 | sprintf( descr, "OS/2 %4.2lf %s", mm, kernelrev); |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | #endif |
|---|
| 336 | rc = (major *10000) + (minor *100) + micro; // numeric version |
|---|
| 337 | |
|---|
| 338 | RETURN (rc); |
|---|
| 339 | } // end 'TxOsVersion' |
|---|
| 340 | /*---------------------------------------------------------------------------*/ |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | /*****************************************************************************/ |
|---|
| 344 | // Return 15-character TXLIB version string |
|---|
| 345 | /*****************************************************************************/ |
|---|
| 346 | char *txVersionString // RET 15-char version string |
|---|
| 347 | ( |
|---|
| 348 | void |
|---|
| 349 | ) |
|---|
| 350 | { |
|---|
| 351 | sprintf( txVersion, "%s %s", TXLIB_V, TXLIB_C); |
|---|
| 352 | return( txVersion); |
|---|
| 353 | } // end 'txVersionString' |
|---|
| 354 | /*---------------------------------------------------------------------------*/ |
|---|
| 355 | |
|---|
| 356 | #if defined (DOS32) |
|---|
| 357 | |
|---|
| 358 | /*****************************************************************************/ |
|---|
| 359 | // Return DOSEXTENDER version string |
|---|
| 360 | /*****************************************************************************/ |
|---|
| 361 | char *txDosExtVersion // RET version string |
|---|
| 362 | ( |
|---|
| 363 | void |
|---|
| 364 | ) |
|---|
| 365 | { |
|---|
| 366 | #if defined (CAUSEWAY) |
|---|
| 367 | return ("Causeway 3.52 (c) 1992-2000: M.E. Devore"); |
|---|
| 368 | #else |
|---|
| 369 | return ("DOS32A 7.20 (c) 1996-2002: DOS/32 Advanced Team"); |
|---|
| 370 | #endif |
|---|
| 371 | } // end 'txDosExtVersion' |
|---|
| 372 | /*---------------------------------------------------------------------------*/ |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | /*****************************************************************************/ |
|---|
| 376 | // Return DOSEXTENDER DPMI info string |
|---|
| 377 | /*****************************************************************************/ |
|---|
| 378 | char *txDosExtDpmiInfo // RET DPMI info string |
|---|
| 379 | ( |
|---|
| 380 | void |
|---|
| 381 | ) |
|---|
| 382 | { |
|---|
| 383 | union REGS regs; |
|---|
| 384 | struct SREGS sreg; |
|---|
| 385 | |
|---|
| 386 | memset( ®s, 0, sizeof(regs)); |
|---|
| 387 | memset( &sreg, 0, sizeof(sreg)); |
|---|
| 388 | regs.w.ax = TXDX_DPMI_VERS; |
|---|
| 389 | |
|---|
| 390 | txDpmiCall( ®s, &sreg) |
|---|
| 391 | |
|---|
| 392 | sprintf( exVersion, "%1.1hu.%02.2hu switchmode %s swap: %s", |
|---|
| 393 | regs.h.ah, regs.h.al, |
|---|
| 394 | (regs.w.bx & 0x02) ? "REAL" : "VM86", |
|---|
| 395 | (regs.w.bx & 0x04) ? "NO" : "YES"); |
|---|
| 396 | return( exVersion); |
|---|
| 397 | } // end 'txDosExtDpmiInfo' |
|---|
| 398 | /*---------------------------------------------------------------------------*/ |
|---|
| 399 | |
|---|
| 400 | #endif |
|---|