/* $Id: rl.c,v 1.2 2003/04/01 06:51:11 wafer Exp $ */ #include "rl.h" #include #include #include #include #include /* this is stolen from the GNU readline manual */ /* A static variable for holding the line. */ static char *line_read = (char *)NULL; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ char *ambush_gets () { /* If the buffer has already been allocated, return the memory to the free pool. */ if (line_read) { free (line_read); line_read = (char *)NULL; } /* Get a line from the user. */ line_read = readline ("[AMBuSh] "); /* If the line has any text in it, save it on the history. */ if (line_read && *line_read) add_history (line_read); return (line_read); } int ambush_getc () { static char initialize = 1; static char *line; static char *i; if (initialize) { line = ambush_gets(); i = line; initialize = 0; } if (!line) { printf("\n"); initialize = 1; return EOF; } if (!*i) { initialize = 1; return EOF; } return *i++; }