// Copyright 2007-2013, various authors // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include #include #include "halcmd.h" Tcl_Interp *target_interp = NULL; static int pending_cr = 0; static void halError(Tcl_Interp *interp, int result) { // Usually, halcmd leaves a good string message via halcmd_error() // but just in case, fall back to using the result of the halcmd api call as // a negative errno value... if(!*Tcl_GetStringResult(interp)) Tcl_SetResult(interp, strerror(-result), TCL_VOLATILE); } static int refcount = 0; static void shutdown(void) { if(refcount > 0) { refcount --; if(refcount == 0) halcmd_shutdown(); } } static int init() { int result = 0; if(refcount == 0) { result = halcmd_startup(0); atexit(shutdown); } if(result == 0) { refcount ++; } return result; } static void halExit(ClientData d) { shutdown(); } static int halCmd(ClientData cd, Tcl_Interp *interp, int argc, const char **argv) { int result; Tcl_ResetResult(interp); if(argc < 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " command ...\"", NULL); return TCL_ERROR; } if(strcmp(argv[1], "--commands") == 0) { int i; Tcl_ResetResult(interp); for(i=0; i