rendered paste body#include <dos.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
struct __execblock {
unsigned short envseg;
void far * cmdtail;
void far * fcb1;
void far * fcb2;
};
int __dodexec( const char *path, struct __execblock *xb );
#pragma aux __dodexec = \
"mov ax, 0x4B00" \
"int 0x21" \
"jnc finish" \
"mov _doserrno, ax" \
"mov ax, 0xFFFF" \
"finish:" \
parm [dx] [bx] \
value [ax] \
modify [ax bx dx];
unsigned char __dogetrt( void );
#pragma aux __dogetrt = \
"mov ah, 0x4D" \
"int 0x21" \
value [al] \
modify [ax];
int _exec( const char *path, const char *cmdline )
{
char fullcmdline[ 128 ];
#if 1
char far *envp;
int i, size = 0;
unsigned j = 0, seg;
#endif
struct __execblock xb = { 0, NULL, NULL, NULL };
#if 1
for( i = 0; environ[ i ]; i++, size += 2 ) {
int j;
while( environ[ i ][ j ] ) j++;
size += j;
}
size += 2;
allocmem( size / 16 + 1, &seg );
envp = MK_FP( seg, 0 );
for( i = 0, j = 0; environ[ i ]; i++, j = 0 ) {
while( environ[ i ][ j ] ) {
*envp++ = environ[ i ][ j++ ];
}
}
_dos_write( 1, MK_FP( seg, 0 ), size, &j );
*envp = '\0';
xb.envseg = seg;
#endif
xb.cmdtail = fullcmdline;
fullcmdline[ 0 ] = strlen( cmdline );
fullcmdline[ fullcmdline[ 0 ] ] = '\r';
strcpy( &fullcmdline[ 1 ], cmdline );
if( __dodexec( path, &xb ) < 0 ) return( -1 );
return( __dogetrt() );
}