/************************************* * eif_away * * The main routine. */ void eif_away() { /* Stuff for the readline. */ (void) rl_unbind_key(17); /* Ctrl-Q */ (void) rl_unbind_key(19); /* Ctrl-S */ /* initialize signal handling */ (void) signal(SIGQUIT, eif_sigdebug); /* Debugging */ (void) signal(SIGALRM, SIG_IGN); (void) signal(SIGPIPE, eif_pipe); (void) signal(SIGINT, eif_interrupt); /* We want ^C to abort system calls. */ /* siginterrupt(SIGINT, 1); */ prt("\nWelcome to EIF\n"); prt("Empire Interface Version " VERSION "\n\n"); /* * The problem with this is that the file is not actually executed * here. It is executed in the commandloop(). This just sets it up * for input as an exec file. */ if (cntl.st.readstartup) { cmd_exec(cntl.st.startupf, 2); } /* Only allow up to 100 commands in history */ stifle_history(100); /* Install readline event hook */ rl_event_hook = (Function *)event_hook; while (1) commandloop(); }
static void remove_line_handler() { rl_unbind_key(RETURN); rl_callback_handler_remove(); }
int main(int argc, char *argv[]) { /* We always require a file, will guess a nick if none provided.*/ if(argc < 2) { fprintf(stderr, "%s v%s - a small chat system for multiple users\n", argv[0], VERSION); fprintf(stderr, "usage: %s file [nick]\n", argv[0]); return 1; } if(argv[2] == NULL) { /* If no nick is provided, pick based on the username. */ getlogin_r(nick, MAX_NICK_SIZE); } else { /* Copy from argv and make sure its null-terminated.*/ strncpy(nick, argv[2], MAX_NICK_SIZE); nick[MAX_NICK_SIZE-1] = '\0'; } /* Open the file. Always write at the end. */ ctrl = fopen(argv[1], "a+"); if(ctrl == NULL) { fprintf(stderr, "Unable to open %s!\n", argv[1]); return 1; } /* We don't want to see past messages, as they could be loooooong.*/ fseek(ctrl, 0L, SEEK_END); /* This is now our "last read" position. */ last_read_pos = ftell(ctrl); /* Tell readline to let us know when the user hits enter. */ rl_bind_key(RETURN, handle_enter); /* Setup the fake handler for when readline thinks we're done. */ rl_callback_handler_install(PROMPT, handle_line_fake); /* Done with setup! Now let everyone know the user has arrived. */ write_status("joined"); /* Until we decide to quit, tell readline to grab characters if they're available. */ while(cont) { get_input(); usleep(10000); check_msgs(); usleep(10000); } /* We're quitting now. Say goodbye. */ write_status("left"); /* Clean up for readline now */ rl_unbind_key(RETURN); rl_callback_handler_remove(); /* Being a good citizen. Closing file handles. */ fclose(ctrl); /* Clean up screen. */ rl_set_prompt(""); rl_redisplay(); return 0; }