/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>

#include <ios.h>
#include <iostypes.h>
#include "iossh.h"
#include "edit_line.h"
#include "cmd.h"


void
iossh(u32 id)
{
    fd_set rfds;
    struct timeval tv;
    int retval;
    printf("iossh version: %s starting...\n", IOSSH_VER_STR);
    print_usage();
    setup_editline("iossh");

    while(1) {
        /* Watch stdin (fd 0) to see when it has input. */
        FD_ZERO(&rfds);
        FD_SET(0, &rfds);
        tv.tv_sec = 0;
        tv.tv_usec = 10000;
        retval = select(1, &rfds, NULL, NULL, &tv);
        if ( retval > 0 ) {
            if (NULL != (editline_inl = el_gets(el, &editline_count))) {
                int ac; const char **av; const LineInfo *li;
                li = el_line(el);
                tok_line(tok, li, &ac, &av, NULL, NULL); 
                history(hs, &ev, H_ENTER, editline_inl);
                if ( ac > 0) run_cmd(ac, av);
                tok_reset(tok);
            }
        }
        IOS_YieldThread();
    }
    delete_editline();
    IOS_DestroyThread(0, NULL);
}
