DSPRelated.com
Forums

Brain going numb

Started by Unknown January 29, 2013
j21341234@gmail.com wrote:
> Because I'm probably not the first person who have asked this question? >
Dunno. Since I stuck my nose in.... :) Here's a Tcl script that will at least indent the thing in a... way. Hopefully, the Tcl isn't worse than what you're trying to fix. It's a variation on a pretty printer I had laying around. This is why scripting languages are important. +--- BEGIN EXCERPT ---+ set indent 0 proc put { c } { # if we find a linefeed character then indent it. if {[string first \n $c] != -1} { # change the dot '.' in the next line to a space eventually. # Replace all linefeeds with $indent count of dots and also #the linefeed. regsub \n $c \n[string repeat "." $::indent ] c } puts -nonewline $c } # the stuff between the braces should be two lines in your editor. set s { coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) >> 16) * (int)((short)(1024 << 1))) + ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) & 0x0000FFFF) * (int)((short)(1024 << 1))) >> 16)); } array set w { {(} { put "\n(" ; incr indent } {)} { incr indent -1 ; put "\n)" } } # split the string into individual characters. foreach c [split $s "" ] { # if there is a small program for this character in w, # execute it. If there isn't then "catch {...}" will # return 1 set t [ catch { eval $w($c) } ] if {$t} { put $c } } +--- END EXCERPT ---+ This is the output: coef = ( .( ..( ...( ....( .....( ......( .......( ........( .........(inv_nrg >> 16 .........) * .........(int .........) .........( ..........(short ..........)nl .........) ........) + ........( .........( ..........(inv_nrg & 0x0000FFFF ..........) * ..........(int ..........) ..........( ...........(short ...........)nl ..........) .........) >> 16 ........) .......) ......) .....) + .....( ......(inv_nrg * .......( ........(16 == 1 ? .........(nl >> 1 .........) + .........(nl & 1 .........) : .........( ..........(nl >> 15 ..........) + 1 .........) >> 1 ........) .......) ......) .....) ....) ...) >> 16 ..) * ..(int ..) ..( ...(short ...) ...(1024 << 1 ...) ..) .) + .( ..( ...( ....( .....( ......( .......( ........( .........( ..........(inv_nrg >> 16 ..........) * ..........(int ..........) ..........( ...........(short ...........)nl ..........) .........) + .........( ..........( ...........(inv_nrg & 0x0000FFFF ...........) * ...........(int ...........) ...........( ............(short ............)nl ...........) ..........) >> 16 .........) ........) .......) ......) + ......( .......(inv_nrg * ........( .........(16 == 1 ? ..........(nl >> 1 ..........) + ..........(nl & 1 ..........) : ..........( ...........(nl >> 15 ...........) + 1 ..........) >> 1 .........) ........) .......) ......) .....) ....) & 0x0000FFFF ...) * ...(int ...) ...( ....(short ....) ....(1024 << 1 ....) ...) ..) >> 16 .) ); -- Les Cargill