Added an icon with c:iconx as default tools.
[AROS-Contrib.git] / regina / os2funcs.c
blob03a500d26ba2ca1b390b44d36ae64ed564158d10
1 #ifndef lint
2 static char *RCSid = "$Id$";
3 #endif
5 /*
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifdef OS2
25 # define INCL_DOSPROCESS
26 #endif
28 #ifdef __EMX__
29 # define DONT_TYPEDEF_PFN
30 # include <io.h>
31 # include <os2emx.h>
32 # include <fcntl.h>
33 #endif
35 #include "rexx.h"
36 #include <errno.h>
37 #include <stdio.h>
38 #include <string.h>
39 #ifdef HAVE_ASSERT_H
40 # include <assert.h>
41 #endif
42 #ifdef HAVE_LIMITS_H
43 # include <limits.h>
44 #endif
45 #include <ctype.h>
46 #include <time.h>
48 #if defined(VMS)
49 # include <stat.h>
50 #elif defined(OS2)
51 # include <sys/stat.h>
52 # ifdef HAVE_UNISTD_H
53 # include <unistd.h>
54 # endif
55 #elif defined(__WATCOMC__) || defined(_MSC_VER)
56 # include <sys/stat.h>
57 # include <fcntl.h>
58 # ifdef HAVE_UNISTD_H
59 # include <unistd.h>
60 # endif
61 # if defined(_MSC_VER) && !defined(__WINS__)
62 # include <direct.h>
63 # include <io.h>
64 # endif
65 #elif defined(MAC)
66 # include "mac.h"
67 #else
68 # include <sys/stat.h>
69 # ifdef HAVE_PWD_H
70 # include <pwd.h>
71 # endif
72 # ifdef HAVE_GRP_H
73 # include <grp.h>
74 # endif
75 # include <fcntl.h>
76 # ifdef HAVE_UNISTD_H
77 # include <unistd.h>
78 # endif
79 #endif
81 #ifdef DJGPP
82 # include <pc.h>
83 # include <dir.h>
84 #endif
87 #ifdef __WATCOMC__
88 # include <i86.h>
89 #endif
91 #ifdef WIN32
92 # if defined(__BORLANDC__)
93 # include <dir.h>
94 # endif
95 # if defined(_MSC_VER)
96 # if _MSC_VER >= 1100
97 /* Stupid MSC can't compile own headers without warning at least in VC 5.0 */
98 # pragma warning(disable: 4115 4201 4214)
99 # endif
100 # endif
101 # include <windows.h>
102 # ifdef _MSC_VER
103 # if _MSC_VER >= 1100
104 # pragma warning(default: 4115 4201 4214)
105 # endif
106 # endif
107 # if defined(__WATCOMC__)
108 # include <io.h>
109 # endif
110 #endif
113 * Since development of Ultrix has ceased, and they never managed to
114 * fix a few things, we want to define a few things, just in order
115 * to kill a few warnings ...
117 #if defined(FIX_PROTOS) && defined(FIX_ALL_PROTOS) && defined(ultrix)
118 int fstat( int fd, struct stat *buf ) ;
119 int stat( char *path, struct stat *buf ) ;
120 #endif
122 streng *os2_directory( tsd_t *TSD, cparamboxptr parms )
124 streng *result ;
125 #ifdef __EMX__
126 int i;
127 #endif
128 char *path;
130 checkparam( parms, 0, 1 , "DIRECTORY" ) ;
132 if (parms&&parms->value)
134 path = str_of( TSD, parms->value ) ;
135 if (chdir( path ) )
137 FreeTSD( path ) ;
138 return nullstringptr() ;
140 FreeTSD( path ) ;
143 #if defined(HAVE__FULLPATH)
144 result = Str_makeTSD( REXX_PATH_MAX );
145 _fullpath(result->value, ".", REXX_PATH_MAX);
146 # if defined(__EMX__)
148 * Convert / to \ as the API call doesn't do this for us
150 result->len = strlen( result->value ) ;
151 for ( i=0; i < result->len; i++)
153 if ( result->value[i] == '/' )
154 result->value[i] = '\\';
156 # endif
157 #elif defined(HAVE__TRUENAME)
158 result = Str_makeTSD( _MAX_PATH ) ;
159 _truename(".", result->value);
160 #else
161 result = Str_makeTSD( 1024 ) ;
162 if (my_fullpath(result->value, ".", 1024) == -1)
163 result = nullstringptr() ;
164 #endif
165 result->len = strlen( result->value ) ;
167 return result;
170 streng *os2_beep( tsd_t *TSD, cparamboxptr parms )
172 int freq=0,dur=1;
174 checkparam( parms, 2, 1 , "BEEP" ) ;
176 if (parms && parms->value)
178 freq = atopos( TSD, parms->value, "BEEP", 1 ) ;
179 if (freq < 37 || freq > 32767)
180 exiterror( ERR_INCORRECT_CALL, 0 );
182 if (parms->next && parms->next->value)
184 dur = atopos( TSD, parms->next->value, "BEEP", 2 ) ;
185 if (dur < 1 || freq > 60000)
186 exiterror( ERR_INCORRECT_CALL, 0 );
189 #if defined(WIN32)
190 Beep( (DWORD)freq, (DWORD)dur );
191 #elif defined (__EMX__)
192 if (_osmode != DOS_MODE)
193 DosBeep( freq, dur );
194 else
196 int hdl;
198 /* stdout and/or stderr may be redirected */
199 if ((hdl = open("con", O_WRONLY)) != -1)
201 write(hdl, "\x07" /* ^G == bell */, 1);
202 close(hdl);
205 #elif defined(DOS)
206 putchar(7);
207 #elif defined(OS2)
208 DosBeep( freq, dur );
209 #elif defined(__QNX__)
210 printf("\a");
211 #elif defined(__WATCOMC__)
212 sound( freq );
213 delay( dur );
214 nosound( );
215 #elif defined(__DJGPP__)
216 sound( freq );
217 delay( dur );
218 nosound( );
219 #elif defined(__WINS__) || defined(__EPOC32__)
220 beep( freq, dur );
221 #endif
222 return nullstringptr();
225 streng *os2_filespec( tsd_t *TSD, cparamboxptr parms )
227 streng *result=NULL ;
228 streng *inpath=NULL;
229 char format = '?' ;
230 #if defined(DJGPP)
231 char fdrive[MAXDRIVE], fdir[MAXDIR], fname[MAXFILE], fext[MAXEXT];
232 #elif defined(__EMX__)
233 char fdrive[_MAX_DRIVE], fdir[_MAX_DIR], fname[_MAX_FNAME], fext[_MAX_EXT];
234 #elif defined(HAVE__SPLITPATH2)
235 char fpath[_MAX_PATH2], *fdrive=NULL, *fdir=NULL, *fname=NULL, *fext=NULL;
236 #elif defined(HAVE__SPLITPATH)
237 char fdrive[_MAX_PATH], fdir[_MAX_PATH], fname[_MAX_PATH], fext[_MAX_PATH];
238 #else
239 char fpath[REXX_PATH_MAX+5],*fdrive=NULL,*fdir=NULL,*fname=NULL,*fext=NULL;
240 #endif
242 checkparam( parms, 2, 2 , "FILESPEC" ) ;
243 format = getoptionchar( TSD, parms->value, "FILESPEC", 1, "DNP", "?" ) ;
244 inpath = Str_dupstrTSD( parms->next->value ) ;
245 #if defined(DJGPP)
246 fnsplit( inpath->value, fdrive, fdir, fname, fext );
247 #elif defined(__EMX__)
248 _splitpath( inpath->value, fdrive, fdir, fname, fext );
249 #elif defined(HAVE__SPLITPATH2)
250 _splitpath2( inpath->value, fpath, &fdrive, &fdir, &fname, &fext );
251 #elif defined(HAVE__SPLITPATH)
252 _splitpath( inpath->value, fdrive, fdir, fname, fext );
253 #else
254 my_splitpath2( inpath->value, fpath, &fdrive, &fdir, &fname, &fext );
255 #endif
256 switch( format )
258 case 'D':
259 result = Str_creTSD( fdrive );
260 break;
261 case 'N':
262 result = Str_makeTSD( strlen( fname) + strlen( fext ) );
263 Str_catstrTSD( result, fname );
264 Str_catstrTSD( result, fext );
265 break;
266 case 'P':
267 result = Str_creTSD( fdir );
268 break;
270 FreeTSD( inpath );
271 return result;