windows/MiscSystem.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /*********************************************************************/
39 /* */
40 /* Function: Miscellaneous system specific routines */
41 /* */
42 /*********************************************************************/
43 #include "RexxCore.h"
44 #include "StringClass.hpp"
45 #include "DirectoryClass.hpp"
46 #include "RexxActivity.hpp"
47 #include "RexxActivation.hpp"
48 #include "PointerClass.hpp"
49 #include <stdlib.h>
50 #include <process.h>
51 #include "malloc.h"
52 #include <signal.h>
53 #include "Interpreter.hpp"
54 #include "SystemInterpreter.hpp"
55 
57 {
58  return getSystemName(); // this is the same
59 }
60 
61 
62 static OSVERSIONINFO version_info={0}; /* for optimization so that GetVersionEx */
63  /* don't have to be called each time */
64 
66 {
67  if (!version_info.dwOSVersionInfoSize)
68  {
69  /* GetVersionEx called for the first time */
70  version_info.dwOSVersionInfoSize = sizeof(version_info); // if not set --> violation error
71  GetVersionEx(&version_info);
72  }
73  if (version_info.dwPlatformId == VER_PLATFORM_WIN32s) return 0; // Windows 3.1
74  else
75  if (version_info.dwPlatformId == VER_PLATFORM_WIN32_NT) return 1; // Windows NT
76  else return 2; // Windows 95
77 }
78 
80 /******************************************************************************/
81 /* Function: Get System Name */
82 /******************************************************************************/
83 {
84  char chVerBuf[26]; // buffer for version
85  int isys;
86 
87  isys = which_system_is_running();
88 
89  if (isys == 0)
90  {
91  strcpy(chVerBuf, "Windows"); // Windows 3.1
92  }
93  else if (isys == 1)
94  {
95  strcpy(chVerBuf, "WindowsNT"); // Windows NT
96  }
97  else
98  {
99  strcpy(chVerBuf, "Windows95"); // Windows 95
100  }
101  return new_string(chVerBuf); /* return as a string */
102 }
103 
104 
106 /******************************************************************************/
107 /* Function: Return the system specific version identifier that is stored */
108 /* in the image. */
109 /******************************************************************************/
110 {
111  char chVerBuf[8]; // buffer for version
112  OSVERSIONINFO vi;
113  // dont forget to change sysmeths.cmd
114 
115  vi.dwOSVersionInfoSize = sizeof(vi); // if not set --> violation error
116 
117  GetVersionEx(&vi); // get version with extended api
118  /* format into the buffer */
119  wsprintf(chVerBuf,"%i.%02i",(int)vi.dwMajorVersion,(int)vi.dwMinorVersion);
120  return new_string(chVerBuf); /* return as a string */
121 }
122 
123 
125  RexxString * callType, /* type of call token */
126  RexxString * programName ) /* program name token */
127 /******************************************************************************/
128 /* Function: Produce a system specific source string */
129 /******************************************************************************/
130 {
131  char *outPtr; /* copy pointer */
132  const char *chSysName; /* copy pointer */
133 
134  RexxString *rsSysName = getSystemName(); /* start with the system stuff */
135  chSysName= rsSysName->getStringData();
136 
137  RexxString *source_string = raw_string(rsSysName->getBLength() + 2 + callType->getBLength() + programName->getBLength());
138 
139  outPtr = source_string->getWritableData(); /* point to the result data */
140  strcpy(outPtr, chSysName); /* copy the system name */
141  outPtr +=rsSysName->getBLength(); /* step past the name */
142  *outPtr++ = ' '; /* put a blank between */
143  /* copy the call type */
144  memcpy(outPtr, callType->getStringData(), callType->getBLength());
145  outPtr += callType->getBLength(); /* step over the call type */
146  *outPtr++ = ' '; /* put a blank between */
147  /* copy the system name */
148  memcpy(outPtr, programName->getStringData(), programName->getBLength());
149  return source_string; /* return the source string */
150 }
151 
152 
153 int WinExceptionFilter( int xCode )
154 /******************************************************************************/
155 /* Function: Exception Filter used by Windows exception handling */
156 /******************************************************************************/
157 {
158  return EXCEPTION_CONTINUE_SEARCH;
159 }
160 
161 
162 #define MAX_ADDRESS_NAME_LENGTH 250 /* maximum command environment name */
163 
164 
165 
166 /**
167  * Validate an external address name.
168  *
169  * @param Name The name to validate
170  */
172 {
173  /* name too long? */
174  if (name->getBLength() > MAX_ADDRESS_NAME_LENGTH)
175  {
176  /* go report an error */
178  }
179 }
180 
181 
182 /**
183  * This was an undocumented API prior to 4.0, but is known to have been used by
184  * some IBM applications. Therefore this was maintained solely for binary
185  * compatibility.
186  *
187  * However, it is now also used to turn off processing Windows messages in a
188  * special case situation. See the SysSemaphore::waitHandle() comments for more
189  * info. This is done on a per-thread basis, RexxSetProcessMessages() must be
190  * invoked while executing on the proper thread.
191  *
192  * @return TRUE always.
193  */
194 BOOL APIENTRY RexxSetProcessMessages(BOOL turnOn)
195 {
196  if ( ! turnOn )
197  {
199  }
200  return TRUE;
201 }
202 
void reportException(wholenumber_t error)
#define Error_Environment_name_name
RexxString * new_string(const char *s, stringsizeB_t bl, sizeC_t cl=-1)
RexxString * raw_string(stringsizeB_t bl, stringsizeC_t cl=-1)
const char * getStringData()
char * getWritableData()
sizeB_t getBLength()
static void setNoMessageLoop()
static RexxString * getSystemVersion()
static RexxString * getSystemName()
static RexxString * getSourceString(RexxString *callType, RexxString *programName)
static RexxString * getInternalSystemName()
static void validateAddressName(RexxString *name)
static OSVERSIONINFO version_info
#define MAX_ADDRESS_NAME_LENGTH
BOOL APIENTRY RexxSetProcessMessages(BOOL turnOn)
int which_system_is_running()
int WinExceptionFilter(int xCode)