/* * aeLink.c * UNIX environment handling stuff for macos * * These routines make MacCVS able to accept a standard UNIX command line, * environment, output redirection, and startup directory via AppleEvents * and redirect all output to AppleEvents, a file, or the SIOUX tty window. * * Michael Ladwig --- April 1996 */ #include "mac_config.h" #ifdef AE_IO_HANDLERS #ifdef __POWERPC__ #include #else #include #endif #include #include #include #include #include #include extern char *xmalloc (size_t bytes); enum { outToAE, outToFile }; static int outputMode = outToAE; static char tempOutputFileName[256], outputFileName[256]; static int outputFile; static int noLineBuffer; AppleEvent gResponseEvent = {'null', nil}; AppleEvent gResponseReplyEvent = {'null', nil}; AEAddressDesc gResponseAddress; static char aeCmdIn = 0; static char aeLinkDone = 0; char **Args; char **EnvVars, **EnvVals; int ArgC = 1; int EnvC = 1; char * CopyInfo(Handle info) { if( info ) { char * retarg = xmalloc(GetHandleSize(info) + 1); if (retarg) { memcpy(retarg, *info, GetHandleSize(info) ); retarg[GetHandleSize(info)] = 0; } return retarg; } else return nil; } void MakeEnvironment(const AppleEvent *event) { AEDesc args; long i, argCount; if (AEGetParamDesc(event, 'ENVT', typeAEList, &args) || AECountItems(&args, &argCount) || !argCount) { EnvVars[EnvC] = nil; EnvVals[EnvC] = nil; return; } for (i = 0; i++ AE_OUTBUF_SIZE ) { SendOutBuffer( FALSE ); InitOutBuffer(); } for( tCh = buf; tCh < (char *) (buf+length); tCh++ ) { if( *tCh == '\012' ) *tCh = '\015'; outBuf[outBufLen] = *tCh; outBufLen++; } if( noLineBuffer && ( *(buf+length) == '\015') ) { SendOutBuffer( FALSE ); InitOutBuffer(); } return length; } void RemoveConsole( void ) { CleanUpArgsAndEnv(); if( outputMode == outToFile ) { close(outputFile); if( rename(tempOutputFileName, outputFileName) != 0 ) SysBeep( 100 ); return; } SendOutBuffer( TRUE ); AEDisposeDesc( &gResponseEvent ); AEDisposeDesc( &gResponseAddress ); } #endif // AE_IO_HANDLERS