VOID WINAPI DestroyCompression( IN PVOID context ) { auto cc = (CompressionContext *)context; DestroyCmdLine(&cc->cmd_line_context); if (cc->input_buffer != NULL) { free(cc->input_buffer); cc->input_buffer = NULL; } cc->input_buffer_size = 0; if (cc->output_buffer != NULL) { free(cc->output_buffer); cc->output_buffer = NULL; } cc->output_buffer_size = 0; cc->output_used = 0; if (ProcDestroyCompression != NULL) ProcDestroyCompression(cc->iis_compression_context); cc->iis_compression_context = NULL; delete cc; }
/* * Spawn the Watcom wmake. Returns NMAKE_ERROR if wmake returned a bad * status code or if it could not be spawned, or else NMAKE_SUCCESS if * everything went smoothly. */ static int nmake( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine ) /**************************************************************/ { char ** args; int rc; int count; char * cwd; char flagstmp[32] = {0}; /*** get value for MAKEDIR field ***/ cwd = getcwd( NULL, 0 ); /*** construct MAKEFLAGS field ***/ if( cmdOpts->a ) strcat(flagstmp, "A"); if( cmdOpts->c ) strcat(flagstmp, "C"); if( cmdOpts->d ) strcat(flagstmp, "D"); if( cmdOpts->e ) strcat(flagstmp, "E"); if( cmdOpts->nologo ) strcat(flagstmp, "L"); if( cmdOpts->n ) strcat(flagstmp, "N"); if( cmdOpts->p ) strcat(flagstmp, "P"); if( cmdOpts->r ) strcat(flagstmp, "R"); if( cmdOpts->s ) strcat(flagstmp, "S"); if( cmdOpts->u ) strcat(flagstmp, "U"); if( cmdOpts->y ) strcat(flagstmp, "Y"); /*** pass builtin macros to wmake, so nmake wrapper gets called in recursive actions ***/ AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKE=\"%s\"", "nmake" ); AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEDIR=\"%s\"", cwd ); AppendFmtCmdLine( cmdLine, NMAKE_OPTS_SECTION, "MAKEFLAGS=\"%s\"", flagstmp ); /*** merge commands ***/ AppendCmdLine( cmdLine, NMAKE_PROGNAME_SECTION, MAKE ); args = MergeCmdLine( cmdLine, INVALID_MERGE_CMDLINE ); /*** Spawn the wmake ***/ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, MAKE, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", MAKE ); } else { return( NMAKE_ERROR ); } } } DestroyCmdLine( cmdLine ); return( NMAKE_SUCCESS ); }
/* * Spawn the Watcom linker. Returns LINK_NOACTION if there was no file to * link, LINK_ERROR if the linker returned a bad status code or if it could * not be spawned, or else LINK_SUCCESS if everything went smoothly. */ static int link( const OPT_STORAGE *cmdOpts, CmdLine *cmdLine ) /*************************************************************/ { char ** args; int rc; char * cmdFileName; FILE * fp; int count; CmdLine * spawnCmdLine; /*** Make the command file ***/ args = MergeCmdLine( cmdLine, INVALID_MERGE_CMDLINE ); cmdFileName = tmpnam( NULL ); if( !cmdOpts->noinvoke ) { fp = fopen( cmdFileName, "wt" ); if( fp == NULL ) { FatalError( "Cannot open temporary file '%s' -- aborting", cmdFileName ); } } for( count=0; args[count]!=NULL; count++ ) { if( !cmdOpts->noinvoke ) { fprintf( fp, "%s\n", args[count] ); } if( cmdOpts->showwopts ) { fprintf( stderr, "echo.%s%s%s\n", args[count], (count == 0 ? ">" : ">>"), cmdFileName ); } } if( !cmdOpts->noinvoke ) { fclose( fp ); } /*** Spawn the linker ***/ spawnCmdLine = InitCmdLine( LINK_NUM_SECTIONS ); AppendCmdLine( spawnCmdLine, LINK_PROGNAME_SECTION, LINKER ); AppendFmtCmdLine( spawnCmdLine, LINK_OPTS_SECTION, "@%s", cmdFileName ); args = MergeCmdLine( spawnCmdLine, INVALID_MERGE_CMDLINE ); if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, LINKER, (const char **)args ); } if( cmdOpts->showwopts ) { fprintf( stderr, "del %s\n", cmdFileName ); } if( !cmdOpts->noinvoke ) { remove( cmdFileName ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", LINKER ); } else { return( LINK_ERROR ); } } } DestroyCmdLine( spawnCmdLine ); return( LINK_SUCCESS ); }
/* * Compile any C and C++ files. Returns COMPILE_NOACTION if there was no * file to compile, COMPILE_ERROR if the compiler returned a bad status code * or if the compiler could not be spawned, or else COMPILE_SUCCESS if * everything went smoothly. */ static int compile( const OPT_STORAGE *cmdOpts, CmdLine *compCmdLine ) /********************************************************************/ { CmdLine * cloneCmdLine; char ** args = NULL; char * filename; int fileType; char * compiler = NULL; int rc; int alive = 1; int numCompiled = 0; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; char fullPath[_MAX_PATH]; int count; /*** Process all the source files, in the order they were given ***/ while( alive ) { filename = GetNextFile( &fileType, TYPE_C_FILE, TYPE_CPP_FILE, TYPE_INVALID_FILE ); if( filename == NULL ) break; /*** Prepare to spawn the compiler ***/ cloneCmdLine = CloneCmdLine( compCmdLine ); HandleFileTranslate( filename, cloneCmdLine, NULL ); switch( fileType ) { case TYPE_C_FILE: compiler = C_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); if( !cmdOpts->nowopts ) { AppendCmdLine( cloneCmdLine, CL_C_OPTS_SECTION, "-aa" ); } args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; case TYPE_CPP_FILE: compiler = CPP_COMPILER; AppendCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, compiler ); AppendCmdLine( cloneCmdLine, CL_C_FILENAMES_SECTION, filename ); args = MergeCmdLine( cloneCmdLine, CL_C_PROGNAME_SECTION, CL_C_MACROS_SECTION, CL_C_OPTS_SECTION, CL_C_CPP_OPTS_SECTION, CL_C_FILENAMES_SECTION, INVALID_MERGE_CMDLINE ); break; default: Zoinks(); } /*** Spawn the compiler ***/ _splitpath( filename, drive, dir, fname, ext ); fprintf( stderr, "%s%s\n", fname, ext ); /* print name of file we're compiling */ if( cmdOpts->showwopts ) { for( count=0; args[count]!=NULL; count++ ) { fprintf( stderr, "%s ", args[count] ); } fprintf( stderr, "\n" ); } if( !cmdOpts->noinvoke ) { rc = spawnvp( P_WAIT, compiler, (const char **)args ); if( rc != 0 ) { if( rc == -1 || rc == 255 ) { FatalError( "Unable to execute '%s'", compiler ); } else { return( COMPILE_ERROR ); } } } /*** Add the object file to the linker list, observe -Fo ***/ if( cmdOpts->Fo ) { AddFile( TYPE_OBJ_FILE, PathConvert( cmdOpts->Fo_value->data, '"' ) ); } else { _makepath( fullPath, NULL, NULL, fname, ".obj" ); AddFile( TYPE_OBJ_FILE, fullPath ); } /*** Prepare for the next iteration ***/ DestroyCmdLine( cloneCmdLine ); numCompiled++; } if( numCompiled > 0 ) { return( COMPILE_SUCCESS ); } else { return( COMPILE_NOACTION ); } }