/*
 * compile this program, and run it with the cli.ad file
 * It makes the cli widget act like a shell, by callign
 * system() on the input, and intercepting any text sent
 * to stdout or stderr.  It is very simple, however, and
 * commands with lots of output (ls -l /dev, perhaps)
 * will deadlock it.  So keep it to simple commands for
 * this demo.  Don't worry if you don't know what I mean
 * by deadlock--its is a tricky low-level Unix thing.
 * Do try out the up and down arrows for command history,
 * and try a command that produces more than a page of ouput
 * so that the pager kicks in.  Type 'quit' to exit.
 */

#include <stdio.h>
#include <Xmt/Xmt.h>    
#include <Xmt/Cli.h>
#include <Xmt/Symbols.h>
#include <Xm/ScrolledW.h>

Widget cli;
    
void input(w, tag, cmd)
XmtCliWidget w;
caddr_t tag;
char *cmd;
{
    extern void system();
    int i;

    if (strcmp(cmd, "quit") == 0) exit(0);
    else system(cmd);
}

main(argc,argv)
int argc;
char **argv;
{
    Widget toplevel;
    Widget s;
    Arg al[10];
    int ac;

    toplevel = XtInitialize("test","Test",NULL,0,(Cardinal *)&argc,argv);

    cli = XmtCreateScrolledCli(toplevel, "cli", NULL, 0);
    XtManageChild(cli);
    XtAddCallback(cli,XmNinputCallback,input,NULL);

    XtRealizeWidget(toplevel);

    XtMainLoop();
}
