mildly obfuscating c
Thomas Scott Christiansen
root at rsch.wisc.edu
Wed Dec 11 22:51:38 AEST 1985
Thanks to all of you who have mailed me suggestions regarding my
C question on computed gotos. No, I have not been doing too much
FORTRAN programming. I was actually just curious what various
systems would do with that code. Most of you suggested that I
use a switch statement. My own solution (which I have actually
used) is the jump table code given below. Any routine that really
wants to exit will do a "longjump(env,1);" to return from the msgs()
function. Forgive me for declaring all of these functions ints;
the compiler I was using hated voids with a passion.
tom
===================================================================
extern int superuser;
extern jmp_buf env;
extern int show_menu();
msgs() {
int (*jump[128])();
static beenhere = 0;
load_table(jump);
if (setjmp(env) == 0)
for (;;) {
show_menu();
(*jump [get_opt()])();
}
}
load_table( j )
int (*j[])();
{
register i;
extern
leave_comment(),enter_message(),file_transfer(),kill_message(),
go_back(),newdir(),whos_on(),finger(),get_help(),quick_summary(),
reset_time(),do_shell(),delete_comment(), show_comments(),
long_summary(),say_time_on(),message_stat(),logout(),do_nothing(),
switch_expert(),long_menu(),super_expert(),get_mesg(),toggle_pause();
for (i=0;i < 128; i++)
j[i] = do_nothing;
j [ 'C' ] = leave_comment; j [ 'E' ] = enter_message;
j [ 'F' ] = file_transfer; j [ 'K' ] = kill_message;
j [ 'M' ] = go_back; j [ 'G' ] = logout;
j [ 'N' ] = newdir; j [ 'O' ] = whos_on;
j [ 'P' ] = toggle_pause; j [ 'Q' ] = quick_summary;
j [ 'S' ] = long_summary; j [ 'R' ] = get_mesg;
j [ 'T' ] = say_time_on; j [ 'U' ] = do_finger;
j [ '#' ] = message_stat; j [ 'X' ] = switch_expert;
j [ '?' ] = long_menu; j [ 'H' ] = long_menu;
if ( superuser ) { /* sysop */
j [ '6' ] = reset_time; j [ '7' ] = do_shell;
j [ '8' ] = delete_comment; j [ '9' ] = show_comments;
}
}
===================================================================
More information about the Comp.lang.c
mailing list