Wrapper for Oracle SQL*Plus to give you command editing and history

#include 
#include 
#include 
#include 
#include 
#include 
#include <sys/wait.h>
#include <readline/readline.h>
#include <readline/history.h>
#define SQLPLUS "sqlplus"
/******************************************************/
static volatile int g_done = 0;
static volatile int g_exit_code = 0;
static pid_t g_childpid = -1;
char *commands[] = {
/* SQL*Plus commands */
"ACCEPT",
"DEFINE",
"EDIT",
"EXIT",
"QUIT",
"GET",
"HOST",
"HELP",
"LIST",
"PROMPT",
"RUN",
"SAVE",
"SHOW",
"SPOOL",
"START",
/* SQL commands */
"ALTER",
"CLEAR",
"COMMIT",
"CREATE",
"DELETE",
"DESCRIBE",
"DROP",
"EXPLAIN",
"GRANT",
"INSERT",
"LOCK",
"RENAME",
"REVOKE",
"ROLLBACK",
"SAVEPOINT",
"SELECT",
"SET",
"TRUNCATE",
"UPDATE",
/* SQL modifiers */
"WHERE",
"FROM",
"INTO",
"VALUES",
"LIKE",
/* add your tables here */
NULL
};
/******************************************************/
void sigchld_handler(int sig)
{
int exit_code;
g_done = 1;
wait(&exit_code);
g_exit_code = exit_code;
}
void signal_forwarder(int sig)
{
kill(g_childpid, sig);
signal(sig, signal_forwarder);
}
char *command_generator(char *text, int state)
{
static int list_index, len;
char *name;
/*
* If this is a new word to complete, initialize now.  This includes
* saving the length of TEXT for efficiency, and initializing the index
* variable to 0.
*/
if(!state)
{
list_index = 0;
len = strlen(text);
}
/* Return the next name which partially matches from the command list. */
while((name=commands[list_index]) != NULL)
{

Syed