On 2/6/06, boblq <[EMAIL PROTECTED]> wrote:
> Here is a lovely little snippet
> /* Function Body */
> switch(n__) {
> case 1: goto L_reaval;
> case 2: goto L_alfval;
> case 3: goto L_txtwvl;
> }
>
> intg = TRUE_;
> goto L999;
> /* ---- #*************** */
>
> L_reaval:
> /* ---- # purpose: obtain a floating point value from user */
> intg = FALSE_;
> L999:
> prompt_(&z__[1], &text[1], &z__[lincom_1.wrkp], &z__[lincom_1.outp]);
> ia = 1;
> /* ---- # eat leading blanks: */
> while(z__[lincom_1.outp - 1 + ia] == blankw__ && ia <= lincom_1.extchr) {
> ++ia;
> /* ---- # found a number, eat it up: */
> }
> while(z__[lincom_1.outp - 1 + ia] != blankw__ && ia <= lincom_1.extchr) {
> ++ia;
> }
> pnum = ia;
>
> etc ...
>
> for hundreds of lines.
>
> Note the really neat use of the switch statement. If n__ != 1, 2, or 3 it
> falls through
> to the goto L999; which is how the flag intg=TRUE_ gets set for the code
> associated
> with L_reaval ... I suspect this code resulted from a FORTRAN computed goto.
>
> Ah that was "Back in the day ..."
>
> The horrible thing is that after you look at this stuff long enough it
> starts to make a weird sort of sense. That is when you know that
> your brain is really being messed up badly by even trying to work
> with code that looks like this. God only knows what the next code
> I write for myself with look like.
The weird sort of sense is due to the fact that this code was
generated by a program that was parsing Fortran and compiling it into
C. Perhaps the approach could be to make a decompiler to go back to
the original source. Of course the comments in the source have been
lost long ago.
I once spent some time on manual decompilation back to Fortran from
threaded-code PDP-11 machine instructions. First, of course, turning
them into pseudo-assembly language. By the time I had finished this,
I had identified a couple of coding errors in the original Fortran, by
the mental process of "why does the code do this weird thing." Like
INCHES is an integer but CENTIMETERS is not.
carl
--
carl lowenstein marine physical lab u.c. san diego
[EMAIL PROTECTED]
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list