1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#ifndef lint
static char *RCSid = "$Id: unxfuncs.c,v 1.2 1999/09/26 20:25:44 mark Exp $";
#endif
/*
* The Regina Rexx Interpreter
* Copyright (C) 1992 Anders Christensen <anders@pvv.unit.no>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/****************************************************************************
* This code modified for Multithread Win32 port by Les Moull April 1999. *
****************************************************************************/
/*
* _XOPEN_SOURCE required for crypt()
*/
#ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE
#endif
#include "rexx.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_ASSERT_H
# include <assert.h>
#endif
#include <errno.h>
#ifdef VMS
# include <types.h>
#else
# include <sys/types.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
# if defined(WIN32) && defined(__IBMC__)
# include <process.h>
# include <direct.h>
typedef struct utsname
{
char *sysname ;
char *nodename ;
char *release ;
char *version ;
char *machine ;
} _utsname ;
# elif defined(__WATCOMC__) || defined(_MSC_VER) || defined(__SASC) || defined(__MINGW32__)
# include "utsname.h"
# if !defined(__SASC) && !defined(__QNX__)
# include <process.h>
# include <direct.h>
# endif
# else
# ifndef VMS
# include <sys/utsname.h>
# endif
# endif
#endif
#if defined(CRAY)
FILE *popen( char *command, char *access ) ;
#endif
streng *unx_getpath( paramboxptr dummy )
{
return nullstringptr() ;
}
streng *unx_popen( paramboxptr parms )
{
streng *string=NULL, *result=NULL ;
streng *cptr=NULL ;
int length=0, lines=0 ;
#if !defined(HAVE_WINMULTITHREADING)
extern proclevel currlevel ;
#else
# include "multi.h"
#endif
checkparam( parms, 1, 2 , "POPEN" ) ;
string = (parms->value) ;
cptr = Str_make( length=Str_len(string) + 6 ) ;
cptr = Str_cat( cptr, string ) ;
cptr = Str_catstr( cptr, ">LIFO" ) ;
if (parms->next && parms->next->value)
{
lines = lines_in_stack() ;
}
result = perform( cptr, currlevel->environment, NULL ) ;
Free_string( cptr ) ;
if (parms->next && parms->next->value)
{
streng *varname=NULL, *varstem=NULL ;
int stemlen=0 ;
char *cptr=NULL, *eptr=NULL ;
streng *tmpptr=NULL ;
varstem = parms->next->value ;
varname = Str_make( (stemlen=varstem->len) + 8 ) ;
memcpy( varname->value, varstem->value, stemlen ) ;
cptr = varname->value ;
eptr = cptr + varstem->len ;
for (; cptr<eptr; cptr++)
if (islower(*cptr))
*cptr = (char) toupper(*cptr) ;
if (*(eptr-1)!='.')
{
*((eptr++)-1) = '.' ;
stemlen++ ;
}
lines = lines_in_stack() - lines ;
*eptr = '0' ;
varname->len = stemlen+1 ;
tmpptr = int_to_streng( lines ) ;
setvalue( varname, tmpptr ) ;
for (; lines>0; lines--)
{
tmpptr = popline() ;
sprintf(eptr, "%d", lines ) ;
varname->len = strlen( varname->value ) ;
setvalue( varname, tmpptr ) ;
}
Free_string( varname ); /* bja */
}
return result ;
/* Free_string( cptr ) ;
sprintf( (result=Str_make(SMALLSTR))->value, "%d", rcode ) ;
result->len = Str_len(result) ;
return result ; */
#include "unmulti.h"
}
streng *unx_getpid( paramboxptr parms )
{
checkparam( parms, 0, 0 , "GETPID" ) ;
return int_to_streng( getpid() ) ;
}
streng *unx_eof( paramboxptr parms )
{
checkparam( parms, 0, 0 , "EOF" ) ;
/* sprintf(ptr=Malloc(SMALLSTR),"%d",eof_on_input()) ; */
return( nullstringptr() ) ;
}
streng *unx_uname( paramboxptr parms )
{
char option=' ' ;
char *cptr=NULL ;
int length=0 ;
streng *result=NULL ;
struct utsname utsbox ;
#include "multi.h"
checkparam( parms, 0, 1 , "UNAME" ) ;
if (parms->value)
option = getoptionchar( parms->value, "UNAME", 1, "ASMNRV" ) ;
else
option = 'A' ;
#if !(defined(WIN32) && defined(__IBMC__))
if (uname( &utsbox ) <0)
exiterror( ERR_SYSTEM_FAILURE, 0 ) ;
#endif
switch( option )
{
case 'A':
result = Str_make( sizeof(struct utsname)) ;
sprintf( result->value, "%s %s %s %s %s", utsbox.sysname,
utsbox.nodename, utsbox.release, utsbox.version,
utsbox.machine ) ;
result->len = strlen( result->value ) ;
assert( result->len+1 <= result->max ) ; /* +1 for "\0" */
return result ;
case 'S': cptr = utsbox.sysname ; break ;
case 'N': cptr = utsbox.nodename ; break ;
case 'R': cptr = utsbox.release ; break ;
case 'V': cptr = utsbox.version ; break ;
case 'M': cptr = utsbox.machine ; break ;
default:
assert( 0 ) ;
}
result = Str_make( length=strlen(cptr) ) ;
memcpy( result->value, cptr, length ) ;
result->len = length ;
assert( result->len+1 <= result->max ) ;
return result ;
#include "unmulti.h"
}
streng *unx_fork( paramboxptr parms )
{
int i=0 ;
checkparam( parms, 0, 0 , "FORK" ) ;
#if !defined(__WATCOMC__) && !defined(_MSC_VER) && !(defined(__IBMC__) && defined(WIN32)) && !defined(__SASC) && !defined(__MINGW32__)
i = fork() ;
#endif /* MH 10-06-96 */
return int_to_streng( i ) ;
}
char *unx_unixerror( paramboxptr parms )
{
char *result=NULL, *errtxt=NULL ;
int errnum=0 ; /* change name from errno to not conflist with global errno */
checkparam( parms, 1, 1 , "UNIXERROR" ) ;
errnum = atozpos( parms->value, "UNIXERROR", 1 ) ;
errtxt = strerror(errnum) ;
/* unixerror returns char, not streng ! bja
strcpy( result=Malloc(strlen(errtxt)+1+STRHEAD), errtxt ) ;
*/ /* bja */
strcpy( result=Malloc(strlen(errtxt)+1), errtxt ) ;
return result ;
}
streng *unx_chdir( paramboxptr parms )
{
checkparam( parms, 1, 1 , "CD" ) ;
return int_to_streng( chdir(Str_ify(parms->value)->value)!=0 ) ;
}
streng *unx_getenv( paramboxptr parms )
{
streng *retval=NULL ;
char *output=NULL ;
checkparam( parms, 1, 1 , "GETENV" ) ;
output = mygetenv( Str_ify(parms->value)->value, NULL, 0 ) ;
if ( output )
{
retval = Str_cre( output ) ;
free( output );
}
else
retval = nullstringptr() ;
return retval ;
}
streng *unx_crypt( paramboxptr parms )
{
streng *retval=NULL ;
char *output=NULL ;
int ch2,i;
#include "multi.h"
checkparam( parms, 2, 2 , "CRYPT" ) ;
for ( i = 0; i < Str_len( parms->next->value ); i++ )
{
ch2 = (int)*(parms->next->value->value+i);
if ((ch2 >= (int)'A' && ch2 <= (int)'Z')
|| (ch2 >= (int)'a' && ch2 <= (int)'z')
|| (ch2 >= (int)'0' && ch2 <= (int)'9')
|| (ch2 == (int)'.' || ch2 == (int)'/'))
{
}
else
{
char tmp[2];
tmp[0] = ch2;
tmp[1] = '\0';
exiterror( ERR_INCORRECT_CALL, 914, "CRYPT", 2, "A-Za-z0-9./", tmp ) ;
}
}
#ifdef HAVE_CRYPT
output = crypt( Str_ify(parms->value)->value, Str_ify(parms->next->value)->value ) ;
if (output)
retval = Str_cre(output) ;
else
retval = nullstringptr() ;
#else
retval = parms->value ;
#endif
return retval ;
#include "unmulti.h"
}
|