| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992-1994 Anders Christensen <[email protected]> |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifdef OS2 |
| 21 |
# define INCL_DOSPROCESS |
| 22 |
#endif |
| 23 |
|
| 24 |
#ifdef __EMX__ |
| 25 |
# define DONT_TYPEDEF_PFN |
| 26 |
# include <io.h> |
| 27 |
# include <os2emx.h> |
| 28 |
# include <fcntl.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
#if defined(__WATCOMC__) && defined(OS2) |
| 32 |
# include <os2.h> |
| 33 |
# define DONT_TYPEDEF_PFN |
| 34 |
#endif |
| 35 |
|
| 36 |
#if defined(__WATCOMC__) && !defined(__QNX__) |
| 37 |
# include <i86.h> |
| 38 |
# if defined(OS2) |
| 39 |
# define DONT_TYPEDEF_PFN |
| 40 |
# include <os2.h> |
| 41 |
# endif |
| 42 |
#endif |
| 43 |
|
| 44 |
#include "rexx.h" |
| 45 |
#include <errno.h> |
| 46 |
#include <stdio.h> |
| 47 |
#include <string.h> |
| 48 |
#ifdef HAVE_ASSERT_H |
| 49 |
# include <assert.h> |
| 50 |
#endif |
| 51 |
#ifdef HAVE_LIMITS_H |
| 52 |
# include <limits.h> |
| 53 |
#endif |
| 54 |
#include <time.h> |
| 55 |
|
| 56 |
#if defined(VMS) |
| 57 |
# include <stat.h> |
| 58 |
#elif defined(OS2) |
| 59 |
# include <sys/stat.h> |
| 60 |
# ifdef HAVE_UNISTD_H |
| 61 |
# include <unistd.h> |
| 62 |
# endif |
| 63 |
#elif defined(__WATCOMC__) || defined(_MSC_VER) |
| 64 |
# include <sys/stat.h> |
| 65 |
# include <fcntl.h> |
| 66 |
# ifdef HAVE_UNISTD_H |
| 67 |
# include <unistd.h> |
| 68 |
# endif |
| 69 |
# if defined(_MSC_VER) && !defined(__WINS__) |
| 70 |
# include <direct.h> |
| 71 |
# include <io.h> |
| 72 |
# endif |
| 73 |
#elif defined(MAC) |
| 74 |
# include "mac.h" |
| 75 |
#else |
| 76 |
# include <sys/stat.h> |
| 77 |
# ifdef HAVE_PWD_H |
| 78 |
# include <pwd.h> |
| 79 |
# endif |
| 80 |
# ifdef HAVE_GRP_H |
| 81 |
# include <grp.h> |
| 82 |
# endif |
| 83 |
# include <fcntl.h> |
| 84 |
# ifdef HAVE_UNISTD_H |
| 85 |
# include <unistd.h> |
| 86 |
# endif |
| 87 |
#endif |
| 88 |
|
| 89 |
#ifdef DJGPP |
| 90 |
# include <pc.h> |
| 91 |
# include <dir.h> |
| 92 |
#endif |
| 93 |
|
| 94 |
#ifdef HAVE_DIRECT_H |
| 95 |
# include <direct.h> |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifdef WIN32 |
| 99 |
# if defined(__BORLANDC__) |
| 100 |
# include <dir.h> |
| 101 |
# endif |
| 102 |
# if defined(_MSC_VER) |
| 103 |
# if _MSC_VER >= 1100 |
| 104 |
/* Stupid MSC can't compile own headers without warning at least in VC 5.0 */ |
| 105 |
# pragma warning(disable: 4115 4201 4214 4514) |
| 106 |
# endif |
| 107 |
# endif |
| 108 |
# include <windows.h> |
| 109 |
# ifdef _MSC_VER |
| 110 |
# if _MSC_VER >= 1100 |
| 111 |
# pragma warning(default: 4115 4201 4214) |
| 112 |
# endif |
| 113 |
# endif |
| 114 |
# if defined(__WATCOMC__) |
| 115 |
# include <io.h> |
| 116 |
# endif |
| 117 |
#endif |
| 118 |
|
| 119 |
/* |
| 120 |
* Since development of Ultrix has ceased, and they never managed to |
| 121 |
* fix a few things, we want to define a few things, just in order |
| 122 |
* to kill a few warnings ... |
| 123 |
*/ |
| 124 |
#if defined(FIX_PROTOS) && defined(FIX_ALL_PROTOS) && defined(ultrix) |
| 125 |
int fstat( int fd, struct stat *buf ) ; |
| 126 |
int stat( char *path, struct stat *buf ) ; |
| 127 |
#endif |
| 128 |
|
| 129 |
streng *os2_directory( tsd_t *TSD, cparamboxptr parms ) |
| 130 |
{ |
| 131 |
streng *result=NULL ; |
| 132 |
int ok=HOOK_GO_ON ; |
| 133 |
char *path; |
| 134 |
|
| 135 |
checkparam( parms, 0, 1 , "DIRECTORY" ) ; |
| 136 |
|
| 137 |
if (parms&&parms->value) |
| 138 |
{ |
| 139 |
if (TSD->systeminfo->hooks & HOOK_MASK(HOOK_SETCWD)) |
| 140 |
ok = hookup_output( TSD, HOOK_SETCWD, parms->value ) ; |
| 141 |
|
| 142 |
if (ok==HOOK_GO_ON) |
| 143 |
{ |
| 144 |
path = str_of( TSD, parms->value ) ; |
| 145 |
if (chdir( path ) ) |
| 146 |
{ |
| 147 |
FreeTSD( path ) ; |
| 148 |
return nullstringptr() ; |
| 149 |
} |
| 150 |
FreeTSD( path ) ; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
/* |
| 155 |
* The remainder of this is for obtaining the current working directory... |
| 156 |
*/ |
| 157 |
if (TSD->systeminfo->hooks & HOOK_MASK(HOOK_GETCWD)) |
| 158 |
ok = hookup_input( TSD, HOOK_GETCWD, &result ) ; |
| 159 |
|
| 160 |
if (ok==HOOK_GO_ON) |
| 161 |
{ |
| 162 |
result = Str_makeTSD( REXX_PATH_MAX ); |
| 163 |
my_fullpath( TSD, result->value, "." ); |
| 164 |
result->len = strlen( result->value ); |
| 165 |
} |
| 166 |
return result; |
| 167 |
} |
| 168 |
|
| 169 |
streng *os2_beep( tsd_t *TSD, cparamboxptr parms ) |
| 170 |
{ |
| 171 |
int freq=0,dur=1; |
| 172 |
|
| 173 |
checkparam( parms, 1, 2 , "BEEP" ) ; |
| 174 |
|
| 175 |
if (parms && parms->value) |
| 176 |
{ |
| 177 |
freq = atopos( TSD, parms->value, "BEEP", 1 ) ; |
| 178 |
if (freq < 37 || freq > 32767) |
| 179 |
exiterror( ERR_INCORRECT_CALL, 0 ); |
| 180 |
} |
| 181 |
if (parms->next && parms->next->value) |
| 182 |
{ |
| 183 |
dur = atopos( TSD, parms->next->value, "BEEP", 2 ) ; |
| 184 |
if (dur < 1 || freq > 60000) |
| 185 |
exiterror( ERR_INCORRECT_CALL, 0 ); |
| 186 |
} |
| 187 |
|
| 188 |
#if defined(WIN32) |
| 189 |
Beep( (DWORD)freq, (DWORD)dur ); |
| 190 |
#elif defined (__EMX__) |
| 191 |
if (_osmode != DOS_MODE) |
| 192 |
DosBeep( freq, dur ); |
| 193 |
else |
| 194 |
{ |
| 195 |
int hdl; |
| 196 |
|
| 197 |
/* stdout and/or stderr may be redirected */ |
| 198 |
if ((hdl = open("con", O_WRONLY)) != -1) |
| 199 |
{ |
| 200 |
write(hdl, "\x07" /* ^G == bell */, 1); |
| 201 |
close(hdl); |
| 202 |
} |
| 203 |
} |
| 204 |
#elif defined(DOS) |
| 205 |
putchar(7); |
| 206 |
#elif defined(OS2) |
| 207 |
DosBeep( freq, dur ); |
| 208 |
#elif defined(__QNX__) |
| 209 |
printf("\a"); |
| 210 |
#elif defined(__WATCOMC__) |
| 211 |
sound( freq ); |
| 212 |
delay( dur ); |
| 213 |
nosound( ); |
| 214 |
#elif defined(__DJGPP__) |
| 215 |
sound( freq ); |
| 216 |
delay( dur ); |
| 217 |
nosound( ); |
| 218 |
#elif defined(__WINS__) || defined(__EPOC32__) |
| 219 |
beep( freq, dur ); |
| 220 |
#endif |
| 221 |
return nullstringptr(); |
| 222 |
} |
| 223 |
|
| 224 |
streng *os2_filespec( tsd_t *TSD, cparamboxptr parms ) |
| 225 |
{ |
| 226 |
streng *result=NULL ; |
| 227 |
streng *inpath=NULL; |
| 228 |
char format = '?' ; |
| 229 |
#if defined(DJGPP) |
| 230 |
char fdrive[MAXDRIVE], fdir[MAXDIR], fname[MAXFILE], fext[MAXEXT]; |
| 231 |
#elif defined(__EMX__) |
| 232 |
char fdrive[_MAX_DRIVE], fdir[_MAX_DIR], fname[_MAX_FNAME], fext[_MAX_EXT]; |
| 233 |
#elif defined(HAVE__SPLITPATH2) |
| 234 |
char fpath[_MAX_PATH2], *fdrive=NULL, *fdir=NULL, *fname=NULL, *fext=NULL; |
| 235 |
#elif defined(HAVE__SPLITPATH) |
| 236 |
char fdrive[_MAX_PATH], fdir[_MAX_PATH], fname[_MAX_PATH], fext[_MAX_PATH]; |
| 237 |
#else |
| 238 |
char fpath[REXX_PATH_MAX+5],*fdrive=NULL,*fdir=NULL,*fname=NULL,*fext=NULL; |
| 239 |
#endif |
| 240 |
|
| 241 |
checkparam( parms, 2, 2 , "FILESPEC" ) ; |
| 242 |
format = getoptionchar( TSD, parms->value, "FILESPEC", 1, "DNP", "?" ) ; |
| 243 |
inpath = Str_dupstrTSD( parms->next->value ) ; |
| 244 |
#if defined(DJGPP) |
| 245 |
fnsplit( inpath->value, fdrive, fdir, fname, fext ); |
| 246 |
#elif defined(__EMX__) |
| 247 |
_splitpath( inpath->value, fdrive, fdir, fname, fext ); |
| 248 |
#elif defined(HAVE__SPLITPATH2) |
| 249 |
_splitpath2( inpath->value, fpath, &fdrive, &fdir, &fname, &fext ); |
| 250 |
#elif defined(HAVE__SPLITPATH) |
| 251 |
_splitpath( inpath->value, fdrive, fdir, fname, fext ); |
| 252 |
#else |
| 253 |
my_splitpath2( inpath->value, fpath, &fdrive, &fdir, &fname, &fext ); |
| 254 |
#endif |
| 255 |
switch( format ) |
| 256 |
{ |
| 257 |
case 'D': |
| 258 |
result = Str_creTSD( fdrive ); |
| 259 |
break; |
| 260 |
case 'N': |
| 261 |
result = Str_makeTSD( strlen( fname) + strlen( fext ) ); |
| 262 |
Str_catstrTSD( result, fname ); |
| 263 |
Str_catstrTSD( result, fext ); |
| 264 |
break; |
| 265 |
case 'P': |
| 266 |
result = Str_creTSD( fdir ); |
| 267 |
break; |
| 268 |
} |
| 269 |
FreeTSD( inpath ); |
| 270 |
return result; |
| 271 |
} |