#include #include #include #include #include "../include/xcommon.h" #include "../include/xmtcl.h" #include "../include/cmddef.h" #define LISTMAX 100 #define STRMAX 256 /* * newcmd -- * Command description */ int newcmd(ClientData cdata,Tcl_Interp* interp,int objc, Tcl_Obj* CONST objv[] ) { int status; cmddef *curcmd; pardef *parlist; int logpar, intpar, listnum, dlistnum; char strpar[STRMAX]; float realpar, listary[LISTMAX]; double dblpar, dlistary[LISTMAX]; curcmd = cdata; status = 0; if ( !CParseParm(interp, objc, objv, curcmd) ) { return TCL_ERROR; } parlist = curcmd->parlist; /* * Check number of arguments here * * cwrongargs prints arguments which are unaccounted for */ if ( curcmd->cmdargc != 0 ) { cwrongargs(curcmd->cmdargs); return TCL_ERROR; } /* * This is just an example where the command takes no arguments * command usage -> command parameter=value parameter=value argument * The arguments are available as strings in the linked list, * curcmd->cmdargs. * * Tcl provides routines for getting the proper type. Take the * following example, which assigns the three arguments to a * double array. * * See the online Tcl manual for other object-based routines: * http://dev.scriptics.com/man/ * (Use command "puts $tcl_patchLevel" in ximage to determine version) * * int i; * double dbl[3]; * Tcl_Obj *tmpObj; * argdef *curarg; * curarg = curcmd->cmdargs; * i = 0; * while ( curarg ) { * tmpObj = Tcl_NewStringObj(curarg->name, -1); * Tcl_GetDoubleFromObj(xm_interp, tmpObj, &dbl[i]); * curarg = curarg->next; * i++; * } */ cgparl(parlist, "LOGPAR", &logpar, &status); cgpars(parlist, "STRPAR", strpar, STRMAX, &status); cgpari(parlist, "INTPAR", &intpar, &status); cgparr(parlist, "REALPAR", &realpar, &status); cgpard(parlist, "DBLPAR", &dblpar, &status); cgparlr(parlist, "LISTPAR", listary, &listnum, LISTMAX, &status); cgparld(parlist, "DLISTPAR", dlistary, &dlistnum, LISTMAX, &status); /* * Command body */ if ( status != 0 ) { return TCL_ERROR; } return TCL_OK; }