
/*
	A demo program on Tcl/Tk and C
		Written by Eunmi Choi
		Update by Stephen Wagner to work with Tcl 7.4
*/


#include <tcl.h>
#include <tk.h>
#include <stdlib.h>
#include <string.h>

main(int argc, char *argv[])
{
	Tk_Main(argc,argv,Tcl_AppInit);
	exit(0);
}

 
int EqCmd(ClientData clientData, Tcl_Interp *interp,
                int argc, char *argv[]) {
        if (argc != 3) {
                interp->result = "wrong # args";
                return TCL_ERROR;
        }
        if (strcmp(argv[1], argv[2]) == 0) {
                interp->result = "1";
        } else {
                interp->result = "0";
        }
        return TCL_OK;
}

int BeatCmd(ClientData clientData, Tcl_Interp *interp,
                int argc, char *argv[]) {
        if (argc != 2) {
                interp->result = "wrong # args";
                return TCL_ERROR;
        }
        strcpy ( interp->result, "Beat me ");
        strcat ( interp->result, argv[1]);
        strcat ( interp->result, " times !!");
        return TCL_OK;
}


int Tcl_AppInit ( Tcl_Interp *interp )
{
     if ( Tcl_Init ( interp ) == TCL_ERROR )
     {
          return TCL_ERROR;
     }
     if ( Tk_Init ( interp ) == TCL_ERROR )
     {
          return TCL_ERROR;
     }

     Tcl_CreateCommand ( interp, "eq", EqCmd,
                        (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );

     Tcl_CreateCommand ( interp, "beat", BeatCmd,
                        (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL );
/*     
     tcl_RcFileName = "~/.myapprc";
*/
     return TCL_OK;
}
     

