// Copyright (C) 1999-2013 // Smithsonian Astrophysical Observatory, Cambridge, MA, USA // For conditions of distribution and use, see copyright notice in "copyright" #include #include #include #include #include using namespace std; #include #include "iistcl.h" extern "C" { #include "iis.h" #include "xim.h" int Tcliis_Init(Tcl_Interp* interp); int TcliisCmd(ClientData data, Tcl_Interp *interp, int argc, const char* argv[]); } IIS* iis=NULL; // Debug int IISDebug= 0; static char* dupstr(const char* str) { char* copy; if (str) { copy=new char[strlen(str)+1]; strcpy(copy,str); } else copy=NULL; return copy; } int Tcliis_Init(Tcl_Interp* interp) { if (IISDebug) cerr << "Iis_Init()" << endl; if (Tcl_InitStubs(interp, TCL_PATCH_LEVEL, 0) == NULL) return TCL_ERROR; Tcl_CreateCommand(interp, "iis", TcliisCmd, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); if (Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION) != TCL_OK) return TCL_ERROR; iis = new IIS(interp); if (iis) return TCL_OK; else return TCL_ERROR; } int TcliisCmd(ClientData data, Tcl_Interp *interp, int argc, const char* argv[]) { if (argc>=2) { if (!strncmp(argv[1], "open", 4)) return iis->open(argc, argv); else if (!strncmp(argv[1], "close", 4)) return iis->close(); else if (!strncmp(argv[1], "retcur", 4)) return iis->retcur(argc, argv); else if (!strncmp(argv[1], "debug", 4)) return iis->debug(argc, argv); else { Tcl_AppendResult(interp, "iis: unknown command: ", argv[1], NULL); return TCL_ERROR; } } else { Tcl_AppendResult(interp, "usage: iis ?open?close?retcur?", NULL); return TCL_ERROR; } } IIS::IIS(Tcl_Interp* intp) { interp = intp; { for (int i=0; i> xim.port; // *port for INET socket delete [] xim.unixaddr; xim.unixaddr = dupstr(argv[5]); // *format for unix socket path } xim_initialize(&xim, xim.def_config, xim.def_nframes, 1); xim_iisOpen(&xim); return TCL_OK; } int IIS::close() { if (IISDebug) cerr << "IIS::close()" << endl; xim_iisClose(&xim); return TCL_OK; } int IIS::retcur(int argc, const char* argv[]) { if (IISDebug) cerr << "IIS::retcur()" << endl; if (argc==6) { if (xim.cursor_chan == NULL) { Tcl_AppendResult(interp, "iis retcur: no cursor channel", NULL); return TCL_ERROR; } float xx,yy; { string x(argv[2]); istringstream str(x); str >> xx; } { string x(argv[3]); istringstream str(x); str >> yy; } int key = argv[4][0]; int frame; { string x(argv[5]); istringstream str(x); str >> frame; } xim_retCursorVal(&xim, xx, yy, frame, 0, key, (char*)""); return TCL_OK; } else { Tcl_AppendResult(interp, "iis retcur: wrong number of args", NULL); return TCL_ERROR; } } int IIS::encodewcs(int argc, const char* argv[]) { if (IISDebug) cerr << "IIS::encodewcs()" << endl; if (argc==4 || argc==5) { float sx,sy; { string x(argv[2]); istringstream str(x); str >> sx; } { string x(argv[3]); istringstream str(x); str >> sy; } int sz = 0; { string x(argv[4]); istringstream str(x); str >> sz; } char buf[SZ_LINE]; xim_encodewcs(&xim, sx, sy, sz, buf); Tcl_SetResult (interp, buf, TCL_VOLATILE); return TCL_OK; } else { Tcl_AppendResult(interp, "iis encodewcs: wrong number of args", NULL); return TCL_ERROR; } } int IIS::debug(int argc, const char* argv[]) { IISDebug = !strncmp(argv[2],"1",1); return TCL_OK; }