# bumpup.awk is intended to process MIDL output files. # bumpup.awk is an awk script. GNU awk is available as # # \\td\sys\bin\gawk.exe # # or from http://www.cygnus.com # bumpup.awk usage: # # gawk -f bumpup.awk [options] # wildcards are NOT allowed # the default values are: # all stubs: alloc sizes changed to 110% plus 2048 bytes # all headers: cleaned up ("[public]" problem) # 32bit client stub only: salted with critical sections to serialize if critsec!=0 # to change, use the options: # gawk -f bumpup.awk perc= bump= critsec= # the new percentage must be a value > 100 (100 is the original size, no increase) # close and rename temporary output file func cl( f, outf ) { close( outf ); close ( f ); system( "del " f ); system( "ren " outf " " f ); } # initialize flags BEGIN { f = ""; e = "/dev/stderr"; outf = "/dev/stdout"; perc = 110; bump = 2048; critsec = 0; } # next line checks if we are working on a new file and creates the output file { if ( f != FILENAME ) { if ( f != "" ) { # output file still open, close it cl( f, outf ); } # create output filename outf = "tmpfile"; # outf = "/dev/stdout"; f = FILENAME; print "" > e; print "Processing " f " into " outf > e; haveclientstub = 0; havewin32 = 0; havetry = 0; havefinally = 0; mustinitcrit = 1; suppressoutput = 0; insertcritsec = 0; needbump = 1; printf "%s: Bumping up allocs to %d percent plus %d bytes\n", f, perc, bump > e; if ( critsec ) print "Win32 client stubs will be serialized" > e; print "[public] in header comments will be removed" > e; print "/* BUMPUP already performed on this file */" > outf; } } # next line looks for bumpup tag /\/\* BUMPUP already performed on this file \*\// { needbump = 0; } # next line matches "/* this ALWAYS GENERATED file contains the RPC client stubs */", sets flag haveclientstub /\/\* this ALWAYS GENERATED file contains the RPC client stubs \*\// { haveclientstub = 1; } # next line matches ... env=win32 ..., sets flag havewin32 /env=Win32/ { havewin32=1; if ( critsec && haveclientstub ) { insertcritsec = 1; } } # next line looks for MIDL_FILE_HEADING /MIDL_FILE_HEADING/ { if ( insertcritsec ) { print "#include " > outf; print "" > outf; print "static CRITICAL_SECTION SerializingCritSec;" > outf; print "static BOOL CritSecNeedInit = TRUE;" > outf; print "" > outf; insertcritsec = 0; } } # next line looks for RpcTryFinally, sets flag for open brace line /^[ \t]*RpcTryFinally[ \t]*$/ { if ( havewin32 && haveclientstub ) { havetry = 1; } } # next line checks for brace /^[ \t]*\{[ \t]*$/ { if ( critsec && havetry ) { print > outf; // emit current line if ( mustinitcrit ) { print " if ( CritSecNeedInit )" > outf; print " {" > outf; print " InitializeCriticalSection( &SerializingCritSec );" > outf; print " CritSecNeedInit = FALSE;" > outf; print " }" > outf; print "" > outf; mustinitcrit = 0; } print " EnterCriticalSection( &SerializingCritSec );" > outf; print "" > outf; havetry = 0; suppressoutput = 1; # remember we output the line } } # next line looks for RpcFinally, sets flag for close brace line /^[ \t]*RpcFinally[ \t]*$/ { if ( havewin32 && haveclientstub ) { havefinally = 1; } } # next line checks for brace /^[ \t]*\}[ \t]*$/ { if ( critsec && havefinally ) { print " LeaveCriticalSection( &SerializingCritSec );" > outf havefinally = 0; } } # next line matches ... /* [public] ... */ ..., removes all [public] /\/\* *\[public\].*\*\// { i = index( $0, "[public]" ); while ( i ) { $0 = substr( $0, 1, i - 1 ) substr( $0, i + 8 ); i = index( $0, "[public]" ); } } # next line matches 1st type of message buffer allocation /_pRpcMessage->BufferLength[ \t]*=[ \t]*_StubMsg\.BufferLength/ { if ( needbump ) { match( $0, /_StubMsg\.BufferLength/ ); $0 = substr( $0, 1, RSTART - 1 ) "_StubMsg.BufferLength * " perc " / 100 + " bump substr( $0, RSTART + 21 ); # sub( /_StubMsg\.BufferLength/, "_StubMsg.BufferLength * " perc " / 100 + " bump, $0 ); } } # next line matches 2nd type of message buffer allocation /NdrGetBuffer[(][ \t]*[(]PMIDL_STUB_MESSAGE[)][ \t]*&[ \t]*_StubMsg,[ \t]*_StubMsg\.BufferLength/ { if ( needbump ) { match( $0, /_StubMsg\.BufferLength/ ); $0 = substr( $0, 1, RSTART - 1 ) "_StubMsg.BufferLength * " perc " / 100 + " bump substr( $0, RSTART + 21 ); # sub( /_StubMsg\.BufferLength/, "_StubMsg.BufferLength * " perc " / 100 + " bump, $0 ); } } # next line matches all, outputs line resp. leftover from prev step { if ( !suppressoutput ) { print > outf; } suppressoutput = 0; } # close/rename last file END { cl( f, outf ); }