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)
22 # define DONT_TYPEDEF_PFN
25 #if defined(__WATCOMC__) && defined(OS2)
28 # define DONT_TYPEDEF_PFN
33 #if !defined(VMS) /* MH 10-06-96 */
35 # include <unistd.h> /* MH 10-06-96 */
38 # include <pwd.h> /* MH 10-06-96 */
39 # endif /* MH 10-06-96 */
45 /* Stupid MSC can't compile own headers without warning at least in VC 5.0 */
46 # pragma warning(disable: 4115 4201 4214 4514)
53 # pragma warning(default: 4115 4201 4214)
58 streng
*rex_userid( tsd_t
*TSD
, cparamboxptr parms
)
62 DWORD bufsize
=sizeof( buf
);
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
) ) ;
72 return nullstringptr( ) ;
74 return nullstringptr( ) ;
77 return( Str_creTSD( getpwuid( getuid( ) )->pw_name
) ) ;
81 streng
*rex_rxqueue( tsd_t
*TSD
, cparamboxptr parms
)
87 checkparam( parms
, 1, 3 , "RXQUEUE" ) ;
89 opt
= getoptionchar( TSD
, parms
->value
, "RXQUEUE", 1, "CDGS", "T" ) ;
92 case 'C': /* Create */
94 && ( parms
->next
->value
) )
95 rc
= create_queue( TSD
, parms
->next
->value
, &result
);
96 /* result created by create_queue() */
98 rc
= create_queue( TSD
, NULL
, &result
);
100 if ( result
== NULL
)
103 exiterror( ERR_EXTERNAL_QUEUE
, 104, tmpstr_of( TSD
, parms
->next
->value
) );
105 exiterror( ERR_EXTERNAL_QUEUE
, 99, rc
, "Creating from stack" );
108 /* result created by create_queue() or an internal error occurred */
110 case 'D': /* Delete */
112 && ( parms
->next
->value
) )
113 result
= int_to_streng( TSD
, delete_queue(TSD
, parms
->next
->value
) );
114 /* result created here */
116 exiterror( ERR_INCORRECT_CALL
, 5, "RXQUEUE", 2 );
120 && ( parms
->next
->value
) )
121 exiterror( ERR_INCORRECT_CALL
, 4, "RXQUEUE", 1 );
123 result
= get_queue( TSD
);
124 /* result created by get_queue() */
128 && ( parms
->next
->value
) )
129 result
= Str_dup_TSD( TSD
, set_queue( TSD
, parms
->next
->value
) );
131 exiterror( ERR_INCORRECT_CALL
, 5, "RXQUEUE", 2 );
133 case 'T': /* Timeout */
135 && ( parms
->next
->value
) )
136 result
= int_to_streng( TSD
, timeout_queue(TSD
, parms
->next
->value
, NULL
) );
137 /* result created here */
139 exiterror( ERR_INCORRECT_CALL
, 5, "RXQUEUE", 3 );
145 char *mygetenv( const tsd_t
*TSD
, const char *name
, char *buf
, int bufsize
)
157 ptr
= MallocTSD(100);
160 ret
= GetEnvironmentVariable( name
, ptr
, 100 );
169 ptr
= MallocTSD(ret
);
172 ret
= GetEnvironmentVariable( name
, ptr
, ret
);
183 ret
= GetEnvironmentVariable( name
, buf
, bufsize
);
188 if (ret
> (DWORD
) bufsize
)
200 ptr1
= (char *)MallocTSD((int)strlen(ptr
)+1);
207 if (strlen(ptr
) > (size_t) bufsize
-1)
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 )
226 if ( actually_pause
)
228 printf("\nPress ENTER key to exit...");
235 void set_pause_at_exit( void )
237 atexit( do_pause_at_exit
);
241 /* You are not allowed to use TSD or __regina_get_tsd() here! */
242 void *IfcAllocateMemory( unsigned long size
)
246 /* We now use the Virtual-functions instead of Global... */
247 ret
= VirtualAlloc( NULL
, size
, MEM_COMMIT
, PAGE_READWRITE
) ;
249 #elif defined( __EMX__ ) && !defined(DOS)
250 if (_osmode
== OS2_MODE
)
252 if ( (BOOL
)DosAllocMem( &ret
, size
, fPERM
|PAG_COMMIT
) )
257 else /* DOS or something else */
259 ret
= (void *)malloc( size
);
263 if ( (BOOL
)DosAllocMem( &ret
, size
, fPERM
|PAG_COMMIT
) )
268 ret
= (void *)malloc( size
);
273 /* You are not allowed to use TSD or __regina_get_tsd() here! */
274 unsigned long IfcFreeMemory( void *ptr
)
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
)
285 else /* DOS or something else */