| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
/* |
| 9 |
*/ |
| 10 |
|
| 11 |
/* |
| 12 |
* DESCRIPTION: |
| 13 |
* This routine defines various operating environment parameters. A |
| 14 |
* character ID is supplied for both the processor hardware type and |
| 15 |
* the operating system. The job processing mode, batch or |
| 16 |
* interactive, is identified; for this purpose an interactive job |
| 17 |
* is defined as one where the standard input device is attended by |
| 18 |
* the user who can respond to unforeseen events. The number of |
| 19 |
* character storage units and the number of numeric storage units |
| 20 |
* in the smallest block of storage which contains an integral |
| 21 |
* number of each are defined here. This routine further defines |
| 22 |
* whether the record length of a direct access unformatted file is |
| 23 |
* counted in character or numeric storage units. |
| 24 |
* |
| 25 |
* This skeleton version returns blank strings for hardware and |
| 26 |
* software IDs, zero to indicate batch mode, and unity for all |
| 27 |
* other values. |
| 28 |
* |
| 29 |
* FORMAL PARAMETERS: |
| 30 |
* HARD CHARACTER System Hardware ID |
| 31 |
* SOFT CHARACTER System Software ID |
| 32 |
* MODE INTEGER Job Mode ( 0=batch , 1=interactive ) |
| 33 |
* KCSU INTEGER Number of Character Storage Units |
| 34 |
* KNSU INTEGER Number of Numeric Storage Units |
| 35 |
* IDAU INTEGER Unformatted Direct Access Units: |
| 36 |
* 0 = Character Storage Units |
| 37 |
* 1 = Numeric Storage Units |
| 38 |
* |
| 39 |
************************************************************************ |
| 40 |
* |
| 41 |
*/ |
| 42 |
|
| 43 |
#include "fortranc.h" |
| 44 |
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || \ |
| 45 |
defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__) || \ |
| 46 |
defined(__NO_CYGWIN_OPTION__) |
| 47 |
#define NOMINMAX |
| 48 |
#include <io.h> |
| 49 |
#include <windows.h> |
| 50 |
#define isatty _isatty |
| 51 |
#else |
| 52 |
#include <sys/utsname.h> |
| 53 |
#include <unistd.h> |
| 54 |
#endif |
| 55 |
#include <stdio.h> |
| 56 |
|
| 57 |
static char *copy_string(char *dest, char const *source, long int elements) |
| 58 |
{ |
| 59 |
char *d; |
| 60 |
for (d = dest; d + 1 < dest + elements && *source; d++, source++) { |
| 61 |
*d = *source; |
| 62 |
} |
| 63 |
*d = '\0'; |
| 64 |
return d; |
| 65 |
} |
| 66 |
|
| 67 |
#define SUPES_MAXCHAR 80 |
| 68 |
#define WORDLEN 8 /* Note that we *FORCE* the Fortran string */ |
| 69 |
/* length be 8 plus 1 for trailing null for the strings hard and soft. */ |
| 70 |
#if defined(ADDC_) |
| 71 |
void exparm_(char *hard, char *soft, FTNINT *mode, FTNINT *kcsu, FTNINT *knsu, FTNINT *idau, |
| 72 |
FTNINT hlen, FTNINT slen) |
| 73 |
#else |
| 74 |
void exparm(char *hard, char *soft, FTNINT *mode, FTNINT *kcsu, FTNINT *knsu, FTNINT *idau, |
| 75 |
FTNINT hlen, FTNINT slen) |
| 76 |
#endif |
| 77 |
{ |
| 78 |
/********************************************************************/ |
| 79 |
#if defined(sgi) |
| 80 |
struct utsname SysInfo; |
| 81 |
char hardname[SUPES_MAXCHAR]; |
| 82 |
char softname[SUPES_MAXCHAR]; |
| 83 |
|
| 84 |
*idau = 0; |
| 85 |
*kcsu = sizeof(FTNREAL); |
| 86 |
*knsu = 1; |
| 87 |
|
| 88 |
uname(&SysInfo); |
| 89 |
|
| 90 |
snprintf(hardname, SUPES_MAXCHAR, "SGI-%.4s", SysInfo.machine); |
| 91 |
snprintf(softname, SUPES_MAXCHAR, "%.8s", SysInfo.release); |
| 92 |
|
| 93 |
copy_string(hard, hardname, WORDLEN); |
| 94 |
copy_string(soft, softname, WORDLEN); |
| 95 |
|
| 96 |
#endif /* Silicon Graphics */ |
| 97 |
/********************************************************************/ |
| 98 |
#if defined(aix) |
| 99 |
|
| 100 |
struct utsname SysInfo; |
| 101 |
char hardname[SUPES_MAXCHAR]; |
| 102 |
char softname[SUPES_MAXCHAR]; |
| 103 |
|
| 104 |
*idau = 0; |
| 105 |
*kcsu = sizeof(FTNREAL); /* IBM has 32 bit words */ |
| 106 |
*knsu = 1; |
| 107 |
|
| 108 |
uname(&SysInfo); |
| 109 |
|
| 110 |
snprintf(hardname, SUPES_MAXCHAR, "IBM %.4s", SysInfo.machine); |
| 111 |
snprintf(softname, SUPES_MAXCHAR, "%03s %.4s", SysInfo.sysname, SysInfo.release); |
| 112 |
|
| 113 |
copy_string(hard, hardname, WORDLEN); |
| 114 |
copy_string(soft, softname, WORDLEN); |
| 115 |
|
| 116 |
#endif /* IBM */ |
| 117 |
/********************************************************************/ |
| 118 |
#if defined(hpux) |
| 119 |
|
| 120 |
struct utsname SysInfo; |
| 121 |
char hardname[SUPES_MAXCHAR]; |
| 122 |
char softname[SUPES_MAXCHAR]; |
| 123 |
|
| 124 |
*idau = 0; |
| 125 |
*kcsu = sizeof(FTNREAL); /* HP has 32 bit words */ |
| 126 |
*knsu = 1; |
| 127 |
|
| 128 |
uname(&SysInfo); |
| 129 |
|
| 130 |
snprintf(hardname, SUPES_MAXCHAR, "HP %.4s", SysInfo.machine); |
| 131 |
snprintf(softname, SUPES_MAXCHAR, "HP-UX%.3s", SysInfo.release); |
| 132 |
|
| 133 |
copy_string(hard, hardname, WORDLEN); |
| 134 |
copy_string(soft, softname, WORDLEN); |
| 135 |
|
| 136 |
#endif /* HPUX */ |
| 137 |
/********************************************************************/ |
| 138 |
#if defined(__osf__) |
| 139 |
|
| 140 |
struct utsname SysInfo; |
| 141 |
char hardname[SUPES_MAXCHAR]; |
| 142 |
char softname[SUPES_MAXCHAR]; |
| 143 |
|
| 144 |
*idau = 0; |
| 145 |
*kcsu = sizeof(FTNREAL); /* Chars/float */ |
| 146 |
*knsu = 1; /* Ditto */ |
| 147 |
|
| 148 |
uname(&SysInfo); |
| 149 |
|
| 150 |
snprintf(hardname, SUPES_MAXCHAR, "%.8s", SysInfo.machine); |
| 151 |
snprintf(softname, SUPES_MAXCHAR, "%.4s%.4s", SysInfo.sysname, SysInfo.release); |
| 152 |
|
| 153 |
copy_string(hard, hardname, WORDLEN); |
| 154 |
copy_string(soft, softname, WORDLEN); |
| 155 |
|
| 156 |
#endif |
| 157 |
/********************************************************************/ |
| 158 |
|
| 159 |
#if defined(__NO_CYGWIN_OPTION__) |
| 160 |
SYSTEM_INFO SysInfo; |
| 161 |
OSVERSIONINFO OSInfo; |
| 162 |
char hardname[SUPES_MAXCHAR]; |
| 163 |
char softname[SUPES_MAXCHAR]; |
| 164 |
|
| 165 |
*idau = 0; |
| 166 |
*kcsu = sizeof(FTNREAL); /* See above */ |
| 167 |
*knsu = 1; /* Ditto */ |
| 168 |
|
| 169 |
GetSystemInfo(&SysInfo); |
| 170 |
|
| 171 |
snprintf(hardname, SUPES_MAXCHAR, "%-8d", SysInfo.dwProcessorType); |
| 172 |
|
| 173 |
OSInfo.dwOSVersionInfoSize = sizeof(OSInfo); |
| 174 |
if (GetVersionEx(&OSInfo) > 0) { |
| 175 |
switch (OSInfo.dwPlatformId) { |
| 176 |
case 1: |
| 177 |
snprintf(softname, SUPES_MAXCHAR, "Win98%d.%d", OSInfo.dwMajorVersion, OSInfo.dwMinorVersion); |
| 178 |
break; |
| 179 |
case 2: |
| 180 |
snprintf(softname, SUPES_MAXCHAR, "WinNT%d.%d", OSInfo.dwMajorVersion, OSInfo.dwMinorVersion); |
| 181 |
break; |
| 182 |
default: |
| 183 |
snprintf(softname, SUPES_MAXCHAR, "WinOS%d.%d", OSInfo.dwMajorVersion, OSInfo.dwMinorVersion); |
| 184 |
break; |
| 185 |
} |
| 186 |
} |
| 187 |
else { |
| 188 |
snprintf(softname, SUPES_MAXCHAR, "Unknown OS"); |
| 189 |
} |
| 190 |
copy_string(hard, hardname, WORDLEN); |
| 191 |
copy_string(soft, softname, WORDLEN); |
| 192 |
|
| 193 |
/* cygwin native */ |
| 194 |
/********************************************************************/ |
| 195 |
#elif defined(__CYGWIN__) |
| 196 |
struct utsname SysInfo; |
| 197 |
char hardname[SUPES_MAXCHAR]; |
| 198 |
char softname[SUPES_MAXCHAR]; |
| 199 |
|
| 200 |
*idau = 0; |
| 201 |
*kcsu = sizeof(FTNREAL); /* See above */ |
| 202 |
*knsu = 1; /* Ditto */ |
| 203 |
|
| 204 |
uname(&SysInfo); |
| 205 |
|
| 206 |
snprintf(hardname, SUPES_MAXCHAR, "%.8s", SysInfo.machine); |
| 207 |
snprintf(softname, SUPES_MAXCHAR, "CW%.6s", SysInfo.release); |
| 208 |
|
| 209 |
copy_string(hard, hardname, WORDLEN); |
| 210 |
copy_string(soft, softname, WORDLEN); |
| 211 |
|
| 212 |
#endif |
| 213 |
/********************************************************************/ |
| 214 |
#if defined(__APPLE__) |
| 215 |
struct utsname SysInfo; |
| 216 |
char hardname[SUPES_MAXCHAR]; |
| 217 |
char softname[SUPES_MAXCHAR]; |
| 218 |
|
| 219 |
*idau = 0; |
| 220 |
*kcsu = sizeof(FTNREAL); /* Darwin has 32 bit words */ |
| 221 |
*knsu = 1; |
| 222 |
|
| 223 |
uname(&SysInfo); |
| 224 |
|
| 225 |
snprintf(hardname, SUPES_MAXCHAR, "%.8s", SysInfo.machine); |
| 226 |
snprintf(softname, SUPES_MAXCHAR, "OSX%.5s", SysInfo.release); |
| 227 |
|
| 228 |
copy_string(hard, hardname, WORDLEN); |
| 229 |
copy_string(soft, softname, WORDLEN); |
| 230 |
|
| 231 |
#endif /* Darwin (Power Macintosh)*/ |
| 232 |
|
| 233 |
/********************************************************************/ |
| 234 |
#if defined(__linux__) || defined(interix) |
| 235 |
struct utsname SysInfo; |
| 236 |
char hardname[SUPES_MAXCHAR]; |
| 237 |
char softname[SUPES_MAXCHAR]; |
| 238 |
|
| 239 |
*idau = 0; |
| 240 |
*kcsu = sizeof(FTNREAL); /* See above */ |
| 241 |
*knsu = 1; /* Ditto */ |
| 242 |
|
| 243 |
uname(&SysInfo); |
| 244 |
|
| 245 |
snprintf(hardname, SUPES_MAXCHAR, "%.8s", SysInfo.machine); |
| 246 |
snprintf(softname, SUPES_MAXCHAR, "Lx%.6s", SysInfo.release); |
| 247 |
|
| 248 |
copy_string(hard, hardname, WORDLEN); |
| 249 |
copy_string(soft, softname, WORDLEN); |
| 250 |
|
| 251 |
#endif /* Linux, Interix */ |
| 252 |
/********************************************************************/ |
| 253 |
|
| 254 |
if (isatty(0) != 0) { /* Test stdin as to whether or not it's a terminal. */ |
| 255 |
*mode = 1; /* Indicates an interactive process. */ |
| 256 |
} |
| 257 |
else { |
| 258 |
*mode = 0; /* Else running from a procedure. */ |
| 259 |
} |
| 260 |
} |