Copy icons and docs.
[AROS-Contrib.git] / regina / rexxext.c
blob0fd7270512c96ed15589233a1e80100b7ec89344
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #if defined( __EMX__ ) && !defined(DOS)
21 # include <os2.h>
22 # define DONT_TYPEDEF_PFN
23 #endif
25 #if defined(__WATCOMC__) && defined(OS2)
26 # define INCL_DOS
27 # include <os2.h>
28 # define DONT_TYPEDEF_PFN
29 #endif
31 #include "rexx.h"
32 #include <stdio.h>
33 #if !defined(VMS) /* MH 10-06-96 */
34 # ifdef HAVE_UNISTD_H
35 # include <unistd.h> /* MH 10-06-96 */
36 # endif
37 # ifdef HAVE_PWD_H
38 # include <pwd.h> /* MH 10-06-96 */
39 # endif /* MH 10-06-96 */
40 #endif
42 #if defined(WIN32)
43 # ifdef _MSC_VER
44 # if _MSC_VER >= 1100
45 /* Stupid MSC can't compile own headers without warning at least in VC 5.0 */
46 # pragma warning(disable: 4115 4201 4214 4514)
47 # endif
48 # endif
49 # include <windows.h>
50 # include <conio.h>
51 # ifdef _MSC_VER
52 # if _MSC_VER >= 1100
53 # pragma warning(default: 4115 4201 4214)
54 # endif
55 # endif
56 #endif
58 streng *rex_userid( tsd_t *TSD, cparamboxptr parms )
60 #if defined(WIN32)
61 char buf[100];
62 DWORD bufsize=sizeof( buf );
63 #endif
64 checkparam( parms, 0, 0 , "USERID" ) ;
65 #if defined(VMS) || defined(MAC) || ( defined(__WATCOMC__) && !defined(__QNX__) ) || defined(_MSC_VER) || defined(_AMIGA) || defined(__MINGW32__) || defined(__BORLANDC__) || defined(__EPOC32__) || defined(__LCC__) || defined(_AMIGA) || defined(__AROS__)
66 # if defined(WIN32) && !defined(WDOSX)
67 if ( GetUserName( buf, &bufsize ) )
69 return( Str_creTSD( buf ) ) ;
71 else
72 return nullstringptr( ) ;
73 # else
74 return nullstringptr( ) ;
75 # endif
76 #else
77 return( Str_creTSD( getpwuid( getuid( ) )->pw_name ) ) ;
78 #endif
81 streng *rex_rxqueue( tsd_t *TSD, cparamboxptr parms )
83 char opt='?';
84 streng *result=NULL;
85 int rc;
87 checkparam( parms, 1, 3 , "RXQUEUE" ) ;
89 opt = getoptionchar( TSD, parms->value, "RXQUEUE", 1, "CDGS", "T" ) ;
90 switch ( opt )
92 case 'C': /* Create */
93 if ( ( parms->next )
94 && ( parms->next->value ) )
95 rc = create_queue( TSD, parms->next->value, &result );
96 /* result created by create_queue() */
97 else
98 rc = create_queue( TSD, NULL, &result );
100 if ( result == NULL )
102 if ( rc == 5 )
103 exiterror( ERR_EXTERNAL_QUEUE, 104, tmpstr_of( TSD, parms->next->value ) );
104 else
105 exiterror( ERR_EXTERNAL_QUEUE, 99, rc, "Creating from stack" );
108 /* result created by create_queue() or an internal error occurred */
109 break;
110 case 'D': /* Delete */
111 if ( ( parms->next )
112 && ( parms->next->value ) )
113 result = int_to_streng( TSD, delete_queue(TSD, parms->next->value ) );
114 /* result created here */
115 else
116 exiterror( ERR_INCORRECT_CALL, 5, "RXQUEUE", 2 );
117 break;
118 case 'G': /* Get */
119 if ( ( parms->next )
120 && ( parms->next->value ) )
121 exiterror( ERR_INCORRECT_CALL, 4, "RXQUEUE", 1 );
122 else
123 result = get_queue( TSD );
124 /* result created by get_queue() */
125 break;
126 case 'S': /* Set */
127 if ( ( parms->next )
128 && ( parms->next->value ) )
129 result = Str_dup_TSD( TSD, set_queue( TSD, parms->next->value ) );
130 else
131 exiterror( ERR_INCORRECT_CALL, 5, "RXQUEUE", 2 );
132 break;
133 case 'T': /* Timeout */
134 if ( ( parms->next )
135 && ( parms->next->value ) )
136 result = int_to_streng( TSD, timeout_queue(TSD, parms->next->value, NULL ) );
137 /* result created here */
138 else
139 exiterror( ERR_INCORRECT_CALL, 5, "RXQUEUE", 3 );
140 break;
142 return result ;
145 char *mygetenv( const tsd_t *TSD, const char *name, char *buf, int bufsize )
147 char *ptr=NULL;
148 #ifdef WIN32
149 DWORD ret=0;
150 #else
151 char *ptr1=NULL;
152 #endif
154 #ifdef WIN32
155 if (!buf)
157 ptr = MallocTSD(100);
158 if (!ptr)
159 return NULL;
160 ret = GetEnvironmentVariable( name, ptr, 100 );
161 if (ret == 0)
163 FreeTSD(ptr);
164 return NULL;
166 if (ret > 100)
168 FreeTSD(ptr);
169 ptr = MallocTSD(ret);
170 if (!ptr)
171 return NULL;
172 ret = GetEnvironmentVariable( name, ptr, ret );
173 if (ret == 0)
175 FreeTSD(ptr);
176 return NULL;
179 return ptr;
181 else
183 ret = GetEnvironmentVariable( name, buf, bufsize );
184 if (ret == 0)
186 return NULL;
188 if (ret > (DWORD) bufsize)
190 return NULL;
192 return buf;
194 #else
195 ptr = getenv(name);
196 if (!ptr)
197 return NULL;
198 if (!buf)
200 ptr1 = (char *)MallocTSD((int)strlen(ptr)+1);
201 if (!ptr1)
202 return NULL;
203 strcpy(ptr1, ptr);
205 else
207 if (strlen(ptr) > (size_t) bufsize-1)
208 return NULL;
209 strcpy(buf, ptr);
210 ptr1 = buf;
212 return ptr1;
213 #endif
216 #if !defined(__WINS__) && !defined(__EPOC32__)
217 static int actually_pause = 1;
220 * These functions are used to allow Regina to display "Press ENTER key to exit..."
221 * in the console if it is NOT started from a console.
223 static void do_pause_at_exit( void )
225 int ch;
226 if ( actually_pause )
228 printf("\nPress ENTER key to exit...");
229 fflush( stdout );
230 ch = getchar();
231 (void)ch; // Unused
235 void set_pause_at_exit( void )
237 atexit( do_pause_at_exit );
239 #endif
241 /* You are not allowed to use TSD or __regina_get_tsd() here! */
242 void *IfcAllocateMemory( unsigned long size )
244 void *ret;
245 #if defined( WIN32 )
246 /* We now use the Virtual-functions instead of Global... */
247 ret = VirtualAlloc( NULL, size, MEM_COMMIT, PAGE_READWRITE ) ;
248 return ret;
249 #elif defined( __EMX__ ) && !defined(DOS)
250 if (_osmode == OS2_MODE)
252 if ( (BOOL)DosAllocMem( &ret, size, fPERM|PAG_COMMIT ) )
253 return NULL;
254 else
255 return ret;
257 else /* DOS or something else */
259 ret = (void *)malloc( size );
260 return ret;
262 #elif defined( OS2 )
263 if ( (BOOL)DosAllocMem( &ret, size, fPERM|PAG_COMMIT ) )
264 return NULL;
265 else
266 return ret;
267 #else
268 ret = (void *)malloc( size );
269 return ret;
270 #endif
273 /* You are not allowed to use TSD or __regina_get_tsd() here! */
274 unsigned long IfcFreeMemory( void *ptr )
276 #if defined( WIN32 )
277 /* In opposite to most(!) of the documentation from Microsoft we shouldn't
278 * decommit and release together. This won't work at least under NT4SP6a.
279 * We can first decommit and then release or release at once. FGC.
281 VirtualFree( ptr, 0, MEM_RELEASE ) ;
282 #elif defined( __EMX__ ) && !defined(DOS)
283 if (_osmode == OS2_MODE)
284 DosFreeMem( ptr );
285 else /* DOS or something else */
286 free( ptr );
287 #elif defined( OS2 )
288 DosFreeMem( ptr );
289 #else
290 free( ptr );
291 #endif
292 return 0;